/DEV/LIB/search.class.php
PHP | 5517 lines | 3264 code | 1114 blank | 1139 comment | 862 complexity | 33034f3386305fec2f04e17c28635424 MD5 | raw file
- <?php
- /*
- 20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- 20091202-1 (3 sections) : not using T_LOCALITY_LCT_FR table when select town name
- 20091202-2 (4 sections) : not using SELECT when use of DATEDIFF
- 20100216-1 (2 sections) : not using T_LOCALITY_LCT_FR table when select town name for AGC
- */
- // search class
- // 97 -> lgm_id
- // 98 -> lgc_id
- // 99 -> lgn_id
- class search_object {
- public $table_name;
- public $table_prfx;
- public $table_locality_name;
- public $table_locality_lang;
- public $has_premium;
- public $has_exclusive;
- public $is_agency_search;
- public $query;
- public $query_agency;
- public $query_premium;
- public $query_count;
- public $select;
- public $select_count;
- public $from;
- public $where;
- public $global_where;
- public $order;
- public $search_request;
- public $search_count;
- public $search_count_premium;
- public $search_results;
- public $search_results_agency;
- public $search_results_premium;
- public $search_results_exclusive;
- public $search_hierarchy_agency;
- public $search_parameters;
- public $loc_keys;
- public $link_trad = true;
- public $PerimProximit = 0;
- public $FirstLocalityProximity = "";
- public $list_lock_proximite;
- public $Proximity_level;
- public $Proximity_lockey;
- public $lat1;
- public $long1;
- public $loc_nameGrp;
- public $isAdvancedSearch = false;
- // vrai si tle type de transaction a été setté dans la requête sql
- // ex. xxx_type_transaction = 1 => pas de besoin de faire ensuite
- // un xxx_type_transaction <> 4 pour exclure les viagers
- public $isTtypeTransactionAlreadySetInSql = false;
- /* Parametres */
- /*
- Ce parametre est d�fini dans /LIB/common.function.php -> $cumul_ad_for_agency_search
- 1= cumul sur Ventes et Locations par d�fault
- 2= Ventes
- 3= Locations
- */
- public $cumul_ad_for_agency_search = 1;
- // *** constructor ***
- function setPerimProximit($val) {
- $this->PerimProximit = $val;
- }
- public function isAdvancedSearch() {
- return $this->isAdvancedSearch;
- }
- // ***
- function getCoord($lockey) {
- global $_global;
- $loctab = explode("_", $lockey);
- $res = array();
- $sql = "SELECT lct_lat,lct_long, lct_name_" . $_global["lang"] . " FROM T_LOCALITY_LCT_" . strtoupper($_global["site"]);
- $this->Proximity_level = $loctab[1];
- $this->Proximity_lockey = $loctab[0];
- switch ($loctab[1]) {
- case 1:
- $sql .=" WHERE lct_id=" . $loctab[0];
- break;
- case 2:
- $sql .=" WHERE lct_id=" . $loctab[0];
- break;
- case 98:
- $sql .=" WHERE lgc_id=" . $loctab[0];
- break;
- case 99:
- $sql .=" WHERE lgn_id=" . $loctab[0];
- break;
- default:
- echo "ERREUR DANS LA CREATION DE LA REQUETE :) (" . $loctab[1] . ")";
- return $res;
- break;
- }
- if ($_global["debug"] == 3 || $_global["debug"] == 1) {
- echo "getCoord()<br />";
- echo $sql . "<br />";
- echo "<hr />";
- }
- $res = pdoquery($sql);
- $this->lat1 = $this->long1 = 0;
- if ($res) {
- $this->lat1 = $res[0]['lct_lat'];
- $this->long1 = $res[0]['lct_long'];
- }
- $this->getLocalityProximit($res[0]['lct_lat'], $res[0]['lct_long']);
- }
- // ***
- function getLocalityProximit($lat, $long) {
- global $_global;
- $this->list_lock_proximite = "";
- //if ($this->Proximity_level <> 1)
- //{
- $sql = "SELECT lct_id FROM (SELECT lct_id,
- (6366*acos(cos(radians($this->lat1))*cos(radians(lct_lat))*cos(radians(lct_long)-radians($this->long1))+sin(radians($this->lat1))*sin(radians(lct_lat))))
- as Proximite from T_LOCALITY_LCT_FR ) AS GLO where Proximite<='$this->PerimProximit'";
- //LOC_LOOKUP_FR
- if ($this->Proximity_lockey == "100") {
- $sql .= " AND lct_id <> 1";
- }
- $sql .= " order by Proximite";
- if ($_global["debug"] == 1 || $_global["debug"] == 3) {
- echo "getLocalityProximit()<br />";
- echo $sql . "<br />";
- echo "<hr />";
- }
- echo $sql . "<br />";
- $res = pdoquery($sql);
- /*
- }
- else
- {
- $res[0]['lct_id'] = $this->Proximity_lockey;
- }
- */
- if ($res) {
- for ($cnt = 0; $cnt < count($res); $cnt++) {
- $this->list_lock_proximite .= $res[$cnt]['lct_id'];
- if ($cnt < count($res) - 1) {
- $this->list_lock_proximite .= ", ";
- }
- }
- } else {
- $this->list_lock_proximite = 100;
- }
- }
- /* Retrouve le nombre d'annonce par ville par univers pour une agence */
- function get_NbAds_Agency($id_agency = "") {
- GLOBAL $_global;
- // sets from
- $this->setFrom();
- $sql = "SELECT count(*) as count, " . $this->table_prfx . "_default_town, " . $this->table_prfx . "_locality_2 ";
- $sql .= ", l.lct_name_fr ";
- $sql .= "FROM " . $this->from . " , T_LOCALITY_LCT_FR l ";
- $sql .= "WHERE id_agence='$id_agency' AND (" . $this->table_prfx . "_ad_status >= 0) ";
- $sql .= "AND t." . $this->table_prfx . "_locality_2 = l.lct_id ";
- $sql .= "AND (" . $this->table_prfx . "_country = 'FR') ";
- if ($_global['univers'] == 1) {
- $sql .= "AND (" . $this->table_prfx . "_price > 10000) ";
- }
- $sql .= "AND (" . $this->table_prfx . "_property_type_id IN (1, 2, 3, 4, 5, 6, 7, 8)) ";
- //$sql .= "AND ".$this->table_prfx."_default_town <> '' "; /// Attention il arrive qu'il soit vide
- //$sql .= "group by ".$this->table_prfx."_default_town ";
- $sql .= "group by lct_name_fr ";
- $sql .= "order by lct_name_fr, count ";
- //$new_sql = "CALL GET_NB_ADS_PER_TOWN_PER_AGENCY(?)";
- //$sql = "CALL GET_NB_ADS_PER_TOWN_PER_AGENCY('2337D4CF-6368-5E2B-F5FB-D2513A7169B1');";
- //$new_sql = "CALL GET_NB_ADS_PER_TOWN_PER_AGENCY('$id_agency')";
- if ($_global["debug"] == 3) {
- echo "get_NbAds_Agency()<br />";
- echo $sql . "<br />";
- echo "<hr />";
- }
- $res = pdoquery($sql);
- //$res = pdoprocstock($new_sql, $id_agency);
- return $res;
- }
- /* Retrouve les 3 annonces pour une agence avec priorité sur les exclusivité */
- function get_Exclusive_Ads_Agency($id_agency = "") {
- GLOBAL $_global;
- // sets from
- $this->setFrom();
- $sql = "SELECT * ";
- $sql .= "FROM " . $this->from . " ";
- $sql .= "WHERE id_agence='$id_agency' AND (" . $this->table_prfx . "_ad_status >= 0) ";
- //$sql .= "AND (".$this->table_prfx."_country = 'FR') ";
- if ($_global['univers'] == 1) {
- $sql .= "AND (" . $this->table_prfx . "_price > 10000) ";
- }
- $sql .= "AND (" . $this->table_prfx . "_property_type_id IN (1, 2)) ";
- $sql .= "AND " . $this->table_prfx . "_default_town <> '' ";
- $sql .= "AND " . $this->table_prfx . "_photo <> '' ";
- $sql .= "ORDER BY " . $this->table_prfx . "_is_exclusive desc, " . $this->table_prfx . "_update_date ";
- $sql .= " LIMIT 0, 3";
- if ($_global["debug"] == 3) {
- echo "get_Exclusive_Ads_Agency()<br />";
- echo $sql . "<br />";
- echo "<hr />";
- }
- $res = pdoquery($sql);
- return $res;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ***
- function search_object($table_name = TABLE_S_NAME, $table_prefix = TABLE_S_PRFX) {
- $this->setTable($table_name, $table_prefix);
- /* Attention peut générer des requête sur la HomePAge */
- //$this->relief();
- }
- // *** set main properties ***
- function setTable($table_name, $table_prefix) {
- global $_global;
- // sets table data
- $this->table_name = $table_name;
- $this->table_prfx = $table_prefix;
- // sets table locality
- $this->table_locality_name = "T_LOCALITY_LCT_FR";
- $this->table_locality_lang = ""; //"_".$_global["lang"]; // forcage pour FR pas de suffixe
- //$this->table_locality_name = "T_LOCALITY_LCT_FR";
- /*
- if (checkLockFile("memorytable_maintenance") == true)
- {
- $this->table_locality_name = "T_LOCALITY_LCT_FR";
- }
- else
- {
- $this->table_locality_name = (memoryTableCheck() == true ? "LOC_LOOKUP" : "T_LOCALITY_LCT_FR");
- }
- */
- }
- function isGrpAgency($liste) {
- $this->isGrpAgency = true;
- $this->list_agency = $liste;
- }
- function get_Where() {
- $sWhere = implode(" AND ", $this->global_where);
- return $sWhere;
- }
- function getAdsCount($request, $advanced = false) {
- global $_global;
- // sets request
- $this->search_request = $this->setRequest($request);
- $where = array();
- // Ajouter le pays
- $this->setWhere($where, "country");
- // Filtrer le status de l'annonce
- $this->setWhere($where, "ad_status");
- // Ajouter la localité
- if ($this->PerimProximit > 0) {
- $this->setWhere($where, "perimproximit");
- } else {
- $this->setWhere($where, "locality");
- }
- $this->setWhere($where, "price");
- $this->setWhere($where, "area");
- $this->setWhere($where, "ck_nb_rooms");
- $this->setWhere($where, "ck_nb_bedrooms");
- if ($_global['univers'] == 1 || $_global['univers'] == 2 AND $advanced) {
- // Champs de recherche avancée par encore en base !
- $this->setWhere($where, "surf"); // Surface du terrain
- $this->setWhere($where, "dpe"); // Recherche par dpe
- $this->setWhere($where, "fresh"); // Recherche par fraicheur d'annonces
- $this->setWhere($where, "ck_advanced");
- }
- // vacances
- if ($_global["univers"] == 13) {
- $this->setWhere($where, "nb_bedrooms");
- $this->setWhere($where, "nb_people");
- $this->setWhere($where, "type_transaction", 3);
- }
- // location
- elseif ($_global["univers"] == 2) {
- $this->setWhere($where, "type_transaction", 2);
- }
- // colocation
- elseif ($_global["univers"] == 8) {
- $this->setWhere($where, "type_transaction", 8);
- }
- // doit être placé après l'appel à ceci :
- // $this->setWhere($where, "type_transaction", ...);
- $this->setWhere($where, "ck_property_type");
- if ($_REQUEST['an_visuel'] == 1)
- $this->setWhere($where, "photo");
- $this->where = $where;
- //////////////////////////////////////////////////////////
- $this->setFrom(false);
- // builds main query
- $this->query = 'SELECT COUNT(*) AS NUM FROM ' . $this->from;
- $this->query .= ' WHERE ' . implode(' AND ', $this->where);
- if ($_global["debug"] == 3) {
- echo 'getAdsCount()<br />';
- echo $this->query . "<br /><hr />";
- }
- $this->result = pdoquery($this->query);
- return $this->result[0]['NUM'];
- }
- /**
- * Function getAgencyAds : uniquement pour l'univers 9 (liste annonces agence vente + location)
- *
- * @global type $_global
- * @param type $request
- * @param type $offset
- */
- function getAgencyAds($request, $offset) {
- global $_global;
- //*** TABLE TO USE !***//
- $sSAL_table_name = '';
- $sRNT_table_name = '';
- $sSql = " SELECT ttu_sal_fr, ttu_rnt_fr FROM TP_TABLE_TO_USE_TTU";
- $r = pdoquery($sSql);
- //var_dump($r);die;
- if (sizeof($r) > 0) {
- $sSAL_table_name = $r[0]["ttu_sal_fr"];
- $sRNT_table_name = $r[0]["ttu_rnt_fr"];
- }
- // Si on trouve une des 2 tables en TM on force à T ! Sinon ça plante !
- if (('TM' == substr($sSAL_table_name, 0, 2) && 'TM' != substr($sRNT_table_name, 0, 2)) ||
- ('TM' == substr($sRNT_table_name, 0, 2) && 'TM' != substr($sSAL_table_name, 0, 2))
- ) {
- $sSAL_table_name = 'T_SALESAD_SAL';
- $sRNT_table_name = 'T_RENTAD_RNT';
- }
- $this->search_parameters["univers"] = $_global["univers"]; // = 9
- $this->is_agency_search = true;
- $this->search_request = $this->setRequest($request);
- $this->setDate();
- $this->search_parameters["offset"] = "" . $offset . "";
- $date_in_where = '';
- if ($_REQUEST['seven_days'] == 1) {
- (!empty($date)) ? "DATEDIFF('$date', sal_first_online_date) AS days_old, " : '' .
- $date_in_where = "DATEDIFF('" . date("Y-m-d", time() - 7 * 24 * 60 * 60) . "', sal_first_online_date) AS days_old, ";
- }
- $this->query = '';
- //pdoquery('(select id_annonce AS id from T_SALESAD_SAL) union all (select id_annonce AS id from T_RENTAD_RNT) ORDER BY id limit 1');die;
- //*** CONSTRUCTION REQUETE VENTE ***//
- $sReq_SAL = ''; //SQL_CALC_FOUND_ROWS
- $sReq_SAL .= "(SELECT id_annonce,
- SAL.sal_ai_id AS ai_id,
- sal_reference AS reference,
- sal_num_mandat AS num_mandat,
- sal_is_premium AS is_premium,
- sal_is_logo_agency AS is_logo_agency,
- sal_is_directory_agency AS is_directory_agency,
- sal_is_website_agency AS is_website_agency,
- sal_type_transaction AS type_transaction,
- id_bien,
- '' AS prg_title,
- '' AS id_bien_programme,
- sal_property_type_id AS property_type_id,
- sal_property_type_id_orig AS property_type_id_orig,
- sal_property_type AS property_type,
- sal_area AS area,
- sal_price AS price,
- sal_nb_rooms AS nb_rooms,
- sal_default_text AS default_text,
- sal_is_exclusive AS is_excusive,
- sal_currency AS currency,
- sal_photo AS photo,
- sal_nb_photo AS nb_photo,
- sal_logicode AS logicode,
- sal_logicode_old AS logicode_old,
- sal_post_code AS post_code,
- sal_default_town AS default_town,
- sal_default_town_2 AS default_town_2,
- sal_default_town_1 AS default_town_1,
- sal_default_town_0 AS default_town_0,
- sal_district_id1 AS district_id1,
- sal_district_name1 AS district_name1,
- sal_district_id2 AS district_id2,
- sal_district_name2 AS district_name2,
- sal_district_id3 AS district_id3,
- sal_district_name3 AS district_name3,
- lgm_id, lgc_id, lgn_id,
- sal_country AS country,
- sal_default_proximity AS default_proximity,
- sal_default_sector AS default_sector,
- sal_locality_0 AS locality_0,
- sal_locality_1 AS locality_1,
- sal_locality_2 AS locality_2,
- sal_first_online_date AS first_online_date,
- sal_update_date AS update_date, "
- . $date_in_where .
- "sal_pub_code AS pub_code,
- id_agence,
- id_presto,
- sal_name_agency AS name_agency,
- sal_post_code_agency AS post_code_agency,
- sal_town_agency AS town_agency,
- sal_tel_agency AS tel_agency,
- sal_fax_agency AS fax_agency,
- sal_email_agency AS email_agency,
- sal_site_agency AS site_agency,
- sal_rcs_agency AS rcs_agency,
- sal_logo_agency AS logo_agency,
- sal_franchising_agency AS franchising_agency,
- sal_is_powersite_agency AS is_powersite_agency,
- sal_powersite_url_agency AS powersite_url_agency,
- sal_powersite_calltracking_agency AS powersite_calltracking_agency,
- sal_advanced_set AS advanced_set,
- sal_personnalisable AS personnalisable,
- 1 as univ
- FROM " . $sSAL_table_name . " SAL
- WHERE id_agence = '" . $this->search_request["id_agence"] . "'
- AND sal_ad_status >= 0
- AND sal_country = '" . strtoupper($_global["site"]) . "') ";
- //*** CONSTRUCTION REQUETE LOCATION ***//
- $sReq_RNT = ''; //SQL_CALC_FOUND_ROWS
- $sReq_RNT .= "(SELECT id_annonce,
- RNT.rnt_ai_id AS ai_id,
- rnt_reference AS reference,
- rnt_num_mandat AS num_mandat,
- rnt_is_premium AS is_premium,
- rnt_is_logo_agency AS is_logo_agency,
- rnt_is_directory_agency AS is_directory_agency,
- rnt_is_website_agency AS is_website_agency,
- rnt_type_transaction AS type_transaction,
- id_bien,
- '' AS prg_title,
- '' AS id_bien_programme,
- rnt_property_type_id AS property_type_id,
- rnt_property_type_id_orig AS property_type_id_orig,
- rnt_property_type AS property_type,
- rnt_area AS area,
- rnt_price AS price,
- rnt_nb_rooms AS nb_rooms,
- rnt_default_text AS default_text,
- rnt_is_exclusive AS is_excusive,
- rnt_currency AS currency,
- rnt_photo AS photo,
- rnt_nb_photo AS nb_photo,
- rnt_logicode AS logicode,
- rnt_logicode_old AS logicode_old,
- rnt_post_code AS post_code,
- rnt_default_town AS default_town,
- rnt_default_town_2 AS default_town_2,
- rnt_default_town_1 AS default_town_1,
- rnt_default_town_0 AS default_town_0,
- rnt_district_id1 AS district_id1,
- rnt_district_name1 AS district_name1,
- rnt_district_id2 AS district_id2,
- rnt_district_name2 AS district_name2,
- rnt_district_id3 AS district_id3,
- rnt_district_name3 AS district_name3,
- lgm_id, lgc_id, lgn_id,
- rnt_country AS country,
- rnt_default_proximity AS default_proximity,
- rnt_default_sector AS default_sector,
- rnt_locality_0 AS locality_0,
- rnt_locality_1 AS locality_1,
- rnt_locality_2 AS locality_2,
- rnt_first_online_date AS first_online_date,
- rnt_update_date AS update_date, "
- . $date_in_where .
- "rnt_pub_code AS pub_code,
- id_agence,
- id_presto,
- rnt_name_agency AS name_agency,
- rnt_post_code_agency AS post_code_agency,
- rnt_town_agency AS town_agency,
- rnt_tel_agency AS tel_agency,
- rnt_fax_agency AS fax_agency,
- rnt_email_agency AS email_agency,
- rnt_site_agency AS site_agency,
- rnt_rcs_agency AS rcs_agency,
- rnt_logo_agency AS logo_agency,
- rnt_franchising_agency AS franchising_agency,
- rnt_is_powersite_agency AS is_powersite_agency,
- rnt_powersite_url_agency AS powersite_url_agency,
- rnt_powersite_calltracking_agency AS powersite_calltracking_agency,
- rnt_advanced_set AS advanced_set,
- rnt_personnalisable AS personnalisable,
- 2 as univ
- FROM " . $sRNT_table_name . " RNT
- WHERE id_agence = '" . $this->search_request["id_agence"] . "'
- AND rnt_ad_status >= 0
- AND rnt_type_transaction = 2
- AND rnt_country = '" . strtoupper($_global["site"]) . "') ";
- $this->query = 'SELECT SQL_CALC_FOUND_ROWS * FROM ( ' . $sReq_SAL . 'UNION ALL ' . $sReq_RNT;
- // sets index
- $force_index = array();
- $this->setIndex($force_index, "locality");
- // common index clause
- // force index when we are doing a search on more than one locality
- if (count($force_index) > 1) {
- $this->force_index = $force_index;
- }
- //*** CONSTRUCTION ORDER ***//
- if (isset($this->search_request["order_ads_agency"])) {
- $this->setOrderAgencyAds($this->search_request["order"]);
- if ($this->search_request["order_ads_agency"] == "") {
- $this->search_request["order_ads_agency"] = "date_asc";
- }
- $this->setOrderAgencyAds($this->search_request["order_ads_agency"]);
- } else {
- $this->setOrderAgencyAds($this->search_request["order"]);
- }
- //*** CONSTRUCTION LIMIT ***//
- $this->setLimit("ad", $offset);
- $this->query .= ") AS RESULTVIEW ORDER BY " . implode(", ", $this->order);
- //-- VARIABLE USED IN TEST FILE DISPLAY/resultats_testpoi.php
- $_global["debug_testpoi"] = $this->query;
- $this->query .= " LIMIT " . $this->limit;
- // adds post code
- $_start = microtime(true);
- $this->setPostCodes();
- $this->showTime("set post codes", $_start);
- // executes the query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo 'getAgencyAds() - 2<br />';
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- $this->showTime("main search", $_start);
- // builds the count query
- $this->query_count = "SELECT FOUND_ROWS() AS NUM";
- // executes the count query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo 'getAds() - 3<br />';
- echo $this->query_count . "<br />";
- echo "<hr />";
- }
- $this->search_count = pdoquery($this->query_count);
- $this->search_count = $this->search_count[0]["NUM"];
- $this->showTime("main count", $_start);
- // save
- $this->search_parameters["count"] = $this->search_count;
- $this->search_request["count"] = $this->search_count;
- // calculates number of pages
- $this->setPages("ad");
- // sets antenna
- $this->setAntenna();
- // saves search
- $this->saveSearch();
- }
- // *** search ads ***
- /**
- *
- * @global type $_global
- * @param string $request
- * @param string $offset
- * @param bool $skip_premium NE SERT A RIEN DANS LES PARAMETRES !!!
- * @param bool $simulate
- */
- function getAds($request, $offset, $skip_premium = false, $simulate = false) {
- global $_global;
- // adds universe
- $this->search_parameters["univers"] = $_global["univers"];
- // is agency search ?
- $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
- // sets request
- //echo "<br><b>search.class.php:424</b> : request : "; var_dump($request); echo "<br>\n";
- $this->search_request = $this->setRequest($request);
- //echo "<br><b>search.class.php:426</b> : getRequest : "; var_dump($this->search_request); echo "<br>\n";
- // adds date
- $this->setDate();
- // sets offset
- $this->search_parameters["offset"] = "" . $offset . "";
- // sets select
- $this->setSelect("ad", false);
- // sets where
- $where = array();
- if ($this->isGrpAgency == true) {
- $this->setWhere($where, "grp_id_agence", $this->list_agency);
- }
- $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
- $this->setWhere($where, "ad_status");
- if (!$this->is_agency_search) {
- if ($this->PerimProximit > 0) {
- $this->setWhere($where, "perimproximit");
- } elseif (!isset($this->search_request['loc_key2'])) {
- $this->setWhere($where, "locality");
- }
- }
- $this->setWhere($where, "country");
- $this->setWhere($where, "price");
- $this->setWhere($where, "area");
- $this->setWhere($where, "ck_nb_rooms");
- if ($_global['univers'] == 1 || $_global['univers'] == 2) {
- // Champs de recherche avancée par encore en base !
- //$this->setWhere($where, "surf"); // Surface du terrain
- $this->setWhere($where, "dpe"); // Recherche par dpe
- $this->setWhere($where, "fresh"); // Recherche par fraicheur d'annonces
- $this->setWhere($where, "ck_nb_bedrooms");
- $this->setWhere($where, "ck_advanced");
- }
- // vacances
- if ($_global["univers"] == 13) {
- $this->setWhere($where, "nb_bedrooms");
- $this->setWhere($where, "nb_people");
- $this->setWhere($where, "type_transaction", 3);
- }
- // location
- elseif ($_global["univers"] == 2) {
- $this->setWhere($where, "type_transaction", 2);
- }
- // colocation
- elseif ($_global["univers"] == 8) {
- $this->setWhere($where, "type_transaction", 8);
- }
- // doit être placé après l'appel à ceci :
- // $this->setWhere($where, "type_transaction", ...);
- $this->setWhere($where, "ck_property_type");
- if ($_REQUEST['an_visuel'] == 1) {
- $this->setWhere($where, "photo");
- }
- if ($_REQUEST['only_old'] == 1) {
- $this->setWhere($where, "only_old");
- }
- if ($_REQUEST['seven_days'] == 1) {
- $date = date("Y-m-d", time() - 7 * 24 * 60 * 60);
- $this->setWhere($where, 'date', $date);
- }
- if ($_global["debug"] == 1) {
- echo "Dump '_REQUEST'<br />";
- var_dump($_REQUEST);
- echo "<hr />";
- }
- $this->setWhere($where, "with_mmf");
- // common where clause
- $this->where = $where;
- // sets index
- $force_index = array();
- $this->setIndex($force_index, "locality");
- // common index clause
- // force index when we are doing a search on more than one locality
- if (count($force_index) > 1) {
- $this->force_index = $force_index;
- }
- // sets order
- /*
- if (isset($this->search_request["order_price"])){
- $this->setOrder("ad", $this->search_request["order"]);
- if ($this->search_request["order_price"]==""){$this->search_request["order_price"]=1;}
- $this->setOrder("filter_ad", $this->search_request["order_price"], "price");
- }
- */
- if (isset($this->search_request["order_ads_agency"])) {
- $this->setOrder("ad", $this->search_request["order"]);
- if ($this->search_request["order_ads_agency"] == "") {
- $this->search_request["order_ads_agency"] = "date_asc";
- }
- $this->setOrder("filter_ad", $this->search_request["order_ads_agency"]);
- } else {
- $this->setOrder("ad", $this->search_request["order"]);
- }
- // sets from
- // SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
- $this->setFrom(false);
- // builds main query
- $this->query = "SELECT SQL_CALC_FOUND_ROWS " . $this->select . " "; //SQL_CALC_FOUND_ROWS
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- // W.asbaiti 24/01/2013
- // Dans le cas de recherche multi localité, on remplace la clause or multi loc par union avec requete mono loc
- if (isset($this->search_request['loc_key2'])) {
- // Ajout de la premiere localite
- $valLoc = explode("_", $this->search_request['loc_key1']);
- $this->query .= " AND " . $this->setLocWhere($valLoc, 1);
- // Ajout de la 2eme localite
- $this->query .= ' UNION ';
- $this->query .= "SELECT " . $this->select . " "; //SQL_CALC_FOUND_ROWS
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- // Ajout requete pour 2eme localite
- $valLoc = explode("_", $this->search_request['loc_key2']);
- $this->query .= " AND " . $this->setLocWhere($valLoc, 2);
- // Traiteent 3eme localite
- if (isset($this->search_request['loc_key3'])) {
- $this->query .= ' UNION ';
- $this->query .= "SELECT " . $this->select . " "; //SQL_CALC_FOUND_ROWS
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- $valLoc = explode("_", $this->search_request['loc_key3']);
- $this->query .= " AND " . $this->setLocWhere($valLoc, 3);
- }
- $this->query = str_replace('SQL_CALC_FOUND_ROWS', '', $this->query);
- $this->query = "SELECT SQL_CALC_FOUND_ROWS * FROM (" . $this->query . ") as search_result ";
- }
- //-- VARIABLE SET BY XAVIER INNAVONG, USED IN TEST FILE DISPLAY/resultats_testpoi.php
- $_global["debug_testpoi_where"] = $this->where;
- // sur l'univers vente
- // si on est pas sur le tri par défaut (du moins cher au plus cher)
- // on ne met pas en avant les annonces exclu orpi et à la une
- if ($_COOKIE['fromSort'] == "true") {
- $skip_premium = true;
- } else if ($_global['page'] == "resultats_agence_annonces") {
- $skip_premium = true;
- } else if ($_global['page'] == "resultats_coloc") {
- $skip_premium = true;
- }
- // Ne pas afficher les annonces ORPI sur page > 1 de PR
- // Garder les annonce premium (annonce a la une)
- if ($offset > 1) {
- $skip_orpi = true;
- } else {
- $skip_orpi = false;
- }
- if ($skip_premium == false) {
- if (isset($this->search_request['loc_key2'])) {
- foreach ($this->search_parameters["loc_keys"] as $sLoc) {
- $aLocInfo = explode('_', $sLoc);
- switch ($aLocInfo[1]) {
- // map group
- case 97 :
- $aComplement[] = "lgm_id = " . $aLocInfo[0];
- break;
- // code group
- case 98 :
- $aComplement[] = "lgc_id = " . $aLocInfo[0];
- break;
- // name group
- case 99 :
- $aComplement[] = "lgn_id = " . $aLocInfo[0];
- break;
- // standard
- default :
- $aComplement[] = $this->table_prfx . "_locality_" . $aLocInfo[1] . " = " . $aLocInfo[0];
- break;
- }
- }
- $sComplement = ' AND (' . implode(' OR ', $aComplement) . ')';
- }
- // Construction de la requete Premium + Exclusive
- if (CURRENT_EXCLUSIVE_NUM > 0 && !$skip_orpi) {
- $where_exclusive = $where;
- // builds premium query
- $this->setWhere($where, "premium");
- // builds premium query
- $this->setWhere($where_exclusive, "exclusive", CURRENT_EXCLUSIVE_NUM);
- $this->query_premium = '( SELECT ' . $this->select . '
- FROM ' . $this->from . '
- WHERE ' . implode(' AND ', $where_exclusive) . '
- ' . $sComplement . '
- LIMIT 0,30
- ) UNION (
- SELECT ' . $this->select . '
- FROM ' . $this->from . '
- WHERE ' . implode(' AND ', $where) . '
- ' . $sComplement . '
- LIMIT 0,30
- )';
- // Construction de la requete Premium
- } else {
- // builds premium query
- $this->setWhere($where, "premium");
- $this->query_premium = 'SELECT ' . $this->select . '
- FROM ' . $this->from . '
- WHERE ' . implode(' AND ', $where) . '
- ' . $sComplement . '
- LIMIT 0,30';
- }
- if ($simulate == false) {
- // executes the premium query
- $_delta = microtime(true);
- if ($_global["debug"] == 3) {
- echo 'getAds() - 1<br />';
- echo $this->query_premium . "<br />";
- echo "<hr />";
- }
- $this->search_results_premium = pdoquery($this->query_premium);
- $nb_total = count($this->search_results_premium);
- // Doit-on traiter les annonces exclusives ?
- if (CURRENT_EXCLUSIVE_NUM > 0) {
- $nb_exclusive = 0;
- // Trouver le nombre d'annonces exclusives
- if (sizeof($this->search_results_premium) > 0) {
- foreach ($this->search_results_premium as $annonce) {
- if ($annonce[$this->table_prfx . '_is_exclusive'] == CURRENT_EXCLUSIVE_NUM)
- ++$nb_exclusive;
- else
- $break;
- }
- }
- // Calculer le nombre d'annonces premium
- $nb_premium = $nb_total - $nb_exclusive;
- if ($nb_exclusive > 0) {
- $randexclu = rand(0, $nb_exclusive - 1);
- $this->search_results_exclusive = $this->search_results_premium[$randexclu];
- //Yo - 2011/08/05 : Exclure cet annonce Orpi dans la liste des résultats pour éviter le doublon
- //Probleme: Si on fait pas: on a une Orpi(aléatoire) à la première position et une autre orpi dans le résultat
- //Et si jamais elles sont les mêmes, on a doublon
- // W.ASBAITI : inclure ORPI dans la liste de recherche pour gérer la navigation sur la page detail (risque de doublons accepte par market)
- // $this->query .= "AND id_annonce != '".$this->search_results_exclusive['id_annonce']."'"." ";
- $this->has_exclusive = true;
- } else {
- $this->has_exclusive = false;
- }
- if ($_global["debug"] == 3) {
- echo 'TOTAL: ' . $nb_total . ' / PREMIUM: ' . $nb_premium . ' / EXCLU: ' . $nb_exclusive . '<hr />';
- }
- } else {
- $nb_premium = $nb_total;
- if ($_global["debug"] == 3) {
- echo 'TOTAL: ' . $nb_total . ' / PREMIUM: ' . $nb_premium . '<hr />';
- }
- }
- //parametres supplémentaires pour corriger la pagination
- //Ajout de Mathieu pour ne pas tout détruire...07/12/2012
- if ($nb_premium > 0) {
- $this->search_parameters["premiumPresente"] = true;
- } else {
- $this->search_parameters["premiumPresente"] = false;
- }
- if ($nb_exclusive > 0) {
- $this->search_parameters["exclusivePresente"] = true;
- } else {
- $this->search_parameters["exclusivePresente"] = false;
- }
- if ($nb_premium > 0) {
- $randpremium = rand($nb_exclusive, $nb_total - 1);
- $this->search_results_premium = array($this->search_results_premium[$randpremium]);
- $this->search_count_premium = $nb_premium;
- $this->has_premium = true;
- $this->search_parameters["premium"] = 1;
- } else {
- $this->search_count_premium = 0;
- $this->has_premium = false;
- $this->search_parameters["premium"] = 0;
- }
- $this->showTime("premium search", $_delta);
- }
- }
- // sets limit
- $this->setLimit("ad", $offset);
- // main query additional clause
- //var_dump($this->order);
- $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
- //-- VARIABLE SET BY XAVIER INNAVONG, USED IN TEST FILE DISPLAY/resultats_testpoi.php
- $_global["debug_testpoi"] = $this->query;
- // Stockage de la requete pour pagination page detail
- // $this->save_query($this->query);
- $this->query .= "LIMIT " . $this->limit;
- // adds post code
- $_start = microtime(true);
- $this->setPostCodes();
- $this->showTime("set post codes", $_start);
- // executes the query
- $_start = microtime(true);
- if ($simulate == false) {
- if ($_global["debug"] == 3) {
- echo 'getAds() - 2<br />';
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- $this->showTime("main search", $_start);
- // builds the count query
- $this->query_count = "SELECT FOUND_ROWS() AS NUM";
- // executes the count query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo 'getAds() - 3<br />';
- echo $this->query_count . "<br />";
- echo "<hr />";
- }
- $this->search_count = pdoquery($this->query_count);
- $this->search_count = $this->search_count[0]["NUM"];
- $this->showTime("main count", $_start);
- // save
- $this->search_parameters["count"] = $this->search_count;
- $this->search_request["count"] = $this->search_count;
- // calculates number of pages
- $this->setPages("ad");
- // sets antenna
- $this->setAntenna();
- // saves search
- $this->saveSearch();
- }
- }
- /*
- Apparamment, cette fonction est
- - appelée dans bloc_principal.php (inclus dans V5_home_fr.php)
- - commentée dans google_gadget/gadget_search.php
- */
- // *** search ads by date ***
- function getAdsByDate($request) {
- global $_global;
- // adds universe
- $this->search_parameters["univers"] = $_global["univers"];
- // sets search parameters
- $this->search_request = $this->setRequest($request);
- // adds date
- $this->setDate(true);
- // sets select
- $this->setSelect("ad", false);
- // sets from
- $this->setFrom();
- // sets where
- $where = array();
- $this->setWhere($where, "ad_status");
- $this->setWhere($where, "locality");
- $this->setWhere($where, "country");
- $this->setWhere($where, "ck_property_type");
- $this->setWhere($where, "price");
- $this->setWhere($where, "area");
- $this->setWhere($where, "ck_nb_rooms");
- $this->setWhere($where, "date", $this->search_request["date"]);
- $this->setWhere($where, "with_mmf");
- /* START:RECHERCHE AVANCEE */
- /*
- //$this->setWhere($where, "with_mmf");
- $this->setWhere($where, "recent_ads");
- //if($request["property_type"][0] == 3)
- $this->setWhere($where, "surf");
- $this->setWhere($where, "floor");
- $this->setWhere($where, "elevator");
- $this->setWhere($where, "caretaker");
- $this->setWhere($where, "interphone");
- $this->setWhere($where, "balcony");
- $this->setWhere($where, "terrace");
- $this->setWhere($where, "parquet");
- $this->setWhere($where, "fireside");
- $this->setWhere($where, "closets");
- $this->setWhere($where, "storage");
- $this->setWhere($where, "parking");
- $this->setWhere($where, "garden");
- $this->setWhere($where, "pool");
- */
- /* STOP:RECHERCHE AVANCEE */
- // common where clause
- $this->where = $where;
- // sets order
- $this->setOrder("ad", $this->search_request["order"]);
- // sets limit
- $this->setLimit("ad", 0);
- // sets index
- $force_index = array();
- $this->setIndex($force_index, "locality");
- // common index clause
- // force index when we are doing a search on more than one locality
- if (count($force_index) > 1) {
- $this->force_index = $force_index;
- }
- // builds main query
- $this->query = "SELECT SQL_CALC_FOUND_ROWS 1 AS revisite, " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- if (isset($this->force_index)) {
- //$this->query .= "FORCE INDEX (".implode(", ", $this->force_index).") ";
- }
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
- $this->query .= "LIMIT " . $this->limit;
- // adds post code
- $this->setPostCodes();
- // executes the query
- if ($_global["debug"] == 3) {
- echo "getAdsByDate() - 1<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- // builds the count query
- $this->query_count = "SELECT FOUND_ROWS() AS NUM";
- // executes the count query
- if ($_global["debug"] == 3) {
- echo "getAdsByDate() - 2<br />";
- echo $this->query_count . "<br />";
- echo "<hr />";
- }
- $this->search_count = pdoquery($this->query_count);
- $this->search_count = $this->search_count[0]["NUM"];
- // save
- $this->search_parameters["count"] = $this->search_count;
- $this->search_request["count"] = $this->search_count;
- }
- /*
- Apparamment, cette fonction est
- - appelée dans ws/soap/server/classes/search.class_from50.php,
- - commentée dans ajax/prod.count.localities.maps.php
- */
- // *** search ads by coordinates ***
- function getAdsByMap($request) {
- global $_global;
- // adds universe
- $this->search_parameters["univers"] = $_global["univers"];
- // is agency search ?
- $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
- // checks if the search form has been activated or if the query has to be pulled from a cookie:
- $this->search_request = $this->setRequest($request);
- // adds date
- $this->setDate();
- // sets select
- $this->select = "COUNT(" . $this->table_prfx . "_ai_id) AS num, lct_id, lct_level, lct_name, lct_lat, lct_long";
- // sets from
- $this->from = $this->table_name . ", " . $this->table_locality_name;
- // sets where
- $where = array();
- $this->setWhere($where, "ad_status");
- $this->setWhere($where, "country");
- $this->setWhere($where, "ck_property_type");
- $this->setWhere($where, "price");
- $this->setWhere($where, "area");
- $this->setWhere($where, "ck_nb_rooms");
- $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
- $this->setWhere($where, "with_mmf");
- /* START:RECHERCHE AVANCEE */
- /*
- //$this->setWhere($where, "with_mmf");
- $this->setWhere($where, "recent_ads");
- //if($request["property_type"][0] == 3)
- $this->setWhere($where, "surf");
- $this->setWhere($where, "floor");
- $this->setWhere($where, "elevator");
- $this->setWhere($where, "caretaker");
- $this->setWhere($where, "interphone");
- $this->setWhere($where, "balcony");
- $this->setWhere($where, "terrace");
- $this->setWhere($where, "parquet");
- $this->setWhere($where, "fireside");
- $this->setWhere($where, "closets");
- $this->setWhere($where, "storage");
- $this->setWhere($where, "parking");
- $this->setWhere($where, "garden");
- $this->setWhere($where, "pool");
- /* STOP:RECHERCHE AVANCEE */
- // common where clause
- $this->where = $where;
- // builds main query
- $this->query = "SELECT " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- $this->query .= "GROUP BY lct_name, lct_extra_detail, lct_lat, lct_long ";
- // adds post code
- $_start = microtime(true);
- $this->setPostCodes();
- $this->showTime("set post codes", $_start);
- // executes the query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo "getAdsByMap() - 1<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- $this->showTime("main search", $_start);
- // count
- if ($this->search_request["offset"] == "") {
- // builds the count query
- $this->query_count = "SELECT FOUND_ROWS() AS NUM";
- // executes the count query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo "getAdsByMap() - 2<br />";
- echo $this->query_count . "<br />";
- echo "<hr />";
- }
- $this->search_count = pdoquery($this->query_count);
- $this->search_count = $this->search_count[0]["NUM"];
- $this->showTime("main count", $_start);
- // save
- $this->search_parameters["count"] = $this->search_count;
- $this->search_request["count"];
- // calculates number of pages
- $this->setPages("ad");
- }
- // saves search
- $this->saveSearch();
- }
- /**
- * Recuperer la position de l annonce EXCLU parmis toutes les annonces de la recherche
- *
- * @param string $id : l'ID de l'annonce à positionner
- * @return array : Tableau contenant l'annonce suivante et precedente de l'id envoye en param
- */
- function getExcluNav($id) {
- global $_global;
- // Reconstruire les parametres de recherche depuis le cookie LISEARCHHISTORY
- $request = $this->loadSearch();
- if (empty($request))
- return null;
- else {
- unset($request['date']);
- unset($request['timestamp']);
- }
- if ($_global['debug'] == 1) {
- echo 'Request from Cookie History ' . ($is_agency ? 'Agency' : '') . ' :<br />';
- print_r($request);
- echo '<hr />';
- }
- // Probleme: Aucun critere de recherche précisé
- if (!is_array($request) || $request == array())
- return null;
- $where = array();
- $this->search_request = $this->setRequest($request);
- $this->setWhere($where, "locality");
- $order = '';
- if (isset($request["order"])) {
- $this->setOrder("ad", $request["order"]);
- $order = ' ORDER BY ' . implode(', ', $this->order);
- }
- $request['country'] = 'FR';
- if (!isset($request['area']))
- $this->setWhere($where, 'area');
- // Ajouter un prix mini de 10000 pour les ventes
- if ($_global['univers'] == 1) {
- if (!isset($this->search_request['price_min']) || $this->search_request['price_min'] < 10000) {
- $this->search_request['price_min'] = 10000;
- /**
- * VBA [11/10/2012]
- * The price is to be unset after the query is done because we don't want it in the url.
- * @var boolean
- */
- $price_to_unset = true;
- }
- }
- // Si la valeur price n'est pas précisée, déclencher manuellement
- // l'appel pour renseigner les valeurs min/max
- if (!isset($request['price']))
- $this->setWhere($where, 'price');
- foreach ($request as $key => $value)
- $this->setWhere($where, $key, $value);
- // Problème : Aucun critère de recherche valide
- if ($where == array())
- return null;
- if ($_global['univers'] == 2)
- $where[] = '(' . $this->table_prfx . '_type_transaction = 2)';
- elseif ($_global['univers'] == 8)
- $where[] = '(' . $this->table_prfx . '_type_transaction = 8)';
- // builds the query
- $this->query = ' SELECT id_annonce FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where) . $order;
- if ($_global['univers'] == 1) {
- if ($price_to_unset) {
- $this->search_request['price_min'] = '';
- }
- }
- $result = pdoquery($this->query, null, null, null, PDO::FETCH_ASSOC);
- return $result;
- }
- function getNavigateDetail($request, $num_row, $is_agency = false) {
- global $_global;
- if (is_null($request)) {
- $this->is_agency_search = $is_agency;
- $request = $this->loadSearch();
- if (empty($request))
- return null;
- else {
- unset($request['date']);
- unset($request['timestamp']);
- }
- if ($_global['debug'] == 1) {
- echo 'Request from Cookie History ' . ($is_agency ? 'Agency' : '') . ' :<br />';
- print_r($request);
- echo '<hr />';
- }
- }
- // Probleme: Aucun critere de recherche précisé
- if (!is_array($request) || $request == array())
- return null;
- $where = array();
- $this->search_request = $this->setRequest($request);
- $this->setWhere($where, "locality");
- $order = '';
- if (isset($request["order"])) {
- $this->setOrder("ad", $request["order"]);
- $order = ' ORDER BY ' . implode(', ', $this->order);
- }
- $request['country'] = 'FR';
- if (!isset($request['area']))
- $this->setWhere($where, 'area');
- // Ajouter un prix mini de 10000 pour les ventes
- if ($_global['univers'] == 1) {
- if (!isset($this->search_request['price_min']) || $this->search_request['price_min'] < 10000) {
- $this->search_request['price_min'] = 10000;
- $ll = true;
- }
- }
- // Si la valeur price n'est pas précisée, déclencher manuellement
- // l'appel pour renseigner les valeurs min/max
- if (!isset($request['price']))
- $this->setWhere($where, 'price');
- foreach ($request as $key => $value)
- $this->setWhere($where, $key, $value);
- // Problème : Aucun critère de recherche valide
- if ($where == array())
- return null;
- if ($_global['univers'] == 2)
- $where[] = '(' . $this->table_prfx . '_type_transaction = 2)';
- elseif ($_global['univers'] == 8)
- $where[] = '(' . $this->table_prfx . '_type_transaction = 8)';
- // builds the query
- $this->query = ' SELECT SQL_CACHE * FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where) . $order;
- if ($_global['univers'] == 1) {
- if ($ll) {
- $this->search_request['price_min'] = '';
- }
- }
- // Si on n'est pas sur la toute premiere annonce
- if ($num_row > 0) {
- // S'il y a des premium, il faut gérer le décalage dans les résultats de la requete
- // Et faire une requete spécifique si précédent ou suivant sera une premium
- if ($_global['is_there_premium']) {
- // Si ce n'est ni la premiere, ni la derniere annonce d'une page
- // (actuelle premium ou suivante premium ou précédente premium)
- // Alors les liens sont classiques => Pas de requete premium en plus
- $ecart = ($num_row + 1) % MAX_RESULTS_PER_PAGE;
- if ($ecart == 0 || $ecart == 2)
- $classic = false;
- else {
- $classic = true;
- // Corriger le décalage avec les premiums
- if ($ecart == 1)
- $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE);
- else
- $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE) - 1;
- }
- }
- else {
- $classic = true;
- // Pas de premium => Pas de decalage
- }
- // Classique => Précédent et Suivant ne sont pas des premiums
- if ($classic) {
- if ($ecart == 1)
- $this->query .= ' LIMIT ' . ($num_row - 1) . ',2';
- else
- $this->query .= ' LIMIT ' . ($num_row - 1) . ',3';
- if ($_global["debug"] == 3) {
- echo "getNavigateDetail() - Précédent/Suivant<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $result = pdoquery($this->query);
- if ($_global['debug'] == 1 || $_global['debug'] == 3) {
- echo 'Resultat de la requete :<br />';
- foreach ($result as $i => $res)
- echo 'id_annonce_' . $i . ' => ' . $res . '<br />';
- echo '<hr />';
- }
- if (isset($result[0]))
- $navigation['prev'] = $result[0];
- else
- $navigation['prev'] = null;
- if (isset($result[1]) && $ecart == 1)
- $navigation['next'] = $result[1];
- elseif (isset($result[2]))
- $navigation['next'] = $result[2];
- else
- $navigation['next'] = null;
- }
- // Non classique => Précédent est premium ou Suivant est premium
- else {
- $where[] = '(' . $this->table_prfx . '_is_premium = 1)';
- $this->query_premium = ' SELECT SQL_CACHE * FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where) . $order;
- $this->query_premium .= ' LIMIT 0,30';
- $result = pdoquery($this->query_premium, null, null, null, PDO::FETCH_ASSOC);
- $nb_results_premium = count($result);
- // Si l'annonce précédente est une premium
- if ($num_row % MAX_RESULTS_PER_PAGE == 1) {
- $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE) - 1;
- // REQUETE ANNONCE PRECEDENTE PREMIUM
- if ($_global["debug"] == 3) {
- echo "getNavigateDetail() - Précédent Premium<br />";
- echo $this->query_premium . "<br />";
- echo "<hr />";
- }
- if ($nb_results_premium > 0) {
- $random = rand(0, $nb_results_premium - 1);
- $navigation['prev'] = $result[$random];
- }
- else
- $navigation['prev'] = null;
- if ($_global['debug'] == 1 || $_global['debug'] == 3) {
- echo 'Resultat de la requete : ' . $nb_results_premium . ' annonce(s) => ' . $navigation['prev'] . '<hr />';
- }
- // REQUETE ANNONCE SUIVANTE CLASSIQUE
- $this->query .= ' LIMIT ' . ($num_row + 1) . ',1';
- if ($_global["debug"] == 3) {
- echo "getNavigateDetail() - Suivant Classique<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $result = pdoquery($this->query);
- if ($_global['debug'] == 1 || $_global['debug'] == 3) {
- echo 'Resultat de la requete :<br />';
- foreach ($result as $i => $res)
- echo 'id_annonce_' . $i . ' => ' . $res . '<br />';
- echo '<hr />';
- }
- if (isset($result[0]))
- $navigation['next'] = $result[0];
- else
- $navigation['next'] = null;
- }
- else {
- $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE) - 1;
- // REQUETE ANNONCE SUIVANTE PREMIUM
- if ($_global["debug"] == 3) {
- echo "getNavigateDetail() - Suivant Premium<br />";
- echo $this->query_premium . "<br />";
- echo "<hr />";
- }
- if ($nb_results_premium > 0) {
- $random = rand(0, $nb_results_premium - 1);
- $navigation['next'] = $result[$random];
- }
- else
- $navigation['next'] = null;
- if ($_global['debug'] == 1 || $_global['debug'] == 3) {
- echo 'Resultat de la requete : ' . $nb_results_premium . ' annonce(s) => ' . $navigation['next'] . '<hr />';
- }
- // REQUETE ANNONCE SUIVANTE CLASSIQUE
- $this->query .= ' LIMIT ' . ($num_row - 1) . ',1';
- if ($_global["debug"] == 3) {
- echo "getNavigateDetail() - Précédent Classique<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $result = pdoquery($this->query);
- if ($_global['debug'] == 1 || $_global['debug'] == 3) {
- echo 'Resultat de la requete :<br />';
- foreach ($result as $i => $res)
- echo 'id_annonce_' . $i . ' => ' . $res . '<br />';
- echo '<hr />';
- }
- if (isset($result[0]))
- $navigation['prev'] = $result[0];
- else
- $navigation['prev'] = null;
- }
- }
- }
- // Première annonce => Pas de précédent
- else {
- // Si on est sur la premiere annonce, alors charger le premier resultat
- if ($_global['is_there_premium'])
- $this->query .= ' LIMIT 0,3';
- // Sinon on charge le resultat suivant dans la liste
- else
- $this->query .= ' LIMIT 1,3';
- if ($_global["debug"] == 3) {
- echo "getNavigateDetail() - Pas de précédent<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $result = pdoquery($this->query);
- if ($_global['debug'] == 1 || $_global['debug'] == 3) {
- echo 'Resultat de la requete :<br />';
- foreach ($result as $i => $res)
- echo 'id_annonce_' . $i . ' => ' . $res['id_annonce'] . '<br />';
- echo '<hr />';
- }
- $navigation['prev'] = null;
- if (isset($result[0]))
- $navigation['next'] = $result[0];
- else
- $navigation['next'] = null;
- }
- return $navigation;
- }
- // *** search ad ***
- function getAd($request, $code, $mode, $deleted = false) {
- global $_global;
- // is agency search ?
- $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
- // sets search parameters
- $this->search_request = $request;
- // $this->search_request = $this->setRequest($request);
- switch ($mode) {
- // ID
- case 1 :
- // sets select
- if ($deleted) {
- $this->setSelect("ad", true, true);
- } else {
- $this->setSelect("ad", true, false);
- }
- // sets from
- $this->setFrom();
- // sets where
- $where = array();
- $this->setWhere($where, "id", $code);
- // vacances
- if ($_global["univers"] == 13) {
- $this->setWhere($where, "type_transaction", 3);
- } else if ($_global["univers"] == 2) {
- $this->setWhere($where, "type_transaction", 2);
- } else if ($_global["univers"] == 8) {
- $this->setWhere($where, "type_transaction", 8);
- }
- // builds the query
- $this->query = "SELECT " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" AND ", $where) . " ";
- if ($_global["debug"] == 3) {
- echo "getAd()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- break;
- // LOGICODE / LOGICODE_OLD
- case 2 :
- // Patch pour les annonces expirées
- if (strpos($this->table_name, 'DEL') !== false) {
- $this->getAdByLogicode($this->table_name, $this->table_prfx, $code, true);
- break;
- }else
- $this->getAdByLogicode(TABLE_S_NAME, TABLE_S_PRFX, $code);
- // $this->getAdByLogicode(TABLE_S_NAME, TABLE_S_PRFX, $code);
- // tests if any ad found, switches to rentals
- if (count($this->search_results) == 0) {
- $this->getAdByLogicode(TABLE_R_NAME, TABLE_R_PRFX, $code);
- if (count($this->search_results) > 0) {
- // sets current universe to rentals
- $_global["univers"] = 2;
- $_global["table_name"] = TABLE_R_NAME;
- $_global["table_prefix"] = TABLE_R_PRFX;
- }
- } else {
- // sets current univers to sales
- $_global["univers"] = 1;
- $_global["table_name"] = TABLE_S_NAME;
- $_global["table_prefix"] = TABLE_S_PRFX;
- }
- break;
- }
- }
- // *** search ad by logicode ***
- function getAdByLogicode($table, $prefix, $code, $deleted = false) {
- global $_global;
- // sets the search to rentals
- $this->setTable($table, $prefix);
- // sets select
- //$this->setSelect("ad", true);
- if ($deleted) {
- $this->setSelect("ad", true, true);
- } else {
- $this->setSelect("ad", true, false);
- }
- // sets from
- $this->setFrom();
- // sets where
- $where = array();
- $this->setWhere($where, "logicode", $code);
- $this->setWhere($where, "logicode_old", $code);
- // builds the query
- $this->query = "SELECT " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" OR ", $where) . " ";
- // executes the query
- if ($_global["debug"] == 3) {
- echo "getAdByLogicode()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- if (count($this->search_results) == 0) {
- $sql = " SELECT ttu_" . $prefix . "bis_fr AS bistable FROM TP_TABLE_TO_USE_TTU";
- $res = pdoquery($sql);
- $this->from = $res[0]["bistable"];
- // builds the query
- $this->query = "SELECT " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" OR ", $where) . " ";
- // executes the query
- if ($_global["debug"] == 3) {
- echo "getAdByLogicode()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- }
- }
- /**
- * Modification Mathieu pour parametre optionnel nom d'agence Refonte fin 2012
- * @global type $_global
- * @param type $request
- * @param type $offset
- * @param string $agc_name Nom de l'agence
- */
- function getAgencies($request, $offset, $bHasAgency = false) {
- // debug2($request);
- global $_global;
- // adds universe
- $this->search_parameters["univers"] = $_global["univers"];
- // is agency search ?
- $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
- // adds date
- $this->setDate();
- // adds request
- $this->search_request = $this->setRequest($request);
- // $this->search_request = $request;
- // sets offset
- $this->search_parameters["offset"] = "" . $offset . "";
- // sets select
- $this->setSelect("agency", false);
- // sets from
- //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
- $this->setFrom(true);
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- $join_on = "adp.adp_id_agence = t.id_agence";
- // sets where
- $where = array();
- $this->setWhere($where, "ag_locality");
- $this->setWhere($where, "ag_count");
- $this->setWhere($where, "country");
- if ($bHasAgency) {
- $this->setWhere($where, "agc_name");
- }
- $this->where = $where;
- // sets order
- $this->setOrder("agency", $this->search_request["order"]);
- //var_dump($this->search_request["order"]);exit();
- // builds main query
- $this->query = "SELECT SQL_CALC_FOUND_ROWS " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "ON " . $join_on . " ";
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- // sets limit
- if (is_null($user_ihm['nb_results'])) {
- $var = MAX_RESULTS_AGENCY_PER_PAGE;
- } else {
- $var = $user_ihm['nb_results'];
- }
- $this->limit = (($offset - 1) * $var);
- $this->limit .= ' , ';
- $this->limit .= $var;
- // main query additional clause
- $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
- $this->query .= "LIMIT " . $this->limit;
- // adds post code
- $_start = microtime(true);
- $this->setPostCodes();
- $this->showTime("set post codes", $_start);
- // executes the query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo "getAgencies()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- $this->showTime("main search", $_start);
- // builds the count query
- $this->query_count = "SELECT FOUND_ROWS() AS NUM";
- // executes the count query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo "getAgencies()<br />";
- echo $this->query_count . "<br />";
- echo "<hr />";
- }
- $this->search_count = pdoquery($this->query_count);
- $this->search_count = $this->search_count[0]["NUM"];
- $id_loc = $this->search_parameters['loc_hierarchy'][1]['lct_id'];
- $this->showTime("main count", $_start);
- // save
- $this->search_parameters["count"] = $this->search_count;
- $this->search_request["count"] = $this->search_count;
- $this->saveSearch();
- // calculates number of pages
- $this->setPages("agency");
- }
- // *** search agency ***
- /**
- *
- * @global type $_global
- * @param type $request
- * @param type $code
- * @param string $agc_name nom de l'agence, paramètre optionnel.
- */
- function getAgency($request, $code, $agc_name = null) {
- global $_global;
- // adds request
- $this->search_request = $request;
- // sets select
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- $this->setSelect("agency", false);
- // sets from
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- $this->setFrom(true);
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- $join_on = "adp.adp_id_presto = t.id_presto";
- // sets where
- $where = array();
- $this->setWhere($where, "id_agence", $code);
- if (!is_null($agc_name)) {
- $this->setWhere($where, "agc_name", $agc_name);
- }
- // builds the query
- $this->query = "SELECT " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "ON " . $join_on . " ";
- $this->query .= "WHERE " . implode(" AND ", $where) . " ";
- // executes the query
- if ($_global["debug"] == 3) {
- echo "getAgency()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results_agency = pdoquery($this->query);
- // agency railroad
- for ($i = 0; $i < 3; $i++) {
- if ($this->search_results_agency[0]["agc_loc_id_" . $i] > 0) {
- $query = "SELECT lct_id, lct_level, lct_name, lct_post_code ";
- $query .= "FROM " . $this->table_locality_name . " ";
- $query .= "WHERE lct_id = " . $this->search_results_agency[0]["agc_loc_id_" . $i];
- if ($_global["debug"] == 3) {
- echo "getAgency()<br />";
- echo $query . "<br />";
- echo "<hr />";
- }
- $locality = pdoquery($query);
- if (count($locality) > 0) {
- $this->search_hierarchy_agency[$i] = $locality[0];
- }
- }
- }
- }
- // *** search coordinates ***
- function getCoordinates($request) {
- if (isset($request["loc_key"]) && $request["loc_key"] != "") {
- $loc_key = $request["loc_key"];
- } else {
- for ($i = 1; $i < SEARCH_FIELDS_NUMBER + 1; $i++) {
- if (isset($request["loc_key" . $i]) && $request["loc_key" . $i] != "") {
- $loc_key = $request["loc_key" . $i];
- break;
- }
- }
- }
- // lct_id, lct_level
- $loc_tmp = explode("_", $loc_key);
- switch ($loc_tmp[1]) {
- // code group
- case 98 :
- $this->query = "SELECT lgc_id AS lct_id, lgc_parent_id AS lct_parent_id, lgc_post_code AS lct_post_code, lgc_lat AS lct_lat, lgc_long AS lct_long ";
- $this->query .= "FROM T_LOCGROUPCODE_LGC_" . strtoupper($request["site"]) . " ";
- $this->query .= "WHERE lgc_id = " . $loc_tmp[0] . " ";
- break;
- // name group
- case 99 :
- $this->query = "SELECT lgn_id AS lct_id, lgn_parent_id AS lct_parent_id, lgn_post_code AS lct_post_code, lgn_lat AS lct_lat, lgn_long AS lct_long ";
- $this->query .= "FROM T_LOCGROUPNAME_LGN_" . strtoupper($request["site"]) . " ";
- $this->query .= "WHERE lgn_id = " . $loc_tmp[0] . " ";
- break;
- // standard
- default :
- $this->query = "SELECT lct_id, lct_parent_id, lct_post_code, lct_lat, lct_long ";
- $this->query .= "FROM " . $this->table_locality_name . " ";
- $this->query .= "WHERE lct_id = " . $loc_tmp[0] . " ";
- $this->query .= "AND lct_level = " . $loc_tmp[1];
- break;
- }
- if ($_global["debug"] == 3) {
- echo "getCoordinates() - 1<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $results = pdoquery($this->query);
- if (count($results) > 0) {
- // si coordonnées nulles, recherche d'une localité au même code postal ou au pire, le niveau supérieur
- $loc_tmp2 = $results[0];
- if ((empty($loc_tmp2["lct_lat"])) && (empty($loc_tmp2["lct_long"]))) { // 0 ou NULL
- if ($loc_tmp2["lct_post_code"] != 0) { // autre localité de même code postal et avec coords non nulles
- $this->query2 = "SELECT lct_id, lct_parent_id, lct_lat, lct_long ";
- $this->query2 .= "FROM " . $this->table_locality_name . " ";
- $this->query2 .= "WHERE lct_post_code = '" . $loc_tmp2["lct_post_code"] . "' ";
- $this->query2 .= "AND (lct_lat != 0 AND lct_lat IS NOT NULL) ";
- $this->query2 .= "AND (lct_long != 0 AND lct_long IS NOT NULL) ";
- } else { // département (ou région) de la localité
- $this->query2 = "SELECT lct_id, lct_parent_id, lct_lat, lct_long ";
- $this->query2 .= "FROM " . $this->table_locality_name . " ";
- $this->query2 .= "WHERE lct_id = " . $loc_tmp2["lct_parent_id"];
- }
- if ($_global["debug"] == 3) {
- echo "getCoordinates() - 2<br />";
- echo $this->query2 . "<br />";
- echo "<hr />";
- }
- $results2 = pdoquery($this->query2);
- $results = $results2;
- // si pas de résultat, recherche d'une "localité" de niveau supérieur
- if (count($results) == 0) {
- $this->query3 = "SELECT lct_id, lct_parent_id, lct_lat, lct_long ";
- $this->query3 .= "FROM " . $this->table_locality_name . " ";
- $this->query3 .= "WHERE lct_id = " . $loc_tmp2["lct_parent_id"];
- if ($_global["debug"] == 3) {
- echo "getCoordinates() - 3<br />";
- echo $this->query3 . "<br />";
- echo "<hr />";
- }
- $results3 = pdoquery($this->query3);
- $results = $results3;
- }
- }
- return array("loc_key" => $loc_key, "latitude" => $results[0]["lct_lat"], "longitude" => $results[0]["lct_long"]);
- }
- }
- // *** new search when cookie is empty ***
- function setNewSearch($request) {
- global $_global;
- // adds universe
- $this->search_parameters["univers"] = $_global["univers"];
- // is agency search ?
- $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
- // sets request
- $this->search_request = $this->setRequest($request);
- // adds date
- $this->setDate();
- // sets from
- $this->setFrom();
- // sets where
- $where = array();
- $this->setWhere($where, "ad_status");
- $this->setWhere($where, "locality");
- $this->setWhere($where, "country");
- $this->setWhere($where, "ck_property_type");
- $this->setWhere($where, "price");
- $this->setWhere($where, "area");
- $this->setWhere($where, "ck_nb_rooms");
- $this->setWhere($where, "with_mmf");
- /* START:RECHERCHE AVANCEE */
- /*
- //$this->setWhere($where, "with_mmf");
- $this->setWhere($where, "recent_ads");
- //if($request["property_type"][0] == 3)
- $this->setWhere($where, "surf");
- $this->setWhere($where, "floor");
- $this->setWhere($where, "elevator");
- $this->setWhere($where, "caretaker");
- $this->setWhere($where, "interphone");
- $this->setWhere($where, "balcony");
- $this->setWhere($where, "terrace");
- $this->setWhere($where, "parquet");
- $this->setWhere($where, "fireside");
- $this->setWhere($where, "closets");
- $this->setWhere($where, "storage");
- $this->setWhere($where, "parking");
- $this->setWhere($where, "garden");
- $this->setWhere($where, "pool");
- /* STOP:RECHERCHE AVANCEE */
- // common where clause
- $this->where = $where;
- // sets index
- $force_index = array();
- $this->setIndex($force_index, "locality");
- // common index clause
- // force index when we are doing a search on more than one locality
- if (count($force_index) > 1) {
- $this->force_index = $force_index;
- }
- // builds main query
- $this->query = "SELECT COUNT(*) AS NUM ";
- $this->query .= "FROM " . $this->from . " ";
- if (isset($this->force_index)) {
- //$this->query .= "FORCE INDEX (".implode(", ", $this->force_index).") ";
- }
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- // adds post code
- $_start = microtime(true);
- $this->setPostCodes();
- $this->showTime("set post codes", $_start);
- // executes the query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo "setNewSearch()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- $this->showTime("main search", $_start);
- $this->search_count = $this->search_results[0]["NUM"];
- $this->showTime("main count", $_start);
- // save
- $this->search_parameters["count"] = $this->search_count;
- $this->search_request["count"] = $this->search_count;
- // sets antenna
- $this->setAntenna();
- }
- // *** sets date ***
- function setDate($skip_request = false) {
- $time = time();
- if ($skip_request == false) {
- $this->search_request["date"] = date("Y-m-d", $time);
- $this->search_request["timestamp"] = $time;
- }
- $this->search_parameters["date"] = date("Y-m-d", $time);
- $this->search_parameters["timestamp"] = $time;
- }
- // *** returns select clause including all needed fields ***
- function setSelect($mode = "ad", $extended = false, $deleted = false) {
- global $_global;
- // field list
- $fields = array();
- switch ($mode) {
- // ad fields
- case "ad" :
- // ad extended
- if ($extended == true) {
- // ad all
- $fields[] = "*";
- // ad localisation
- //20091202-1 (1/3) not using T_LOCALITY_LCT_FR table when select town name
- $fields[] = $this->table_prfx . "_default_town_2";
- $fields[] = $this->table_prfx . "_default_town_1";
- $fields[] = $this->table_prfx . "_default_town_0";
- /*
- $fields[] = "(IF(t.".$this->table_prfx."_locality_2 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_2))) AS ".$this->table_prfx."_default_town_2";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_1 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_1))) AS ".$this->table_prfx."_default_town_1";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_0 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_0))) AS ".$this->table_prfx."_default_town_0";
- */
- // ad dates
- //20091202-2 (1/4) not using SELECT when use of DATEDIFF
- if ($deleted == true) {
- $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_date_deleted) AS " . $this->table_prfx . "_days_old";
- } else {
- $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_first_online_date) AS " . $this->table_prfx . "_days_old";
- }
- }
- // ad standard
- else {
- // ad identifiers
- $fields[] = "id_annonce";
- $fields[] = "t." . $this->table_prfx . "_ai_id";
- $fields[] = $this->table_prfx . "_reference";
- $fields[] = $this->table_prfx . "_num_mandat";
- // ad premium
- $fields[] = $this->table_prfx . "_is_premium";
- //logo_agency
- $fields[] = $this->table_prfx . "_is_logo_agency";
- //directory_agency
- $fields[] = $this->table_prfx . "_is_directory_agency";
- //website_agency
- $fields[] = $this->table_prfx . "_is_website_agency";
- // ad features
- $fields[] = $this->table_prfx . "_type_transaction";
- $fields[] = "id_bien";
- $fields[] = ($_global['univers'] == 1 ? "prg_title" : "''") . " AS prg_title";
- $fields[] = ($_global['univers'] == 1 ? "id_bien_programme" : "''") . " AS id_bien_programme";
- $fields[] = $this->table_prfx . "_property_type_id";
- $fields[] = $this->table_prfx . "_property_type_id_orig";
- $fields[] = $this->table_prfx . "_property_type";
- $fields[] = $this->table_prfx . "_area";
- $fields[] = $this->table_prfx . "_price";
- $fields[] = $this->table_prfx . "_nb_rooms";
- $fields[] = $this->table_prfx . "_default_text";
- //ad is exclusive
- $fields[] = $this->table_prfx . "_is_exclusive";
- // ad currency
- $fields[] = $this->table_prfx . "_currency";
- // ad pictures
- $fields[] = $this->table_prfx . "_photo";
- $fields[] = $this->table_prfx . "_nb_photo";
- /*
- $fields[] = $this->table_prfx."_photo_2";
- $fields[] = $this->table_prfx."_photo_3";
- $fields[] = $this->table_prfx."_photo_4";
- $fields[] = $this->table_prfx."_photo_5";
- $fields[] = $this->table_prfx."_photo_6";
- $fields[] = $this->table_prfx."_photo_7";
- $fields[] = $this->table_prfx."_photo_8";
- $fields[] = $this->table_prfx."_photo_9";
- $fields[] = $this->table_prfx."_photo_10";
- // ad multimedia
- for ($i = 1; $i < 6; $i ++)
- {
- $fields[] = $this->table_prfx."_mmf_".$i;
- $fields[] = $this->table_prfx."_mmf_type_".$i;
- }
- */
- // ad logicode
- $fields[] = $this->table_prfx . "_logicode";
- $fields[] = $this->table_prfx . "_logicode_old";
- // ad localisation
- $fields[] = $this->table_prfx . "_post_code";
- $fields[] = $this->table_prfx . "_default_town";
- //20091202-1 (2/3) not using T_LOCALITY_LCT_FR table when select town name
- $fields[] = $this->table_prfx . "_default_town_2";
- $fields[] = $this->table_prfx . "_default_town_1";
- $fields[] = $this->table_prfx . "_default_town_0";
- //if($_global['district'] == 1){
- for ($i = 1; $i <= 3; $i++) {
- $fields[] = $this->table_prfx . "_district_id" . $i;
- $fields[] = $this->table_prfx . "_district_name" . $i;
- }
- //}
- /*
- $fields[] = "(IF(t.".$this->table_prfx."_locality_2 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_2))) AS ".$this->table_prfx."_default_town_2";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_1 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_1))) AS ".$this->table_prfx."_default_town_1";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_0 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_0))) AS ".$this->table_prfx."_default_town_0";
- */
- $fields[] = "lgm_id";
- $fields[] = "lgc_id";
- $fields[] = "lgn_id";
- $fields[] = $this->table_prfx . "_country";
- $fields[] = $this->table_prfx . "_default_proximity";
- $fields[] = $this->table_prfx . "_default_sector";
- for ($i = 0; $i < 3; $i++) {
- $fields[] = $this->table_prfx . "_locality_" . $i;
- }
- // ad dates
- $fields[] = $this->table_prfx . "_first_online_date";
- $fields[] = $this->table_prfx . "_update_date";
- //20091202-2 (2/4) not using SELECT when use of DATEDIFF
- $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_first_online_date) AS " . $this->table_prfx . "_days_old";
- // ad pub
- $fields[] = $this->table_prfx . "_pub_code";
- // ad agency
- $fields[] = "id_agence";
- $fields[] = "id_presto";
- $fields[] = $this->table_prfx . "_name_agency";
- // $fields[] = $this->table_prfx."_address_agency";
- $fields[] = $this->table_prfx . "_post_code_agency";
- $fields[] = $this->table_prfx . "_town_agency";
- // $fields[] = $this->table_prfx."_country_agency";
- $fields[] = $this->table_prfx . "_tel_agency";
- $fields[] = $this->table_prfx . "_fax_agency";
- $fields[] = $this->table_prfx . "_email_agency";
- $fields[] = $this->table_prfx . "_site_agency";
- $fields[] = $this->table_prfx . "_rcs_agency";
- $fields[] = $this->table_prfx . "_logo_agency";
- $fields[] = $this->table_prfx . "_franchising_agency";
- //if location/rent we must include charge details (Michel)
- if ($_global["univers"] == 2) {
- $fields[] = $this->table_prfx . "_property_charges";
- $fields[] = $this->table_prfx . "_agency_rent_fees";
- }
- // vacances
- if ($_global["univers"] == 13) {
- $fields[] = $this->table_prfx . "_nb_bedrooms";
- $fields[] = $this->table_prfx . "_nb_people";
- $fields[] = $this->table_prfx . "_partner_url";
- }
- //ad Agency POWERSITE
- $fields[] = $this->table_prfx . "_is_powersite_agency";
- $fields[] = $this->table_prfx . "_powersite_url_agency";
- $fields[] = $this->table_prfx . "_powersite_calltracking_agency";
- /* Ad force order for proximity */
- if ($this->PerimProximit > 0) {
- //$fields[] = "(IF (".$this->table_prfx."_locality_".$this->Proximity_level." = '".$this->FirstLocalityProximity."', 0, 1)) as LocalityProximity, (6366*acos(cos(radians($this->lat1))*cos(radians(".$this->table_prfx."_latitude))*cos(radians(".$this->table_prfx."_longitude)-radians($this->long1))+sin(radians($this->lat1))*sin(radians(".$this->table_prfx."_latitude)))) as DistProximity";
- $fields[] = "(IF (" . $this->table_prfx . "_locality_2 = '" . $this->FirstLocalityProximity . "', 0, 1)) as LocalityProximity, (6366*acos(cos(radians($this->lat1))*cos(radians(" . $this->table_prfx . "_latitude))*cos(radians(" . $this->table_prfx . "_longitude)-radians($this->long1))+sin(radians($this->lat1))*sin(radians(" . $this->table_prfx . "_latitude)))) as DistProximity";
- }
- // recherche avancee
- $fields[] = $this->table_prfx . "_advanced_set";
- // Bandeau personnalisable
- $fields[] = $this->table_prfx . "_personnalisable";
- }
- break;
- // agency fields
- case "agency" :
- // agency extended
- if ($extended == true) {
- // agency all
- $fields[] = "*";
- // agency localisation
- /*
- $fields[] = "(IF(t.".$this->table_prfx."_loc_id_2 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_loc_id_2))) AS ".$this->table_prfx."_town_agency_2";
- $fields[] = "(IF(t.".$this->table_prfx."_loc_id_1 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_loc_id_1))) AS ".$this->table_prfx."_town_agency_1";
- $fields[] = "(IF(t.".$this->table_prfx."_loc_id_0 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_loc_id_0))) AS ".$this->table_prfx."_town_agency_0";
- */
- //20100216-1 (1/2): not using T_LOCALITY_LCT_FR table when select town name for AGC
- $fields[] = $this->table_prfx . "_default_town_2 AS " . $this->table_prfx . "_town_agency_2";
- $fields[] = $this->table_prfx . "_default_town_1 AS " . $this->table_prfx . "_town_agency_1";
- $fields[] = $this->table_prfx . "_default_town_0 AS " . $this->table_prfx . "_town_agency_0";
- // agency ad counts
- $fields[] = "(t." . $this->table_prfx . "_rnt_count + t." . $this->table_prfx . "_sal_count) AS " . $this->table_prfx . "_count";
- }
- // agency standard
- else {
- // agency identifiers
- $fields[] = "id_agence";
- $fields[] = $this->table_prfx . "_id";
- $fields[] = "id_presto";
- $fields[] = $this->table_prfx . "_rcs";
- $fields[] = "agc_is_phonemandatory4contact";
- // agency data
- $fields[] = $this->table_prfx . "_name";
- $fields[] = $this->table_prfx . "_franchising";
- $fields[] = $this->table_prfx . "_company_name";
- $fields[] = $this->table_prfx . "_description";
- // agency premium
- $fields[] = $this->table_prfx . "_is_premium";
- // agency logo & pictures
- $fields[] = $this->table_prfx . "_logo";
- // agency localisation
- $fields[] = $this->table_prfx . "_address";
- $fields[] = $this->table_prfx . "_post_code";
- $fields[] = $this->table_prfx . "_town_agency";
- $fields[] = $this->table_prfx . "_country";
- /*
- $fields[] = "(IF(t.".$this->table_prfx."_loc_id_2 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_loc_id_2))) AS ".$this->table_prfx."_town_agency_2";
- $fields[] = "(IF(t.".$this->table_prfx."_loc_id_1 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_loc_id_1))) AS ".$this->table_prfx."_town_agency_1";
- $fields[] = "(IF(t.".$this->table_prfx."_loc_id_0 = 0, '', (SELECT lct_name".$this->table_locality_lang." lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_loc_id_0))) AS ".$this->table_prfx."_town_agency_0";
- */
- //20100216-1 (2/2): not using T_LOCALITY_LCT_FR table when select town name for AGC
- $fields[] = $this->table_prfx . "_default_town_2 AS " . $this->table_prfx . "_town_agency_2";
- $fields[] = $this->table_prfx . "_default_town_1 AS " . $this->table_prfx . "_town_agency_1";
- $fields[] = $this->table_prfx . "_default_town_0 AS " . $this->table_prfx . "_town_agency_0";
- $fields[] = "lgc_id";
- $fields[] = "lgn_id";
- for ($i = 0; $i < 3; $i++) {
- $fields[] = $this->table_prfx . "_loc_id_" . $i;
- }
- // agency contact
- $fields[] = $this->table_prfx . "_tel";
- $fields[] = $this->table_prfx . "_fax";
- $fields[] = $this->table_prfx . "_email";
- $fields[] = $this->table_prfx . "_site";
- if (AGC_EXCLUSIVE_FRANCHISING != '') {
- if (is_numeric(AGC_EXCLUSIVE_FRANCHISING) && AGC_EXCLUSIVE_FRANCHISING > 0) {
- $fields[] = "(IF({$this->table_prfx}_franchising_id=" . AGC_EXCLUSIVE_FRANCHISING . ", 1, 0)) AS {$this->table_prfx}_franchising_order";
- } else {
- $fields[] = "(IF({$this->table_prfx}_franchising = '" . AGC_EXCLUSIVE_FRANCHISING . "', 1, 0)) AS {$this->table_prfx}_franchising_order";
- }
- } else {
- $fields[] = "0 AS {$this->table_prfx}_franchising_order";
- }
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- // agency ad counts
- $fields[] = "(IF((adp.adp_rnt_count IS NULL), 0, adp.adp_rnt_count)) AS " . $this->table_prfx . "_rnt_count";
- $fields[] = "(IF((adp.adp_sal_count IS NULL), 0, adp.adp_sal_count)) AS " . $this->table_prfx . "_sal_count";
- switch ($this->cumul_ad_for_agency_search) {
- case 2:
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- $fields[] = "(adp.adp_sal_count) AS " . $this->table_prfx . "_count";
- break;
- case 3:
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- $fields[] = "(adp.adp_rnt_count) AS " . $this->table_prfx . "_count";
- break;
- default:
- //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
- $fields[] = "(IF((adp.adp_sal_count+adp.adp_rnt_count) IS NULL, 0, (adp.adp_sal_count+adp.adp_rnt_count))) AS " . $this->table_prfx . "_count";
- break;
- }
- //POWERSITE
- $fields[] = $this->table_prfx . "_is_powersite";
- $fields[] = $this->table_prfx . "_powersite_url";
- $fields[] = $this->table_prfx . "_powersite_calltracking";
- // Projet POLCO (W.ASBAITI 14/01/10)
- $fields[] = $this->table_prfx . "_is_logo";
- $fields[] = $this->table_prfx . "_is_directory";
- $fields[] = $this->table_prfx . "_is_website";
- // Tel obligatoire ou pas
- $fields[] = $this->table_prfx . "_is_phonemandatory4contact";
- }
- break;
- case "refville" :
- // ad identifiers
- $fields[] = "id_annonce";
- $fields[] = "id_presto";
- // ad features
- $fields[] = $this->table_prfx . "_reference";
- $fields[] = $this->table_prfx . "_num_mandat";
- $fields[] = $this->table_prfx . "_first_online_date";
- $fields[] = $this->table_prfx . "_property_type";
- $fields[] = $this->table_prfx . "_property_type_id";
- $fields[] = $this->table_prfx . "_price";
- $fields[] = $this->table_prfx . "_area";
- $fields[] = $this->table_prfx . "_nb_rooms";
- $fields[] = $this->table_prfx . "_photo";
- $fields[] = $this->table_prfx . "_default_text";
- $fields[] = $this->table_prfx . "_default_town";
- $fields[] = $this->table_prfx . "_post_code";
- $fields[] = $this->table_prfx . "_locality_0";
- $fields[] = $this->table_prfx . "_locality_1";
- $fields[] = $this->table_prfx . "_locality_2";
- //20091202-1 (3/3) not using T_LOCALITY_LCT_FR table when select town name
- $fields[] = $this->table_prfx . "_default_town_2";
- $fields[] = $this->table_prfx . "_default_town_1";
- $fields[] = $this->table_prfx . "_default_town_0";
- /*
- $fields[] = "(IF(t.".$this->table_prfx."_locality_2 = 0, '', (SELECT lct_name_fr AS lct_name FROM T_LOCALITY_LCT_FR WHERE lct_id = t.".$this->table_prfx."_locality_2))) AS ".$this->table_prfx."_default_town_2";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_1 = 0, '', (SELECT lct_name_fr AS lct_name FROM T_LOCALITY_LCT_FR WHERE lct_id = t.".$this->table_prfx."_locality_1))) AS ".$this->table_prfx."_default_town_1";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_0 = 0, '', (SELECT lct_name_fr AS lct_name FROM T_LOCALITY_LCT_FR WHERE lct_id = t.".$this->table_prfx."_locality_0))) AS ".$this->table_prfx."_default_town_0";
- */
- $fields[] = "UNIX_TIMESTAMP(" . $this->table_prfx . "_update_date) AS " . $this->table_prfx . "_update_date";
- $fields[] = $this->table_prfx . "_name_agency";
- $fields[] = $this->table_prfx . "_town_agency";
- $fields[] = $this->table_prfx . "_tel_agency";
- $fields[] = $this->table_prfx . "_email_agency";
- $fields[] = "'" . $_global["univers"] . "' AS univers";
- break;
- }
- // concatenates
- $this->select = implode(", ", $fields);
- //var_dump($this->select);
- //die();
- }
- // *** returns select clause including all needed fields ***
- function setGdmSelect() {
- // fields
- $fields = array();
- // ad all
- $fields[] = "*";
- // ad localisation
- /*
- $fields[] = "(IF(t.".$this->table_prfx."_locality_2 = 0, '', (SELECT lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_2))) AS ".$this->table_prfx."_default_town_2";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_1 = 0, '', (SELECT lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_1))) AS ".$this->table_prfx."_default_town_1";
- $fields[] = "(IF(t.".$this->table_prfx."_locality_0 = 0, '', (SELECT lct_name FROM ".$this->table_locality_name." WHERE lct_id = t.".$this->table_prfx."_locality_0))) AS ".$this->table_prfx."_default_town_0";
- */
- //20091202-2
- $fields[] = $this->table_prfx . "_default_town_2 AS " . $this->table_prfx . "_default_town_2";
- $fields[] = $this->table_prfx . "_default_town_1 AS " . $this->table_prfx . "_default_town_1";
- $fields[] = $this->table_prfx . "_default_town_0 AS " . $this->table_prfx . "_default_town_0";
- // ad dates
- //20091202-2 (3/4) not using SELECT when use of DATEDIFF
- $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_update_date) AS " . $this->table_prfx . "_days_old";
- }
- // *** sets query from ***
- //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
- function setFrom($use_data_pondering = false) {
- global $_global;
- $this->from = $this->table_name . " t";
- if ($use_data_pondering) {
- //$this->from .= ", T_AGENCY_DATA_PONDERING_ADP adp ";
- $this->from .= " LEFT OUTER JOIN T_AGENCY_DATA_PONDERING_ADP adp ";
- }
- }
- // *** sets query search criterion ***
- function setIndex(&$force_index, $criterion) {
- switch ($criterion) {
- // AD LOCALITY
- case "locality" :
- if ($this->search_request["loc_key"] != "") {
- $value = $this->search_request["loc_key"];
- // processes
- $value = explode("_", $value);
- // sets index
- switch ($value[1]) {
- // map group
- case 97 :
- $force_index[] = "lgm_id";
- break;
- // code group
- case 98 :
- $force_index[] = "lgc_id";
- break;
- // name group
- case 99 :
- $force_index[] = "lgn_id";
- break;
- // standard
- default :
- $force_index[] = $this->table_prfx . "_locality_" . $value[1];
- break;
- }
- } else {
- $indexes = array();
- for ($i = 1; $i < (SEARCH_FIELDS_NUMBER + 1); $i++) {
- $value = $this->search_request["loc_key" . $i];
- if ($value != "") {
- // processes
- $value = explode("_", $value);
- // sets indexes
- switch ($value[1]) {
- // map group
- case 97 :
- $force_index[] = "lgm_id";
- break;
- // code group
- case 98 :
- $force_index[] = "lgc_id";
- break;
- // name group
- case 99 :
- $force_index[] = "lgn_id";
- break;
- // standard
- default :
- $force_index[] = $this->table_prfx . "_locality_" . $value[1];
- break;
- }
- }
- }
- }
- break;
- // COUNTRY
- case "country" :
- // sets index
- $force_index[] = $this->table_prfx . "_country";
- break;
- // PROPERTY TYPE
- case "property_type" :
- // sets index
- $force_index[] = $this->table_prfx . "_property_type_id";
- break;
- }
- }
- function setWherePropertyTypeVsRoom(&$where) {
- $propertyType = $this->search_request['ck_property_type'];
- $nbRooms = $this->search_request['ck_nb_rooms'];
- $this->search_parameters['ck_property_type'] = $propertyType;
- $this->search_parameters['ck_nb_rooms'] = $nbRooms;
- $sql_part = '';
- if (strpos($nbRooms, '1') !== false) {
- if (strpos($propertyType, '1') !== false) {
- // Construire les couples type de bien / nombre de pieces
- // Ajout du terrain sans pièces
- if ($propertyType[3] == '1')
- $sql_part .= '';
- } else {
- // Renseigner le nombre de pièces sans tenir compte du type de biens
- $this->setWhere($where, 'ck_nb_rooms', $nbRooms);
- }
- } else if (strpos($propertyType, '1') !== false) {
- // Renseigner le type de bien sans tenir compte du nombre de pièces
- $this->setWhere($where, 'ck_nb_rooms', $nbRooms);
- }
- }
- function setLocWhere($value, $i) {
- $this->search_parameters["loc_key" . $i] = implode('_', $value);
- $this->search_parameters["loc_keys"][] = implode('_', $value);
- // stores parameters
- $this->search_parameters["loc_ids"][] = $value[0];
- $this->search_parameters["loc_levels"][] = $value[1];
- switch ($value[1]) {
- // map group
- case 97 :
- $clause = "lgm_id = " . $value[0];
- break;
- // code group
- case 98 :
- $clause = "lgc_id = " . $value[0];
- break;
- // name group
- case 99 :
- $clause = "lgn_id = " . $value[0];
- break;
- // standard
- default :
- $clause = $this->table_prfx . "_locality_" . $value[1] . " = " . $value[0];
- break;
- }
- // add postcode
- $this->addPostCode($value[0], $value[1]);
- return $clause;
- }
- // *** sets query search criterion ***
- function setWhere(&$where, $criterion, $value = "") {
- global $_global;
- if ($value == '' && isset($this->search_request[$criterion]))
- $value = $this->search_request[$criterion];
- switch ($criterion) {
- case "only_old": // Uniquement dans l'ancien
- $clause = $this->table_prfx . "_type_transaction <> 5";
- break;
- // TYPE_TRANSACTION
- case "type_transaction" :
- if ($value > 0) {
- $this->search_parameters["type_transaction"] = $value;
- $clause = $this->table_prfx . "_type_transaction = " . $value;
- $this->isTtypeTransactionAlreadySetInSql = true;
- }
- break;
- //NOM D'AGENCE
- case "agc_name":
- $this->search_parameters["agc_name"] = $value;
- if ($this->table_prfx == 'agc') {
- $value = addslashes($value);
- $clause = 'UPPER(' . $this->table_prfx . "_name) LIKE UPPER('%" . $value . "%')";
- } else {
- $clause = $this->table_prfx . "_agc_name LIKE '%" . $value . "'";
- }
- break;
- // DATE
- case "date" :
- // stores parameters
- $this->search_parameters["date"] = $value;
- // sets clause
- $clause = $this->table_prfx . "_update_date >= '" . $value . "'";
- break;
- // ID
- case "id" :
- if ($value != "") {
- // stores parameters
- $this->search_parameters["id"] = $value;
- // sets clause
- $clause = "id_annonce = '" . $value . "'";
- }
- break;
- // ID_AGENCE
- case "id_agence" :
- if ($value != "") {
- // stores parameters
- $this->search_parameters["id_agence"] = $value;
- // sets clause
- $clause = "id_agence = '" . $value . "'";
- }
- break;
- // ID_AGENCE
- case "grp_id_agence" :
- if (is_array($value) && count($value) > 0) {
- // stores parameters
- $this->search_parameters["grp_id_agence"] = $value;
- // sets clause
- $val = "";
- for ($cnt = 0; $cnt < count($value); $cnt++) {
- $val .= "'" . $value[$cnt] . "' ";
- }
- $val = rtrim($val);
- $val = str_replace(" ", ", ", $val);
- $clause = "id_agence in (" . $val . ")";
- }
- break;
- // LOGICODE
- case "logicode" :
- $clause = $this->table_prfx . "_logicode = '" . $value . "'";
- // $clause .= " AND ".$this->table_prfx."_type_transaction != '3'"; // locations saisonnières
- break;
- // LOGICODE_OLD
- case "logicode_old" :
- $clause = $this->table_prfx . "_logicode_old = '" . $value . "'";
- // $clause .= " AND ".$this->table_prfx."_type_transaction != '3'"; // locations saisonnières
- break;
- // PREMIUM
- case "premium" :
- $clause = $this->table_prfx . "_is_premium = 1";
- break;
- // PREMIUM
- case "exclusive" :
- if ($value > 0) {
- $clause = $this->table_prfx . '_is_exclusive = ' . $value;
- }
- break;
- // AD LOCALITY
- case "locality" :
- if (($this->search_request["loc_key"] != "") && ($this->search_request["loc_key"] != "_")) {
- $value = $this->search_request["loc_key"];
- // stores parameters
- $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
- // $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name"]);
- $this->search_parameters["loc_key"] = $value;
- $this->search_parameters["loc_keys"][] = $value;
- // processes
- $value = explode("_", $value);
- // stores parameters
- $this->search_parameters["loc_ids"][] = $value[0];
- $this->search_parameters["loc_levels"][] = $value[1];
- // sets clause
- switch ($value[1]) {
- // map group
- case 97 :
- $clause = "lgm_id = " . $value[0];
- break;
- // code group
- case 98 :
- $clause = "lgc_id = " . $value[0];
- break;
- // name group
- case 99 :
- $clause = "lgn_id = " . $value[0];
- break;
- // standard
- default :
- $clause = $this->table_prfx . "_locality_" . $value[1] . " = " . $value[0];
- break;
- }
- // add postcode
- $this->addPostCode($value[0], $value[1]);
- } else {
- $clauses = array();
- for ($i = 1; $i < (SEARCH_FIELDS_NUMBER + 1); $i++) {
- $value = $this->search_request["loc_key" . $i];
- if ($value != "") {
- $loc_names[] = $this->search_request["loc_name" . $i];
- // $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name".$i]);
- // processes
- $values = $value;
- $value = explode("_", $value);
- if (($value[0] != "") && ($value[1] != "")) {
- // stores parameters
- $this->search_parameters["loc_key" . $i] = $values;
- $this->search_parameters["loc_keys"][] = $values;
- // stores parameters
- $this->search_parameters["loc_ids"][] = $value[0];
- $this->search_parameters["loc_levels"][] = $value[1];
- // sets clause
- switch ($value[1]) {
- // map group
- case 97 :
- $clauses[] = "lgm_id = " . $value[0];
- break;
- // code group
- case 98 :
- $clauses[] = "lgc_id = " . $value[0];
- break;
- // name group
- case 99 :
- $clauses[] = "lgn_id = " . $value[0];
- break;
- // standard
- default :
- $clauses[] = $this->table_prfx . "_locality_" . $value[1] . " = " . $value[0];
- break;
- }
- // add postcode
- $this->addPostCode($value[0], $value[1]);
- }
- }
- }
- // stores parameters
- if (!isset($this->search_request["loc_name"])) {
- $this->search_parameters["loc_name"] = implode(", ", $loc_names);
- } else {
- $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
- }
- // reorders request parameters
- for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
- unset($this->search_request["loc_key" . $i]);
- //unset($this->search_request["loc_name".$i]);
- }
- for ($i = 0; $i < count($this->search_parameters["loc_keys"]); $i++) {
- $this->search_request["loc_key" . ($i + 1)] = $this->search_parameters["loc_keys"][$i];
- //$this->search_request["loc_name".($i + 1)] = $this->search_parameters["loc_name".($i + 1)];
- }
- // sets clause
- $clause = implode(" OR ", $clauses);
- }
- break;
- // COUNTRY
- case "country" :
- $value = strtoupper($_global["site"]);
- #if($value=='') $value = strtoupper($_global["site"]);
- #else $value = strtoupper($value);
- // stores parameters
- $this->search_parameters["country"] = $value;
- // sets clause
- $clause = $this->table_prfx . "_country = '" . $value . "'";
- break;
- // PROPERTY TYPE
- case "property_type" :
- // stores parameters
- $this->search_parameters["property_type"] = $value;
- // sets clause
- if (is_array($value)) {
- $clause = $this->table_prfx . "_property_type_id IN (" . implode(", ", $value) . ")";
- } elseif ($value > 0) {
- $clause = $this->table_prfx . "_property_type_id = " . $value;
- }
- break;
- // STATUS
- case "ad_status" :
- if ($this->table_name != "TM_SAL_FR" && $this->table_name != "TM_RNT_FR") {
- $clause = $this->table_prfx . "_ad_status >= 0";
- }
- break;
- case "ad_in_nav_lang" :
- //$clause = "t.sal_ai_id=lg.sal_ai_id AND lg.tad_language='".strtoupper($_global["lang"])."' AND lg.tad_text<>''";
- $clause = "lg.tad_language='" . strtoupper($_global["lang"]) . "'";
- break;
- // visuel photo
- case "photo" :
- $clause = $this->table_prfx . "_nb_photo > 0";
- break;
- // LEGAL TYPE
- case "property_ownership_type" :
- // stores parameters
- $this->search_parameters["property_ownership_type"] = $value;
- if (is_array($value)) {
- $clause = $this->table_prfx . "_id_property_ownership_type IN (" . implode(", ", $value) . ")";
- } else {
- $clause = $this->table_prfx . "_id_property_ownership_type IN (" . $value . ")";
- }
- break;
- case "perimproximit" :
- /* $clause = " lct_name_fr in (SELECT * FROM (SELECT lct_name,
- (6366*acos(cos(radians($this->lat1))*cos(radians(lct_lat))*cos(radians(lct_long)-radians($this->long1))+sin(radians($this->lat1))*sin(radians(lct_lat))))
- as Proximite from LOC_LOOKUP_FR) AS GLO where Proximite<='$this->PerimProximit' order by Proximite"; */
- $clause = $this->table_prfx . "_locality_2 IN (" . $this->list_lock_proximite . ")";
- break;
- // vacances
- case "nb_bedrooms" :
- $value = (int) $value;
- if ($value >= 0) {
- if ($value == 9) {
- $clause = $this->table_prfx . "_nb_bedrooms >= 10";
- } else {
- $clause = $this->table_prfx . "_nb_bedrooms = " . ($value + 1);
- }
- $this->search_parameters["nb_bedrooms"] = $value;
- }
- break;
- case "nb_people" :
- if ($value != "") {
- $value = (int) $value;
- switch ($value) {
- case 0 :
- $clause = $this->table_prfx . "_nb_people BETWEEN 1 AND 5";
- break;
- case 1 :
- $clause = $this->table_prfx . "_nb_people BETWEEN 4 AND 7";
- break;
- case 2 :
- $clause = $this->table_prfx . "_nb_people BETWEEN 6 AND 9";
- break;
- case 3 :
- $clause = $this->table_prfx . "_nb_people BETWEEN 8 AND 12";
- break;
- case 4 :
- $clause = $this->table_prfx . "_nb_people > 11";
- break;
- }
- $this->search_parameters["nb_people"] = $value;
- }
- break;
- case "refville_field" : // champs de localisation des annonces dans T_RENTAD_RNT et T_SALESAD_SAL
- $lct_value = $value["lct_val"];
- if (isset($value["lct_lvl"])) { // peut être "empty"
- $lct_level = $value["lct_lvl"];
- // calcul du bon nom de champ en fonction du niveau
- if ($lct_level == "99") {
- $lct_field = "lgn_id";
- } else if ($lct_level == "98") {
- $lct_field = "lgc_id";
- } else { // 1 ou 2 a priori
- if (($lct_value == "100") && ($lct_level == "1")) { // Paris
- $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . "locality_1";
- } else { // autre ville
- $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . "locality_" . $lct_level;
- }
- }
- } else if (isset($value["lct_field"]) && !empty($value["lct_field"])) {
- $lct_field = $value["lct_field"];
- // calcul du bon nom de champ en fonction de celui qui a été donné et qui est peut-être erroné
- if ($lct_field == "lct_id") {
- $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . "locality_2";
- }
- // rajout du préfixe pour les "localiy_" si nécessaire
- if (string_begins_with($lct_field, "locality_")) {
- $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . $lct_field;
- }
- }
- $clause = $lct_field . " = " . $lct_value;
- //echo "[clause=".$clause."]";
- break;
- case "refville_locality" :
- $clause = $this->table_prfx . "_locality_2 > 0";
- break;
- case "post_code_departem" :
- if ($value == "98") { // Monaco
- $clause = $this->table_prfx . "_post_code = '98000'";
- } else { // départements
- $clause = $this->table_prfx . "_post_code LIKE '" . $value . "%'";
- }
- break;
- // PROPERTY TYPE
- case "ck_property_type" :
- // stores parameters
- $this->search_parameters["ck_property_type"] = $value;
- $length = strlen($value);
- // Traitement particulier du type viager
- if ($value[$length - 1] == '1') {
- $ignore_viager = false;
- $value[$length - 1] = '0';
- }
- else
- $ignore_viager = true;
- if (strpos($value, '1') !== false) {
- $ids = array();
- for ($i = 0; $i < $length; $i++) {
- if ($value[$i] == '1')
- $ids[] = $i + 1;
- }
- //$clause = $this->table_prfx."_property_type_id_orig IN (".implode(", ", $ids).") AND ".$this->table_prfx."_type_transaction <> 4";
- //if( $clause_viager!='' ) $clause .= ') OR ('.$clause_viager;
- $clause = $this->table_prfx . "_property_type_id_orig IN (" . implode(", ", $ids) . ")";
- if ($ignore_viager && !$this->isTtypeTransactionAlreadySetInSql)
- $clause .= ") AND (" . $this->table_prfx . "_type_transaction <> 4";
- }
- // Sinon, pas de filtre sur les types de bien
- elseif (!$ignore_viager && !$this->isTtypeTransactionAlreadySetInSql)
- $clause = $this->table_prfx . "_type_transaction = 4";
- break;
- // CRITERES AVANCES
- case "ck_advanced" :
- // stores parameters
- $this->search_parameters["ck_advanced"] = $value;
- $length = strlen($value);
- if (strpos($value, '1') !== false) {
- /*
- *
- * Attention :
- * PHP complète les valeurs par des 0 à droite avec l'opération binaire,
- * contrairement à MYSQL qui complète à gauche
- *
- *
- * Instructions :
- *
- * Utiliser une opération de type binaire AND
- * advanced_set & X = X, où X est un nombre décimal ou binaire
- *
- * Utiliser une opération de type binaire OR
- * advanced_set & X, où X est un nombre décimal ou binaire
- *
- */
- $length = strlen($value);
- $clause = '';
- global $_MASK_ADV_OR;
- foreach ($_MASK_ADV_OR as $mask_or) {
- $mask_value = $value & $mask_or;
- // Ajouter la clause OU du chauffage
- if ($mask_value > 0) {
- // Equivalent d'un NON + compléter avec des 1 pour le ET ci-dessous
- $remove_mask = str_pad(strtr($mask_value, '01', '10'), $length, 1);
- // Effacer les critères de chauffage du masque principal
- $value = $value & $remove_mask;
- // Ajouter l'opération binaire, avec la chaine dans le bon sens
- $mask_value = strrev(rtrim($mask_value, '0'));
- $clause .= ' AND ' . $this->table_prfx . "_advanced_set & b'{$mask_value}'";
- }
- }
- // Traiter ensuite tout le reste comme des champs requis (ET logique)
- if ($value > 0) {
- // Envoyer l'opération binaire, avec la chaine dans le bon sens
- $value = strrev(rtrim($value, '0'));
- $clause .= ' AND ' . $this->table_prfx . "_advanced_set & b'{$value}' = b'{$value}'";
- }
- $clause = substr($clause, 5);
- $this->isAdvancedSearch = true;
- }
- break;
- // NB ROOMS
- case "ck_nb_rooms" :
- // stores parameters
- $this->search_parameters["ck_nb_rooms"] = $value;
- if ($_global['univers'] == 8)
- $champs = '_nb_bedrooms'; else
- $champs = '_nb_rooms';
- if (strpos($value, '1') !== false) {
- $ids = array();
- // Le dernier nombre avant le "et plus"
- $last_single_num = 5;
- for ($i = 0; $i < $last_single_num; $i++) {
- if ($value[$i] == '1')
- $ids[] = $i + 1;
- }
- // Si aucun autre nombre est coché
- if ($ids == array()) {
- // Si le "et plus" est coché
- if ($value[$last_single_num] == '1')
- $clause .= $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
- // Sinon, aucun filtre
- }
- // Si d'autre nombres sont cochés
- else {
- $clause = $this->table_prfx . $champs . " IN (" . implode(", ", $ids) . ")";
- // Si le sixieme est coche, ajouter le OR
- if ($value[$last_single_num] == '1')
- $clause .= ' OR ' . $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
- }
- }
- break;
- // NB ROOMS
- case "ck_nb_bedrooms" :
- // stores parameters
- $this->search_parameters["ck_nb_bedrooms"] = $value;
- $champs = '_nb_bedrooms';
- if (strpos($value, '1') !== false) {
- $ids = array();
- // Le dernier nombre avant le "et plus"
- $last_single_num = 5;
- for ($i = 0; $i < $last_single_num; $i++) {
- if ($value[$i] == '1')
- $ids[] = $i + 1;
- }
- // Si aucun autre nombre est coché
- if ($ids == array()) {
- // Si le "et plus" est coché
- if ($value[$last_single_num] == '1') {
- $clause .= $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
- }
- // Sinon, aucun filtre
- }
- // Si d'autre nombres sont cochés
- else {
- $clause = $this->table_prfx . $champs . " IN (" . implode(", ", $ids) . ")";
- // Si le sixieme est coche, ajouter le OR
- if ($value[$last_single_num] == '1') {
- $clause .= ' OR ' . $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
- }
- }
- //$this->isAdvancedSearch = true;
- }
- break;
- // SURFACE DU TERRAIN
- case 'surf':
- $value_min = $this->search_request["surf_min"];
- $value_max = $this->search_request["surf_max"];
- // stores parameters
- $this->search_parameters["surf_min"] = "" . $value_min;
- $this->search_parameters["surf_max"] = "" . $value_max;
- // On a une valeur min ?
- if ($value_min != "") {
- // Et on a une valeur max ?
- if ($value_max != "") {
- // restores order
- if ($value_min > $value_max) {
- $value_tmp = $value_min;
- $value_min = $value_max;
- $value_max = $value_tmp;
- }
- $clause = $this->table_prfx . "_garden_area BETWEEN " . $value_min . " AND " . $value_max;
- // Seulement le min
- } else {
- $clause = $this->table_prfx . "_garden_area >= " . $value_min;
- }
- $this->isAdvancedSearch = true;
- // Seulement le max ?
- } elseif ($value_max != "") {
- $clause = $this->table_prfx . "_garden_area <= " . $value_max;
- $this->isAdvancedSearch = true;
- }
- break;
- // PRICE, AREA, NB_ROOMS
- case 'price':
- case 'area':
- case 'nb_rooms':
- $value_min = $this->search_request[$criterion . "_min"];
- $value_max = $this->search_request[$criterion . "_max"];
- // stores parameters
- $this->search_parameters[$criterion] = $value;
- $this->search_parameters[$criterion . "_min"] = "" . $value_min;
- $this->search_parameters[$criterion . "_max"] = "" . $value_max;
-
- // sets clause
- if ($value != "") {
- if ($criterion == "nb_rooms") {
- if (is_array($this->search_request[$criterion])) {
- $value_unique = array_unique($value); // supprime les doublons
- if (count($value_unique) > 1) {
- $clause = $this->table_prfx . "_" . $criterion . " IN (" . implode(", ", $value_unique) . ")";
- } else if (sizeof($value_unique) == 1) {
- $clause = $this->table_prfx . "_" . $criterion . " = " . $value_unique[0];
- }
- } else {
- $clause = $this->table_prfx . "_" . $criterion . ($value == 0 ? " = " : " >= ") . ($value + 1);
- }
- }
- } else {
-
- if ($value_min != "" && $value_max != "") {
- // restores order
- if ($value_min > $value_max) {
- $value_tmp = $value_min;
- $value_min = $value_max;
- $value_max = $value_tmp;
- }
- $this->search_parameters[$criterion . "_min"] = $value_min;
- $this->search_parameters[$criterion . "_max"] = $value_max;
- $clause = $this->table_prfx . "_" . $criterion . " BETWEEN " . $value_min . " AND " . $value_max;
-
- } else {
- if ($value_min != "") {
- $clause = $this->table_prfx . "_" . $criterion . " >= " . $value_min;
- } elseif ($value_max != "") {
- $clause = $this->table_prfx . "_" . $criterion . " <= " . $value_max;
- }
- }
- }
- // sets price minimum, for everything else than parkings
- if ($criterion == "price" && $this->search_request["property_type"][0] != 7) {
- $price_clause = $this->table_prfx . "_price > " . constant("MIN_PRICE_" . strtoupper($this->table_prfx));
- $clause .= ($clause != "" ? ") AND (" : "") . $price_clause;
- }
- break;
- // AG LOCALITY
- case "ag_locality" :
- if (($this->search_request["loc_key"] != "") && ($this->search_request["loc_key"] != "_")) {
- $value = $this->search_request["loc_key"];
- // stores parameters
- $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
- $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name"]);
- $this->search_parameters["loc_key"] = $value;
- $this->search_parameters["loc_keys"][] = $value;
- // processes
- $value = explode("_", $value);
- // stores parameters
- $this->search_parameters["loc_ids"][] = $value[0];
- $this->search_parameters["loc_levels"][] = $value[1];
- // sets clause
- switch ($value[1]) {
- // map group
- case 97 :
- $clause = "lgm_id = " . $value[0];
- break;
- // code group
- case 98 :
- $clause = "lgc_id = " . $value[0];
- break;
- // name group
- case 99 :
- $clause = "lgn_id = " . $value[0];
- break;
- // standard
- default :
- $clause = $this->table_prfx . "_loc_id_" . $value[1] . " = " . $value[0];
- break;
- }
- /* Patch Specifique pour Marseille(421) et Lyon(422) */
- switch ($value[0]) {
- case 19667:
- $clause = "lgn_id = 421";
- break;
- case 18897:
- $clause = "lgn_id = 422";
- break;
- default:
- break;
- }
- // add postcode
- $this->addPostCode($value[0], $value[1]);
- } else {
- $clauses = array();
- for ($i = 1; $i < (SEARCH_FIELDS_NUMBER + 1); $i++) {
- $value = $this->search_request["loc_key" . $i];
- if ($value != "") {
- $loc_names[] = $this->search_request["loc_name" . $i];
- // $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name".$i]);
- // processes
- $values = $value;
- $value = explode("_", $value);
- if (($value[0] != "") && ($value[1] != "")) {
- // stores parameters
- $this->search_parameters["loc_key" . $i] = $values;
- $this->search_parameters["loc_keys"][] = $values;
- // stores parameters
- $this->search_parameters["loc_ids"][] = $value[0];
- $this->search_parameters["loc_levels"][] = $value[1];
- // sets clause
- switch ($value[1]) {
- // map group
- case 97 :
- $clauses[] = "lgm_id = " . $value[0];
- break;
- // code group
- case 98 :
- $clauses[] = "lgc_id = " . $value[0];
- break;
- // name group
- case 99 :
- $clauses[] = "lgn_id = " . $value[0];
- break;
- // standard
- default :
- $clauses[] = $this->table_prfx . "_loc_id_" . $value[1] . " = " . $value[0];
- break;
- }
- // add postcode
- $this->addPostCode($value[0], $value[1]);
- }
- }
- }
- // stores parameters
- if (!isset($this->search_request["loc_name"])) {
- $this->search_parameters["loc_name"] = implode(", ", $loc_names);
- } else {
- $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
- }
- // reorders request parameters
- for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
- unset($this->search_request["loc_key" . $i]);
- //unset($this->search_request["loc_name".$i]);
- }
- for ($i = 0; $i < count($this->search_parameters["loc_keys"]); $i++) {
- $this->search_request["loc_key" . ($i + 1)] = $this->search_parameters["loc_keys"][$i];
- //$this->search_request["loc_name".($i + 1)] = $this->search_parameters["loc_name".($i + 1)];
- }
- // sets clause
- $clause = implode(" OR ", $clauses);
- }
- break;
- // AG COUNT
- case "ag_count" :
- //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
- //$clause = $this->table_prfx."_rnt_count > 0 OR ".$this->table_prfx."_sal_count > 0";
- $clause = "adp.adp_id_presto = t.id_presto AND (adp.adp_rnt_count > 0 OR adp.adp_sal_count > 0)";
- /*
- // FP. 03/02/11 - Disable showing exclusive agencies even if they don't have announces
- if(AGC_EXCLUSIVE_FRANCHISING!='') {
- if(is_numeric(AGC_EXCLUSIVE_FRANCHISING) && AGC_EXCLUSIVE_FRANCHISING>0) {
- $clause .= ' OR agc_franchising_id='.AGC_EXCLUSIVE_FRANCHISING;
- } else {
- $clause .= " OR agc_franchising='".AGC_EXCLUSIVE_FRANCHISING."'";
- }
- }
- */
- break;
- // Consommation énergétique
- case "dpe" :
- $this->search_parameters['dpe'] = $value;
- break;
- // Fraicheur des annonces
- case "fresh" :
- $this->search_parameters['fresh'] = $value;
- break;
- case "lct_post_code" :
- if ($value) {
- $clause = $this->table_prfx . "_lct_post_code = " . $value;
- }
- break;
- }
- // adds clause
- if ($clause != "") {
- $where[] = "(" . $clause . ")";
- }
- $this->global_where = $where;
- }
- /**
- * Function setOrderAgencyAds : uniquement pour l'univers 9 (annonces ventes + location)
- *
- * @param type $sOrder : field to "order by"
- */
- function setOrderAgencyAds($sOrder) {
- $default_order = false;
- if (!empty($sOrder)) {
- if ($this->PerimProximit > 0) {
- $sOrder = $this->order[] = "LocalityProximity ASC";
- $sOrder = $this->order[] = "DistProximity ASC";
- }
- $aOrders = array("update_date", "property_type", "price", "area", "nb_rooms");
- if ($sOrder == "post_code") {
- $aOrders[] = "post_code";
- }
- if (!in_array($sOrder, $aOrders)) {
- $sOrder = "price";
- }
- } else {
- // TRI PAR PRIX DESC PAR DEFAUT
- $sOrder = "price";
- $this->search_request['order'] = 'price';
- $this->search_request['hi_order'] = 0; // DESC
- $default_order = true;
- }
- if ($default_order) { // Si tri par defaut, on affiche les vene en premier
- $this->order[] = " univ ASC";
- }
- // default order
- $this->order[] = $sOrder . " " . ($this->search_request['hi_order'] == 1 ? 'DESC' : 'ASC');
- if (($sOrder == "post_code")) {
- $this->order[] = "price DESC";
- }
- // optional order
- if (($sOrder != "update_date") && (!isset($this->search_request["order_price"]))) {
- $this->order[] = "update_date DESC";
- }
- }
- // *** sets query order clause ***
- function setOrder($mode, $order, $field = "") {
- global $_global;
- switch ($mode) {
- // ad order
- case "ad" :
- if ($order != "") {
- if ($this->PerimProximit > 0) {
- $order = $this->order[] = "LocalityProximity ASC";
- $order = $this->order[] = "DistProximity ASC";
- }
- // array of authorized sort fields
- if ($_global["univers"] == 13) {
- $orders = array("update_date", "property_type", "price", "nb_bedrooms", "nb_people");
- } else {
- $orders = array("update_date", "property_type", "price", "area", "nb_rooms");
- if ($order == "post_code") {
- // array_push($orders, $order);
- $orders[] = "post_code";
- }
- }
- // only adds if required order field is allowed
- if (!in_array($order, $orders)) {
- $order = "price";
- }
- } else {
- $order = "price";
- $this->search_request['hi_order'] = 0; // ASC
- }
- $direction = ($this->search_request["hi_order"] == 1 ? "DESC" : "ASC");
- // default order
- $this->order[] = $this->table_prfx . "_" . $order . " " . $direction;
- if (($order == "post_code") || ($_global["self"] == "resultats_refnat.php")) {
- $this->order[] = $this->table_prfx . "_price " . $direction;
- }
- // optional order
- if (($order != "update_date") && (!isset($this->search_request["order_price"]))) {
- $this->order[] = $this->table_prfx . "_update_date DESC";
- }
- if ($_global["self"] == "resultats_refnat.php") {
- $this->order = array();
- $this->order[] = $this->table_prfx . "_update_date DESC";
- }
- break;
- case "filter_ad" :
- if (!isset($this->order)) {
- $this->order = array();
- }
- $direction = ($order == 1 ? "DESC" : "ASC");
- $orderthis = $this->table_prfx . "_" . $field . " " . $direction;
- if (!in_array($orderthis, $this->order)) {
- $this->order[] = $orderthis;
- }
- break;
- // agency order
- case "agency" :
- $user_ihm = json_decode($_COOKIE[USER_DATA_IHM_COOKIE_NAME], true);
- $allowedOrder = array('count', 'name');
- if (isset($user_ihm['hi_order']) && in_array($user_ihm['order'], $allowedOrder)) {
- $direction = ((int) $user_ihm['hi_order'] > 0 ? 'DESC' : 'ASC');
- $order = $user_ihm['order'];
- //order == 1 tri croissant
- //order == 0 tri décroissant
- } else {
- if (AGC_EXCLUSIVE_FRANCHISING != '') { // ORPI en haut de list si pas de tri
- $this->order[] = $this->table_prfx . '_franchising_order DESC';
- }
- //Tri par defaut
- $direction = 'DESC';
- $order = 'count';
- // $this->order[] = 'agc_count DESC';
- }
- // default order
- $this->order[] = $this->table_prfx . "_" . $order . " " . $direction;
- break;
- case "random" :
- $this->order[] = "rand()";
- break;
- }
- // stores parameter
- if ($mode <> "filter_ad") {
- $this->search_parameters["order"] = $order;
- $this->search_request["order"] = $order;
- }
- }
- // *** sets query limit ***
- /**
- *
- * @global type $_global
- * @param type $mode
- * @param type $offset
- * @param type $limit
- */
- function setLimit($mode, $offset, $limit = 5) {
- global $_global;
-
-
- if ($mode == "ad") {
- $max_results = ($this->is_agency_search ? MAX_RESULTS_AGENCY : MAX_RESULTS);
- // N° de page a afficher moins 1 pour gérer le Limit
- if (!isset($_global['powersite']) || $_global['powersite'] <> 1) {
- $offset = $offset - 1;
- }
- if ($offset < 0) {
- $offset = 0;
- }
- } elseif ($mode == "adHomeGallery") {
- $max_results = 4; //MAX_RESULTS_AGENCY;
- } else {
- $max_results = MAX_RESULTS_AGENCY;
- }
- $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
-
- $count = $max_results_per_page;
- $count = $max_results_per_page - ($this->has_premium == true ? 1 : 0) - ($this->has_exclusive == true ? 1 : 0);
- //$count = $max_results_per_page;
- //$offset = $offset - ($this->has_premium == true ? 1 : 0);
- $start = $offset * $count;
-
-
- if ($start + $count > $max_results) {
- $count = $max_results - $start;
- }
- if ($mode == "free") {
- $max_results_per_page = $limit;
- $start = $offset;
- }
- if ($count < 0) {
- $count = MAX_RESULTS_PER_PAGE;
- }
- //modification pierre : calcul limit
- if ($_REQUEST['offset']==1) {
- setcookie('nbAdFirstPage', $count);
- } else if (isset($_COOKIE['nbAdFirstPage'])) {
- $start = $_COOKIE['nbAdFirstPage']+($_REQUEST['offset']-2)*$count;
- }
- $this->limit = $start . ", " . $count;
-
- }
- // *** sets post codes ***
- function setPostCodes() {
- global $_global;
- if (count($this->loc_keys) > 0) {
- $this->search_parameters["lzip"] = array();
- $i = 0;
- //debug2($this->loc_keys);
- foreach ($this->loc_keys as $loc_key) {
- // AGU 30/09
- if ($this->search_parameters["loc_levels"][$i] == 97) {
- // builds the query
- $query = "SELECT lgm_parent_id AS lct_parent_id, lgm_name" . $this->table_locality_lang . " AS lct_name, lgm_post_code AS lct_post_code ";
- $query .= "FROM T_LOCGROUPMAP_LGM_" . strtoupper($_global["site"]) . " ";
- $query .= "WHERE " . $loc_key;
- } else {
- // builds the query
- $query = "SELECT lct_parent_id, lct_name" . $this->table_locality_lang . " AS lct_name, lct_post_code, lgc_id, lgn_id ";
- $query .= "FROM " . $this->table_locality_name . " ";
- $query .= "WHERE " . $loc_key;
- }
- // executes the query
- if ($_global["debug"] == 3) {
- echo "setPostCodes()<br />";
- echo $query . "<br />";
- echo "<hr />";
- }
- $locality = pdoquery($query);
- // set
- $this->search_parameters["loc_names"][] = $locality[0]["lct_name"];
- // set post_code
- if ($this->search_parameters["loc_levels"][0] == 99) {
- $lzips = array();
- for ($j = 0; $j < count($locality); $j++) {
- $lzips[] = $locality[$j]["lct_post_code"];
- }
- $this->search_parameters["lzip"][] = implode(", ", $lzips);
- // agu 14/08/2009
- $this->search_request["lzips"][] = implode(", ", $lzips);
- } else {
- $this->search_parameters["lzip"][] = $locality[0]["lct_post_code"];
- // agu 14/08/2009
- $this->search_request["lzips"][] = $locality[0]["lct_post_code"];
- }
- //
- $this->search_parameters["lgc_ids"][] = $locality[0]["lgc_id"];
- //
- $this->search_parameters["lgn_ids"][] = $locality[0]["lgn_id"];
- // set department code
- $this->search_parameters["szip"][] = substr($locality[0]["lct_post_code"], 0, 2);
- // agu 14/08/2009
- $this->search_request["szips"][] = substr($locality[0]["lct_post_code"], 0, 2);
- // set parent id
- $this->search_parameters["loc_parent_ids"][] = $locality[0]["lct_parent_id"];
- $i++;
- }
- $this->search_request["szip"] = get_zip_code($this->search_parameters, "szip");
- $this->search_request["lzip"] = get_zip_code($this->search_parameters, "lzip");
- $this->setLocalityHierarchy();
- }
- }
- // *** sets locality hierarchy
- function setLocalityHierarchy() {
- global $_global;
- switch ($this->search_parameters["loc_levels"][0]) {
- case 0 :
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $this->search_parameters["loc_levels"][0], "lct_name" => $this->search_parameters["loc_names"][0], "lct_post_code" => $this->search_parameters["lzip"][0], "lct_id" => $this->search_parameters["loc_ids"][0]);
- break;
- case 1 :
- // builds the query
- $query = "SELECT lct_level, lct_name" . $this->table_locality_lang . " lct_name, lct_post_code, lct_id ";
- $query .= "FROM " . $this->table_locality_name . " ";
- $query .= "WHERE lct_id = " . $this->search_parameters["loc_parent_ids"][0];
- // executes the query
- if ($_global["debug"] == 3) {
- echo "setLocalityHierarchy()<br />";
- echo $query . "<br />";
- echo "<hr />";
- }
- $locality = pdoquery($query);
- // set
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $locality[0]["lct_level"], "lct_name" => $locality[0]["lct_name"], "lct_post_code" => $locality[0]["lct_post_code"], "lct_id" => $locality[0]["lct_id"]);
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $this->search_parameters["loc_levels"][0], "lct_name" => $this->search_parameters["loc_names"][0], "lct_post_code" => $this->search_parameters["lzip"][0], "lct_id" => $this->search_parameters["loc_ids"][0]);
- break;
- default :
- // builds the query
- $query = "SELECT lct_level, lct_name" . $this->table_locality_lang . " lct_name, lct_post_code, lct_id ";
- $query .= "FROM " . $this->table_locality_name . " ";
- if ($this->search_parameters["loc_parent_ids"][0] != "")
- $query .= "WHERE lct_id IN (" . $this->search_parameters["loc_parent_ids"][0] . ", (SELECT t.lct_parent_id FROM " . $this->table_locality_name . " t WHERE t.lct_id = " . $this->search_parameters["loc_parent_ids"][0] . ")) ";
- $query .= "ORDER BY lct_level";
- // executes the query
- if ($_global["debug"] == 3) {
- echo "setLocalityHierarchy()<br />";
- echo $query . "<br />";
- echo "<hr />";
- }
- $localities = pdoquery($query);
- // set
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $localities[0]["lct_level"], "lct_name" => $localities[0]["lct_name"], "lct_post_code" => $localities[0]["lct_post_code"], "lct_id" => $localities[0]["lct_id"]);
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $localities[1]["lct_level"], "lct_name" => $localities[1]["lct_name"], "lct_post_code" => $localities[1]["lct_post_code"], "lct_id" => $localities[1]["lct_id"]);
- switch ($this->search_parameters["loc_levels"][0]) {
- // map group
- case 97 :
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $this->search_parameters["loc_levels"][0], "lct_name" => $this->search_parameters["loc_names"][0], "lct_post_code" => $this->search_parameters["lzip"][0], "lct_id" => $this->search_parameters["loc_ids"][0]);
- break;
- // code group
- case 98 :
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $this->search_parameters["loc_levels"][0], "lct_name" => LABEL_LGC_ALL, "lct_post_code" => $this->search_parameters["lzip"][0], "lct_id" => $this->search_parameters["loc_ids"][0]);
- break;
- // name group
- case 99 :
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $this->search_parameters["loc_levels"][0], "lct_name" => $this->search_parameters["loc_names"][0], "lct_post_code" => LABEL_LGN_ALL, "lct_id" => $this->search_parameters["loc_ids"][0]);
- break;
- // standard
- default :
- $this->search_parameters["loc_hierarchy"][] = array("lct_level" => $this->search_parameters["loc_levels"][0], "lct_name" => $this->search_parameters["loc_names"][0], "lct_post_code" => $this->search_parameters["lzip"][0], "lct_id" => $this->search_parameters["loc_ids"][0]);
- break;
- }
- break;
- }
- }
- // *** sets coordinates ***
- function setCoordinates() {
- $query = "SELECT lct_lat, lct_long ";
- $query .= "FROM " . $this->table_locality_name . " ";
- $query .= "WHERE lct_id = ";
- }
- // *** sets number of pages ***
- function setPages($mode) {
- global $_global;
- if ($mode == "ad") {
- $max_results = ($this->is_agency_search ? MAX_RESULTS_AGENCY : MAX_RESULTS);
- } else {
- $max_results = MAX_RESULTS_AGENCY;
- }
- $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
- //$max_results_per_page = $max_results_per_page - ($this->has_premium == true ? 1 : 0);
-
- //echo "<pre>"; print_r($_REQUEST);echo "</pre>";
- if (isset($_REQUEST['user_data_ihm'])) {
- $anbPages = json_decode($_REQUEST['user_data_ihm'], true);
- $anbPages = $anbPages['nb_results'];
- if ($anbPages == NULL) {
- $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
- } else {
- $max_results_per_page = $anbPages;
- }
- } else {
- $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
- }
-
- $count = $this->search_count;
-
-
- if ($count >= $max_results) {
- $count = $max_results;
- }
-
- $nbPages = ceil($count / $max_results_per_page);
-
-
-
- if ($this->search_parameters['premiumPresente']) {
-
- $max_results_per_page = $max_results_per_page - 1;
- $nbPages = ceil($count / $max_results_per_page);
-
- }
-
- $this->search_parameters["pages"] = $nbPages;
- $this->search_request["pages"] = $nbPages;
- }
- // *** sets request ***
- function setRequest($http_request) {
- //var_dump($http_request); die;
- global $_global;
- if ($this->enableSearch($http_request) == true) {
- $request = array();
- if ($http_request["loc_name"] != "") {
- $request["loc_name"] = $http_request["loc_name"];
- } else {
- $loc_names = array();
- for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
- if ($http_request["loc_name" . $i] != "" && $http_request["loc_name" . $i] != LABEL_DEFAULT_LOCALITY) {
- $loc_names[] = $http_request["loc_name" . $i];
- }
- $request["loc_name" . $i] = $http_request["loc_name" . $i];
- }
- $request["loc_name"] = implode(", ", $loc_names);
- }
- // loc_keys
- if ($http_request["loc_key"] != "") {
- $request["loc_key"] = $http_request["loc_key"];
- } else {
- for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
- $request["loc_key" . $i] = $http_request["loc_key" . $i];
- $request["loc_name" . $i] = $http_request["loc_name" . $i];
- }
- }
- if (empty($_REQUEST['old'])) {
- if (isset($http_request["ck_property_type"]))
- $request["ck_property_type"] = $http_request["ck_property_type"];
- if (isset($http_request["ck_nb_rooms"]))
- $request["ck_nb_rooms"] = $http_request["ck_nb_rooms"];
- if (isset($http_request["ck_nb_bedrooms"]))
- $request["ck_nb_bedrooms"] = $http_request["ck_nb_bedrooms"];
- if (isset($http_request["ck_advanced"]))
- $request["ck_advanced"] = $http_request["ck_advanced"];
- }
- else {
- if (isset($http_request["property_type"]))
- $request["ck_property_type"] = convert_property_value($http_request["property_type"], 40);
- if (isset($http_request["nb_rooms"]))
- $request["ck_nb_rooms"] = convert_nb_rooms($http_request["nb_rooms"], $http_request["nb_rooms_min"], $http_request["nb_rooms_max"], 40);
- }
- $parameters = array("area", "price", "surf");
- foreach ($parameters as $parameter) {
- if ($http_request[$parameter] != "") {
- $request[$parameter] = $http_request[$parameter];
- }
- if ($http_request[$parameter . "_min"] != "") {
- $request[$parameter . "_min"] = $http_request[$parameter . "_min"];
- }
- if ($http_request[$parameter . "_max"] != "") {
- $request[$parameter . "_max"] = $http_request[$parameter . "_max"];
- }
- }
- if ($http_request["property_ownership_type"] != "") {
- $request["property_ownership_type"] = $http_request["property_ownership_type"];
- }
- // advanced search parameters
- if ($http_request["with_mmf"] != "") {
- $request["with_mmf"] = $http_request["with_mmf"];
- }
- if (isset($http_request["dpe"]))
- $request["dpe"] = $http_request["dpe"];
- if (isset($http_request["fresh"]))
- $request["fresh"] = $http_request["fresh"];
- // order_pages (cz)
- if ($http_request["order_pages"] != "") {
- $request["order_pages"] = $http_request["order_pages"];
- }
- // szip
- if ($http_request["szip"] != "") {
- $request["szip"] = $http_request["szip"];
- }
- // lzip
- if ($http_request["lzip"] != "") {
- $request["lzip"] = $http_request["lzip"];
- }
- // id agence
- if ($http_request["id_agence"] != "") {
- $request["id_agence"] = $http_request["id_agence"];
- }
- //use map for cz
- if ($http_request["use_map"] != "") {
- $request["use_map"] = $http_request["use_map"];
- }
- if ($http_request["agc_name"] != "") {
- $request["agc_name"] = $http_request["agc_name"];
- }
- // order
- $request["order"] = $http_request["order"];
- if (isset($http_request["order_price"])) {
- if ($http_request["order_price"] == "") {
- $http_request["order_price"] = 1;
- }
- $request["order_price"] = $http_request["order_price"];
- }
- if ($http_request["order2"] != "") {
- $request["order2"] = $http_request["order2"];
- }
- // offset
- $request["offset"] = $http_request["offset"];
- // date
- $request["date"] = $http_request["date"];
- // site
- $request["site"] = $_global["site"];
- // univers
- $request["univers"] = $http_request["univers"];
- //visuel annonce
- $request["an_visuel"] = $http_request["an_visuel"];
- //visuel annonce
- $request["hi_order"] = $http_request["hi_order"];
- //Nb Results par Page
- //print_r($http_request["LISearchHistoryCookie"]);
- //$aSearch = unserialize($http_request["LISearchHistoryCookie"]);
- //$aSearch = unserialize($aSearch[0]);
- // nb_results vient du cookie, qui peut avoir été modifié juste avant (voir tools.js)
- $request["nb_results"] = MAX_RESULTS_PER_PAGE;
- // vacances
- if ($_global["univers"] == 13) {
- // nb_bedrooms
- $request["nb_bedrooms"] = $http_request["nb_bedrooms"];
- // nb_people
- $request["nb_people"] = $http_request["nb_people"];
- // type_transaction
- $request["type_transaction"] = $http_request["type_transaction"];
- }
- // returns
- return $request;
- } else {
- /*
- // Attention : on peut arriver là si l'expression reguliere dans rw.decode echoue !
- // Bien regarder si le tableau request contient ce que l'on veut.
- if(empty($_REQUEST['old'])) {
- echo '<b>Florian</b><br />Fichier `',__FILE__,'` (l. ',__LINE__,')<hr /><pre>';
- var_dump( $http_request );
- die();
- }
- */
- header("Location:/index.php", true, 301);
- die();
- }
- }
- // *** allows search ***
- function enableSearch($http_request) {
- if ($http_request["loc_key"] != "" || $http_request["loc_key1"] != "" || $http_request["loc_key2"] != "" || $http_request["loc_key3"] != "" || $http_request["loc_key4"] != "") {
- return true;
- } else {
- if ($http_request["id_agence"] != "") {
- return true;
- }
- }
- return false;
- }
- // *** sets antenna code ***
- function setAntenna() {
- if ($this->search_count > 0) {
- // get the first filled pub_code
- for ($i = 0; $i < count($this->search_results); $i++) {
- $value = get_pub_data($this->search_results[$i][$this->table_prfx . "_pub_code"], "area1");
- if ($value != "") {
- $this->search_parameters["antenna"] = str_pad($value, 3, "0", STR_PAD_LEFT);
- $this->search_request["antenna"] = str_pad($value, 3, "0", STR_PAD_LEFT);
- break;
- }
- }
- }
- }
- // *** adds post code ***
- function addPostCode($id, $level) {
- switch ($level) {
- // map group
- case 97 :
- $this->loc_keys[] = "(lgm_id = " . $id . ")";
- break;
- // code group
- case 98 :
- $this->loc_keys[] = "(lgc_id = " . $id . ")";
- break;
- // name group
- case 99 :
- $this->loc_keys[] = "(lgn_id = " . $id . ")";
- break;
- // standard
- default :
- $this->loc_keys[] = "(lct_id = " . $id . " AND lct_level = " . $level . ")";
- break;
- }
- }
- // *** returns search results ***
- function getSearchResults($mode = "ad") {
- switch ($mode) {
- // ad results
- case "ad" :
- if ($this->has_premium) {
- $this->search_results = array_merge($this->search_results_premium, $this->search_results);
- }
- if ($this->has_exclusive) {
- $this->search_results['exclu'] = $this->search_results_exclusive;
- }
- $search_results = $this->search_results;
- break;
- // agency results
- case "agency" :
- $search_results = $this->search_results_agency;
- break;
- }
- return $search_results;
- }
- // Ads for a locality (for cities pages, cities and arrondissement pages...)
- function getAdsCities($tab_ville, $max_ads = "", $property_type = NULL, $tab_nb_rooms = NULL, $results_piece = NULL, $with_photos = true, $val_offset = "") {
-
- if (empty($max_ads)) $max_ads = 4;
- if (empty($val_offset)) $val_offset = 0;
-
- global $_global;
- //print_r($tab_ville);
- if (($tab_ville["lct_val"] != "") && (($tab_ville["lct_lvl"] != "") || ($tab_ville["lct_field"] != ""))) {
- // sets select
- if ($results_piece != NULL) {
- $this->setSelect("ad", false);
- } else {
- $this->setSelect("refville", false);
- }
- // sets from
- $this->setFrom();
- // sets where
- $where = array();
- $this->setWhere($where, "ad_status"); // ..._ad_status >= 0
- $this->setWhere($where, "price"); // ..._price > 0
- $this->setWhere($where, "country"); // ..._country = 'FR'
- $this->setWhere($where, "refville_field", $tab_ville); // lgn_id, lgc_id ou ..._locality_2
- $this->setWhere($where, "refville_locality"); // ..._locality_2 > 0
- if ($property_type != NULL) {
- $this->search_request["property_type"] = $property_type;
- $this->setWhere($where, "property_type");
- }
- if ($tab_nb_rooms != NULL) {
- $this->search_request["nb_rooms"] = $tab_nb_rooms;
- $this->setWhere($where, "nb_rooms");
- }
- // common where clause
- $this->where = $where;
- // set order
- $this->setOrder("filter_ad", 1, "update_date");
- // builds the query
- $this->subquery = "SELECT " . $this->select . " ";
- $this->subquery .= "FROM " . $this->from . " ";
- $this->subquery .= "WHERE " . implode(" AND ", $this->where) . " ";
- // only ads width at least 1 photo
- if ($with_photos) {
- $this->subquery .= "AND (" . $_global["table_prefix"] . "_nb_photo > 0)" . " ";
- }
- if (isset($tab_ville['lct_locality_2_arrond']) && !empty($tab_ville['lct_locality_2_arrond'])) {
- $this->subquery .= "OR " . $_global["table_prefix"] . "_locality_2 IN (" . implode(", ", $tab_ville["lct_locality_2_arrond"]) . ")";
- }
- // vacances
- if ($_global["univers"] == 13) {
- $this->subquery .= "AND (" . $_global["table_prefix"] . "_type_transaction = 3)" . " ";
- } else if ($_global["univers"] == 2) {
- $this->subquery .= "AND (" . $_global["table_prefix"] . "_type_transaction = 2)" . " ";
- } else if ($_global["univers"] == 8) {
- $this->subquery .= "AND (" . $_global["table_prefix"] . "_type_transaction = 8)" . " ";
- }
-
- $this->subquery .= "ORDER BY " . implode(", ", $this->order) . " ";
-
- // on récupère 10 fois plus d'annonces que souhaité véritablement, pour ensuite effectuer
- // un tri aléatoire sur cette première liste et n'en garder ensuite que me nombre voulu
- // (permet de ne pas tout le temps avoir les mêmes annonces à chaque requête)
- $this->subquery .= "LIMIT " . $val_offset . ", " . $max_ads * 10 . " ";
-
- //die($this->subquery);
-
- $this->query = "
- SELECT SQL_CALC_FOUND_ROWS " . $this->select . "
- FROM (
- " . $this->subquery . ") AS sub
- ORDER BY RAND()
- LIMIT 0, $max_ads
- ";
-
- // Optimisation : begin (BM, 01/07/2010)
- // recherche du nom de la table des annonces à utiliser
- // NB: tables TM_... uniquement pour les pages résultat, pas détail !
- $prfx = $_global["table_prefix"];
- $sql = " SELECT ttu_" . $prfx . "_fr FROM TP_TABLE_TO_USE_TTU";
- $res = pdoquery($sql);
- //echo "<hr>$sql<hr>";
- // table des annonces (moteur InnoDB ou MEMORY)
- if (sizeof($res) > 0) {
- $table_name_ads = $res[0]["ttu_" . $prfx . "_fr"];
- if (in_array($_global["univers"], array(2, 8, 13))) {
- $table_name_ads_old = "T_RENTAD_RNT";
- } else {
- $table_name_ads_old = "T_SALESAD_SAL";
- }
- $this_query = $this->query;
- $this_query = str_replace($table_name_ads_old, $table_name_ads, $this_query);
- //echo "<hr>".$this_query."<hr>";
- $this->query = $this_query;
- }
- // Optimisation : end
- //echo "select = ".$this->select."<br />";
- //echo "query = ".$this->query."<br />";
- // executes the query
- if ($_global["debug"] == 3) {
- echo "getAdsCities()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- // --------------------------------------------
- // builds the count query
- $this->query_count = "SELECT FOUND_ROWS() AS NUM";
- //echo "query_count = ".$this->query_count."<br />";
- $this->search_count = pdoquery($this->query_count);
- $this->search_count = $this->search_count[0]["NUM"];
- //echo "search_count = ".$this->search_count."<br />";
- }
- }
- // Ads for a departement
- function getAdsDepartment($post_code_departem, $max_ads, $property_type = NULL, $tab_nb_rooms = NULL) {
- global $_global;
- if ($post_code_departem != "") {
- // sets select
- $this->setSelect("ad", false);
- // sets from
- $this->setFrom();
- // sets where
- $where = array();
- $this->setWhere($where, "ad_status");
- $this->setWhere($where, "price");
- $this->setWhere($where, "country");
- $this->setWhere($where, "post_code_departem", $post_code_departem);
- if ($property_type != NULL) {
- $this->search_request["property_type"] = $property_type;
- $this->setWhere($where, "property_type");
- }
- if ($tab_nb_rooms != NULL) {
- $this->search_request["nb_rooms"] = $tab_nb_rooms;
- $this->setWhere($where, "nb_rooms");
- }
- // common where clause
- $this->where = $where;
- // set order
- $this->setOrder("filter_ad", 1, "update_date");
- // builds the query
- $this->query = "SELECT SQL_CALC_FOUND_ROWS " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- $this->query .= "AND (" . $_global["table_prefix"] . "_nb_photo > 0)" . " ";
- $this->query .= "AND (" . $_global["table_prefix"] . "_photo != '')" . " ";
- $this->query .= "AND (" . $_global["table_prefix"] . "_type_transaction = " . $_global['univers'] . ")" . " ";
- $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
- $this->query .= "LIMIT 0, " . ($max_ads != "" ? $max_ads : 4);
- // executes the query
- if ($_global["debug"] == 3) {
- echo "getAdsDepartment()<br />";
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- }
- }
- // Arrondissements of important french cities
- function getArrondCities($city) {
- //print_r($city);
- $res = array();
- if (isset($city["lgn_id"])) { // si lgn_id défini
- $lgn_id = $city["lgn_id"];
- //echo "[lgn_id = $lgn_id]"; //exit;
- switch ($lgn_id) {
- case "0" : // Paris
- $lct_ids = array(23599, 23601, 23602, 23603, 23604, 23605, 23606, 23607, 23609, 23589, 23590, 23591, 23592, 23593, 23594, 23595, 23596, 23597, 23598, 23600);
- break;
- case "421" : // Marseille
- $lct_ids = array(36102, 36104, 36105, 36106, 36107, 36108, 36109, 36110, 36111, 36112, 36113, 36114, 36115, 36116, 36117, 36118);
- break;
- case "422" : // Lyon
- $lct_ids = array(36119, 36120, 36121, 36122, 36123, 36124, 36125, 36126, 36127);
- break;
- }
- //echo "[lct_ids = ".print_r($lct_ids, true)."]"; //exit;
- if (isset($lct_ids) && !empty($lct_ids)) {
- $sql = "";
- $sql .= " SELECT lct_id,
- lct_level,
- lct_name,
- lct_post_code";
- $sql .= " FROM T_LOCALITY_LCT_FR";
- $sql .= " WHERE lct_id IN (" . implode(",", $lct_ids) . ")";
- $sql .= " ORDER BY lct_post_code ASC";
- if ($_global["debug"] == 3) {
- echo "<hr />";
- echo $sql;
- echo "<hr />";
- }
- $res = pdoquery($sql);
- }
- }
- return $res;
- }
- // Return true if the french city has arrondissements
- static function hasArrondsCity($city) {
- $ret = false;
- if (isset($city["lgn_id"]) && !empty($city["lgn_id"])) { // si lgn_id défini
- $lgn_id = $city["lgn_id"];
- //echo "[lgn_id = $lgn_id]"; //exit;
- $ret = (in_array($lgn_id, array(0, 421, 422)));
- } else if (isset($city["lct_name"]) && !empty($city["lct_name"])) { // si lct_name défini
- $lct_name = $city["lct_name"];
- //echo "[lct_name = $lct_name]"; //exit;
- $ret = (in_array(strtolower($lct_name), array("paris", "marseille", "lyon")));
- }
- return $ret;
- }
- // Return true if the french "city" is in fact an arrondissement of a city
- static function isArrondCity($city) {
- //echo "city = "; var_dump($city);
- $ret = array(false, -1, "");
- $lct_lkey_city_paris = "100_1";
- $lct_name_city_paris = "paris";
- $lct_ids_arronds_paris = array(23599, 23601, 23602, 23603, 23604, 23605, 23606, 23607, 23609, 23589, 23590, 23591, 23592, 23593, 23594, 23595, 23596, 23597, 23598, 23600);
- $lct_lkey_city_marseille = "421_99";
- $lct_name_city_marseille = "marseille";
- $lct_ids_arronds_marseille = array(36102, 36104, 36105, 36106, 36107, 36108, 36109, 36110, 36111, 36112, 36113, 36114, 36115, 36116, 36117, 36118);
- $lct_lkey_city_lyon = "422_99";
- $lct_name_city_lyon = "lyon";
- $lct_ids_arronds_lyon = array(36119, 36120, 36121, 36122, 36123, 36124, 36125, 36126, 36127);
- if (isset($city["lct_val"]) && !empty($city["lct_val"])) { // si lct_val défini
- $lct_id = $city["lct_val"];
- //echo "[lct_id = $lct_id]"; //exit;
- if (in_array($lct_id, $lct_ids_arronds_paris)) {
- $ret = array(true, $lct_lkey_city_paris, $lct_name_city_paris);
- }
- if (in_array($lct_id, $lct_ids_arronds_marseille)) {
- $ret = array(true, $lct_lkey_city_marseille, $lct_name_city_marseille);
- }
- if (in_array($lct_id, $lct_ids_arronds_lyon)) {
- $ret = array(true, $lct_lkey_city_lyon, $lct_name_city_lyon);
- }
- }
- return $ret;
- }
- // Major cities around important french cities
- function getEnvironCities($city, $regions = "") {
- //echo "city = "; var_dump($city); echo "<br>";
- //echo "regions = "; var_dump($regions); echo "<br>";
- $lct_name = $city["lct_name"];
- //echo "[lct_name = $lct_name]"; exit;
- $lct_post_code = $city["lct_post_code"];
- //echo "[lct_post_code = $lct_post_code]"; exit;
- $lct_ids_depart = array();
- $lct_ids_region = array();
- switch (strtolower($lct_name)) {
- // Lot 1
- case "paris" :
- $lct_ids_depart = array();
- $lct_ids_region = array(4285, 22198, 1104, 8802, 21595, 1625, 27495, 35588, 34526, 35588, 7878);
- break;
- case "marseille" :
- $lct_ids_depart = array(36129, 1147, 19707, 1451, 14032);
- $lct_ids_region = array(22514, 33109, 5568, 1909, 897);
- break;
- case "lyon" :
- $lct_ids_depart = array(35343, 34302, 5413, 29852, 34092);
- $lct_ids_region = array(27633, 12875, 836, 33770, 6322);
- break;
- case "toulouse" :
- $lct_ids_depart = array(7905, 33148, 22092, 3671, 8984);
- $lct_ids_region = array(21045, 32522, 408, 5864, 26107);
- break;
- case "nice" :
- $lct_ids_depart = array(897, 5568, 12825, 5343, 16660);
- $lct_ids_region = array(19667, 33109, 36129, 1909, 9442);
- break;
- case "nantes";
- $lct_ids_depart = array(29410, 28164, 25833, 30130, 23248);
- $lct_ids_region = array(767, 36157, 15380, 7498, 16440);
- break;
- case "strasbourg" :
- $lct_ids_depart = array(13216, 31393, 13922, 31498, 3623);
- $lct_ids_region = array(22063, 7862, 28813, 18202, 35954);
- break;
- case "montpellier" :
- $lct_ids_depart = array(3478, 31792, 18797, 11897, 221);
- $lct_ids_region = array(22557, 23846, 429, 22226, 5636);
- break;
- case "bordeaux" :
- $lct_ids_depart = array(20226, 23895, 32468, 35094, 29309);
- $lct_ids_region = array(23675, 796, 223, 2545, 23820);
- break;
- case "rennes" :
- $lct_ids_depart = array(28888, 11541, 35568, 6162, 5066);
- $lct_ids_region = array(4746, 25350, 18523, 33911, 27225);
- break;
- case "lille" :
- $lct_ids_depart = array(26345, 33128, 9842, 35107, 9686);
- $lct_ids_region = array(5384, 4289, 35868, 33775, 1221);
- break;
- case "grenoble" :
- $lct_ids_depart = array(29118, 9937, 34727, 11297, 4384);
- $lct_ids_region = array(18897, 27633, 35343, 33770, 34302);
- break;
- case "rouen" :
- $lct_ids_depart = array(16853, 9423, 32131, 27673, 16829);
- $lct_ids_region = array(10693, 34472, 17070, 20931, 10908);
- break;
- case "toulon" :
- $lct_ids_depart = array(15467, 13866, 11730, 9760, 31961);
- $lct_ids_region = array(19667, 22514, 36129, 1909, 897);
- break;
- case "nimes" :
- $lct_ids_depart = array(429, 2089, 2610, 40186, 28104);
- $lct_ids_region = array(21551, 23846, 3478, 22226, 5636);
- break;
- case "perpignan" :
- $lct_ids_depart = array(5557, 27631, 1092, 27448, 5304);
- $lct_ids_region = array(21551, 22557, 3478, 22226, 5636);
- break;
- // Lot 2
- case "nancy" :
- $lct_ids_depart = array(33901, 18801, 33104, 35262, 16539);
- $lct_ids_region = array(20369, 32835, 10197, 21409, 31088);
- break;
- case "angers" :
- $lct_ids_depart = array(7498, 31212, 1957, 17759, 33323);
- $lct_ids_region = array(22199, 16906, 29410, 16440, 15380);
- break;
- case "caen" :
- $lct_ids_depart = array(13588, 18238, 2542, 35510, 20799);
- $lct_ids_region = array(426, 36829, 28800, 37093, 33132);
- break;
- case "la rochelle" :
- $lct_ids_depart = array(26050, 30787, 26495, 1990, 28301);
- $lct_ids_region = array(24485, 22559, 805, 6952, 30787);
- break;
- case "aix en provence" :
- $lct_ids_depart = array(19667, 1147, 19707, 1451, 14032);
- $lct_ids_region = array(22514, 33109, 1909, 897, 5568);
- break;
- case "metz" :
- $lct_ids_depart = array(32835, 21409, 31088, 11459, 27066);
- $lct_ids_region = array(22183, 10197, 33901, 39374, 18801);
- break;
- case "avignon" :
- $lct_ids_depart = array(23094, 5688, 5954, 23886, 32110);
- $lct_ids_region = array(19667, 22514, 33109, 365, 897);
- break;
- case "le havre" :
- $lct_ids_depart = array(26356, 9423, 32131, 27673, 16829);
- $lct_ids_region = array(10693, 34472, 17070, 20931, 10908);
- break;
- case "clermont-ferrand" :
- $lct_ids_depart = array(8544, 25968, 6307, 14024, 32800);
- $lct_ids_region = array(21479, 1707, 34673, 21908, 17163);
- break;
- case "orleans" :
- $lct_ids_depart = array(11198, 23003, 28321, 28343, 12343);
- $lct_ids_region = array(33174, 4374, 6925, 3793, 6781);
- break;
- case "versailles" :
- $lct_ids_depart = array(31111, 19289, 28016, 24482, 21397);
- $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
- break;
- case "saint-etienne" :
- $lct_ids_depart = array(26018, 27282, 11085, 21116, 25990);
- $lct_ids_region = array(18897, 12875, 35343, 33770, 34302);
- break;
- case "mulhouse" :
- $lct_ids_depart = array(7862, 28813, 35954, 13926, 26014);
- $lct_ids_region = array(32323, 13216, 31393, 13922, 31498);
- break;
- case "narbonne" :
- $lct_ids_depart = array(5636, 5812, 17975, 18184, 33269);
- $lct_ids_region = array(3478, 21551, 22557, 23846, 31792);
- break;
- case "annecy" :
- $lct_ids_depart = array(837, 839, 8699, 31832, 32883);
- $lct_ids_region = array(12875, 18897, 27633, 33770, 35343);
- break;
- case "aix les bains" :
- $lct_ids_depart = array(406, 4367, 6322, 15235, 28353);
- $lct_ids_region = array(12875, 18897, 27633, 33770, 35343);
- break;
- case "colmar" :
- $lct_ids_depart = array(13926, 22064, 26014, 28813, 35954);
- $lct_ids_region = array(13216, 13922, 31393, 31498, 32323);
- break;
- case "bourges" :
- $lct_ids_depart = array(20021, 26803, 27597, 27764, 34740);
- $lct_ids_region = array(3793, 6781, 6925, 23171, 33174);
- break;
- case "biarritz" :
- $lct_ids_depart = array(796, 2545, 3568, 23675, 28350);
- $lct_ids_region = array(223, 4085, 20226, 23895, 32468);
- break;
- case "beauvais" :
- $lct_ids_depart = array(7978, 8752, 8773, 22617, 22845);
- $lct_ids_region = array(132, 648, 16214, 29900, 31982);
- break;
- case "pontoise" :
- $lct_ids_depart = array(1104, 6090, 11670, 12048, 31045);
- $lct_ids_region = array(4285, 21595, 100, 27495, 34526);
- break;
- case "saint-denis" :
- $lct_ids_depart = array(1482, 1625, 9767, 21595, 22653);
- $lct_ids_region = array(1104, 4285, 21595, 100, 34526);
- break;
- case "saint-maur-des-fosses" :
- $lct_ids_depart = array(6493, 8802, 14052, 19093, 35588);
- $lct_ids_region = array(1104, 4285, 21595, 100, 27495);
- break;
- case "fontainebleau" :
- $lct_ids_depart = array(6531, 7220, 19993, 20077, 24648);
- $lct_ids_region = array(1104, 4285, 21595, 100, 27495);
- break;
- case "etampes" :
- $lct_ids_depart = array(8152, 10698, 19795, 30637, 31349);
- $lct_ids_region = array(1104, 4285, 21595, 100, 27495);
- break;
- // Lot 3
- /*
- case "cannes" :
- $lct_ids_depart = array(22514, 897, 5343, 12825, 16660);
- $lct_ids_region = array(19667, 33109, 36129, 1909, 15467);
- break;
- case "limoges" :
- $lct_ids_depart = array(28575, 23509, 13991, 30471, 8671);
- $lct_ids_region = array(4933, 33525, 13045, 33633, 19155);
- break;
- case "pau" :
- $lct_ids_depart = array(2545, 796, 3496, 3568, 28350);
- $lct_ids_region = array(4085, 20226, 23895, 2545, 32468);
- break;
- case "antibes" :
- $lct_ids_depart = array(22514, 5568, 5343, 12825, 16660);
- $lct_ids_region = array(19667, 33109, 36129, 1909, 15467);
- break;
- case "amiens" :
- $lct_ids_depart = array(132, 404, 23837, 26503, 21184);
- $lct_ids_region = array(29900, 2796, 7978, 8752, 31982);
- break;
- case "poitiers" :
- $lct_ids_depart = array(6952, 5267, 18589, 7117, 27124);
- $lct_ids_region = array(15386, 22559, 805, 6952, 26050);
- break;
- case "montreuil" :
- $lct_ids_depart = array(27495, 1625, 1482, 9767, 22653);
- $lct_ids_region = array(100, 4285, 1104, 34526, 22198);
- break;
- case "villeurbanne" :
- $lct_ids_depart = array(18897, 34302, 5413, 29852, 34092);
- $lct_ids_region = array(18897, 27633, 12875, 33770, 6322);
- break;
- case "argenteuil" :
- $lct_ids_depart = array(31045, 6090, 12048, 11670, 24677);
- $lct_ids_region = array(100, 4285, 21595, 27495, 34526);
- break;
- case "roubaix" :
- $lct_ids_depart = array(18149, 33128, 9842, 35107, 9686);
- $lct_ids_region = array(5384, 4289, 35868, 33775, 1221);
- break;
- case "tourcoing" :
- $lct_ids_depart = array(5384, 4289, 35868, 33775, 1221);
- $lct_ids_region = array(18149, 26345, 9842, 35107, 9686);
- break;
- case "colombes" :
- $lct_ids_depart = array(4285, 22198, 1363, 26546, 8445);
- $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
- break;
- case "boulogne-billancourt" :
- $lct_ids_depart = array(22198, 7878, 7878, 1363, 26546);
- $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
- break;
- case "courbevoie" :
- $lct_ids_depart = array(4285, 22198, 7878, 1363, 26546);
- $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
- break;
- case "creteil" :
- $lct_ids_depart = array(35588, 6493, 29227, 19093, 14052);
- $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
- break;
- case "nanterre" :
- $lct_ids_depart = array(4285, 7878, 1363, 26546, 8445);
- $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
- break;
- case "rueil-malmaison" :
- $lct_ids_depart = array(4285, 22198, 7878, 1363, 8445);
- $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
- break;
- case "aulnay-sous-bois" :
- $lct_ids_depart = array(21595, 27495, 1482, 9767, 22653);
- $lct_ids_region = array(100, 4285, 1104, 21595, 34526);
- break;
- case "vitry-sur-seine" :
- $lct_ids_depart = array(8802, 6493, 29227, 19093, 14052);
- $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
- break;
- case "dijon" :
- $lct_ids_depart = array(2747, 7292, 32463, 7380, 25312);
- $lct_ids_region = array(6290, 22495, 1824, 18927, 31606);
- break;
- case "asnieres-sur-seine" :
- $lct_ids_depart = array(4285, 22198, 7878, 26546, 8445);
- $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
- break;
- */
- }
- //echo "lct_ids_depart = "; var_dump($lct_ids_depart);
- //echo "lct_ids_region = "; var_dump($lct_ids_region);
- $res_depart = array();
- if (isset($lct_ids_depart) && !empty($lct_ids_depart)) {
- $sql_depart = "";
- $sql_depart .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
- IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
- lct_name_fr,
- lct_post_code";
- $sql_depart .= " FROM T_LOCALITY_LCT_FR";
- $sql_depart .= " WHERE lct_id IN (" . implode(",", $lct_ids_depart) . ")";
- $sql_depart .= " ORDER BY lct_name_fr ASC";
- if ($_global["debug"] == 3) {
- echo "getEnvironCities()<br />";
- echo $sql_depart . "<br />";
- echo "<hr />";
- }
- $res_depart = pdoquery($sql_depart);
- } else {
- $sql = "";
- $sql .= " SELECT lct_parent_id";
- $sql .= " FROM T_LOCALITY_LCT_FR";
- $sql .= " WHERE lct_name = '" . strtoupper(addslashes($lct_name)) . "'";
- $sql .= " OR lct_name_fr = '" . strtoupper(addslashes($lct_name)) . "'";
- if (isset($lct_post_code) && !empty($lct_post_code)) {
- $sql .= " AND lct_post_code = '" . strtoupper(addslashes($lct_post_code)) . "'";
- }
- $sql .= " LIMIT 0, 1";
- $res = pdoquery($sql);
- if (count($res) > 0) {
- $lct_dept_id = $res[0]["lct_parent_id"];
- }
- //echo $sql; //exit;
- $sql_depart = "";
- $sql_depart .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
- IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
- lct_name_fr,
- lct_post_code";
- $sql_depart .= " FROM T_LOCALITY_LCT_FR";
- $sql_depart .= " WHERE lct_parent_id = '$lct_dept_id'";
- $sql_depart .= " AND lct_name_fr != '" . strtoupper(addslashes($lct_name)) . "'";
- $sql_depart .= " ORDER BY lct_sal_pondering DESC";
- $sql_depart .= " LIMIT 0,5";
- //echo $sql_depart;
- $res_depart = pdoquery($sql_depart);
- }
- $res_region = array();
- if (isset($lct_ids_region) && !empty($lct_ids_region)) {
- $sql_region = "";
- $sql_region .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
- IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
- lct_name_fr,
- lct_post_code";
- $sql_region .= " FROM T_LOCALITY_LCT_FR";
- $sql_region .= " WHERE lct_id IN (" . implode(",", $lct_ids_region) . ")";
- $sql_region .= " ORDER BY lct_sal_pondering DESC";
- //echo $sql_region;
- $res_region = pdoquery($sql_region);
- } else {
- if (isset($regions) && !empty($regions)) {
- $sql_region = "";
- $sql_region .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
- IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
- lct_name_fr,
- lct_post_code";
- $sql_region .= " FROM T_LOCALITY_LCT_FR";
- $sql_region .= " WHERE lct_id IN (" . implode(",", $regions["ids_loc"]) . ")";
- $sql_region .= " AND lct_name_fr != '" . strtoupper(addslashes($lct_name)) . "'";
- $sql_region .= " ORDER BY lct_sal_pondering DESC";
- //echo $sql_region;
- $res_region = pdoquery($sql_region);
- }
- }
- return array("depart" => $res_depart, "region" => $res_region);
- }
- //*** returns all localities from code group (lgc_id) ***
- function getLocCodeGrp($limit = true) {
- global $_global;
- if ($limit) {
- // limit => only when research in one locality
- if (count($this->search_parameters["loc_keys"]) < 2 && count($this->search_parameters["loc_keys"]) != 0) {
- if (!empty($this->search_parameters["lgc_ids"][0]) && $this->search_parameters["lgc_ids"][0] != '0') {
- $sql = "SELECT lct_name, lct_id, lct_level, lct_post_code FROM TM_LOC_FR WHERE lgc_id = '" . $this->search_parameters["lgc_ids"][0] . "'";
- if ($_global["debug"] == 3) {
- echo "getLocCodeGrp()<br />";
- echo $sql . "<br />";
- echo "<hr />";
- }
- $results = pdoquery($sql);
- return $results;
- }
- }
- }
- }
- //*** returns all localities from name group (lgn_id) ***
- function getLocNameGrp($limit = true) {
- global $_global;
- if ($limit) {
- // limit => only when research in one locality
- if (count($this->search_parameters["loc_keys"]) < 2 && count($this->search_parameters["loc_keys"]) != 0) {
- if (!empty($this->search_parameters["lgn_ids"][0]) && $this->search_parameters["lgn_ids"][0] != '0') {
- $sql = "SELECT lct_name, lct_id, lct_level, lct_post_code FROM TM_LOC_FR WHERE lgn_id = '" . $this->search_parameters["lgn_ids"][0] . "'";
- if ($_global["debug"] == 3) {
- echo "getLocNameGrp()<br />";
- echo $sql . "<br />";
- echo "<hr />";
- }
- $results = pdoquery($sql);
- return $results;
- }
- }
- }
- }
- //*** returns all localities from name or code group (lgn_id, lgc_id)
- function get_locGrp($limit = true) {
- global $_global;
- $sql = '';
- if ($limit) {
- // limit => only when research in one locality
- if (count($this->search_parameters["loc_keys"]) < 2 && count($this->search_parameters["loc_keys"]) > 0) {
- if ($this->search_parameters["lgn_ids"][0] > 0 || $this->search_parameters["lgc_ids"][0] > 0) {
- if ($this->search_parameters["lgn_ids"][0] > 0 && $this->search_parameters["lgc_ids"][0] > 0) {
- //lgn_ids en priorité
- $sql = "SELECT lct_name, lct_id, lct_level, lct_post_code FROM T_LOCALITY_LCT_FR WHERE lgn_id = '" . $this->search_parameters["lgn_ids"][0] . "' AND lct_agc_pondering > 0 order by lct_agc_pondering DESC limit 0,10";
- } elseif ($this->search_parameters["lgn_ids"][0] > 0 && $this->search_parameters["lgc_ids"][0] == 0) {
- $sql = "SELECT lct_name, lct_id, lct_level, lct_post_code FROM T_LOCALITY_LCT_FR WHERE lgn_id = '" . $this->search_parameters["lgn_ids"][0] . "' AND lct_agc_pondering > 0 order by lct_agc_pondering DESC limit 0,10";
- } elseif ($this->search_parameters["lgc_ids"][0] > 0 && $this->search_parameters["lgn_ids"][0] == 0) {
- $sql = "SELECT lct_name, lct_id, lct_level, lct_post_code FROM T_LOCALITY_LCT_FR WHERE lgc_id = '" . $this->search_parameters["lgc_ids"][0] . "' AND lct_agc_pondering > 0 order by lct_agc_pondering DESC limit 0,10";
- }
- if ($_global["debug"] == 3) {
- echo "getLocGrp()<br />";
- echo $sql . "<br />";
- echo "<hr />";
- }
- if ($sql != '') {
- $results = pdoquery($sql);
- return $results;
- }
- }
- }
- }
- }
- // *** returns search count ***
- function getSearchCount() {
- return $this->search_count;
- }
- // *** returns search parameters ***
- function getSearchParameters() {
- return $this->search_parameters;
- }
- // *** returns search request ***
- function getSearchRequest() {
- return $this->search_request;
- }
- // *** returns agency locality hierarchy ***
- function getSearchHierarchyAgency() {
- return $this->search_hierarchy_agency;
- }
- // *** returns search agengy state ***
- function isSearchAgency() {
- return $this->is_agency_search;
- }
- // *** stores search parameters in the cookie ***
- function saveSearch() {
- global $_global;
- global $aLISearchHistoryCookieValue;
- if ($_global['debug'] == 1) {
- echo '<hr /><p><b>[Mode debug][Cookie][' . ($this->is_agency_search ? '' : 'Non ') . 'Agence]</b> : Enregistrement de la recherche annulée (Header already sent!).</p>';
- var_dump($this->search_request);
- echo '<hr />';
- return true;
- }
- $expires = time() + (86400 * COOKIE_DURATION);
- $saved_searches = array();
- $aLiSearchCookie_datas = array();
- $aLiSearchCookie_datas = fetchcookie(SEARCH_HISTORY_COOKIE_NAME);
- if (is_array($aLiSearchCookie_datas) && array_key_exists(0, $aLiSearchCookie_datas)) {
- $aLiSearchCookie_datas = unserialize($aLiSearchCookie_datas[0]);
- if ($aLiSearchCookie_datas != FALSE) {
- $aDiff_datas = array_diff_key($this->search_request, $aLiSearchCookie_datas);
- $this->search_request = array_merge($this->search_request, $aDiff_datas);
- }
- }
- $saved_searches[0] = serialize($this->search_request);
- $saved_searches[1] = serialize($this->search_parameters['loc_hierarchy']);
- storecookie(SEARCH_HISTORY_COOKIE_NAME, $saved_searches, $expires);
- /**
- * W.ASBATITI
- * 28/12/2012 :
- * Le cookie USER_DATA_IHM_COOKIE_NAME est MAJ dans redirect .annuaire, pas la peine de le retraiter pour la PR AGENCEs
- */
- if ($_global['self'] != 'resultats_agences.php') {
- // Sur les autres pages (PR par exp) on ne modifie que le nb resulats par page et on garde les tris de la PR AGC
- if (isset($_COOKIE[USER_DATA_IHM_COOKIE_NAME])) {
- $user_data_ihm_array = json_decode($_COOKIE[USER_DATA_IHM_COOKIE_NAME], true);
- $user_data_ihm_array['nb_results'] = $this->search_request['nb_results'];
- } else {
- $user_data_ihm_array = array('nb_results' => $this->search_request['nb_results']);
- }
- $user_data_ihm_string = json_encode($user_data_ihm_array);
- setcookie(USER_DATA_IHM_COOKIE_NAME, $user_data_ihm_string, $expires, '/');
- }
- foreach ($saved_searches as $saved_search) {
- $aLISearchHistoryCookieValue[] = unserialize($saved_search);
- }
- $_global["saved_searches"] = count($aLISearchHistoryCookieValue);
- }
- // *** loads last search from the cookie
- function loadSearch() {
- $saved_searches = fetchcookie(SEARCH_HISTORY_COOKIE_NAME);
- $saved_search = unserialize($saved_searches[0]);
- return $saved_search;
- }
- // debugger
- function showTime($action, $start) {
- global $_global;
- if ($_global["debug"] == 1) {
- echo($action . " : " . (microtime(true) - $start) . " ms<br>");
- }
- }
- // killer
- function relief() {
- if (isset($_global["debug"]) && ($_global["debug"] == 3)) {
- echo "relief()<br />";
- echo "SHOW PROCESSLIST<br />";
- echo "<hr />";
- }
- $processes = pdoquery("SHOW PROCESSLIST");
- foreach ($processes as $process) {
- if ($process["User"] == "phpwebpage" && $process["Command"] == "Sleep" && $process["Time"] > 10) {
- pdoquery("KILL " . $process["Id"]);
- }
- }
- }
- // search ads
- function getAdsHomeGallery($request, $offset, $skip_premium = false, $simulate = false) {
- global $_global;
- if ($_global['univers'] == 8) {
- $this->query = "SELECT * FROM T_RENTAD_RNT WHERE rnt_type_transaction=8 AND rnt_photo!='' ORDER BY rnt_creation_date DESC LIMIT 0,30";
- //$res = pdoquery($sql);
- $this->search_results = pdoquery($this->query);
- //return $res;
- return 0;
- }
- //var_dump($request);
- if ($_global["debug"] == 1) {
- //$proximite = $this->setPerimProximit(5); //5km around
- //$proximite_coor = $this->getCoord($request['loc_key1']);
- }
- // adds universe
- $this->search_parameters["univers"] = $_global["univers"];
- // is agency search ?
- $this->is_agency_search = false; // (isset($request["id_agence"]) ? true : false);
- // sets request
- $this->search_request = $this->setRequest($request);
- // adds date
- $this->setDate();
- // sets offset
- $this->search_parameters["offset"] = "" . $offset . "";
- // sets select
- $this->setSelect("ad", false);
- // sets from
- //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
- $this->setFrom(false);
- // sets where
- $where = array();
- if ($this->isGrpAgency == true) {
- $this->setWhere($where, "grp_id_agence", $this->list_agency);
- }
- $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
- $this->setWhere($where, "ad_status");
- if ($this->PerimProximit > 0) {
- $this->setWhere($where, "perimproximit");
- } else {
- $this->setWhere($where, "locality");
- }
- $this->setWhere($where, "country");
- $this->setWhere($where, "property_type");
- $this->setWhere($where, "price");
- $this->setWhere($where, "area");
- $this->setWhere($where, "nb_rooms");
- // vacances
- if ($_global["univers"] == 13) {
- $this->setWhere($where, "nb_bedrooms");
- $this->setWhere($where, "nb_people");
- $this->setWhere($where, "type_transaction", 3);
- }
- if ($_global["univers"] == 2) {
- $this->setWhere($where, "type_transaction", 2);
- }
- if ($_global["univers"] == 8) {
- $this->setWhere($where, "type_transaction", 8);
- }
- /* We force to get only Ads with photo(s) */
- $this->setWhere($where, "photo");
- if ($_global["debug"] == 1) {
- echo "getAdsHomeGallery - $_REQUEST<br />";
- var_dump($_REQUEST);
- echo "<hr />";
- }
- $this->setWhere($where, "with_mmf");
- // common where clause
- $this->where = $where;
- // sets index
- $force_index = array();
- $this->setIndex($force_index, "locality");
- // common index clause
- // force index when we are doing a search on more than one locality
- if (count($force_index) > 1) {
- //$this->force_index = $force_index;
- }
- // sets order
- /*
- if (isset($this->search_request["order_price"])){
- $this->setOrder("ad", $this->search_request["order"]);
- if ($this->search_request["order_price"]==""){$this->search_request["order_price"]=1;}
- $this->setOrder("filter_ad", $this->search_request["order_price"], "price");
- }
- */
- if (isset($this->search_request["order_ads_agency"])) {
- $this->setOrder("ad", $this->search_request["order"]);
- if ($this->search_request["order_ads_agency"] == "") {
- $this->search_request["order_ads_agency"] = "date_asc";
- }
- $this->setOrder("filter_ad", $this->search_request["order_ads_agency"]);
- } else {
- $this->setOrder("ad", $this->search_request["order"]);
- }
- //$this->setOrder("ad", $this->search_request["order"]);
- // builds main query
- //$this->query = "SELECT SQL_CALC_FOUND_ROWS ".$this->select." ";
- $this->query = "SELECT " . $this->select . " ";
- $this->query .= "FROM " . $this->from . " ";
- if (isset($this->force_index)) {
- //$this->query .= "FORCE INDEX (".implode(", ", $this->force_index).") ";
- }
- $query2 = $this->query;
- $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
- // sets limit
- $this->setLimit("adHomeGallery", $offset);
- //Try to join a UNION QUERY to LIMIT ZeRo Result
- // sets where
- $where = array();
- if ($this->isGrpAgency == true) {
- $this->setWhere($where, "grp_id_agence", $this->list_agency);
- }
- $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
- $this->setWhere($where, "ad_status");
- if ($this->PerimProximit > 0) {
- $this->setWhere($where, "perimproximit");
- } else {
- $this->setWhere($where, "locality");
- }
- $this->setWhere($where, "property_type");
- //
- //$this->query .= "UNION ".$query2;
- //$this->query .= "WHERE ".implode(" AND ", $this->where)." ";
- //
- // main query additional clause
- $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
- $this->query .= "LIMIT 30"; //.$this->limit;
- // adds post code
- $_start = microtime(true);
- $this->setPostCodes();
- $this->showTime("set post codes", $_start);
- // executes the query
- $_start = microtime(true);
- if ($simulate == false) {
- if ($_global["debug"] == 3) {
- echo 'getAdsHomeGallery() - 1<br />';
- echo $this->query . "<br />";
- echo "<hr />";
- }
- $this->search_results = pdoquery($this->query);
- $this->showTime("main search", $_start);
- // builds the count query
- $this->query_count = "SELECT FOUND_ROWS() AS NUM";
- // executes the count query
- $_start = microtime(true);
- if ($_global["debug"] == 3) {
- echo 'getAdsHomeGallery() - 2<br />';
- echo $this->query_count . "<br />";
- echo "<hr />";
- }
- $this->search_count = pdoquery($this->query_count);
- $this->search_count = $this->search_count[0]["NUM"];
- $this->showTime("main count", $_start);
- // save
- $this->search_parameters["count"] = $this->search_count;
- $this->search_request["count"] = $this->search_count;
- // calculates number of pages
- $this->setPages("ad");
- // sets antenna
- $this->setAntenna();
- }
- }
- /**
- * Enter description here...
- *
- * @param unknown_type $code
- * @return unknown
- */
- function getLongLatTown($code) {
- /* $sql = "SELECT DISTINCT(".$this->table_prfx.".".$this->table_prfx."_default_town_2), lctFR.lct_lat, lctFR.lct_long
- FROM ".$this->table_name." ".$this->table_prfx.", T_LOCALITY_LCT_FR lctFR
- WHERE ".$this->table_prfx.".".$this->table_prfx."_default_town_2 = lctFR.lct_name_fr
- AND ".$this->table_prfx.".id_annonce = '".$code."'"; */
- $sql = "SELECT lctFR.lct_lat, lctFR.lct_long
- FROM T_LOCALITY_LCT_FR lctFR
- WHERE lctFR.lct_name_fr = '" . addslashes($code) . "'";
- $result = pdoquery($sql);
- return $result[0];
- }
- /**
- * Crypte la requete et la stocke dans un cookie pour une reutilisation en ajax pour la generation
- * de la navigation sur la page detail
- *
- * @param string $query La requête a crypter et stocker
- */
- function save_query($text) {
- $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
- $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
- $key = "NAV_ADS";
- $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
- setcookie("NAV_ADS", $crypttext);
- }
- }
- ?>