public function actionList()
 {
     $ReisSearchForm = new ReisSearchForm();
     $CostForm = new CostForm();
     if (isset($_POST['ReisSearchForm'])) {
         $ReisSearchForm->setAttributes($_POST['ReisSearchForm'], false);
         //$CostForm->setAttributes($_POST['CostForm'], false);
         $valid = $ReisSearchForm->validate();
         //$valid = $CostForm->validate() && $valid;
         if ($valid) {
             if (isset($_POST['autosearch'])) {
                 $ReisSearchForm->saveAutosearch('Reis');
             }
         }
     }
     $criteria = $ReisSearchForm->getCriteria();
     $reisData = Reis::model()->findAll($criteria);
     Yii::log("actionList after search query", "info");
     $this->render('list', ['Reis' => $reisData, 'ReisSearchForm' => $ReisSearchForm]);
 }
Example #2
0
        </section>
        <section class="col-sm-3">
            <div class="row">
                <section class="col-sm-6">
                    <?php 
echo $form->dropDownListGroup($Reis, 'cost_currency_id', ['widgetOptions' => ['data' => Reis::getCurrency()]]);
?>
                </section>
            </div>
        </section>
    </div>
    <?php 
$radiusHtml = '<div class="input-group-btn radius">
        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">%value%&nbsp;<span class="caret"></span></button>
        <ul class="dropdown-menu dropdown-menu-right">';
foreach (ReisSearchForm::getRadius() as $radius) {
    $radiusHtml .= '<li><a>' . $radius . '</a></li>';
}
$radiusHtml .= '</div></ul>';
?>
    <div class="row">
        <section class="col-sm-6">
            <h3><?php 
echo Yii::t('ReisModule.default', 'Пункт/пункты погрузки');
?>
:</h3>
            <?php 
for ($i = 1; $i <= AddressesForm::count; ++$i) {
    ?>
            <div class="row address" <?php 
    if ($i > 1 && $addreses->{'from_' . $i . '_address_lat'} == 0) {
 public function actionEdit($id)
 {
     $Autosearch = Autosearch::model()->findByPk($id);
     $criteria = unserialize($Autosearch->criteria);
     $criteria->condition = str_replace(' ', '', $criteria->condition);
     $t = explode('AND', $criteria->condition);
     $s = [];
     foreach ($t as $value) {
         if (preg_match('(OR)', $value)) {
             $r = explode('OR', $value);
             foreach ($r as $val) {
                 $s[] = $val;
             }
         } else {
             $s[] = $value;
         }
     }
     switch ($Autosearch->model) {
         case 'Cargo':
             $CargoSearchForm = new CargoSearchForm();
             foreach ($s as $key => $param) {
                 if (!preg_match('(IN)', $param)) {
                     $str = str_replace(['(', ')'], '', $param);
                     if (preg_match('(:\\w+)', $str, $m)) {
                         $m = substr($m[0], 1);
                         if ($m != 'status' && $m != 'deleted_status') {
                             if ($m == 'transport_type_id') {
                                 $CargoSearchForm->transport_type = $criteria->params[':' . $m];
                             } elseif ($m == 'prepay') {
                                 $CargoSearchForm->pre_pay = $criteria->params[':' . $m];
                             } elseif ($m == 'price_asc') {
                                 $CargoSearchForm->call_price = $criteria->params[':' . $m];
                             } else {
                                 $CargoSearchForm->{$m} = $criteria->params[':' . $m];
                             }
                         }
                     } elseif (preg_match('(\\w+=\\w+)', $str, $n)) {
                         $n = explode('=', $n[0]);
                         if ($n[0] == 'prepay') {
                             $CargoSearchForm->pre_pay = $n[1];
                         } elseif ($n[0] == 'price_asc') {
                             $CargoSearchForm->call_price = $n[1];
                         } elseif ($n[0] == 'pay_unloading') {
                             $CargoSearchForm->unload_pay = $n[1];
                         } else {
                             $CargoSearchForm->{$n}[0] = $n[1];
                         }
                     }
                 } else {
                     $ptnArr = "(\\w+IN\\((.+?)\\))";
                     preg_match_all($ptnArr, $criteria->condition, $arrs);
                 }
             }
             foreach ($criteria->with as $key => $value) {
                 if (preg_match("(\\w+IN\\((.+?)\\))", $value['condition'])) {
                     if ($key != 'cost') {
                         $el = explode('IN', $value['condition']);
                         $el = str_replace(['(', ')', ' '], '', $el[1]);
                         $el = explode(',', $el);
                         $CargoSearchForm->{$key} = $el;
                     } else {
                         $item = explode('AND', $value['condition']);
                         foreach ($item as $el) {
                             if (preg_match('(cost\\.value)', $el)) {
                                 $CargoSearchForm->set_price = 1;
                             } elseif (preg_match('(cost\\.cash)', $el) && preg_match('(0)', $el)) {
                                 $CargoSearchForm->nocash_pay = 1;
                             } elseif (preg_match('(cost\\.cash)', $el) && preg_match('(1)', $el)) {
                                 $CargoSearchForm->cash_pay = 1;
                             }
                         }
                     }
                 } elseif (preg_match("(IN_TRIANGLE)", $value['condition'])) {
                     preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                     $result = array_unique($coords[0]);
                     $str = '[{"type":"polygon","coords":[';
                     $i = 1;
                     foreach ($result as $coord) {
                         if ($i % 2 != 0) {
                             $str .= '{"lat":' . $coord . ',';
                         } else {
                             $str .= '"lng":' . $coord . '},';
                         }
                         $i++;
                     }
                     $str = substr($str, 0, -1);
                     $str .= ']}]';
                     if ($key == 'address_from') {
                         $CargoSearchForm->from_shapes = $str;
                     } elseif ($key == 'address_to') {
                         $CargoSearchForm->to_shapes = $str;
                     }
                 } elseif (preg_match("(BETWEEN)", $value['condition'])) {
                     if (preg_match("(SQRT)", $value['condition'])) {
                         if ($key == 'address_from') {
                             preg_match('(\\d{2}\\.\\d+-address_from\\.lat)', $value['condition'], $lat);
                             $lat = explode('-', $lat[0]);
                             preg_match('(\\d{2}\\.\\d+-address_from\\.long)', $value['condition'], $long);
                             $long = explode('-', $long[0]);
                             preg_match('(\\<\\d{1,2}\\.\\d+)', $value['condition'], $radius);
                             $radius = substr($radius[0], 1) * 111144;
                             $str = '[{"type":"circle","center":{"lat":' . $lat[0] . ',"lng":' . $long[0] . '},"radius":' . $radius . '}]';
                             $CargoSearchForm->from_shapes = $str;
                             if (preg_match("(address_from\\.name\\s=\\s\\'.+?\\')", $value['condition'], $name)) {
                                 $name = explode('\'', $name[0]);
                                 $CargoSearchForm->from_name = $name[1];
                             }
                             if (preg_match("(address_from\\.radius\\s=\\s\\'.+?\\')", $value['condition'], $radius)) {
                                 $radius = explode('\'', $radius[0]);
                                 $CargoSearchForm->from_radius = $radius[1];
                                 $CargoSearchForm->from_ind = $radius[1] . 'км';
                             }
                         } elseif ($key == 'address_to') {
                             preg_match('(\\d{2}\\.\\d+-address_to\\.lat)', $value['condition'], $lat);
                             $lat = explode('-', $lat[0]);
                             preg_match('(\\d{2}\\.\\d+-address_to\\.long)', $value['condition'], $long);
                             $long = explode('-', $long[0]);
                             preg_match('(\\<\\d{1,2}\\.\\d+)', $value['condition'], $radius);
                             $radius = substr($radius[0], 1) * 111144;
                             $str = '[{"type":"circle","center":{"lat":' . $lat[0] . ',"lng":' . $long[0] . '},"radius":' . $radius . '}]';
                             $CargoSearchForm->to_shapes = $str;
                             if (preg_match("(address_to\\.name\\s=\\s\\'.+?\\')", $value['condition'], $name)) {
                                 $name = explode('\'', $name[0]);
                                 $CargoSearchForm->to_name = $name[1];
                             }
                             if (preg_match("(address_to\\.radius\\s=\\s\\'.+?\\')", $value['condition'], $radius)) {
                                 $radius = explode('\'', $radius[0]);
                                 $CargoSearchForm->to_radius = $radius[1];
                                 $CargoSearchForm->to_ind = $radius[1] . 'км';
                             }
                         }
                     } else {
                         preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                         $str = '[{"type":"rectangle","NE":{"lat":' . $coords[0][1] . ',"lng":' . $coords[0][3] . '},"SW":{"lat":' . $coords[0][0] . ',"lng":' . $coords[0][2] . '}}]';
                         if ($key == 'address_from') {
                             $CargoSearchForm->from_shapes = $str;
                         } elseif ($key == 'address_to') {
                             $CargoSearchForm->to_shapes = $str;
                         }
                     }
                 }
             }
             if (isset($_POST['save'])) {
                 $CargoSearchForm->setAttributes($_POST['CargoSearchForm'], false);
                 $CargoSearchForm->updateAutosearch($Autosearch->autosearch_id, $_POST['Autosearch']['name']);
                 $this->redirect('/cabinet/autosearch');
             }
             $this->render('_cargo-form', ['CargoSearchForm' => $CargoSearchForm, 'Autosearch' => $Autosearch]);
             break;
         case 'Reis':
             $ReisSearchForm = new ReisSearchForm();
             foreach ($s as $key => $param) {
                 if (!preg_match('(IN)', $param)) {
                     $str = str_replace(['(', ')'], '', $param);
                     if (preg_match('(:\\w+)', $str, $m)) {
                         $m = substr($m[0], 1);
                         if ($m != 'status' && $m != 'deleted_status') {
                             if ($m == 'prepay') {
                                 $ReisSearchForm->pre_pay = $criteria->params[':' . $m];
                             } elseif ($m == 'price_asc') {
                                 $ReisSearchForm->call_price = $criteria->params[':' . $m];
                             } elseif ($m == 'dangerous') {
                                 $ReisSearchForm->dangerous_ADR = 1;
                             } elseif ($m == 'ADR') {
                                 $ReisSearchForm->ADR_ADR = $criteria->params[':' . $m];
                             } else {
                                 $ReisSearchForm->{$m} = $criteria->params[':' . $m];
                             }
                         }
                     } elseif (preg_match('(\\w+=\\w+)', $str, $n)) {
                         $n = explode('=', $n[0]);
                         if ($n[0] == 'prepay') {
                             $ReisSearchForm->pre_pay = $n[1];
                         } elseif ($n[0] == 'price_asc') {
                             if ($n[1] == 0) {
                                 $ReisSearchForm->price_requested[] = 2;
                             }
                             if ($n[1] == 1) {
                                 $ReisSearchForm->price_requested[] = 1;
                             }
                         } elseif ($n[0] == 'pay_unloading') {
                             $ReisSearchForm->unload_pay = $n[1];
                         } else {
                             $ReisSearchForm->{$n}[0] = $n[1];
                         }
                     }
                 } else {
                     $ptnArr = "(\\w+IN\\((.+?)\\))";
                     preg_match_all($ptnArr, $criteria->condition, $arrs);
                 }
                 foreach ($criteria->with as $key => $value) {
                     if (preg_match("(\\w+IN\\((.+?)\\))", $value['condition'])) {
                         $el = explode('IN', $value['condition']);
                         $el = str_replace(['(', ')', ' '], '', $el[1]);
                         $el = explode(',', $el);
                         if ($key == 'body') {
                             switch ($ReisSearchForm->transport_type_id) {
                                 case 19:
                                     $ReisSearchForm->body_auto = $el;
                                     break;
                                 case 20:
                                     $ReisSearchForm->body_sea = $el;
                                     break;
                                 case 21:
                                     $ReisSearchForm->body_train = $el;
                                     break;
                                 case 22:
                                     $ReisSearchForm->body_air = $el;
                                     break;
                                 case 72:
                                     $ReisSearchForm->body_river = $el;
                                     break;
                                 case 73:
                                     $ReisSearchForm->body_multi = $el;
                                     break;
                             }
                         } elseif ($key == 'load_type') {
                             $ReisSearchForm->load_type_auto = $el;
                         } elseif ($key == 'unload_type') {
                             $ReisSearchForm->unload_type_auto = $el;
                         } else {
                             $ReisSearchForm->{$key} = $el;
                         }
                     } elseif (preg_match("(IN_TRIANGLE)", $value['condition'])) {
                         preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                         $result = array_unique($coords[0]);
                         $str = '[{"type":"polygon","coords":[';
                         $i = 1;
                         foreach ($result as $coord) {
                             if ($i % 2 != 0) {
                                 $str .= '{"lat":' . $coord . ',';
                             } else {
                                 $str .= '"lng":' . $coord . '},';
                             }
                             $i++;
                         }
                         $str = substr($str, 0, -1);
                         $str .= ']}]';
                         if ($key == 'address_from') {
                             $ReisSearchForm->from_shapes = $str;
                         } elseif ($key == 'address_to') {
                             $ReisSearchForm->to_shapes = $str;
                         }
                     } elseif (preg_match("(BETWEEN)", $value['condition'])) {
                         if (preg_match("(SQRT)", $value['condition'])) {
                             if ($key == 'address_from') {
                                 preg_match('(\\d{2}\\.\\d+-address_from\\.lat)', $value['condition'], $lat);
                                 $lat = explode('-', $lat[0]);
                                 preg_match('(\\d{2}\\.\\d+-address_from\\.long)', $value['condition'], $long);
                                 $long = explode('-', $long[0]);
                                 preg_match('(\\<\\d{1,2}\\.\\d+)', $value['condition'], $radius);
                                 $radius = substr($radius[0], 1) * 111144;
                                 $str = '[{"type":"circle","center":{"lat":' . $lat[0] . ',"lng":' . $long[0] . '},"radius":' . $radius . '}]';
                                 $ReisSearchForm->from_shapes = $str;
                                 if (preg_match("(address_from\\.name\\s=\\s\\'.+?\\')", $value['condition'], $name)) {
                                     $name = explode('\'', $name[0]);
                                     $ReisSearchForm->from_name = $name[1];
                                 }
                                 if (preg_match("(address_from\\.radius\\s=\\s\\'.+?\\')", $value['condition'], $radius)) {
                                     $radius = explode('\'', $radius[0]);
                                     $ReisSearchForm->from_radius = $radius[1];
                                     $ReisSearchForm->from_ind = $radius[1] . 'км';
                                 }
                             } elseif ($key == 'address_to') {
                                 preg_match('(\\d{2}\\.\\d+-address_to\\.lat)', $value['condition'], $lat);
                                 $lat = explode('-', $lat[0]);
                                 preg_match('(\\d{2}\\.\\d+-address_to\\.long)', $value['condition'], $long);
                                 $long = explode('-', $long[0]);
                                 preg_match('(\\<\\d{1,2}\\.\\d+)', $value['condition'], $radius);
                                 $radius = substr($radius[0], 1) * 111144;
                                 $str = '[{"type":"circle","center":{"lat":' . $lat[0] . ',"lng":' . $long[0] . '},"radius":' . $radius . '}]';
                                 $ReisSearchForm->to_shapes = $str;
                                 if (preg_match("(address_to\\.name\\s=\\s\\'.+?\\')", $value['condition'], $name)) {
                                     $name = explode('\'', $name[0]);
                                     $ReisSearchForm->to_name = $name[1];
                                 }
                                 if (preg_match("(address_to\\.radius\\s=\\s\\'.+?\\')", $value['condition'], $radius)) {
                                     $radius = explode('\'', $radius[0]);
                                     $ReisSearchForm->to_radius = $radius[1];
                                     $ReisSearchForm->to_ind = $radius[1] . 'км';
                                 }
                             }
                         } else {
                             preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                             $str = '[{"type":"rectangle","NE":{"lat":' . $coords[0][1] . ',"lng":' . $coords[0][3] . '},"SW":{"lat":' . $coords[0][0] . ',"lng":' . $coords[0][2] . '}}]';
                             if ($key == 'address_from') {
                                 $ReisSearchForm->from_shapes = $str;
                             } elseif ($key == 'address_to') {
                                 $ReisSearchForm->to_shapes = $str;
                             }
                         }
                     }
                 }
             }
             if (isset($_POST['save'])) {
                 $ReisSearchForm->setAttributes($_POST['ReisSearchForm'], false);
                 $ReisSearchForm->updateAutosearch($Autosearch->autosearch_id, $_POST['Autosearch']['name']);
                 $this->redirect('/cabinet/autosearch');
             }
             $this->render('_reis-form', ['ReisSearchForm' => $ReisSearchForm, 'Autosearch' => $Autosearch]);
             break;
         case 'Sklad':
             $SkladSearchForm = new SkladSearchForm();
             foreach ($s as $key => $param) {
                 if (!preg_match('(IN)', $param)) {
                     $str = str_replace(['(', ')'], '', $param);
                     if (preg_match('(:\\w+)', $str, $m)) {
                         $m = substr($m[0], 1);
                         if ($m != 'status' && $m != 'deleted_status') {
                             if ($m == 'transport_type_id') {
                                 $SkladSearchForm->transport_type = $criteria->params[':' . $m];
                             } elseif ($m == 'prepay') {
                                 $SkladSearchForm->pre_pay = $criteria->params[':' . $m];
                             } elseif ($m == 'price_asc') {
                                 $SkladSearchForm->call_price = $criteria->params[':' . $m];
                             } else {
                                 $SkladSearchForm->{$m} = $criteria->params[':' . $m];
                             }
                         }
                     } elseif (preg_match('(\\w+=\\w+)', $str, $n)) {
                         $n = explode('=', $n[0]);
                         if ($n[0] == 'prepay') {
                             $SkladSearchForm->pre_pay = $n[1];
                         } elseif ($n[0] == 'price_asc') {
                             $SkladSearchForm->call_price = $n[1];
                         } elseif ($n[0] == 'pay_unloading') {
                             $SkladSearchForm->unload_pay = $n[1];
                         } else {
                             $SkladSearchForm->{$n}[0] = $n[1];
                         }
                     }
                 } else {
                     $ptnArr = "(\\w+IN\\((.+?)\\))";
                     preg_match_all($ptnArr, $criteria->condition, $arrs);
                 }
             }
             foreach ($criteria->with as $key => $value) {
                 if (preg_match("(\\w+\\s{1}IN[^_])", $value['condition'])) {
                     $el = explode('IN', $value['condition']);
                     $el = str_replace(['(', ')', ' '], '', $el[1]);
                     $el = explode(',', $el);
                     if ($key == 'type') {
                         $SkladSearchForm->type = $el;
                     } elseif ($key == 'load_type') {
                         $SkladSearchForm->load_type_auto = $el;
                     } elseif ($key == 'unload_type') {
                         $SkladSearchForm->unload_type_auto = $el;
                     } else {
                         $SkladSearchForm->{$key} = $el;
                     }
                 } elseif (preg_match("(IN_TRIANGLE)", $value['condition'])) {
                     preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                     $result = array_unique($coords[0]);
                     $str = '[{"type":"polygon","coords":[';
                     $i = 1;
                     foreach ($result as $coord) {
                         if ($i % 2 != 0) {
                             $str .= '{"lat":' . $coord . ',';
                         } else {
                             $str .= '"lng":' . $coord . '},';
                         }
                         $i++;
                     }
                     $str = substr($str, 0, -1);
                     $str .= ']}]';
                     $SkladSearchForm->from_shapes = $str;
                 } elseif (preg_match("(BETWEEN)", $value['condition'])) {
                     if (preg_match("(SQRT)", $value['condition'])) {
                         preg_match('(\\d{2}\\.\\d+-address\\.lat)', $value['condition'], $lat);
                         $lat = explode('-', $lat[0]);
                         preg_match('(\\d{2}\\.\\d+-address\\.long)', $value['condition'], $long);
                         $long = explode('-', $long[0]);
                         preg_match('(\\<\\d{1,2}\\.\\d+)', $value['condition'], $radius);
                         $radius = substr($radius[0], 1) * 111144;
                         $str = '[{"type":"circle","center":{"lat":' . $lat[0] . ',"lng":' . $long[0] . '},"radius":' . $radius . '}]';
                         $SkladSearchForm->from_shapes = $str;
                         if (preg_match("(address\\.name\\s=\\s\\'.+?\\')", $value['condition'], $name)) {
                             $name = explode('\'', $name[0]);
                             $SkladSearchForm->from_name = $name[1];
                         }
                         if (preg_match("(address\\.radius\\s=\\s\\'.+?\\')", $value['condition'], $radius)) {
                             $radius = explode('\'', $radius[0]);
                             $SkladSearchForm->from_radius = $radius[1];
                             $SkladSearchForm->from_ind = $radius[1] . 'км';
                         }
                     } else {
                         preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                         $str = '[{"type":"rectangle","NE":{"lat":' . $coords[0][1] . ',"lng":' . $coords[0][3] . '},"SW":{"lat":' . $coords[0][0] . ',"lng":' . $coords[0][2] . '}}]';
                         $SkladSearchForm->from_shapes = $str;
                     }
                 } elseif (preg_match("(\\>=|\\<=)", $value['condition'])) {
                     $par = explode('AND', $value['condition']);
                     foreach ($par as $p) {
                         if (preg_match('(from)', $p)) {
                             preg_match("(\\d+)", $p, $dig);
                             $SkladSearchForm->area = $dig[0];
                         } elseif (preg_match('(height)', $p)) {
                             preg_match("(\\d+)", $p, $dig);
                             $SkladSearchForm->height = $dig[0];
                         }
                     }
                 }
             }
             if (isset($_POST['save'])) {
                 $SkladSearchForm->setAttributes($_POST['SkladSearchForm'], false);
                 $SkladSearchForm->updateAutosearch($Autosearch->autosearch_id, $_POST['Autosearch']['name']);
                 $this->redirect('/cabinet/autosearch');
             }
             $this->render('_sklad-form', ['SkladSearchForm' => $SkladSearchForm, 'Autosearch' => $Autosearch]);
             break;
         case 'Custom':
             $CustomSearchForm = new CustomSearchForm();
             foreach ($s as $key => $param) {
                 if (!preg_match('(IN)', $param)) {
                     $str = str_replace(['(', ')'], '', $param);
                     if (preg_match('(:\\w+)', $str, $m)) {
                         $m = substr($m[0], 1);
                         if ($m != 'status' && $m != 'deleted_status') {
                             if ($m == 'type_id') {
                                 $CustomSearchForm->type = $criteria->params[':' . $m];
                             } elseif ($m == 'prepay') {
                                 $CustomSearchForm->pre_pay = $criteria->params[':' . $m];
                             } elseif ($m == 'price_asc') {
                                 $CustomSearchForm->call_price = $criteria->params[':' . $m];
                             } else {
                                 $CustomSearchForm->{$m} = $criteria->params[':' . $m];
                             }
                         }
                     } elseif (preg_match('(\\w+=\\w+)', $str, $n)) {
                         $n = explode('=', $n[0]);
                         if ($n[0] == 'prepay') {
                             $CustomSearchForm->pre_pay = $n[1];
                         } elseif ($n[0] == 'price_asc') {
                             $CustomSearchForm->call_price = $n[1];
                         } elseif ($n[0] == 'pay_unloading') {
                             $CustomSearchForm->unload_pay = $n[1];
                         } else {
                             $CustomSearchForm->{$n}[0] = $n[1];
                         }
                     }
                 } else {
                     $ptnArr = "(\\w+IN\\((.+?)\\))";
                     preg_match_all($ptnArr, $criteria->condition, $arrs);
                 }
             }
             if (isset($_POST['save'])) {
                 $CustomSearchForm->setAttributes($_POST['CustomSearchForm'], false);
                 $CustomSearchForm->updateAutosearch($Autosearch->autosearch_id, $_POST['Autosearch']['name']);
                 $this->redirect('/cabinet/autosearch');
             }
             $this->render('_custom-form', ['CustomSearchForm' => $CustomSearchForm, 'Autosearch' => $Autosearch]);
             break;
         case 'Insurance':
             $InsuranceSearchForm = new InsuranceSearchForm();
             foreach ($s as $key => $param) {
                 if (!preg_match('(IN)', $param)) {
                     $str = str_replace(['(', ')'], '', $param);
                     if (preg_match('(:\\w+)', $str, $m)) {
                         $m = substr($m[0], 1);
                         if ($m != 'status' && $m != 'deleted_status') {
                             if ($m == 'type_id') {
                                 $InsuranceSearchForm->type = $criteria->params[':' . $m];
                             } elseif ($m == 'prepay') {
                                 $InsuranceSearchForm->pre_pay = $criteria->params[':' . $m];
                             } elseif ($m == 'price_asc') {
                                 $InsuranceSearchForm->call_price = $criteria->params[':' . $m];
                             } else {
                                 $InsuranceSearchForm->{$m} = $criteria->params[':' . $m];
                             }
                         }
                     } elseif (preg_match('(\\w+=\\w+)', $str, $n)) {
                         $n = explode('=', $n[0]);
                         if ($n[0] == 'prepay') {
                             $InsuranceSearchForm->pre_pay = $n[1];
                         } elseif ($n[0] == 'price_asc') {
                             $InsuranceSearchForm->call_price = $n[1];
                         } elseif ($n[0] == 'pay_unloading') {
                             $InsuranceSearchForm->unload_pay = $n[1];
                         } else {
                             $InsuranceSearchForm->{$n}[0] = $n[1];
                         }
                     }
                 }
             }
             foreach ($criteria->with as $key => $value) {
                 if (preg_match("(IN_TRIANGLE)", $value['condition'])) {
                     preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                     $result = array_unique($coords[0]);
                     $str = '[{"type":"polygon","coords":[';
                     $i = 1;
                     foreach ($result as $coord) {
                         if ($i % 2 != 0) {
                             $str .= '{"lat":' . $coord . ',';
                         } else {
                             $str .= '"lng":' . $coord . '},';
                         }
                         $i++;
                     }
                     $str = substr($str, 0, -1);
                     $str .= ']}]';
                     $InsuranceSearchForm->shapes = $str;
                 } elseif (preg_match("(BETWEEN)", $value['condition'])) {
                     if (preg_match("(SQRT)", $value['condition'])) {
                         preg_match('(\\d{2}\\.\\d+-address\\.lat)', $value['condition'], $lat);
                         $lat = explode('-', $lat[0]);
                         preg_match('(\\d{2}\\.\\d+-address\\.long)', $value['condition'], $long);
                         $long = explode('-', $long[0]);
                         preg_match('(\\<\\d{1,2}\\.\\d+)', $value['condition'], $radius);
                         $radius = substr($radius[0], 1) * 111144;
                         $str = '[{"type":"circle","center":{"lat":' . $lat[0] . ',"lng":' . $long[0] . '},"radius":' . $radius . '}]';
                         $InsuranceSearchForm->shapes = $str;
                         if (preg_match("(address\\.name\\s=\\s\\'.+?\\')", $value['condition'], $name)) {
                             $name = explode('\'', $name[0]);
                             $InsuranceSearchForm->name = $name[1];
                         }
                         if (preg_match("(address\\.radius\\s=\\s\\'.+?\\')", $value['condition'], $radius)) {
                             $radius = explode('\'', $radius[0]);
                             $InsuranceSearchForm->radius = $radius[1];
                             $InsuranceSearchForm->ind = $radius[1] . 'км';
                         }
                     } else {
                         preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                         $str = '[{"type":"rectangle","NE":{"lat":' . $coords[0][1] . ',"lng":' . $coords[0][3] . '},"SW":{"lat":' . $coords[0][0] . ',"lng":' . $coords[0][2] . '}}]';
                         $InsuranceSearchForm->shapes = $str;
                     }
                 }
             }
             if (isset($_POST['save'])) {
                 $InsuranceSearchForm->setAttributes($_POST['InsuranceSearchForm'], false);
                 $InsuranceSearchForm->updateAutosearch($Autosearch->autosearch_id, $_POST['Autosearch']['name']);
                 $this->redirect('/cabinet/autosearch');
             }
             $this->render('_insurance-form', ['InsuranceSearchForm' => $InsuranceSearchForm, 'Autosearch' => $Autosearch]);
             break;
         case 'SpecialTechnique':
             $SpecialTechniqueForm = new SpecialTechniqueForm();
             $SpecialTechnique = new SpecialTechnique();
             foreach ($s as $key => $param) {
                 if (!preg_match('(IN)', $param)) {
                     $str = str_replace(['(', ')'], '', $param);
                     if (preg_match('(:\\w+)', $str, $m)) {
                         $m = substr($m[0], 1);
                         if ($m != 'status' && $m != 'deleted_status') {
                             if ($m == 'type_id') {
                                 $SpecialTechniqueForm->type = $criteria->params[':' . $m];
                             } elseif ($m == 'prepay') {
                                 $SpecialTechniqueForm->pre_pay = $criteria->params[':' . $m];
                             } elseif ($m == 'price_asc') {
                                 $SpecialTechniqueForm->call_price = $criteria->params[':' . $m];
                             } else {
                                 $SpecialTechniqueForm->{$m} = $criteria->params[':' . $m];
                             }
                         }
                     } elseif (preg_match('(\\w+=\\w+)', $str, $n)) {
                         $n = explode('=', $n[0]);
                         if ($n[0] == 'prepay') {
                             $SpecialTechniqueForm->pre_pay = $n[1];
                         } elseif ($n[0] == 'price_asc') {
                             $SpecialTechniqueForm->call_price = $n[1];
                         } elseif ($n[0] == 'pay_unloading') {
                             $SpecialTechniqueForm->unload_pay = $n[1];
                         } else {
                             $SpecialTechniqueForm->{$n}[0] = $n[1];
                         }
                     }
                 }
             }
             foreach ($criteria->with as $key => $value) {
                 if (preg_match("(IN_TRIANGLE)", $value['condition'])) {
                     preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                     $result = array_unique($coords[0]);
                     $str = '[{"type":"polygon","coords":[';
                     $i = 1;
                     foreach ($result as $coord) {
                         if ($i % 2 != 0) {
                             $str .= '{"lat":' . $coord . ',';
                         } else {
                             $str .= '"lng":' . $coord . '},';
                         }
                         $i++;
                     }
                     $str = substr($str, 0, -1);
                     $str .= ']}]';
                     $SpecialTechniqueForm->from_shapes = $str;
                 } elseif (preg_match("(BETWEEN)", $value['condition'])) {
                     if (preg_match("(SQRT)", $value['condition'])) {
                         preg_match('(\\d{2}\\.\\d+-address\\.lat)', $value['condition'], $lat);
                         $lat = explode('-', $lat[0]);
                         preg_match('(\\d{2}\\.\\d+-address\\.long)', $value['condition'], $long);
                         $long = explode('-', $long[0]);
                         preg_match('(\\<\\d{1,2}\\.\\d+)', $value['condition'], $radius);
                         $radius = substr($radius[0], 1) * 111144;
                         $str = '[{"type":"circle","center":{"lat":' . $lat[0] . ',"lng":' . $long[0] . '},"radius":' . $radius . '}]';
                         $SpecialTechniqueForm->from_shapes = $str;
                         if (preg_match("(address\\.name\\s=\\s\\'.+?\\')", $value['condition'], $name)) {
                             $name = explode('\'', $name[0]);
                             $SpecialTechniqueForm->from_name = $name[1];
                         }
                         if (preg_match("(address\\.radius\\s=\\s\\'.+?\\')", $value['condition'], $radius)) {
                             $radius = explode('\'', $radius[0]);
                             $SpecialTechniqueForm->from_radius = $radius[1];
                             $SpecialTechniqueForm->from_ind = $radius[1] . 'км';
                         }
                     } else {
                         preg_match_all('(\\d{2}\\.\\d+)', $value['condition'], $coords);
                         $str = '[{"type":"rectangle","NE":{"lat":' . $coords[0][1] . ',"lng":' . $coords[0][3] . '},"SW":{"lat":' . $coords[0][0] . ',"lng":' . $coords[0][2] . '}}]';
                         $SpecialTechniqueForm->from_shapes = $str;
                     }
                 }
             }
             if (isset($_POST['save'])) {
                 $SpecialTechniqueForm->setAttributes($_POST['SpecialTechniqueForm'], false);
                 $SpecialTechniqueForm->updateAutosearch($Autosearch->autosearch_id, $_POST['Autosearch']['name']);
                 $this->redirect('/cabinet/autosearch');
             }
             $this->render('_special-form', ['SpecialTechniqueForm' => $SpecialTechniqueForm, 'SpecialTechnique' => $SpecialTechnique, 'Autosearch' => $Autosearch]);
             break;
     }
 }
 /**
  * Запуск виджета
  */
 public function run()
 {
     switch ($this->type) {
         case 'store_add':
             $product = Product::model()->find('t.slug = "' . $this->record_id . '"');
             $criteria = new CDbCriteria();
             $product->category_id = isset($product->category_id) ? $product->category_id : 1;
             $criteria->condition = 't.category_id = ' . $product->category_id . ' AND t.status ="active"';
             $criteria->limit = 5;
             $storecalls = StoreCall::model()->findAll($criteria);
             $this->render('store_add', ['storecalls' => $storecalls]);
             break;
         case 'store_call_add':
             $storecall = StoreCall::model()->findByPk($this->record_id);
             $criteria = new CDbCriteria();
             $storecall->category_id = isset($storecall->category_id) ? $storecall->category_id : 1;
             $criteria->condition = 't.category_id =' . $storecall->category_id . ' AND t.status ="1"';
             $criteria->limit = 5;
             $products = Product::model()->findAll($criteria);
             $this->render('store_call_add', ['products' => $products]);
             break;
         case 'cargo_add':
             $cargo = Cargo::model()->with('address_from', 'address_to')->findByPk($this->record_id);
             $reissearchform = new ReisSearchForm();
             $reissearchform->from_name = $cargo->address_from[0]->name;
             $reissearchform->from_address_lat = $cargo->address_from[0]->lat;
             $reissearchform->from_address_long = $cargo->address_from[0]->long;
             $reissearchform->from_radius = $this->radius;
             $reissearchform->to_name = $cargo->address_to[0]->name;
             $reissearchform->to_address_lat = $cargo->address_to[0]->lat;
             $reissearchform->to_address_long = $cargo->address_to[0]->long;
             $reissearchform->to_radius = $this->radius;
             $reisIds = $reissearchform->relatedReis();
             if (!empty($reisIds)) {
                 $reis = Reis::model()->findAllByAttributes(array('reis_id' => $reisIds), array('order' => 'reis_id desc', 'limit' => 5));
             } else {
                 $reis = array();
             }
             $this->render('cargo_add', ['reis' => $reis]);
             break;
         case 'transport_add':
             $transport = Reis::model()->findByPk($this->record_id);
             $transport->address_from;
             $transport->address_to;
             $cargosearchform = new CargoSearchForm();
             $cargosearchform->from_name = $transport->address_from[0]->name;
             $cargosearchform->from_address_lat = $transport->address_from[0]->lat;
             $cargosearchform->from_address_long = $transport->address_from[0]->long;
             $cargosearchform->from_radius = $this->radius;
             if (!empty($transport->address_to)) {
                 $cargosearchform->to_name = $transport->address_to[0]->name;
                 $cargosearchform->to_address_lat = $transport->address_to[0]->lat;
                 $cargosearchform->to_address_long = $transport->address_to[0]->long;
                 $cargosearchform->to_radius = $this->radius;
             }
             $cargoIds = $cargosearchform->relatedCargo();
             if (!empty($cargoIds)) {
                 $cargo = Cargo::model()->findAllByAttributes(array('cargo_id' => $cargoIds), array('order' => 'cargo_id desc', 'limit' => 5));
             } else {
                 $cargo = array();
             }
             $this->render('transport_add', ['cargo' => $cargo]);
             break;
         case 'sklad_call_add':
             $skladcall = SkladCall::model()->with('address')->findByPk($this->record_id);
             if ($skladcall->address->name && $skladcall->address->lat && $skladcall->address->long) {
                 $skladsearchform = new SkladSearchForm();
                 $skladsearchform->from_name = $skladcall->address->name;
                 $skladsearchform->from_address_lat = $skladcall->address->lat;
                 $skladsearchform->from_address_long = $skladcall->address->long;
                 $skladsearchform->from_radius = $this->radius;
                 $criteria = $skladsearchform->getCriteria();
                 $criteria->limit = 5;
                 $sklads = Sklad::model()->findAll($criteria);
             } else {
                 $sklads = array();
             }
             $this->render('sklad_call', ['sklads' => $sklads]);
             break;
         case 'sklad_add':
             $sklad = Sklad::model()->with('address')->findByPk($this->record_id);
             if ($sklad->address->name && $sklad->address->lat && $sklad->address->long) {
                 $skladcallsearchform = new SkladCallSearchForm();
                 $skladcallsearchform->from_name = $sklad->address->name;
                 $skladcallsearchform->from_address_lat = $sklad->address->lat;
                 $skladcallsearchform->from_address_long = $sklad->address->long;
                 $skladcallsearchform->from_radius = $this->radius;
                 $criteria = $skladcallsearchform->getCriteria();
                 $criteria->limit = 5;
                 $skladcalls = SkladCall::model()->findAll($criteria);
             } else {
                 $skladcalls = array();
             }
             $this->render('sklad_add', ['skladcalls' => $skladcalls]);
             break;
         case 'specialtechnique_call_add':
             $specialTechniqueCall = SpecialTechnique::model()->with('address')->findByPk($this->record_id);
             if ($specialTechniqueCall->address->name && $specialTechniqueCall->address->lat && $specialTechniqueCall->address->long) {
                 $specialtechniqueform = new SpecialTechniqueForm();
                 $specialtechniqueform->from_name = $specialTechniqueCall->address->name;
                 $specialtechniqueform->from_address_lat = $specialTechniqueCall->address->lat;
                 $specialtechniqueform->from_address_long = $specialTechniqueCall->address->long;
                 $specialtechniqueform->from_radius = $this->radius;
                 $specialtechniqueform->type_request = 'offer';
                 $specialtechniqueform->category_id = $specialTechniqueCall->category_id;
                 $criteria = $specialtechniqueform->getCriteria();
                 $criteria->limit = 5;
                 $specialtechnique = SpecialTechnique::model()->findAll($criteria);
             } else {
                 $specialtechnique = array();
             }
             $this->render('specialtechnique_call_add', ['specialtechnique' => $specialtechnique]);
             break;
         case 'specialtechnique_add':
             $specialTechnique = SpecialTechnique::model()->with('address')->findByPk($this->record_id);
             if ($specialTechnique->address->name && $specialTechnique->address->lat && $specialTechnique->address->long) {
                 $specialtechniqueform = new SpecialTechniqueForm();
                 $specialtechniqueform->from_name = $specialTechnique->address->name;
                 $specialtechniqueform->from_address_lat = $specialTechnique->address->lat;
                 $specialtechniqueform->from_address_long = $specialTechnique->address->long;
                 $specialtechniqueform->from_radius = $this->radius;
                 $specialtechniqueform->type_request = 'request';
                 $specialtechniqueform->category_id = $specialTechnique->category_id;
                 $criteria = $specialtechniqueform->getCriteria();
                 $criteria->limit = 5;
                 $specialtechniquecall = SpecialTechnique::model()->findAll($criteria);
             } else {
                 $specialtechniquecall = array();
             }
             $this->render('specialtechnique_add', ['specialtechniquecall' => $specialtechniquecall]);
             break;
         default:
             break;
     }
 }