Ejemplo n.º 1
0
 public function actionList()
 {
     $InsuranceSearchForm = new InsuranceSearchForm();
     if (isset($_POST['InsuranceSearchForm'])) {
         $InsuranceSearchForm->setAttributes($_POST['InsuranceSearchForm'], false);
         $InsuranceSearchForm->validate();
         if (isset($_POST['autosearch'])) {
             $InsuranceSearchForm->saveAutosearch('Insurance');
         }
     }
     $criteria = $InsuranceSearchForm->getCriteria();
     $criteria->order = 'insurance_id DESC';
     $this->render('list', ['Insurance' => Insurance::model()->findAll($criteria), 'InsuranceSearchForm' => $InsuranceSearchForm]);
 }
 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;
     }
 }