query($sql); $request = $data->request; //Типы объектов if ($request == 'get_object_types') { $type_id = json_decode($data->object_type_id); $list = AutoSearch::getCommonFields('object_type', intval($type_id)); echo json_encode($list); exit(); } //Кол-во комнат if ($request == 'get_rooms_counts') { $list = AutoSearch::getCommonFields('rooms_counts'); echo json_encode($list); exit(); } //Источники добавления объектов if ($request == 'get_object_sources') { $source_id = json_decode($data->object_source_id); $list = AutoSearch::getCommonFields('object_source', intval($source_id)); echo json_encode($list); exit(); } //Типы категорий помещений if ($request == 'get_category_types') { $list = AutoSearch::getCommonFields('category_type', $data->category_type_ids); echo json_encode($list); exit(); } // Срок аренды объектов if ($request == 'get_rent_srok') { $srok_id = json_decode($data->rent_srok_id); $list = AutoSearch::getCommonFields('rent_srok', intval($srok_id)); echo json_encode($list); exit(); } // Регионы РФ if ($request == 'get_regions') { $user_id = json_decode($data->user_id); $regions = json_decode($data->regions); $html = ''; $list = AutoSearch::getCommonFields('regions', $regions); if (empty($regions)) { // Устанавливаем регионы пользователя по-умолчанию $user = new User; $user->get($_SESSION['id']); $regions = []; if ($user->region_rf_id == 1) { $regions = [53, 80]; } else if ($user->region_rf_id == 2) { $regions = [50, 81]; } else if ($user->region_rf_id == 3) { $regions = [94, 95]; } else { $sql = "SELECT rf_regions.* FROM rf_regions AS parent JOIN rf_regions ON rf_regions.parent = parent.id WHERE parent.id = {$user->region_rf_id} ORDER BY id ASC"; if ($rez = mysql_query($sql)) { while($row = mysql_fetch_assoc($rez)) { $regions[] = $row['id']; } } } } foreach ($list as $key => $region) { $html .= ''; } echo json_encode(['list' => $list, 'regions' => $regions, 'html' => ('')]); exit(); } // Районы субъекта if ($request == 'get_rayons') { $user_id = json_decode($data->user_id); $regions = json_decode($data->regions); $rayons = json_decode($data->rayons); if (is_null($regions)) { echo "[]"; exit(); } if (in_array(80, $regions)) { $sql = "SELECT * FROM rf_regions WHERE parent = '80'"; $rez = mysql_query($sql); while($sub_regions = mysql_fetch_assoc($rez)) { $regions[] = $sub_regions['id']; } } $html = ''; if (is_array($regions)) $cond = "WHERE id IN (SELECT rayon_id FROM rf_region_rayons WHERE rf_region_id IN (".implode(',', $regions)."))"; else $cond = "WHERE id IN (SELECT rayon_id FROM rf_region_rayons WHERE rf_region_id = $regions)"; $list = AutoSearch::getCommonFields('rayons', $regions, $cond); foreach ($list as $key => $rayon) { $html .= ''; } //ищем отдельные города if (is_array($regions)) { $sqlSep = "SELECT * FROM separate_city where region_id IN (".implode(',', $regions).")"; $rezSep = mysql_query($sqlSep); } else { $sqlSep = "SELECT * FROM separate_city where region_id = " . $regions; $rezSep = mysql_query($sqlSep); } while ($city = mysql_fetch_assoc($rezSep)) { //$html .= ""; $sqlCityRayon = "SELECT * FROM separate_city_rayons where sep_city_id = " . $city['id']; $rezCityRayon = mysql_query($sqlCityRayon); while ($cityRayon = mysql_fetch_assoc($rezCityRayon)) { $sqlRayon = "SELECT * FROM rayon where id = " . $cityRayon['rayon_id']; $rezRayon = mysql_query($sqlRayon); while ($rayon = mysql_fetch_assoc($rezRayon)) { if (in_array($rayon['id'], $rayons)) { $sl = "selected"; } else { $sl = ""; } $html .= ""; } } //$html .= ""; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } // Станции метро if ($request == 'get_metro') { $user_id = json_decode($data->user_id); $regions = json_decode($data->regions); $metro_stations = json_decode($data->metro_stations); if (is_null($regions)) { echo "[]"; exit(); } $html = ''; if (is_array($regions)) { foreach($regions as $key => $region) { if ($region == 1500) // Нижний Новгород $regions[$key] = 1148; else if ($region == 1504) // Новосибирск $regions[$key] = 1152; else if ($region == 1520) // Самара $regions[$key] = 1168; else if ($region == 1526) // Екатеринбург $regions[$key] = 1174; else if ($region == 1432) // Казань $regions[$key] = 1080; else if ($region == 53 || $region == 1) // Москва и Московская область $regions[$key] = 80; else if ($region == 50 || $region == 2) // Санкт-Петербург и Ленинградская обл $regions[$key] = 81; } $cond = "WHERE region_rf_id IN (" . implode(',', $regions) . ")"; } else { $cond = "WHERE region_rf_id = " . $regions; } $list = AutoSearch::getCommonFields('metro_stations', $metro_stations, $cond); foreach ($list as $key => $station) { $html .= ''; } echo json_encode(['list' => $list, 'count' => count($list), 'html' => ('')]); exit(); } // Типы оформления сделки /*if ($request == 'get_deal_type') { $user_id = json_decode($data->user_id); $order_type = intval(json_decode($data->order_type)); $html = ''; $list = AutoSearch::getCommonFields('order_type', $order_type); foreach ($list as $key => $deal) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); }*/ // Типы домов if ($request == 'get_house_type') { $user_id = json_decode($data->user_id); $house_type = intval(json_decode($data->house_type)); $html = ''; $list = AutoSearch::getCommonFields('house_type', $house_type); foreach ($list as $houseType) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } // Типы материала стен if ($request == 'get_house_material') { $user_id = json_decode($data->user_id); $house_material = intval(json_decode($data->house_material)); $html = ''; $list = AutoSearch::getCommonFields('house_material', $house_material); foreach ($list as $houseMaterial) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } // Годы постройки if ($request == 'get_build_year') { $user_id = json_decode($data->user_id); $build_year = json_decode($data->build_year); $html = ''; $list = AutoSearch::getCommonFields('build_year', $build_year); foreach ($list as $buildYear) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } // if ($request == 'get_legal_address') { $user_id = json_decode($data->user_id); $legal_address = json_decode($data->legal_address); $html = ''; $list = AutoSearch::getCommonFields('legal_address', $legal_address); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_is_occupied') { $user_id = json_decode($data->user_id); $is_occupied= json_decode($data->is_occupied); $html = ''; $list = AutoSearch::getCommonFields('is_occupied', $is_occupied); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_layout_id') { $user_id = json_decode($data->user_id); $layout_id = json_decode($data->layout_id); $html = ''; $list = AutoSearch::getCommonFields('layout_id', $layout_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_wet_spots') { $user_id = json_decode($data->user_id); $wet_spots = json_decode($data->wet_spots); $html = ''; $list = AutoSearch::getCommonFields('wet_spots', $wet_spots); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commer_condition') { $user_id = json_decode($data->user_id); $commer_condition = json_decode($data->commer_condition); $html = ''; $list = AutoSearch::getCommonFields('commer_condition', $commer_condition); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_is_furniture') { $user_id = json_decode($data->user_id); $is_furniture = json_decode($data->is_furniture); $html = ''; $list = AutoSearch::getCommonFields('is_furniture', $is_furniture); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commer_access') { $user_id = json_decode($data->user_id); $commer_access = json_decode($data->commer_access); $html = ''; $list = AutoSearch::getCommonFields('commer_access', $commer_access); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_parking_types') { $user_id = json_decode($data->user_id); $parking_types = json_decode($data->parking_types); $html = ''; $list = AutoSearch::getCommonFields('parking_types', $parking_types, "WHERE vid = 0"); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_parking_id') { $user_id = json_decode($data->user_id); $parking_id = json_decode($data->parking_id); $html = ''; $list = AutoSearch::getCommonFields('parking_id', $parking_id, "WHERE vid = 1"); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_vat_type_id') { $user_id = json_decode($data->user_id); $vat_type_id = json_decode($data->vat_type_id); $html = ''; $list = AutoSearch::getCommonFields('vat_type_id', $vat_type_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_floor_material_id') { $user_id = json_decode($data->user_id); $floor_material_id = json_decode($data->floor_material_id); $list = AutoSearch::getCommonFields('floor_material_id', $floor_material_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_portal_id') { $user_id = json_decode($data->user_id); $commerc_portal_id = json_decode($data->commerc_portal_id); $list = AutoSearch::getCommonFields('commerc_portal_id', $commerc_portal_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_purpose') { $user_id = json_decode($data->user_id); $commerc_purpose = json_decode($data->commerc_purpose); $list = AutoSearch::getCommonFields('commerc_purpose', $commerc_purpose); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_land_category_id') { $user_id = json_decode($data->user_id); $commerc_land_category_id = json_decode($data->commerc_land_category_id); $list = AutoSearch::getCommonFields('commerc_land_category_id', $commerc_land_category_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_permitted_use_id') { $user_id = json_decode($data->user_id); $commerc_permitted_use_id = json_decode($data->commerc_permitted_use_id); $list = AutoSearch::getCommonFields('commerc_permitted_use_id', $commerc_permitted_use_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_electricity_id') { $user_id = json_decode($data->user_id); $commerc_electricity_id = json_decode($data->commerc_electricity_id); $html = ''; $list = AutoSearch::getCommonFields('commerc_electricity_id', $commerc_electricity_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_gas_id') { $user_id = json_decode($data->user_id); $commerc_gas_id = json_decode($data->commerc_gas_id); $html = ''; $list = AutoSearch::getCommonFields('commerc_gas_id', $commerc_gas_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_water_id') { $user_id = json_decode($data->user_id); $commerc_water_id = json_decode($data->commerc_water_id); $html = ''; $list = AutoSearch::getCommonFields('commerc_water_id', $commerc_water_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_sewage_id') { $user_id = json_decode($data->user_id); $commerc_sewage_id = json_decode($data->commerc_sewage_id); $html = ''; $list = AutoSearch::getCommonFields('commerc_sewage_id', $commerc_sewage_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_driveways') { $user_id = json_decode($data->user_id); $commerc_driveways = json_decode($data->commerc_driveways); $html = ''; $list = AutoSearch::getCommonFields('commerc_driveways', $commerc_driveways); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_building_type_id') { $user_id = json_decode($data->user_id); $commerc_building_type_id = json_decode($data->commerc_building_type_id); $list = AutoSearch::getCommonFields('commerc_building_type_id', $commerc_building_type_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_building_class_id') { $user_id = json_decode($data->user_id); $commerc_building_class_id = json_decode($data->commerc_building_class_id); $list = AutoSearch::getCommonFields('commerc_building_class_id', $commerc_building_class_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_houseline_type_id') { $user_id = json_decode($data->user_id); $commerc_houseline_type_id = json_decode($data->commerc_houseline_type_id); $html = ''; $list = AutoSearch::getCommonFields('commerc_houseline_type_id', $commerc_houseline_type_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_building_category_id') { $user_id = json_decode($data->user_id); $commerc_building_category_id = json_decode($data->commerc_building_category_id); $html = ''; $list = AutoSearch::getCommonFields('commerc_building_category_id', $commerc_building_category_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_opened_id') { $user_id = json_decode($data->user_id); $commerc_opened_id = json_decode($data->commerc_opened_id); $list = AutoSearch::getCommonFields('commerc_opened_id', $commerc_opened_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_building_ventilation') { $user_id = json_decode($data->user_id); $commerc_building_ventilation = json_decode($data->commerc_building_ventilation); $html = ''; $list = AutoSearch::getCommonFields('commerc_building_ventilation', $commerc_building_ventilation); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_building_conditioning') { $user_id = json_decode($data->user_id); $commerc_building_conditioning = json_decode($data->commerc_building_conditioning); $html = ''; $list = AutoSearch::getCommonFields('commerc_building_conditioning', $commerc_building_conditioning); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_building_heating') { $user_id = json_decode($data->user_id); $commerc_building_heating = json_decode($data->commerc_building_heating); $html = ''; $list = AutoSearch::getCommonFields('commerc_building_heating', $commerc_building_heating); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_building_fire') { $user_id = json_decode($data->user_id); $commerc_building_fire = json_decode($data->commerc_building_fire); $html = ''; $list = AutoSearch::getCommonFields('commerc_building_fire', $commerc_building_fire); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_garage_type_id') { $user_id = json_decode($data->user_id); $garage_type_id = json_decode($data->garage_type_id); $html = ''; $list = AutoSearch::getCommonFields('garage_type_id', $garage_type_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_garage_vid_id') { $user_id = json_decode($data->user_id); $garage_vid_id = json_decode($data->garage_vid_id); $html = ''; $list = AutoSearch::getCommonFields('garage_vid_id', $garage_vid_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_boks_vid_id') { $user_id = json_decode($data->user_id); $boks_vid_id = json_decode($data->boks_vid_id); $html = ''; $list = AutoSearch::getCommonFields('boks_vid_id', $boks_vid_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_status_id') { $user_id = json_decode($data->user_id); $commerc_status_id = json_decode($data->commerc_status_id); $html = ''; $list = AutoSearch::getCommonFields('commerc_status_id', $commerc_status_id); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_specifications') { $user_id = json_decode($data->user_id); $commerc_specifications = json_decode($data->commerc_specifications); $list = AutoSearch::getCommonFields('commerc_specifications', $commerc_specifications); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_infrastructure') { $user_id = json_decode($data->user_id); $commerc_infrastructure = json_decode($data->commerc_infrastructure); $list = AutoSearch::getCommonFields('commerc_infrastructure', $commerc_infrastructure, "WHERE id < 27"); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_infrastructure1') { $user_id = json_decode($data->user_id); $commerc_infrastructure1 = json_decode($data->commerc_infrastructure1); $list = AutoSearch::getCommonFields('commerc_infrastructure', $commerc_infrastructure1, "WHERE vid=1"); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } if ($request == 'get_commerc_infrastructure2') { $user_id = json_decode($data->user_id); $commerc_infrastructure2 = json_decode($data->commerc_infrastructure2); $list = AutoSearch::getCommonFields('commerc_infrastructure', $commerc_infrastructure2, "WHERE vid1=1"); foreach ($list as $item) { $html .= ''; } echo json_encode(['list' => $list, 'html' => ('')]); exit(); } // Поиск и получение ранее сохраненного фильтра if ($request == 'get_filter') { $user_id = json_decode($data->user_id); $req_id = json_decode($data->req_id); $filter_id = json_decode($data->filter_id); $autosearch = new AutoSearch(); if (!is_null($filter_id)) echo json_encode($autosearch->getFilter(intval($filter_id), intval($user_id), false)); else echo json_encode($autosearch->getFilterByReq(intval($req_id), intval($user_id), false)); exit(); } // if ($request == 'save_field_input') { /*if($_SESSION['id'] == 5427){ error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); }*/ $user_id = json_decode($data->user_id); $id = json_decode($data->filter_id); $param_id = $data->param_id; $fields = $data->fields; $result = null; $autosearch = new AutoSearch(); if ($result = $autosearch->saveFilterFields(intval($id), intval($user_id), (array)$fields)) { $filter = $autosearch->getFilter(intval($id), intval($user_id), false); $_SESSION['asfilter_'.$id] = $filter; } if (!is_null($filter)) { $new_fields = $autosearch->getFilterInfo($filter, true, false); $new_value = $new_fields[$param_id]['value']; } else { $new_value = $filter[$param_id]; } echo json_encode([ 'result' => $result, 'filter_id' => $id, 'user_id' => $user_id, 'param_id' => $param_id, 'fields' => $fields, 'value' => $new_value ]); exit(); } // if ($request == 'get_field_input') { $user_id = $data->user_id; $id = $data->filter_id; $field_id = $data->field_id; $autosearch = new AutoSearch(); $filter = $autosearch->getFilter(intval($id), intval($user_id)); echo json_encode($autosearch->buildFilterInput($filter, $field_id)); exit(); } if ($request == 'get_filter_by_req') { $user_id = $data->user_id; $req_ids = $data->req_ids; if (empty($user_id) || empty($req_ids)) { echo json_encode([ 'success' => false, 'result' => null ]); exit(); } if (is_array($req_ids)) { $req_ids = array_map('intval', $req_ids); } $results = []; $autosearch = new AutoSearch(); $user = new \User; $user_company_id = $user->getAgencyIdForUser($user_id); $sql_users = "SELECT id FROM users WHERE company_id = '$user_company_id'"; $query = mysql_query($sql_users); $agents_ids = []; while ($row = mysql_fetch_assoc($query)) { $agents_ids[] = (int)$row['id']; } $all_filters = $autosearch->getFiltersByReqs($req_ids, $agents_ids, false); foreach ($req_ids as $req_id) { $filter = isset($all_filters[$req_id]) ? $all_filters[$req_id] : null; if ($filter && isset($filter['id'])) { $filter_id = intval($filter['id']); $result['autosearch_id'] = $filter_id; $result['autosearch'] = [ 'active' => intval($filter['is_active']), 'count' => $filter['count'], 'is_search' => $filter['is_search'], 'is_reverse' => $filter['is_reverse'], 'total' => $filter['total'], 'error' => $filter['error'], '_raw' => $filter ]; $info = ''; $comment = ''; $info_ar = $autosearch->getFilterInfo($filter, true, true); foreach ($info_ar as $key => $field) { if (isset($field['label']) && isset($field['value'])) { if ($key === "comment") { $comment = '' . $field['label'] . ': ' . $field['value']; } else { $info .= ' ' . $field['label'] . ': ' . $field['value'] . ';'; } } $result['autosearch']['filter'][$key] = [ 'id' => $field['id'], 'label' => $field['label'], 'value' => $field['value'] ]; } if (!empty($info)) { $result['autosearch_info'] = rtrim(rtrim($info, ';'), '
'); $result['autosearch_comment'] = trim($comment) . 'ID фильтра: ' . $filter_id; $result['autosearch_comment'] .= ', Автопоиск: ' . ((intval($filter['is_active'])) ? 'включен' : 'отключен'); $result['autosearch_comment'] .= ', Уведомления: ' . ((intval($filter['telegram_notify'])) ? 'включены' : 'отключены'); } } else { $result = null; } if (!is_null($result)) { $results[(string)$req_id] = $result; } } echo json_encode([ 'success' => true, 'count' => count($results), 'results' => $results, '_req_ids' => $req_ids ]); exit(); } // if ($request == 'delete_field_input') { $user_id = intval($data->user_id); $id = intval($data->filter_id); $field_id = $data->field_id; $autosearch = new AutoSearch(); echo json_encode([ 'field_id' => $field_id, 'result' => $autosearch->unsetFilterField($id, $user_id, $field_id) ]); exit(); } // Сохранение/редактирование параметров автопоиска if ($request == 'add_edit') { $user_id = json_decode($data->user_id); $is_new_req = json_decode($data->is_new_req); $params = (array)$data->params; $error = false; $success = false; $autosearch = new AutoSearch(); $result = $autosearch->addEditFilter($params['id'], $params, !(isset($params['req_id']))); if ($result['success']) { $filter = $autosearch->getFilter(intval($result['id']), $user_id); $filter_info = $autosearch->getFilterInfo($filter, true); echo json_encode(['success' => $result['success'], 'id' => $result['id'], 'filter' => $filter_info, 'error' => $result['error'], 'sql' => $result['sql']]); } else { echo json_encode(['error' => $result['error'], 'sql' => $result['sql']]); } exit(); } // if ($request == 'set_req_filter') { $user_id = intval($data->user_id); $req_id = intval($data->req_id); $filter_id = intval($data->filter_id); $autosearch = new AutoSearch(); if ($result = $autosearch->setReqToFilter($req_id, $filter_id, $user_id)) { echo json_encode(['success' => true, 'req_id' => $result['req_id'], 'filter_id' => $result['filter_id']]); } else { echo json_encode(['error' => $result]); } exit(); } $get = clearInputData($_GET); if ($get['request'] == 'get_filter_info') { $user_id = $_SESSION['id']; $req_id = $get['req_id']; $filter_id = $get['filter_id']; $autosearch = new AutoSearch(); if (!is_null($filter_id)) { $filter = $autosearch->getFilter(intval($filter_id), intval($user_id), false); } else { $filter = $autosearch->getFilterByReq(intval($req_id), intval($user_id), false); } echo json_encode($autosearch->getFilterInfo($filter)); exit(); } // if ($request == 'set_object_viewed') { $user_id = json_decode($data->user_id); $filter_id = json_decode($data->filter_id); $object_id = json_decode($data->object_id); if (intval($user_id) !== intval($_SESSION['id'])) exit(); if (!is_null($filter_id) && !is_null($object_id)) { $autosearch = new AutoSearch(); if ($results = $autosearch->addObjectToViewed($filter_id, $object_id)) { echo json_encode($results); } else { echo json_encode([ 'error' => $results['error'] ]); } } else { echo json_encode([ 'error' => "Не указан ИД фильтра или объекта" ]); } exit(); } // if ($request == 'add_object_to_favour') { $user_id = json_decode($data->user_id); $filter_id = json_decode($data->filter_id); $object_id = json_decode($data->object_id); if (intval($user_id) !== intval($_SESSION['id'])) exit(); if (!is_null($filter_id) && !is_null($object_id)) { $autosearch = new AutoSearch(); if ($results = $autosearch->addObjectToFavour($filter_id, $object_id, true, true)) { echo json_encode($results); } else { echo json_encode([ 'error' => $results['error'] ]); } } else { echo json_encode([ 'error' => "Не указан ИД фильтра или объекта" ]); } exit(); } // if ($request == 'add_object_to_ignored') { $user_id = json_decode($data->user_id); $filter_id = json_decode($data->filter_id); $object_id = json_decode($data->object_id); if (intval($user_id) !== intval($_SESSION['id'])) exit(); if (!is_null($filter_id) && !is_null($object_id)) { $autosearch = new AutoSearch(); if ($results = $autosearch->addObjectToIgnored($filter_id, $object_id)) { echo json_encode($results); } else { echo json_encode([ 'error' => $results['error'] ]); } } else { echo json_encode([ 'error' => "Не указан ИД фильтра или объекта" ]); } exit(); } // if ($request == 'restart_search') { /*error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1);*/ $user_id = json_decode($data->user_id); $filter_id = json_decode($data->filter_id); if (intval($user_id) !== intval($_SESSION['id'])) exit(); if (!is_null($filter_id)) { $autosearch = new AutoSearch(); //$results = $autosearch->clearAllResults($filter_id); if ($results = $autosearch->search($filter_id, 0, 100)) { echo json_encode([ 'success' => true, 'total' => $results['total'], 'error' => $results['error'], 'time' => $results['time'], 'info' => $results['info'] ]); } else { echo json_encode([ 'error' => $results['error'], 'total' => $results['total'], 'time' => $results['time'], 'info' => $results['info'] ]); } } else { echo json_encode([ 'error' => "Не указан ИД фильтра" ]); } exit(); } // if ($request == 'clear_results') { $user_id = json_decode($data->user_id); $filter_id = json_decode($data->filter_id); if (intval($user_id) !== intval($_SESSION['id'])) exit(); if (!is_null($filter_id)) { $autosearch = new AutoSearch(); if ($results = $autosearch->clearAllResults($filter_id, true)) { echo json_encode([ 'success' => true ]); } else { echo json_encode([ 'error' => $results['error'] ]); } } else { echo json_encode([ 'error' => "Не указан ИД фильтра" ]); } exit(); } // if ($request == 'get_results') { //error_reporting(E_ALL | E_STRICT); //ini_set('display_errors', 1); $user_id = intval($data->user_id); $filter_id = intval($data->filter_id); $section = $data->section; $sort_order = $data->order; $offset = intval($data->offset); if ($user_id !== intval($_SESSION['id'])) exit(); $autosearch = new AutoSearch(null); if ($filter = $autosearch->getFilter($filter_id, $user_id)) { if ($results = $autosearch->getResults($filter['id'], $section, $offset, (array)$sort_order, 10, true, true)) { echo json_encode([ 'success' => true, 'section' => $section, 'filter_id' => intval($filter['id']), 'req_id' => intval($filter['req_id']), 'objects' => $results['results'], 'count' => intval($results['count']), 'total' => intval($results['total']), 'perpage' => intval($results['perpage']), 'error' => $results['error'], 'sort_order' => $results['sort_order'], 'sql' => $results['sql'], 'viewed_id' => $results['viewed'], //'ignored_id' => $results['ignored'], 'favoured_id' => $results['favoured'], 'sended_id' => $results['sended'], 'filter' => $filter ]); } else { echo json_encode([ 'error' => $results['error'], 'section' => $section, 'filter_id' => $filter['id'], 'req_id' => $filter['req_id'], 'sort_order' => $results['sort_order'], 'sql' => $results['sql'], 'filter' => $filter, ]); } } exit(); } // if ($request == 'get_reverse_counter') { $object_id = json_decode($data->object_id); $autosearch = new AutoSearch(); $results = $autosearch->reverseSearch($object_id, 0, 100, false, true, true, true); $output = [ 'time' => $results['time'], 'total' => intval($results['total']), 'has_items' => $results['has_items'], ]; if (in_array($_SESSION['id'], [4, 6635, 5427])) { $output['object'] = $results['object']; $output['sql'] = preg_replace('/\r|\n|\t/', '', $results['sql']); $output['sql_count'] = preg_replace('/\r|\n|\t/', '', $results['sql_count']); } echo json_encode($output); exit(); } // if ($request == 'get_requisitions') { //error_reporting(E_ALL | E_STRICT); //ini_set('display_errors', 1); $perpage = 10; $object_id = json_decode($data->object_id); $offset = json_decode($data->offset); $autosearch = new AutoSearch(); $results = $autosearch->reverseSearch($object_id, $offset, $perpage, false, false, true, true); $user = new \User; $user->get($_SESSION['id']); $user->checkPermissions($_SESSION['id'], false); $requisitions = []; if ($results['total'] > 0) { $req = new Requisitions($pdo); $req->set_user($user); $results['requisitions'] = array_unique($results['requisitions']); foreach ($results['requisitions'] as $req_id) { if (!empty($req_id)) { if ($requisition = $req->get_req_id($req_id)) { unset($requisition['is_kanban']); unset($requisition['e']); $requisitions = array_merge($requisition, $requisitions); } } } $requisitions = array_reverse($requisitions); } echo json_encode([ 'count' => intval($results['total']), 'offset' => intval($results['offset']), 'perpage' => intval($perpage), 'requisitions' => $requisitions, 'error' => $results['error'], //'_results' => $results, ]); exit(); } // if ($request == 'get_filter_info') { //error_reporting(E_ALL | E_STRICT); //ini_set('display_errors', 1); $filter_id = $data->filter_id; $user_id = $data->user_id; $autosearch = new AutoSearch(); if ($filter = $autosearch->getFilter(intval($filter_id), intval($user_id), false)) { $info = ''; $comment = ''; $info_ar = $autosearch->getFilterInfo($filter, true, true); foreach ($info_ar as $key => $filter) { if (isset($filter['label']) && isset($filter['value'])) { if ($key === "comment") $comment = '' . $filter['label'] . ': ' . $filter['value']; else $info .= ' ' . $filter['label'] . ': ' . $filter['value'] . ';'; } } if (!empty($filter['geo'])) { $geo = (array)json_decode($filter['geo'], true); $geo = array_filter(array_map(function($item) { return !empty($item); }, $geo)); $info .= ' Гео: ' . declOfNum(count($geo), ['%d уточнение', '%d уточнения', '%d уточнений']). ';'; } echo json_encode([ 'html' => rtrim(trim($info), ';') ."
". trim($comment) ."
". 'ID фильтра: ' . $filter_id ]); } else { echo json_encode([ 'html' => '' ]); } exit(); } ?>