'; if ($_SESSION['id'] && isset($_GET['objectId'])) { $view = array(); $favour = array(); $sql = "SELECT * FROM views WHERE id_user = $_SESSION[id]"; $rez = mysql_query($sql); while($f=mysql_fetch_assoc($rez)) $view[] = $f['id_obj']; $sql = "SELECT * FROM favor WHERE id_user = $_SESSION[id]"; $rez = mysql_query($sql); while($f=mysql_fetch_assoc($rez)) $favour[] = $f['id_obj']; $agencyId = User::getAgencyIdForUser($_SESSION['id']); $usersIds = User::getAllAgencyUsers($agencyId); $usersIds[] = $_SESSION['id']; $usersIds = array_unique($usersIds); $notes_bd_usl = "created_by IN (" . implode(",", $usersIds) . ")"; $cabinetObjCompetitors = []; $numOnPage = 10; $db = new MysqlPdo(hstsph, null, null, null, true, '9306'); $get = clearInputData($_GET); $objectId = trim($_GET['objectId']); $pageNumber = trim($_GET['page']); if (!$pageNumber) { $pageNumber = 1; } $sql = "SELECT * FROM objects WHERE id = $objectId"; $res = mysql_query($sql); $obj = mysql_fetch_assoc($res); $forCabinet = isset($get['cabinet']) && $get['cabinet'] == 1; //если у нас форма для кабинета, то тащим все, что было выбрано раньше для отметка как выбранного if ($forCabinet) { $cabinetObjCompetitors[] = ObjectCabinet::getCabinetObjCompetitorsAsObjectIds($mdb, $objectId); } $parentRegion = '2'; $parentRegionName = ''; $sqlRegion = "SELECT parent, name FROM rf_regions WHERE id=$obj[id_rf_region] or parent=$obj[id_rf_region]"; $resRegion = mysql_query($sqlRegion); if (mysql_num_rows($resRegion) > 0) { while($row = mysql_fetch_assoc($resRegion)){ if ($row['parent']) { $parentRegion = $row['parent']; } } } $sqlParentRegion = "SELECT name FROM rf_regions WHERE id=$parentRegion"; $resParentRegion = mysql_query($sqlParentRegion); if (mysql_num_rows($resParentRegion)) { $parentReg = mysql_fetch_assoc($resParentRegion); $parentRegionName = $parentReg['name']; } //ищем исключения для этого объекта и этого пользователя $sqlExcl = "SELECT excluded_object_id FROM objects_analytic_exclude WHERE object_id = $objectId and user_id = $_SESSION[id]"; $resExcl = mysql_query($sqlExcl); $exclIds = array(); $exclSql = ""; $komnSql = ""; $commTypeSql = ""; $studioSql = ""; if (mysql_num_rows($resExcl) > 0) { while($row = mysql_fetch_assoc($resExcl)){ if ($row['excluded_object_id']) { $exclIds[] = $row['excluded_object_id']; } } } if (count($exclIds)) { $exclSql = "AND id NOT IN (" . implode(",", $exclIds) . ")"; } if ($obj['komnat'] && $obj['type'] != 3) { $komnSql = "AND komnat=$obj[komnat]"; } if ($obj['type'] == 4) { $commTypeSql = "AND type_category=$obj[type_category]"; } if ($obj['studio_flag'] > 0) { $studioSql .= "AND studio_flag = '1'"; } if (!preg_match('~\d~', $obj['adres']) && $obj['dom']) { $obj['adres'] = $obj['adres'] . " " . $obj['dom']; } $adres_search = getAdresSearch($obj['adres']); $adres_mas = explode(" ", $adres_search); $ausl_mas = array(); for ($a = 0; $a < count($adres_mas); $a++) { if ($adres_mas[$a]) { $ausl_mas[] = trim($adres_mas[$a]); } } $foundIds = array(); $latitude = null; $longitude = null; $objectLatitude = null; $objectLongitude = null; $hasLocRecord = false; $sqlLocationInfo = "SELECT * FROM object_location WHERE object_id=$objectId"; $rezLocationInfo = mysql_query($sqlLocationInfo); if (mysql_num_rows($rezLocationInfo) > 0) { $objLocationInfo = mysql_fetch_assoc($rezLocationInfo); $objectLatitude = $objLocationInfo['latitude']; $objectLongitude = $objLocationInfo['longitude']; $hasLocRecord = true; } //берем координаты по адресу if (!preg_match('~\d~', $obj['adres']) && $obj['dom']) { $obj['adres'] = $obj['adres'] . " " . $obj['dom']; if ($obj['korpus']) { $obj['adres'] = $obj['adres'] . " " . $obj['korpus']; } if (!$obj['litera']) { $obj['adres'] = $obj['adres'] . " " . $obj['litera']; } } $yaParams['geocode'] = $obj['adres']; $yaParams['format'] = 'json'; $yaParams['results'] = "1"; $yaParams['apikey'] = "898fc684-cdf6-4af8-af57-15e2781d68d1"; $yaUrlParams = http_build_query($yaParams); $url = "https://geocode-maps.yandex.ru/1.x/?" . $yaUrlParams; $json = file_get_contents($url); $json = json_decode($json, true); if ($json['response'] && $json['response']['GeoObjectCollection'] && $json['response']['GeoObjectCollection']['featureMember'] && $json['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']) { $geoObj = $json['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']; if ($geoObj['Point'] && $geoObj['Point']['pos']) { $coordsArrayStr = $geoObj['Point']['pos']; $coordsArray = explode(" ", $coordsArrayStr); $latitude = $coordsArray[1]; $longitude = $coordsArray[0]; if (!$hasLocRecord) { $sql = "INSERT INTO object_location (object_id, address, latitude, longitude) VALUES ('$obj[id]', '$obj[adres]', '$latitude', '$longitude')"; mysql_query($sql); } } } $coordinatesSql = ""; if ($latitude != null && $longitude != null) { $coordinatesSql = "MATCH ('@(id_rf_region,parent) $parentRegion') AND latitude = " . $latitude ." AND longitude = " . $longitude; $sqlCountCoords = "SELECT id, IF(use_in_advert = 1 OR ads_source > 0, 1, 0) AS is_advert_enabled_or_rscan FROM objects, objects_delta WHERE archive = 0 AND fbn_id = 0 AND black = 0 AND moder = 0 AND is_advert_enabled_or_rscan = 1 AND id <> $obj[id] AND operation_type = $obj[operation_type] AND type=$obj[type] $commTypeSql $komnSql $exclSql $studioSql AND $coordinatesSql LIMIT 0, 10000 OPTION max_matches=1000000" ; if ($_SESSION['id'] == 93) { echo $sqlCountCoords; } $rezCoordsSearch = $db->query($sqlCountCoords, true); if ($db->num_rows($rezCoordsSearch) > 0) { while ($objCoords = $db->fetch_assoc($rezCoordsSearch)) { $foundIds[] = $objCoords['id']; } } } if ($objectLatitude != null && $objectLongitude != null) { $coordinatesSql = "MATCH ('@(id_rf_region,parent) $parentRegion') AND latitude = " . $objectLatitude ." AND longitude = " . $objectLongitude; $sqlCountCoords = "SELECT id, IF(use_in_advert = 1 OR ads_source > 0, 1, 0) AS is_advert_enabled_or_rscan FROM objects, objects_delta WHERE archive = 0 AND fbn_id = 0 AND black = 0 AND moder = 0 AND is_advert_enabled_or_rscan = 1 AND id <> $obj[id] AND operation_type = $obj[operation_type] AND type=$obj[type] $commTypeSql $komnSql $exclSql $studioSql AND $coordinatesSql LIMIT 0, 10000 OPTION max_matches=1000000" ; if ($_SESSION['id'] == 93) { echo $sqlCountCoords; } $rezCoordsSearch = $db->query($sqlCountCoords, true); if ($db->num_rows($rezCoordsSearch) > 0) { while ($objCoords = $db->fetch_assoc($rezCoordsSearch)) { $foundIds[] = $objCoords['id']; } } } $strSph = ''; for ($a = 0; $a < count($ausl_mas); $a++) { if (strlen($strSph) > 1) { $strSph = $strSph . ' '; } $strSph = $strSph . '@adres ' . trim(str_replace("/","-",$ausl_mas[$a])); } $adres_usl = "MATCH ('@(id_rf_region,parent) $parentRegion $strSph')"; $sqlCount = "SELECT id, IF(use_in_advert = 1 OR ads_source > 0, 1, 0) AS is_advert_enabled_or_rscan FROM objects, objects_delta WHERE archive = 0 AND fbn_id = 0 AND black = 0 AND moder = 0 AND is_advert_enabled_or_rscan = 1 AND id <> $obj[id] AND operation_type = $obj[operation_type] AND type=$obj[type] $commTypeSql $komnSql $exclSql $studioSql AND $adres_usl LIMIT 0, 10000 OPTION max_matches=1000000" ; if ($_SESSION['id'] == 93) { echo $sqlCount; } $rezAddressSearch = $db->query($sqlCount, true); if ($db->num_rows($rezAddressSearch) > 0) { while ($objAddr = $db->fetch_assoc($rezAddressSearch)) { if (!in_array($objAddr['id'], $foundIds)) { $foundIds[] = $objAddr['id']; } } } $vsego = count($foundIds); if ($vsego > 0) { $from = ($pageNumber - 1) * $numOnPage; $all_pages = ceil($vsego / $numOnPage); $sqlSearch = "SELECT *, IF(use_in_advert = 1 OR ads_source > 0, 1, 0) AS is_advert_enabled_or_rscan FROM objects, objects_delta WHERE id in (" . implode(",", $foundIds) . ") AND is_advert_enabled_or_rscan = 1 ORDER BY date_add DESC LIMIT $from, $numOnPage OPTION max_matches=1000000" ; /*if ($_SESSION['id'] == 93) { echo $sqlSearch; }*/ $rezSearch = $db->query($sqlSearch); if ($db->num_rows($rezSearch) > 0) { $user = new User; $user->get($_SESSION['id']); if (!isset($user->agencyId)) { $user->agencyId = $_SESSION['id']; $user->agencyName = $user->agency_name; $user->fio = trim($user->last_name . ' ' . $user->first_name . ' ' . $user->middle_name); } while ($obj = $db->fetch_assoc($rezSearch)) { $photo = ""; $sqlPhotoInfo = "SELECT oop.sort_order, p.photo FROM objects_object_photo oop, object_photo p WHERE p.id = oop.object_photo_id AND oop.object_id = $obj[id] ORDER BY oop.sort_order"; $rezPhotoInfo = mysql_query($sqlPhotoInfo); if (mysql_num_rows($rezPhotoInfo) > 0) { while ($photoInfo = mysql_fetch_assoc($rezPhotoInfo)) { $photo = $photoInfo; $obj['photo' . $photoInfo['sort_order']] = $photoInfo['photo']; } } $sql_count_notes = "SELECT COUNT(*) FROM object_notes WHERE object_id = $obj[id] AND $notes_bd_usl"; if ($_SESSION['id'] == 10246) { echo '
' . $sql_count_notes . '
'; } $obj['notes'] = mysql_result(mysql_query($sql_count_notes), 0); include($_SERVER['DOCUMENT_ROOT'] . "/templates/object_analytics_template.php"); } echo '
'; } else { echo "Объекты не найдены."; } } else { echo "Объекты не найдены."; } } function pagingCurHouse($page, $all_pages, $objId) { if ($page == 1) { echo "
  • 1
  • "; } else { $prev = $page - 1; echo "
  • «
  • "; echo "
  • 1
  • "; } if ($all_pages > 8) { if ($page > 4) { $ot = $page - 3; echo "
  • ...
  • "; } else { $ot = 2; } if ($page < $all_pages - 4) { $do = $page + 3; } else { $do = $all_pages; } } else { $ot = 2; $do = $all_pages; } for ($i = $ot; $i < $do; $i++) { if ($i == $page) $cl = "active"; else $cl = ""; echo "
  • $i
  • "; } if ($all_pages > 8 and $page < $all_pages - 4) { echo "
  • ...
  • "; } if ($page == $all_pages) echo "
  • $all_pages
  • "; else { echo "
  • $all_pages
  • "; $nxt = $page + 1; echo "
  • »
  • "; } } ?>