PageRenderTime 45ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/DEV/LIB/search.class.php

https://github.com/chrisbst35/LI_LEMONDE
PHP | 5517 lines | 3264 code | 1114 blank | 1139 comment | 862 complexity | 33034f3386305fec2f04e17c28635424 MD5 | raw file
  1. <?php
  2. /*
  3. 20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  4. 20091202-1 (3 sections) : not using T_LOCALITY_LCT_FR table when select town name
  5. 20091202-2 (4 sections) : not using SELECT when use of DATEDIFF
  6. 20100216-1 (2 sections) : not using T_LOCALITY_LCT_FR table when select town name for AGC
  7. */
  8. // search class
  9. // 97 -> lgm_id
  10. // 98 -> lgc_id
  11. // 99 -> lgn_id
  12. class search_object {
  13. public $table_name;
  14. public $table_prfx;
  15. public $table_locality_name;
  16. public $table_locality_lang;
  17. public $has_premium;
  18. public $has_exclusive;
  19. public $is_agency_search;
  20. public $query;
  21. public $query_agency;
  22. public $query_premium;
  23. public $query_count;
  24. public $select;
  25. public $select_count;
  26. public $from;
  27. public $where;
  28. public $global_where;
  29. public $order;
  30. public $search_request;
  31. public $search_count;
  32. public $search_count_premium;
  33. public $search_results;
  34. public $search_results_agency;
  35. public $search_results_premium;
  36. public $search_results_exclusive;
  37. public $search_hierarchy_agency;
  38. public $search_parameters;
  39. public $loc_keys;
  40. public $link_trad = true;
  41. public $PerimProximit = 0;
  42. public $FirstLocalityProximity = "";
  43. public $list_lock_proximite;
  44. public $Proximity_level;
  45. public $Proximity_lockey;
  46. public $lat1;
  47. public $long1;
  48. public $loc_nameGrp;
  49. public $isAdvancedSearch = false;
  50. // vrai si tle type de transaction a été setté dans la requête sql
  51. // ex. xxx_type_transaction = 1 => pas de besoin de faire ensuite
  52. // un xxx_type_transaction <> 4 pour exclure les viagers
  53. public $isTtypeTransactionAlreadySetInSql = false;
  54. /* Parametres */
  55. /*
  56. Ce parametre est d�fini dans /LIB/common.function.php -> $cumul_ad_for_agency_search
  57. 1= cumul sur Ventes et Locations par d�fault
  58. 2= Ventes
  59. 3= Locations
  60. */
  61. public $cumul_ad_for_agency_search = 1;
  62. // *** constructor ***
  63. function setPerimProximit($val) {
  64. $this->PerimProximit = $val;
  65. }
  66. public function isAdvancedSearch() {
  67. return $this->isAdvancedSearch;
  68. }
  69. // ***
  70. function getCoord($lockey) {
  71. global $_global;
  72. $loctab = explode("_", $lockey);
  73. $res = array();
  74. $sql = "SELECT lct_lat,lct_long, lct_name_" . $_global["lang"] . " FROM T_LOCALITY_LCT_" . strtoupper($_global["site"]);
  75. $this->Proximity_level = $loctab[1];
  76. $this->Proximity_lockey = $loctab[0];
  77. switch ($loctab[1]) {
  78. case 1:
  79. $sql .=" WHERE lct_id=" . $loctab[0];
  80. break;
  81. case 2:
  82. $sql .=" WHERE lct_id=" . $loctab[0];
  83. break;
  84. case 98:
  85. $sql .=" WHERE lgc_id=" . $loctab[0];
  86. break;
  87. case 99:
  88. $sql .=" WHERE lgn_id=" . $loctab[0];
  89. break;
  90. default:
  91. echo "ERREUR DANS LA CREATION DE LA REQUETE :) (" . $loctab[1] . ")";
  92. return $res;
  93. break;
  94. }
  95. if ($_global["debug"] == 3 || $_global["debug"] == 1) {
  96. echo "getCoord()<br />";
  97. echo $sql . "<br />";
  98. echo "<hr />";
  99. }
  100. $res = pdoquery($sql);
  101. $this->lat1 = $this->long1 = 0;
  102. if ($res) {
  103. $this->lat1 = $res[0]['lct_lat'];
  104. $this->long1 = $res[0]['lct_long'];
  105. }
  106. $this->getLocalityProximit($res[0]['lct_lat'], $res[0]['lct_long']);
  107. }
  108. // ***
  109. function getLocalityProximit($lat, $long) {
  110. global $_global;
  111. $this->list_lock_proximite = "";
  112. //if ($this->Proximity_level <> 1)
  113. //{
  114. $sql = "SELECT lct_id FROM (SELECT lct_id,
  115. (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))))
  116. as Proximite from T_LOCALITY_LCT_FR ) AS GLO where Proximite<='$this->PerimProximit'";
  117. //LOC_LOOKUP_FR
  118. if ($this->Proximity_lockey == "100") {
  119. $sql .= " AND lct_id <> 1";
  120. }
  121. $sql .= " order by Proximite";
  122. if ($_global["debug"] == 1 || $_global["debug"] == 3) {
  123. echo "getLocalityProximit()<br />";
  124. echo $sql . "<br />";
  125. echo "<hr />";
  126. }
  127. echo $sql . "<br />";
  128. $res = pdoquery($sql);
  129. /*
  130. }
  131. else
  132. {
  133. $res[0]['lct_id'] = $this->Proximity_lockey;
  134. }
  135. */
  136. if ($res) {
  137. for ($cnt = 0; $cnt < count($res); $cnt++) {
  138. $this->list_lock_proximite .= $res[$cnt]['lct_id'];
  139. if ($cnt < count($res) - 1) {
  140. $this->list_lock_proximite .= ", ";
  141. }
  142. }
  143. } else {
  144. $this->list_lock_proximite = 100;
  145. }
  146. }
  147. /* Retrouve le nombre d'annonce par ville par univers pour une agence */
  148. function get_NbAds_Agency($id_agency = "") {
  149. GLOBAL $_global;
  150. // sets from
  151. $this->setFrom();
  152. $sql = "SELECT count(*) as count, " . $this->table_prfx . "_default_town, " . $this->table_prfx . "_locality_2 ";
  153. $sql .= ", l.lct_name_fr ";
  154. $sql .= "FROM " . $this->from . " , T_LOCALITY_LCT_FR l ";
  155. $sql .= "WHERE id_agence='$id_agency' AND (" . $this->table_prfx . "_ad_status >= 0) ";
  156. $sql .= "AND t." . $this->table_prfx . "_locality_2 = l.lct_id ";
  157. $sql .= "AND (" . $this->table_prfx . "_country = 'FR') ";
  158. if ($_global['univers'] == 1) {
  159. $sql .= "AND (" . $this->table_prfx . "_price > 10000) ";
  160. }
  161. $sql .= "AND (" . $this->table_prfx . "_property_type_id IN (1, 2, 3, 4, 5, 6, 7, 8)) ";
  162. //$sql .= "AND ".$this->table_prfx."_default_town <> '' "; /// Attention il arrive qu'il soit vide
  163. //$sql .= "group by ".$this->table_prfx."_default_town ";
  164. $sql .= "group by lct_name_fr ";
  165. $sql .= "order by lct_name_fr, count ";
  166. //$new_sql = "CALL GET_NB_ADS_PER_TOWN_PER_AGENCY(?)";
  167. //$sql = "CALL GET_NB_ADS_PER_TOWN_PER_AGENCY('2337D4CF-6368-5E2B-F5FB-D2513A7169B1');";
  168. //$new_sql = "CALL GET_NB_ADS_PER_TOWN_PER_AGENCY('$id_agency')";
  169. if ($_global["debug"] == 3) {
  170. echo "get_NbAds_Agency()<br />";
  171. echo $sql . "<br />";
  172. echo "<hr />";
  173. }
  174. $res = pdoquery($sql);
  175. //$res = pdoprocstock($new_sql, $id_agency);
  176. return $res;
  177. }
  178. /* Retrouve les 3 annonces pour une agence avec priorité sur les exclusivité */
  179. function get_Exclusive_Ads_Agency($id_agency = "") {
  180. GLOBAL $_global;
  181. // sets from
  182. $this->setFrom();
  183. $sql = "SELECT * ";
  184. $sql .= "FROM " . $this->from . " ";
  185. $sql .= "WHERE id_agence='$id_agency' AND (" . $this->table_prfx . "_ad_status >= 0) ";
  186. //$sql .= "AND (".$this->table_prfx."_country = 'FR') ";
  187. if ($_global['univers'] == 1) {
  188. $sql .= "AND (" . $this->table_prfx . "_price > 10000) ";
  189. }
  190. $sql .= "AND (" . $this->table_prfx . "_property_type_id IN (1, 2)) ";
  191. $sql .= "AND " . $this->table_prfx . "_default_town <> '' ";
  192. $sql .= "AND " . $this->table_prfx . "_photo <> '' ";
  193. $sql .= "ORDER BY " . $this->table_prfx . "_is_exclusive desc, " . $this->table_prfx . "_update_date ";
  194. $sql .= " LIMIT 0, 3";
  195. if ($_global["debug"] == 3) {
  196. echo "get_Exclusive_Ads_Agency()<br />";
  197. echo $sql . "<br />";
  198. echo "<hr />";
  199. }
  200. $res = pdoquery($sql);
  201. return $res;
  202. }
  203. /////////////////////////////////////////////////////////////////////////////
  204. // ***
  205. function search_object($table_name = TABLE_S_NAME, $table_prefix = TABLE_S_PRFX) {
  206. $this->setTable($table_name, $table_prefix);
  207. /* Attention peut générer des requête sur la HomePAge */
  208. //$this->relief();
  209. }
  210. // *** set main properties ***
  211. function setTable($table_name, $table_prefix) {
  212. global $_global;
  213. // sets table data
  214. $this->table_name = $table_name;
  215. $this->table_prfx = $table_prefix;
  216. // sets table locality
  217. $this->table_locality_name = "T_LOCALITY_LCT_FR";
  218. $this->table_locality_lang = ""; //"_".$_global["lang"]; // forcage pour FR pas de suffixe
  219. //$this->table_locality_name = "T_LOCALITY_LCT_FR";
  220. /*
  221. if (checkLockFile("memorytable_maintenance") == true)
  222. {
  223. $this->table_locality_name = "T_LOCALITY_LCT_FR";
  224. }
  225. else
  226. {
  227. $this->table_locality_name = (memoryTableCheck() == true ? "LOC_LOOKUP" : "T_LOCALITY_LCT_FR");
  228. }
  229. */
  230. }
  231. function isGrpAgency($liste) {
  232. $this->isGrpAgency = true;
  233. $this->list_agency = $liste;
  234. }
  235. function get_Where() {
  236. $sWhere = implode(" AND ", $this->global_where);
  237. return $sWhere;
  238. }
  239. function getAdsCount($request, $advanced = false) {
  240. global $_global;
  241. // sets request
  242. $this->search_request = $this->setRequest($request);
  243. $where = array();
  244. // Ajouter le pays
  245. $this->setWhere($where, "country");
  246. // Filtrer le status de l'annonce
  247. $this->setWhere($where, "ad_status");
  248. // Ajouter la localité
  249. if ($this->PerimProximit > 0) {
  250. $this->setWhere($where, "perimproximit");
  251. } else {
  252. $this->setWhere($where, "locality");
  253. }
  254. $this->setWhere($where, "price");
  255. $this->setWhere($where, "area");
  256. $this->setWhere($where, "ck_nb_rooms");
  257. $this->setWhere($where, "ck_nb_bedrooms");
  258. if ($_global['univers'] == 1 || $_global['univers'] == 2 AND $advanced) {
  259. // Champs de recherche avancée par encore en base !
  260. $this->setWhere($where, "surf"); // Surface du terrain
  261. $this->setWhere($where, "dpe"); // Recherche par dpe
  262. $this->setWhere($where, "fresh"); // Recherche par fraicheur d'annonces
  263. $this->setWhere($where, "ck_advanced");
  264. }
  265. // vacances
  266. if ($_global["univers"] == 13) {
  267. $this->setWhere($where, "nb_bedrooms");
  268. $this->setWhere($where, "nb_people");
  269. $this->setWhere($where, "type_transaction", 3);
  270. }
  271. // location
  272. elseif ($_global["univers"] == 2) {
  273. $this->setWhere($where, "type_transaction", 2);
  274. }
  275. // colocation
  276. elseif ($_global["univers"] == 8) {
  277. $this->setWhere($where, "type_transaction", 8);
  278. }
  279. // doit être placé après l'appel à ceci :
  280. // $this->setWhere($where, "type_transaction", ...);
  281. $this->setWhere($where, "ck_property_type");
  282. if ($_REQUEST['an_visuel'] == 1)
  283. $this->setWhere($where, "photo");
  284. $this->where = $where;
  285. //////////////////////////////////////////////////////////
  286. $this->setFrom(false);
  287. // builds main query
  288. $this->query = 'SELECT COUNT(*) AS NUM FROM ' . $this->from;
  289. $this->query .= ' WHERE ' . implode(' AND ', $this->where);
  290. if ($_global["debug"] == 3) {
  291. echo 'getAdsCount()<br />';
  292. echo $this->query . "<br /><hr />";
  293. }
  294. $this->result = pdoquery($this->query);
  295. return $this->result[0]['NUM'];
  296. }
  297. /**
  298. * Function getAgencyAds : uniquement pour l'univers 9 (liste annonces agence vente + location)
  299. *
  300. * @global type $_global
  301. * @param type $request
  302. * @param type $offset
  303. */
  304. function getAgencyAds($request, $offset) {
  305. global $_global;
  306. //*** TABLE TO USE !***//
  307. $sSAL_table_name = '';
  308. $sRNT_table_name = '';
  309. $sSql = " SELECT ttu_sal_fr, ttu_rnt_fr FROM TP_TABLE_TO_USE_TTU";
  310. $r = pdoquery($sSql);
  311. //var_dump($r);die;
  312. if (sizeof($r) > 0) {
  313. $sSAL_table_name = $r[0]["ttu_sal_fr"];
  314. $sRNT_table_name = $r[0]["ttu_rnt_fr"];
  315. }
  316. // Si on trouve une des 2 tables en TM on force à T ! Sinon ça plante !
  317. if (('TM' == substr($sSAL_table_name, 0, 2) && 'TM' != substr($sRNT_table_name, 0, 2)) ||
  318. ('TM' == substr($sRNT_table_name, 0, 2) && 'TM' != substr($sSAL_table_name, 0, 2))
  319. ) {
  320. $sSAL_table_name = 'T_SALESAD_SAL';
  321. $sRNT_table_name = 'T_RENTAD_RNT';
  322. }
  323. $this->search_parameters["univers"] = $_global["univers"]; // = 9
  324. $this->is_agency_search = true;
  325. $this->search_request = $this->setRequest($request);
  326. $this->setDate();
  327. $this->search_parameters["offset"] = "" . $offset . "";
  328. $date_in_where = '';
  329. if ($_REQUEST['seven_days'] == 1) {
  330. (!empty($date)) ? "DATEDIFF('$date', sal_first_online_date) AS days_old, " : '' .
  331. $date_in_where = "DATEDIFF('" . date("Y-m-d", time() - 7 * 24 * 60 * 60) . "', sal_first_online_date) AS days_old, ";
  332. }
  333. $this->query = '';
  334. //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;
  335. //*** CONSTRUCTION REQUETE VENTE ***//
  336. $sReq_SAL = ''; //SQL_CALC_FOUND_ROWS
  337. $sReq_SAL .= "(SELECT id_annonce,
  338. SAL.sal_ai_id AS ai_id,
  339. sal_reference AS reference,
  340. sal_num_mandat AS num_mandat,
  341. sal_is_premium AS is_premium,
  342. sal_is_logo_agency AS is_logo_agency,
  343. sal_is_directory_agency AS is_directory_agency,
  344. sal_is_website_agency AS is_website_agency,
  345. sal_type_transaction AS type_transaction,
  346. id_bien,
  347. '' AS prg_title,
  348. '' AS id_bien_programme,
  349. sal_property_type_id AS property_type_id,
  350. sal_property_type_id_orig AS property_type_id_orig,
  351. sal_property_type AS property_type,
  352. sal_area AS area,
  353. sal_price AS price,
  354. sal_nb_rooms AS nb_rooms,
  355. sal_default_text AS default_text,
  356. sal_is_exclusive AS is_excusive,
  357. sal_currency AS currency,
  358. sal_photo AS photo,
  359. sal_nb_photo AS nb_photo,
  360. sal_logicode AS logicode,
  361. sal_logicode_old AS logicode_old,
  362. sal_post_code AS post_code,
  363. sal_default_town AS default_town,
  364. sal_default_town_2 AS default_town_2,
  365. sal_default_town_1 AS default_town_1,
  366. sal_default_town_0 AS default_town_0,
  367. sal_district_id1 AS district_id1,
  368. sal_district_name1 AS district_name1,
  369. sal_district_id2 AS district_id2,
  370. sal_district_name2 AS district_name2,
  371. sal_district_id3 AS district_id3,
  372. sal_district_name3 AS district_name3,
  373. lgm_id, lgc_id, lgn_id,
  374. sal_country AS country,
  375. sal_default_proximity AS default_proximity,
  376. sal_default_sector AS default_sector,
  377. sal_locality_0 AS locality_0,
  378. sal_locality_1 AS locality_1,
  379. sal_locality_2 AS locality_2,
  380. sal_first_online_date AS first_online_date,
  381. sal_update_date AS update_date, "
  382. . $date_in_where .
  383. "sal_pub_code AS pub_code,
  384. id_agence,
  385. id_presto,
  386. sal_name_agency AS name_agency,
  387. sal_post_code_agency AS post_code_agency,
  388. sal_town_agency AS town_agency,
  389. sal_tel_agency AS tel_agency,
  390. sal_fax_agency AS fax_agency,
  391. sal_email_agency AS email_agency,
  392. sal_site_agency AS site_agency,
  393. sal_rcs_agency AS rcs_agency,
  394. sal_logo_agency AS logo_agency,
  395. sal_franchising_agency AS franchising_agency,
  396. sal_is_powersite_agency AS is_powersite_agency,
  397. sal_powersite_url_agency AS powersite_url_agency,
  398. sal_powersite_calltracking_agency AS powersite_calltracking_agency,
  399. sal_advanced_set AS advanced_set,
  400. sal_personnalisable AS personnalisable,
  401. 1 as univ
  402. FROM " . $sSAL_table_name . " SAL
  403. WHERE id_agence = '" . $this->search_request["id_agence"] . "'
  404. AND sal_ad_status >= 0
  405. AND sal_country = '" . strtoupper($_global["site"]) . "') ";
  406. //*** CONSTRUCTION REQUETE LOCATION ***//
  407. $sReq_RNT = ''; //SQL_CALC_FOUND_ROWS
  408. $sReq_RNT .= "(SELECT id_annonce,
  409. RNT.rnt_ai_id AS ai_id,
  410. rnt_reference AS reference,
  411. rnt_num_mandat AS num_mandat,
  412. rnt_is_premium AS is_premium,
  413. rnt_is_logo_agency AS is_logo_agency,
  414. rnt_is_directory_agency AS is_directory_agency,
  415. rnt_is_website_agency AS is_website_agency,
  416. rnt_type_transaction AS type_transaction,
  417. id_bien,
  418. '' AS prg_title,
  419. '' AS id_bien_programme,
  420. rnt_property_type_id AS property_type_id,
  421. rnt_property_type_id_orig AS property_type_id_orig,
  422. rnt_property_type AS property_type,
  423. rnt_area AS area,
  424. rnt_price AS price,
  425. rnt_nb_rooms AS nb_rooms,
  426. rnt_default_text AS default_text,
  427. rnt_is_exclusive AS is_excusive,
  428. rnt_currency AS currency,
  429. rnt_photo AS photo,
  430. rnt_nb_photo AS nb_photo,
  431. rnt_logicode AS logicode,
  432. rnt_logicode_old AS logicode_old,
  433. rnt_post_code AS post_code,
  434. rnt_default_town AS default_town,
  435. rnt_default_town_2 AS default_town_2,
  436. rnt_default_town_1 AS default_town_1,
  437. rnt_default_town_0 AS default_town_0,
  438. rnt_district_id1 AS district_id1,
  439. rnt_district_name1 AS district_name1,
  440. rnt_district_id2 AS district_id2,
  441. rnt_district_name2 AS district_name2,
  442. rnt_district_id3 AS district_id3,
  443. rnt_district_name3 AS district_name3,
  444. lgm_id, lgc_id, lgn_id,
  445. rnt_country AS country,
  446. rnt_default_proximity AS default_proximity,
  447. rnt_default_sector AS default_sector,
  448. rnt_locality_0 AS locality_0,
  449. rnt_locality_1 AS locality_1,
  450. rnt_locality_2 AS locality_2,
  451. rnt_first_online_date AS first_online_date,
  452. rnt_update_date AS update_date, "
  453. . $date_in_where .
  454. "rnt_pub_code AS pub_code,
  455. id_agence,
  456. id_presto,
  457. rnt_name_agency AS name_agency,
  458. rnt_post_code_agency AS post_code_agency,
  459. rnt_town_agency AS town_agency,
  460. rnt_tel_agency AS tel_agency,
  461. rnt_fax_agency AS fax_agency,
  462. rnt_email_agency AS email_agency,
  463. rnt_site_agency AS site_agency,
  464. rnt_rcs_agency AS rcs_agency,
  465. rnt_logo_agency AS logo_agency,
  466. rnt_franchising_agency AS franchising_agency,
  467. rnt_is_powersite_agency AS is_powersite_agency,
  468. rnt_powersite_url_agency AS powersite_url_agency,
  469. rnt_powersite_calltracking_agency AS powersite_calltracking_agency,
  470. rnt_advanced_set AS advanced_set,
  471. rnt_personnalisable AS personnalisable,
  472. 2 as univ
  473. FROM " . $sRNT_table_name . " RNT
  474. WHERE id_agence = '" . $this->search_request["id_agence"] . "'
  475. AND rnt_ad_status >= 0
  476. AND rnt_type_transaction = 2
  477. AND rnt_country = '" . strtoupper($_global["site"]) . "') ";
  478. $this->query = 'SELECT SQL_CALC_FOUND_ROWS * FROM ( ' . $sReq_SAL . 'UNION ALL ' . $sReq_RNT;
  479. // sets index
  480. $force_index = array();
  481. $this->setIndex($force_index, "locality");
  482. // common index clause
  483. // force index when we are doing a search on more than one locality
  484. if (count($force_index) > 1) {
  485. $this->force_index = $force_index;
  486. }
  487. //*** CONSTRUCTION ORDER ***//
  488. if (isset($this->search_request["order_ads_agency"])) {
  489. $this->setOrderAgencyAds($this->search_request["order"]);
  490. if ($this->search_request["order_ads_agency"] == "") {
  491. $this->search_request["order_ads_agency"] = "date_asc";
  492. }
  493. $this->setOrderAgencyAds($this->search_request["order_ads_agency"]);
  494. } else {
  495. $this->setOrderAgencyAds($this->search_request["order"]);
  496. }
  497. //*** CONSTRUCTION LIMIT ***//
  498. $this->setLimit("ad", $offset);
  499. $this->query .= ") AS RESULTVIEW ORDER BY " . implode(", ", $this->order);
  500. //-- VARIABLE USED IN TEST FILE DISPLAY/resultats_testpoi.php
  501. $_global["debug_testpoi"] = $this->query;
  502. $this->query .= " LIMIT " . $this->limit;
  503. // adds post code
  504. $_start = microtime(true);
  505. $this->setPostCodes();
  506. $this->showTime("set post codes", $_start);
  507. // executes the query
  508. $_start = microtime(true);
  509. if ($_global["debug"] == 3) {
  510. echo 'getAgencyAds() - 2<br />';
  511. echo $this->query . "<br />";
  512. echo "<hr />";
  513. }
  514. $this->search_results = pdoquery($this->query);
  515. $this->showTime("main search", $_start);
  516. // builds the count query
  517. $this->query_count = "SELECT FOUND_ROWS() AS NUM";
  518. // executes the count query
  519. $_start = microtime(true);
  520. if ($_global["debug"] == 3) {
  521. echo 'getAds() - 3<br />';
  522. echo $this->query_count . "<br />";
  523. echo "<hr />";
  524. }
  525. $this->search_count = pdoquery($this->query_count);
  526. $this->search_count = $this->search_count[0]["NUM"];
  527. $this->showTime("main count", $_start);
  528. // save
  529. $this->search_parameters["count"] = $this->search_count;
  530. $this->search_request["count"] = $this->search_count;
  531. // calculates number of pages
  532. $this->setPages("ad");
  533. // sets antenna
  534. $this->setAntenna();
  535. // saves search
  536. $this->saveSearch();
  537. }
  538. // *** search ads ***
  539. /**
  540. *
  541. * @global type $_global
  542. * @param string $request
  543. * @param string $offset
  544. * @param bool $skip_premium NE SERT A RIEN DANS LES PARAMETRES !!!
  545. * @param bool $simulate
  546. */
  547. function getAds($request, $offset, $skip_premium = false, $simulate = false) {
  548. global $_global;
  549. // adds universe
  550. $this->search_parameters["univers"] = $_global["univers"];
  551. // is agency search ?
  552. $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
  553. // sets request
  554. //echo "<br><b>search.class.php:424</b> : request : "; var_dump($request); echo "<br>\n";
  555. $this->search_request = $this->setRequest($request);
  556. //echo "<br><b>search.class.php:426</b> : getRequest : "; var_dump($this->search_request); echo "<br>\n";
  557. // adds date
  558. $this->setDate();
  559. // sets offset
  560. $this->search_parameters["offset"] = "" . $offset . "";
  561. // sets select
  562. $this->setSelect("ad", false);
  563. // sets where
  564. $where = array();
  565. if ($this->isGrpAgency == true) {
  566. $this->setWhere($where, "grp_id_agence", $this->list_agency);
  567. }
  568. $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
  569. $this->setWhere($where, "ad_status");
  570. if (!$this->is_agency_search) {
  571. if ($this->PerimProximit > 0) {
  572. $this->setWhere($where, "perimproximit");
  573. } elseif (!isset($this->search_request['loc_key2'])) {
  574. $this->setWhere($where, "locality");
  575. }
  576. }
  577. $this->setWhere($where, "country");
  578. $this->setWhere($where, "price");
  579. $this->setWhere($where, "area");
  580. $this->setWhere($where, "ck_nb_rooms");
  581. if ($_global['univers'] == 1 || $_global['univers'] == 2) {
  582. // Champs de recherche avancée par encore en base !
  583. //$this->setWhere($where, "surf"); // Surface du terrain
  584. $this->setWhere($where, "dpe"); // Recherche par dpe
  585. $this->setWhere($where, "fresh"); // Recherche par fraicheur d'annonces
  586. $this->setWhere($where, "ck_nb_bedrooms");
  587. $this->setWhere($where, "ck_advanced");
  588. }
  589. // vacances
  590. if ($_global["univers"] == 13) {
  591. $this->setWhere($where, "nb_bedrooms");
  592. $this->setWhere($where, "nb_people");
  593. $this->setWhere($where, "type_transaction", 3);
  594. }
  595. // location
  596. elseif ($_global["univers"] == 2) {
  597. $this->setWhere($where, "type_transaction", 2);
  598. }
  599. // colocation
  600. elseif ($_global["univers"] == 8) {
  601. $this->setWhere($where, "type_transaction", 8);
  602. }
  603. // doit être placé après l'appel à ceci :
  604. // $this->setWhere($where, "type_transaction", ...);
  605. $this->setWhere($where, "ck_property_type");
  606. if ($_REQUEST['an_visuel'] == 1) {
  607. $this->setWhere($where, "photo");
  608. }
  609. if ($_REQUEST['only_old'] == 1) {
  610. $this->setWhere($where, "only_old");
  611. }
  612. if ($_REQUEST['seven_days'] == 1) {
  613. $date = date("Y-m-d", time() - 7 * 24 * 60 * 60);
  614. $this->setWhere($where, 'date', $date);
  615. }
  616. if ($_global["debug"] == 1) {
  617. echo "Dump '_REQUEST'<br />";
  618. var_dump($_REQUEST);
  619. echo "<hr />";
  620. }
  621. $this->setWhere($where, "with_mmf");
  622. // common where clause
  623. $this->where = $where;
  624. // sets index
  625. $force_index = array();
  626. $this->setIndex($force_index, "locality");
  627. // common index clause
  628. // force index when we are doing a search on more than one locality
  629. if (count($force_index) > 1) {
  630. $this->force_index = $force_index;
  631. }
  632. // sets order
  633. /*
  634. if (isset($this->search_request["order_price"])){
  635. $this->setOrder("ad", $this->search_request["order"]);
  636. if ($this->search_request["order_price"]==""){$this->search_request["order_price"]=1;}
  637. $this->setOrder("filter_ad", $this->search_request["order_price"], "price");
  638. }
  639. */
  640. if (isset($this->search_request["order_ads_agency"])) {
  641. $this->setOrder("ad", $this->search_request["order"]);
  642. if ($this->search_request["order_ads_agency"] == "") {
  643. $this->search_request["order_ads_agency"] = "date_asc";
  644. }
  645. $this->setOrder("filter_ad", $this->search_request["order_ads_agency"]);
  646. } else {
  647. $this->setOrder("ad", $this->search_request["order"]);
  648. }
  649. // sets from
  650. // SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
  651. $this->setFrom(false);
  652. // builds main query
  653. $this->query = "SELECT SQL_CALC_FOUND_ROWS " . $this->select . " "; //SQL_CALC_FOUND_ROWS
  654. $this->query .= "FROM " . $this->from . " ";
  655. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  656. // W.asbaiti 24/01/2013
  657. // Dans le cas de recherche multi localité, on remplace la clause or multi loc par union avec requete mono loc
  658. if (isset($this->search_request['loc_key2'])) {
  659. // Ajout de la premiere localite
  660. $valLoc = explode("_", $this->search_request['loc_key1']);
  661. $this->query .= " AND " . $this->setLocWhere($valLoc, 1);
  662. // Ajout de la 2eme localite
  663. $this->query .= ' UNION ';
  664. $this->query .= "SELECT " . $this->select . " "; //SQL_CALC_FOUND_ROWS
  665. $this->query .= "FROM " . $this->from . " ";
  666. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  667. // Ajout requete pour 2eme localite
  668. $valLoc = explode("_", $this->search_request['loc_key2']);
  669. $this->query .= " AND " . $this->setLocWhere($valLoc, 2);
  670. // Traiteent 3eme localite
  671. if (isset($this->search_request['loc_key3'])) {
  672. $this->query .= ' UNION ';
  673. $this->query .= "SELECT " . $this->select . " "; //SQL_CALC_FOUND_ROWS
  674. $this->query .= "FROM " . $this->from . " ";
  675. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  676. $valLoc = explode("_", $this->search_request['loc_key3']);
  677. $this->query .= " AND " . $this->setLocWhere($valLoc, 3);
  678. }
  679. $this->query = str_replace('SQL_CALC_FOUND_ROWS', '', $this->query);
  680. $this->query = "SELECT SQL_CALC_FOUND_ROWS * FROM (" . $this->query . ") as search_result ";
  681. }
  682. //-- VARIABLE SET BY XAVIER INNAVONG, USED IN TEST FILE DISPLAY/resultats_testpoi.php
  683. $_global["debug_testpoi_where"] = $this->where;
  684. // sur l'univers vente
  685. // si on est pas sur le tri par défaut (du moins cher au plus cher)
  686. // on ne met pas en avant les annonces exclu orpi et à la une
  687. if ($_COOKIE['fromSort'] == "true") {
  688. $skip_premium = true;
  689. } else if ($_global['page'] == "resultats_agence_annonces") {
  690. $skip_premium = true;
  691. } else if ($_global['page'] == "resultats_coloc") {
  692. $skip_premium = true;
  693. }
  694. // Ne pas afficher les annonces ORPI sur page > 1 de PR
  695. // Garder les annonce premium (annonce a la une)
  696. if ($offset > 1) {
  697. $skip_orpi = true;
  698. } else {
  699. $skip_orpi = false;
  700. }
  701. if ($skip_premium == false) {
  702. if (isset($this->search_request['loc_key2'])) {
  703. foreach ($this->search_parameters["loc_keys"] as $sLoc) {
  704. $aLocInfo = explode('_', $sLoc);
  705. switch ($aLocInfo[1]) {
  706. // map group
  707. case 97 :
  708. $aComplement[] = "lgm_id = " . $aLocInfo[0];
  709. break;
  710. // code group
  711. case 98 :
  712. $aComplement[] = "lgc_id = " . $aLocInfo[0];
  713. break;
  714. // name group
  715. case 99 :
  716. $aComplement[] = "lgn_id = " . $aLocInfo[0];
  717. break;
  718. // standard
  719. default :
  720. $aComplement[] = $this->table_prfx . "_locality_" . $aLocInfo[1] . " = " . $aLocInfo[0];
  721. break;
  722. }
  723. }
  724. $sComplement = ' AND (' . implode(' OR ', $aComplement) . ')';
  725. }
  726. // Construction de la requete Premium + Exclusive
  727. if (CURRENT_EXCLUSIVE_NUM > 0 && !$skip_orpi) {
  728. $where_exclusive = $where;
  729. // builds premium query
  730. $this->setWhere($where, "premium");
  731. // builds premium query
  732. $this->setWhere($where_exclusive, "exclusive", CURRENT_EXCLUSIVE_NUM);
  733. $this->query_premium = '( SELECT ' . $this->select . '
  734. FROM ' . $this->from . '
  735. WHERE ' . implode(' AND ', $where_exclusive) . '
  736. ' . $sComplement . '
  737. LIMIT 0,30
  738. ) UNION (
  739. SELECT ' . $this->select . '
  740. FROM ' . $this->from . '
  741. WHERE ' . implode(' AND ', $where) . '
  742. ' . $sComplement . '
  743. LIMIT 0,30
  744. )';
  745. // Construction de la requete Premium
  746. } else {
  747. // builds premium query
  748. $this->setWhere($where, "premium");
  749. $this->query_premium = 'SELECT ' . $this->select . '
  750. FROM ' . $this->from . '
  751. WHERE ' . implode(' AND ', $where) . '
  752. ' . $sComplement . '
  753. LIMIT 0,30';
  754. }
  755. if ($simulate == false) {
  756. // executes the premium query
  757. $_delta = microtime(true);
  758. if ($_global["debug"] == 3) {
  759. echo 'getAds() - 1<br />';
  760. echo $this->query_premium . "<br />";
  761. echo "<hr />";
  762. }
  763. $this->search_results_premium = pdoquery($this->query_premium);
  764. $nb_total = count($this->search_results_premium);
  765. // Doit-on traiter les annonces exclusives ?
  766. if (CURRENT_EXCLUSIVE_NUM > 0) {
  767. $nb_exclusive = 0;
  768. // Trouver le nombre d'annonces exclusives
  769. if (sizeof($this->search_results_premium) > 0) {
  770. foreach ($this->search_results_premium as $annonce) {
  771. if ($annonce[$this->table_prfx . '_is_exclusive'] == CURRENT_EXCLUSIVE_NUM)
  772. ++$nb_exclusive;
  773. else
  774. $break;
  775. }
  776. }
  777. // Calculer le nombre d'annonces premium
  778. $nb_premium = $nb_total - $nb_exclusive;
  779. if ($nb_exclusive > 0) {
  780. $randexclu = rand(0, $nb_exclusive - 1);
  781. $this->search_results_exclusive = $this->search_results_premium[$randexclu];
  782. //Yo - 2011/08/05 : Exclure cet annonce Orpi dans la liste des résultats pour éviter le doublon
  783. //Probleme: Si on fait pas: on a une Orpi(aléatoire) à la première position et une autre orpi dans le résultat
  784. //Et si jamais elles sont les mêmes, on a doublon
  785. // W.ASBAITI : inclure ORPI dans la liste de recherche pour gérer la navigation sur la page detail (risque de doublons accepte par market)
  786. // $this->query .= "AND id_annonce != '".$this->search_results_exclusive['id_annonce']."'"." ";
  787. $this->has_exclusive = true;
  788. } else {
  789. $this->has_exclusive = false;
  790. }
  791. if ($_global["debug"] == 3) {
  792. echo 'TOTAL: ' . $nb_total . ' / PREMIUM: ' . $nb_premium . ' / EXCLU: ' . $nb_exclusive . '<hr />';
  793. }
  794. } else {
  795. $nb_premium = $nb_total;
  796. if ($_global["debug"] == 3) {
  797. echo 'TOTAL: ' . $nb_total . ' / PREMIUM: ' . $nb_premium . '<hr />';
  798. }
  799. }
  800. //parametres supplémentaires pour corriger la pagination
  801. //Ajout de Mathieu pour ne pas tout détruire...07/12/2012
  802. if ($nb_premium > 0) {
  803. $this->search_parameters["premiumPresente"] = true;
  804. } else {
  805. $this->search_parameters["premiumPresente"] = false;
  806. }
  807. if ($nb_exclusive > 0) {
  808. $this->search_parameters["exclusivePresente"] = true;
  809. } else {
  810. $this->search_parameters["exclusivePresente"] = false;
  811. }
  812. if ($nb_premium > 0) {
  813. $randpremium = rand($nb_exclusive, $nb_total - 1);
  814. $this->search_results_premium = array($this->search_results_premium[$randpremium]);
  815. $this->search_count_premium = $nb_premium;
  816. $this->has_premium = true;
  817. $this->search_parameters["premium"] = 1;
  818. } else {
  819. $this->search_count_premium = 0;
  820. $this->has_premium = false;
  821. $this->search_parameters["premium"] = 0;
  822. }
  823. $this->showTime("premium search", $_delta);
  824. }
  825. }
  826. // sets limit
  827. $this->setLimit("ad", $offset);
  828. // main query additional clause
  829. //var_dump($this->order);
  830. $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
  831. //-- VARIABLE SET BY XAVIER INNAVONG, USED IN TEST FILE DISPLAY/resultats_testpoi.php
  832. $_global["debug_testpoi"] = $this->query;
  833. // Stockage de la requete pour pagination page detail
  834. // $this->save_query($this->query);
  835. $this->query .= "LIMIT " . $this->limit;
  836. // adds post code
  837. $_start = microtime(true);
  838. $this->setPostCodes();
  839. $this->showTime("set post codes", $_start);
  840. // executes the query
  841. $_start = microtime(true);
  842. if ($simulate == false) {
  843. if ($_global["debug"] == 3) {
  844. echo 'getAds() - 2<br />';
  845. echo $this->query . "<br />";
  846. echo "<hr />";
  847. }
  848. $this->search_results = pdoquery($this->query);
  849. $this->showTime("main search", $_start);
  850. // builds the count query
  851. $this->query_count = "SELECT FOUND_ROWS() AS NUM";
  852. // executes the count query
  853. $_start = microtime(true);
  854. if ($_global["debug"] == 3) {
  855. echo 'getAds() - 3<br />';
  856. echo $this->query_count . "<br />";
  857. echo "<hr />";
  858. }
  859. $this->search_count = pdoquery($this->query_count);
  860. $this->search_count = $this->search_count[0]["NUM"];
  861. $this->showTime("main count", $_start);
  862. // save
  863. $this->search_parameters["count"] = $this->search_count;
  864. $this->search_request["count"] = $this->search_count;
  865. // calculates number of pages
  866. $this->setPages("ad");
  867. // sets antenna
  868. $this->setAntenna();
  869. // saves search
  870. $this->saveSearch();
  871. }
  872. }
  873. /*
  874. Apparamment, cette fonction est
  875. - appelée dans bloc_principal.php (inclus dans V5_home_fr.php)
  876. - commentée dans google_gadget/gadget_search.php
  877. */
  878. // *** search ads by date ***
  879. function getAdsByDate($request) {
  880. global $_global;
  881. // adds universe
  882. $this->search_parameters["univers"] = $_global["univers"];
  883. // sets search parameters
  884. $this->search_request = $this->setRequest($request);
  885. // adds date
  886. $this->setDate(true);
  887. // sets select
  888. $this->setSelect("ad", false);
  889. // sets from
  890. $this->setFrom();
  891. // sets where
  892. $where = array();
  893. $this->setWhere($where, "ad_status");
  894. $this->setWhere($where, "locality");
  895. $this->setWhere($where, "country");
  896. $this->setWhere($where, "ck_property_type");
  897. $this->setWhere($where, "price");
  898. $this->setWhere($where, "area");
  899. $this->setWhere($where, "ck_nb_rooms");
  900. $this->setWhere($where, "date", $this->search_request["date"]);
  901. $this->setWhere($where, "with_mmf");
  902. /* START:RECHERCHE AVANCEE */
  903. /*
  904. //$this->setWhere($where, "with_mmf");
  905. $this->setWhere($where, "recent_ads");
  906. //if($request["property_type"][0] == 3)
  907. $this->setWhere($where, "surf");
  908. $this->setWhere($where, "floor");
  909. $this->setWhere($where, "elevator");
  910. $this->setWhere($where, "caretaker");
  911. $this->setWhere($where, "interphone");
  912. $this->setWhere($where, "balcony");
  913. $this->setWhere($where, "terrace");
  914. $this->setWhere($where, "parquet");
  915. $this->setWhere($where, "fireside");
  916. $this->setWhere($where, "closets");
  917. $this->setWhere($where, "storage");
  918. $this->setWhere($where, "parking");
  919. $this->setWhere($where, "garden");
  920. $this->setWhere($where, "pool");
  921. */
  922. /* STOP:RECHERCHE AVANCEE */
  923. // common where clause
  924. $this->where = $where;
  925. // sets order
  926. $this->setOrder("ad", $this->search_request["order"]);
  927. // sets limit
  928. $this->setLimit("ad", 0);
  929. // sets index
  930. $force_index = array();
  931. $this->setIndex($force_index, "locality");
  932. // common index clause
  933. // force index when we are doing a search on more than one locality
  934. if (count($force_index) > 1) {
  935. $this->force_index = $force_index;
  936. }
  937. // builds main query
  938. $this->query = "SELECT SQL_CALC_FOUND_ROWS 1 AS revisite, " . $this->select . " ";
  939. $this->query .= "FROM " . $this->from . " ";
  940. if (isset($this->force_index)) {
  941. //$this->query .= "FORCE INDEX (".implode(", ", $this->force_index).") ";
  942. }
  943. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  944. $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
  945. $this->query .= "LIMIT " . $this->limit;
  946. // adds post code
  947. $this->setPostCodes();
  948. // executes the query
  949. if ($_global["debug"] == 3) {
  950. echo "getAdsByDate() - 1<br />";
  951. echo $this->query . "<br />";
  952. echo "<hr />";
  953. }
  954. $this->search_results = pdoquery($this->query);
  955. // builds the count query
  956. $this->query_count = "SELECT FOUND_ROWS() AS NUM";
  957. // executes the count query
  958. if ($_global["debug"] == 3) {
  959. echo "getAdsByDate() - 2<br />";
  960. echo $this->query_count . "<br />";
  961. echo "<hr />";
  962. }
  963. $this->search_count = pdoquery($this->query_count);
  964. $this->search_count = $this->search_count[0]["NUM"];
  965. // save
  966. $this->search_parameters["count"] = $this->search_count;
  967. $this->search_request["count"] = $this->search_count;
  968. }
  969. /*
  970. Apparamment, cette fonction est
  971. - appelée dans ws/soap/server/classes/search.class_from50.php,
  972. - commentée dans ajax/prod.count.localities.maps.php
  973. */
  974. // *** search ads by coordinates ***
  975. function getAdsByMap($request) {
  976. global $_global;
  977. // adds universe
  978. $this->search_parameters["univers"] = $_global["univers"];
  979. // is agency search ?
  980. $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
  981. // checks if the search form has been activated or if the query has to be pulled from a cookie:
  982. $this->search_request = $this->setRequest($request);
  983. // adds date
  984. $this->setDate();
  985. // sets select
  986. $this->select = "COUNT(" . $this->table_prfx . "_ai_id) AS num, lct_id, lct_level, lct_name, lct_lat, lct_long";
  987. // sets from
  988. $this->from = $this->table_name . ", " . $this->table_locality_name;
  989. // sets where
  990. $where = array();
  991. $this->setWhere($where, "ad_status");
  992. $this->setWhere($where, "country");
  993. $this->setWhere($where, "ck_property_type");
  994. $this->setWhere($where, "price");
  995. $this->setWhere($where, "area");
  996. $this->setWhere($where, "ck_nb_rooms");
  997. $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
  998. $this->setWhere($where, "with_mmf");
  999. /* START:RECHERCHE AVANCEE */
  1000. /*
  1001. //$this->setWhere($where, "with_mmf");
  1002. $this->setWhere($where, "recent_ads");
  1003. //if($request["property_type"][0] == 3)
  1004. $this->setWhere($where, "surf");
  1005. $this->setWhere($where, "floor");
  1006. $this->setWhere($where, "elevator");
  1007. $this->setWhere($where, "caretaker");
  1008. $this->setWhere($where, "interphone");
  1009. $this->setWhere($where, "balcony");
  1010. $this->setWhere($where, "terrace");
  1011. $this->setWhere($where, "parquet");
  1012. $this->setWhere($where, "fireside");
  1013. $this->setWhere($where, "closets");
  1014. $this->setWhere($where, "storage");
  1015. $this->setWhere($where, "parking");
  1016. $this->setWhere($where, "garden");
  1017. $this->setWhere($where, "pool");
  1018. /* STOP:RECHERCHE AVANCEE */
  1019. // common where clause
  1020. $this->where = $where;
  1021. // builds main query
  1022. $this->query = "SELECT " . $this->select . " ";
  1023. $this->query .= "FROM " . $this->from . " ";
  1024. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  1025. $this->query .= "GROUP BY lct_name, lct_extra_detail, lct_lat, lct_long ";
  1026. // adds post code
  1027. $_start = microtime(true);
  1028. $this->setPostCodes();
  1029. $this->showTime("set post codes", $_start);
  1030. // executes the query
  1031. $_start = microtime(true);
  1032. if ($_global["debug"] == 3) {
  1033. echo "getAdsByMap() - 1<br />";
  1034. echo $this->query . "<br />";
  1035. echo "<hr />";
  1036. }
  1037. $this->search_results = pdoquery($this->query);
  1038. $this->showTime("main search", $_start);
  1039. // count
  1040. if ($this->search_request["offset"] == "") {
  1041. // builds the count query
  1042. $this->query_count = "SELECT FOUND_ROWS() AS NUM";
  1043. // executes the count query
  1044. $_start = microtime(true);
  1045. if ($_global["debug"] == 3) {
  1046. echo "getAdsByMap() - 2<br />";
  1047. echo $this->query_count . "<br />";
  1048. echo "<hr />";
  1049. }
  1050. $this->search_count = pdoquery($this->query_count);
  1051. $this->search_count = $this->search_count[0]["NUM"];
  1052. $this->showTime("main count", $_start);
  1053. // save
  1054. $this->search_parameters["count"] = $this->search_count;
  1055. $this->search_request["count"];
  1056. // calculates number of pages
  1057. $this->setPages("ad");
  1058. }
  1059. // saves search
  1060. $this->saveSearch();
  1061. }
  1062. /**
  1063. * Recuperer la position de l annonce EXCLU parmis toutes les annonces de la recherche
  1064. *
  1065. * @param string $id : l'ID de l'annonce à positionner
  1066. * @return array : Tableau contenant l'annonce suivante et precedente de l'id envoye en param
  1067. */
  1068. function getExcluNav($id) {
  1069. global $_global;
  1070. // Reconstruire les parametres de recherche depuis le cookie LISEARCHHISTORY
  1071. $request = $this->loadSearch();
  1072. if (empty($request))
  1073. return null;
  1074. else {
  1075. unset($request['date']);
  1076. unset($request['timestamp']);
  1077. }
  1078. if ($_global['debug'] == 1) {
  1079. echo 'Request from Cookie History ' . ($is_agency ? 'Agency' : '') . ' :<br />';
  1080. print_r($request);
  1081. echo '<hr />';
  1082. }
  1083. // Probleme: Aucun critere de recherche précisé
  1084. if (!is_array($request) || $request == array())
  1085. return null;
  1086. $where = array();
  1087. $this->search_request = $this->setRequest($request);
  1088. $this->setWhere($where, "locality");
  1089. $order = '';
  1090. if (isset($request["order"])) {
  1091. $this->setOrder("ad", $request["order"]);
  1092. $order = ' ORDER BY ' . implode(', ', $this->order);
  1093. }
  1094. $request['country'] = 'FR';
  1095. if (!isset($request['area']))
  1096. $this->setWhere($where, 'area');
  1097. // Ajouter un prix mini de 10000 pour les ventes
  1098. if ($_global['univers'] == 1) {
  1099. if (!isset($this->search_request['price_min']) || $this->search_request['price_min'] < 10000) {
  1100. $this->search_request['price_min'] = 10000;
  1101. /**
  1102. * VBA [11/10/2012]
  1103. * The price is to be unset after the query is done because we don't want it in the url.
  1104. * @var boolean
  1105. */
  1106. $price_to_unset = true;
  1107. }
  1108. }
  1109. // Si la valeur price n'est pas précisée, déclencher manuellement
  1110. // l'appel pour renseigner les valeurs min/max
  1111. if (!isset($request['price']))
  1112. $this->setWhere($where, 'price');
  1113. foreach ($request as $key => $value)
  1114. $this->setWhere($where, $key, $value);
  1115. // Problème : Aucun critère de recherche valide
  1116. if ($where == array())
  1117. return null;
  1118. if ($_global['univers'] == 2)
  1119. $where[] = '(' . $this->table_prfx . '_type_transaction = 2)';
  1120. elseif ($_global['univers'] == 8)
  1121. $where[] = '(' . $this->table_prfx . '_type_transaction = 8)';
  1122. // builds the query
  1123. $this->query = ' SELECT id_annonce FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where) . $order;
  1124. if ($_global['univers'] == 1) {
  1125. if ($price_to_unset) {
  1126. $this->search_request['price_min'] = '';
  1127. }
  1128. }
  1129. $result = pdoquery($this->query, null, null, null, PDO::FETCH_ASSOC);
  1130. return $result;
  1131. }
  1132. function getNavigateDetail($request, $num_row, $is_agency = false) {
  1133. global $_global;
  1134. if (is_null($request)) {
  1135. $this->is_agency_search = $is_agency;
  1136. $request = $this->loadSearch();
  1137. if (empty($request))
  1138. return null;
  1139. else {
  1140. unset($request['date']);
  1141. unset($request['timestamp']);
  1142. }
  1143. if ($_global['debug'] == 1) {
  1144. echo 'Request from Cookie History ' . ($is_agency ? 'Agency' : '') . ' :<br />';
  1145. print_r($request);
  1146. echo '<hr />';
  1147. }
  1148. }
  1149. // Probleme: Aucun critere de recherche précisé
  1150. if (!is_array($request) || $request == array())
  1151. return null;
  1152. $where = array();
  1153. $this->search_request = $this->setRequest($request);
  1154. $this->setWhere($where, "locality");
  1155. $order = '';
  1156. if (isset($request["order"])) {
  1157. $this->setOrder("ad", $request["order"]);
  1158. $order = ' ORDER BY ' . implode(', ', $this->order);
  1159. }
  1160. $request['country'] = 'FR';
  1161. if (!isset($request['area']))
  1162. $this->setWhere($where, 'area');
  1163. // Ajouter un prix mini de 10000 pour les ventes
  1164. if ($_global['univers'] == 1) {
  1165. if (!isset($this->search_request['price_min']) || $this->search_request['price_min'] < 10000) {
  1166. $this->search_request['price_min'] = 10000;
  1167. $ll = true;
  1168. }
  1169. }
  1170. // Si la valeur price n'est pas précisée, déclencher manuellement
  1171. // l'appel pour renseigner les valeurs min/max
  1172. if (!isset($request['price']))
  1173. $this->setWhere($where, 'price');
  1174. foreach ($request as $key => $value)
  1175. $this->setWhere($where, $key, $value);
  1176. // Problème : Aucun critère de recherche valide
  1177. if ($where == array())
  1178. return null;
  1179. if ($_global['univers'] == 2)
  1180. $where[] = '(' . $this->table_prfx . '_type_transaction = 2)';
  1181. elseif ($_global['univers'] == 8)
  1182. $where[] = '(' . $this->table_prfx . '_type_transaction = 8)';
  1183. // builds the query
  1184. $this->query = ' SELECT SQL_CACHE * FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where) . $order;
  1185. if ($_global['univers'] == 1) {
  1186. if ($ll) {
  1187. $this->search_request['price_min'] = '';
  1188. }
  1189. }
  1190. // Si on n'est pas sur la toute premiere annonce
  1191. if ($num_row > 0) {
  1192. // S'il y a des premium, il faut gérer le décalage dans les résultats de la requete
  1193. // Et faire une requete spécifique si précédent ou suivant sera une premium
  1194. if ($_global['is_there_premium']) {
  1195. // Si ce n'est ni la premiere, ni la derniere annonce d'une page
  1196. // (actuelle premium ou suivante premium ou précédente premium)
  1197. // Alors les liens sont classiques => Pas de requete premium en plus
  1198. $ecart = ($num_row + 1) % MAX_RESULTS_PER_PAGE;
  1199. if ($ecart == 0 || $ecart == 2)
  1200. $classic = false;
  1201. else {
  1202. $classic = true;
  1203. // Corriger le décalage avec les premiums
  1204. if ($ecart == 1)
  1205. $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE);
  1206. else
  1207. $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE) - 1;
  1208. }
  1209. }
  1210. else {
  1211. $classic = true;
  1212. // Pas de premium => Pas de decalage
  1213. }
  1214. // Classique => Précédent et Suivant ne sont pas des premiums
  1215. if ($classic) {
  1216. if ($ecart == 1)
  1217. $this->query .= ' LIMIT ' . ($num_row - 1) . ',2';
  1218. else
  1219. $this->query .= ' LIMIT ' . ($num_row - 1) . ',3';
  1220. if ($_global["debug"] == 3) {
  1221. echo "getNavigateDetail() - Précédent/Suivant<br />";
  1222. echo $this->query . "<br />";
  1223. echo "<hr />";
  1224. }
  1225. $result = pdoquery($this->query);
  1226. if ($_global['debug'] == 1 || $_global['debug'] == 3) {
  1227. echo 'Resultat de la requete :<br />';
  1228. foreach ($result as $i => $res)
  1229. echo 'id_annonce_' . $i . ' => ' . $res . '<br />';
  1230. echo '<hr />';
  1231. }
  1232. if (isset($result[0]))
  1233. $navigation['prev'] = $result[0];
  1234. else
  1235. $navigation['prev'] = null;
  1236. if (isset($result[1]) && $ecart == 1)
  1237. $navigation['next'] = $result[1];
  1238. elseif (isset($result[2]))
  1239. $navigation['next'] = $result[2];
  1240. else
  1241. $navigation['next'] = null;
  1242. }
  1243. // Non classique => Précédent est premium ou Suivant est premium
  1244. else {
  1245. $where[] = '(' . $this->table_prfx . '_is_premium = 1)';
  1246. $this->query_premium = ' SELECT SQL_CACHE * FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where) . $order;
  1247. $this->query_premium .= ' LIMIT 0,30';
  1248. $result = pdoquery($this->query_premium, null, null, null, PDO::FETCH_ASSOC);
  1249. $nb_results_premium = count($result);
  1250. // Si l'annonce précédente est une premium
  1251. if ($num_row % MAX_RESULTS_PER_PAGE == 1) {
  1252. $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE) - 1;
  1253. // REQUETE ANNONCE PRECEDENTE PREMIUM
  1254. if ($_global["debug"] == 3) {
  1255. echo "getNavigateDetail() - Précédent Premium<br />";
  1256. echo $this->query_premium . "<br />";
  1257. echo "<hr />";
  1258. }
  1259. if ($nb_results_premium > 0) {
  1260. $random = rand(0, $nb_results_premium - 1);
  1261. $navigation['prev'] = $result[$random];
  1262. }
  1263. else
  1264. $navigation['prev'] = null;
  1265. if ($_global['debug'] == 1 || $_global['debug'] == 3) {
  1266. echo 'Resultat de la requete : ' . $nb_results_premium . ' annonce(s) => ' . $navigation['prev'] . '<hr />';
  1267. }
  1268. // REQUETE ANNONCE SUIVANTE CLASSIQUE
  1269. $this->query .= ' LIMIT ' . ($num_row + 1) . ',1';
  1270. if ($_global["debug"] == 3) {
  1271. echo "getNavigateDetail() - Suivant Classique<br />";
  1272. echo $this->query . "<br />";
  1273. echo "<hr />";
  1274. }
  1275. $result = pdoquery($this->query);
  1276. if ($_global['debug'] == 1 || $_global['debug'] == 3) {
  1277. echo 'Resultat de la requete :<br />';
  1278. foreach ($result as $i => $res)
  1279. echo 'id_annonce_' . $i . ' => ' . $res . '<br />';
  1280. echo '<hr />';
  1281. }
  1282. if (isset($result[0]))
  1283. $navigation['next'] = $result[0];
  1284. else
  1285. $navigation['next'] = null;
  1286. }
  1287. else {
  1288. $num_row = $num_row - floor($num_row / MAX_RESULTS_PER_PAGE) - 1;
  1289. // REQUETE ANNONCE SUIVANTE PREMIUM
  1290. if ($_global["debug"] == 3) {
  1291. echo "getNavigateDetail() - Suivant Premium<br />";
  1292. echo $this->query_premium . "<br />";
  1293. echo "<hr />";
  1294. }
  1295. if ($nb_results_premium > 0) {
  1296. $random = rand(0, $nb_results_premium - 1);
  1297. $navigation['next'] = $result[$random];
  1298. }
  1299. else
  1300. $navigation['next'] = null;
  1301. if ($_global['debug'] == 1 || $_global['debug'] == 3) {
  1302. echo 'Resultat de la requete : ' . $nb_results_premium . ' annonce(s) => ' . $navigation['next'] . '<hr />';
  1303. }
  1304. // REQUETE ANNONCE SUIVANTE CLASSIQUE
  1305. $this->query .= ' LIMIT ' . ($num_row - 1) . ',1';
  1306. if ($_global["debug"] == 3) {
  1307. echo "getNavigateDetail() - Précédent Classique<br />";
  1308. echo $this->query . "<br />";
  1309. echo "<hr />";
  1310. }
  1311. $result = pdoquery($this->query);
  1312. if ($_global['debug'] == 1 || $_global['debug'] == 3) {
  1313. echo 'Resultat de la requete :<br />';
  1314. foreach ($result as $i => $res)
  1315. echo 'id_annonce_' . $i . ' => ' . $res . '<br />';
  1316. echo '<hr />';
  1317. }
  1318. if (isset($result[0]))
  1319. $navigation['prev'] = $result[0];
  1320. else
  1321. $navigation['prev'] = null;
  1322. }
  1323. }
  1324. }
  1325. // Première annonce => Pas de précédent
  1326. else {
  1327. // Si on est sur la premiere annonce, alors charger le premier resultat
  1328. if ($_global['is_there_premium'])
  1329. $this->query .= ' LIMIT 0,3';
  1330. // Sinon on charge le resultat suivant dans la liste
  1331. else
  1332. $this->query .= ' LIMIT 1,3';
  1333. if ($_global["debug"] == 3) {
  1334. echo "getNavigateDetail() - Pas de précédent<br />";
  1335. echo $this->query . "<br />";
  1336. echo "<hr />";
  1337. }
  1338. $result = pdoquery($this->query);
  1339. if ($_global['debug'] == 1 || $_global['debug'] == 3) {
  1340. echo 'Resultat de la requete :<br />';
  1341. foreach ($result as $i => $res)
  1342. echo 'id_annonce_' . $i . ' => ' . $res['id_annonce'] . '<br />';
  1343. echo '<hr />';
  1344. }
  1345. $navigation['prev'] = null;
  1346. if (isset($result[0]))
  1347. $navigation['next'] = $result[0];
  1348. else
  1349. $navigation['next'] = null;
  1350. }
  1351. return $navigation;
  1352. }
  1353. // *** search ad ***
  1354. function getAd($request, $code, $mode, $deleted = false) {
  1355. global $_global;
  1356. // is agency search ?
  1357. $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
  1358. // sets search parameters
  1359. $this->search_request = $request;
  1360. // $this->search_request = $this->setRequest($request);
  1361. switch ($mode) {
  1362. // ID
  1363. case 1 :
  1364. // sets select
  1365. if ($deleted) {
  1366. $this->setSelect("ad", true, true);
  1367. } else {
  1368. $this->setSelect("ad", true, false);
  1369. }
  1370. // sets from
  1371. $this->setFrom();
  1372. // sets where
  1373. $where = array();
  1374. $this->setWhere($where, "id", $code);
  1375. // vacances
  1376. if ($_global["univers"] == 13) {
  1377. $this->setWhere($where, "type_transaction", 3);
  1378. } else if ($_global["univers"] == 2) {
  1379. $this->setWhere($where, "type_transaction", 2);
  1380. } else if ($_global["univers"] == 8) {
  1381. $this->setWhere($where, "type_transaction", 8);
  1382. }
  1383. // builds the query
  1384. $this->query = "SELECT " . $this->select . " ";
  1385. $this->query .= "FROM " . $this->from . " ";
  1386. $this->query .= "WHERE " . implode(" AND ", $where) . " ";
  1387. if ($_global["debug"] == 3) {
  1388. echo "getAd()<br />";
  1389. echo $this->query . "<br />";
  1390. echo "<hr />";
  1391. }
  1392. $this->search_results = pdoquery($this->query);
  1393. break;
  1394. // LOGICODE / LOGICODE_OLD
  1395. case 2 :
  1396. // Patch pour les annonces expirées
  1397. if (strpos($this->table_name, 'DEL') !== false) {
  1398. $this->getAdByLogicode($this->table_name, $this->table_prfx, $code, true);
  1399. break;
  1400. }else
  1401. $this->getAdByLogicode(TABLE_S_NAME, TABLE_S_PRFX, $code);
  1402. // $this->getAdByLogicode(TABLE_S_NAME, TABLE_S_PRFX, $code);
  1403. // tests if any ad found, switches to rentals
  1404. if (count($this->search_results) == 0) {
  1405. $this->getAdByLogicode(TABLE_R_NAME, TABLE_R_PRFX, $code);
  1406. if (count($this->search_results) > 0) {
  1407. // sets current universe to rentals
  1408. $_global["univers"] = 2;
  1409. $_global["table_name"] = TABLE_R_NAME;
  1410. $_global["table_prefix"] = TABLE_R_PRFX;
  1411. }
  1412. } else {
  1413. // sets current univers to sales
  1414. $_global["univers"] = 1;
  1415. $_global["table_name"] = TABLE_S_NAME;
  1416. $_global["table_prefix"] = TABLE_S_PRFX;
  1417. }
  1418. break;
  1419. }
  1420. }
  1421. // *** search ad by logicode ***
  1422. function getAdByLogicode($table, $prefix, $code, $deleted = false) {
  1423. global $_global;
  1424. // sets the search to rentals
  1425. $this->setTable($table, $prefix);
  1426. // sets select
  1427. //$this->setSelect("ad", true);
  1428. if ($deleted) {
  1429. $this->setSelect("ad", true, true);
  1430. } else {
  1431. $this->setSelect("ad", true, false);
  1432. }
  1433. // sets from
  1434. $this->setFrom();
  1435. // sets where
  1436. $where = array();
  1437. $this->setWhere($where, "logicode", $code);
  1438. $this->setWhere($where, "logicode_old", $code);
  1439. // builds the query
  1440. $this->query = "SELECT " . $this->select . " ";
  1441. $this->query .= "FROM " . $this->from . " ";
  1442. $this->query .= "WHERE " . implode(" OR ", $where) . " ";
  1443. // executes the query
  1444. if ($_global["debug"] == 3) {
  1445. echo "getAdByLogicode()<br />";
  1446. echo $this->query . "<br />";
  1447. echo "<hr />";
  1448. }
  1449. $this->search_results = pdoquery($this->query);
  1450. if (count($this->search_results) == 0) {
  1451. $sql = " SELECT ttu_" . $prefix . "bis_fr AS bistable FROM TP_TABLE_TO_USE_TTU";
  1452. $res = pdoquery($sql);
  1453. $this->from = $res[0]["bistable"];
  1454. // builds the query
  1455. $this->query = "SELECT " . $this->select . " ";
  1456. $this->query .= "FROM " . $this->from . " ";
  1457. $this->query .= "WHERE " . implode(" OR ", $where) . " ";
  1458. // executes the query
  1459. if ($_global["debug"] == 3) {
  1460. echo "getAdByLogicode()<br />";
  1461. echo $this->query . "<br />";
  1462. echo "<hr />";
  1463. }
  1464. $this->search_results = pdoquery($this->query);
  1465. }
  1466. }
  1467. /**
  1468. * Modification Mathieu pour parametre optionnel nom d'agence Refonte fin 2012
  1469. * @global type $_global
  1470. * @param type $request
  1471. * @param type $offset
  1472. * @param string $agc_name Nom de l'agence
  1473. */
  1474. function getAgencies($request, $offset, $bHasAgency = false) {
  1475. // debug2($request);
  1476. global $_global;
  1477. // adds universe
  1478. $this->search_parameters["univers"] = $_global["univers"];
  1479. // is agency search ?
  1480. $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
  1481. // adds date
  1482. $this->setDate();
  1483. // adds request
  1484. $this->search_request = $this->setRequest($request);
  1485. // $this->search_request = $request;
  1486. // sets offset
  1487. $this->search_parameters["offset"] = "" . $offset . "";
  1488. // sets select
  1489. $this->setSelect("agency", false);
  1490. // sets from
  1491. //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
  1492. $this->setFrom(true);
  1493. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  1494. $join_on = "adp.adp_id_agence = t.id_agence";
  1495. // sets where
  1496. $where = array();
  1497. $this->setWhere($where, "ag_locality");
  1498. $this->setWhere($where, "ag_count");
  1499. $this->setWhere($where, "country");
  1500. if ($bHasAgency) {
  1501. $this->setWhere($where, "agc_name");
  1502. }
  1503. $this->where = $where;
  1504. // sets order
  1505. $this->setOrder("agency", $this->search_request["order"]);
  1506. //var_dump($this->search_request["order"]);exit();
  1507. // builds main query
  1508. $this->query = "SELECT SQL_CALC_FOUND_ROWS " . $this->select . " ";
  1509. $this->query .= "FROM " . $this->from . " ";
  1510. $this->query .= "ON " . $join_on . " ";
  1511. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  1512. // sets limit
  1513. if (is_null($user_ihm['nb_results'])) {
  1514. $var = MAX_RESULTS_AGENCY_PER_PAGE;
  1515. } else {
  1516. $var = $user_ihm['nb_results'];
  1517. }
  1518. $this->limit = (($offset - 1) * $var);
  1519. $this->limit .= ' , ';
  1520. $this->limit .= $var;
  1521. // main query additional clause
  1522. $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
  1523. $this->query .= "LIMIT " . $this->limit;
  1524. // adds post code
  1525. $_start = microtime(true);
  1526. $this->setPostCodes();
  1527. $this->showTime("set post codes", $_start);
  1528. // executes the query
  1529. $_start = microtime(true);
  1530. if ($_global["debug"] == 3) {
  1531. echo "getAgencies()<br />";
  1532. echo $this->query . "<br />";
  1533. echo "<hr />";
  1534. }
  1535. $this->search_results = pdoquery($this->query);
  1536. $this->showTime("main search", $_start);
  1537. // builds the count query
  1538. $this->query_count = "SELECT FOUND_ROWS() AS NUM";
  1539. // executes the count query
  1540. $_start = microtime(true);
  1541. if ($_global["debug"] == 3) {
  1542. echo "getAgencies()<br />";
  1543. echo $this->query_count . "<br />";
  1544. echo "<hr />";
  1545. }
  1546. $this->search_count = pdoquery($this->query_count);
  1547. $this->search_count = $this->search_count[0]["NUM"];
  1548. $id_loc = $this->search_parameters['loc_hierarchy'][1]['lct_id'];
  1549. $this->showTime("main count", $_start);
  1550. // save
  1551. $this->search_parameters["count"] = $this->search_count;
  1552. $this->search_request["count"] = $this->search_count;
  1553. $this->saveSearch();
  1554. // calculates number of pages
  1555. $this->setPages("agency");
  1556. }
  1557. // *** search agency ***
  1558. /**
  1559. *
  1560. * @global type $_global
  1561. * @param type $request
  1562. * @param type $code
  1563. * @param string $agc_name nom de l'agence, paramètre optionnel.
  1564. */
  1565. function getAgency($request, $code, $agc_name = null) {
  1566. global $_global;
  1567. // adds request
  1568. $this->search_request = $request;
  1569. // sets select
  1570. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  1571. $this->setSelect("agency", false);
  1572. // sets from
  1573. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  1574. $this->setFrom(true);
  1575. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  1576. $join_on = "adp.adp_id_presto = t.id_presto";
  1577. // sets where
  1578. $where = array();
  1579. $this->setWhere($where, "id_agence", $code);
  1580. if (!is_null($agc_name)) {
  1581. $this->setWhere($where, "agc_name", $agc_name);
  1582. }
  1583. // builds the query
  1584. $this->query = "SELECT " . $this->select . " ";
  1585. $this->query .= "FROM " . $this->from . " ";
  1586. $this->query .= "ON " . $join_on . " ";
  1587. $this->query .= "WHERE " . implode(" AND ", $where) . " ";
  1588. // executes the query
  1589. if ($_global["debug"] == 3) {
  1590. echo "getAgency()<br />";
  1591. echo $this->query . "<br />";
  1592. echo "<hr />";
  1593. }
  1594. $this->search_results_agency = pdoquery($this->query);
  1595. // agency railroad
  1596. for ($i = 0; $i < 3; $i++) {
  1597. if ($this->search_results_agency[0]["agc_loc_id_" . $i] > 0) {
  1598. $query = "SELECT lct_id, lct_level, lct_name, lct_post_code ";
  1599. $query .= "FROM " . $this->table_locality_name . " ";
  1600. $query .= "WHERE lct_id = " . $this->search_results_agency[0]["agc_loc_id_" . $i];
  1601. if ($_global["debug"] == 3) {
  1602. echo "getAgency()<br />";
  1603. echo $query . "<br />";
  1604. echo "<hr />";
  1605. }
  1606. $locality = pdoquery($query);
  1607. if (count($locality) > 0) {
  1608. $this->search_hierarchy_agency[$i] = $locality[0];
  1609. }
  1610. }
  1611. }
  1612. }
  1613. // *** search coordinates ***
  1614. function getCoordinates($request) {
  1615. if (isset($request["loc_key"]) && $request["loc_key"] != "") {
  1616. $loc_key = $request["loc_key"];
  1617. } else {
  1618. for ($i = 1; $i < SEARCH_FIELDS_NUMBER + 1; $i++) {
  1619. if (isset($request["loc_key" . $i]) && $request["loc_key" . $i] != "") {
  1620. $loc_key = $request["loc_key" . $i];
  1621. break;
  1622. }
  1623. }
  1624. }
  1625. // lct_id, lct_level
  1626. $loc_tmp = explode("_", $loc_key);
  1627. switch ($loc_tmp[1]) {
  1628. // code group
  1629. case 98 :
  1630. $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 ";
  1631. $this->query .= "FROM T_LOCGROUPCODE_LGC_" . strtoupper($request["site"]) . " ";
  1632. $this->query .= "WHERE lgc_id = " . $loc_tmp[0] . " ";
  1633. break;
  1634. // name group
  1635. case 99 :
  1636. $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 ";
  1637. $this->query .= "FROM T_LOCGROUPNAME_LGN_" . strtoupper($request["site"]) . " ";
  1638. $this->query .= "WHERE lgn_id = " . $loc_tmp[0] . " ";
  1639. break;
  1640. // standard
  1641. default :
  1642. $this->query = "SELECT lct_id, lct_parent_id, lct_post_code, lct_lat, lct_long ";
  1643. $this->query .= "FROM " . $this->table_locality_name . " ";
  1644. $this->query .= "WHERE lct_id = " . $loc_tmp[0] . " ";
  1645. $this->query .= "AND lct_level = " . $loc_tmp[1];
  1646. break;
  1647. }
  1648. if ($_global["debug"] == 3) {
  1649. echo "getCoordinates() - 1<br />";
  1650. echo $this->query . "<br />";
  1651. echo "<hr />";
  1652. }
  1653. $results = pdoquery($this->query);
  1654. if (count($results) > 0) {
  1655. // si coordonnées nulles, recherche d'une localité au même code postal ou au pire, le niveau supérieur
  1656. $loc_tmp2 = $results[0];
  1657. if ((empty($loc_tmp2["lct_lat"])) && (empty($loc_tmp2["lct_long"]))) { // 0 ou NULL
  1658. if ($loc_tmp2["lct_post_code"] != 0) { // autre localité de même code postal et avec coords non nulles
  1659. $this->query2 = "SELECT lct_id, lct_parent_id, lct_lat, lct_long ";
  1660. $this->query2 .= "FROM " . $this->table_locality_name . " ";
  1661. $this->query2 .= "WHERE lct_post_code = '" . $loc_tmp2["lct_post_code"] . "' ";
  1662. $this->query2 .= "AND (lct_lat != 0 AND lct_lat IS NOT NULL) ";
  1663. $this->query2 .= "AND (lct_long != 0 AND lct_long IS NOT NULL) ";
  1664. } else { // département (ou région) de la localité
  1665. $this->query2 = "SELECT lct_id, lct_parent_id, lct_lat, lct_long ";
  1666. $this->query2 .= "FROM " . $this->table_locality_name . " ";
  1667. $this->query2 .= "WHERE lct_id = " . $loc_tmp2["lct_parent_id"];
  1668. }
  1669. if ($_global["debug"] == 3) {
  1670. echo "getCoordinates() - 2<br />";
  1671. echo $this->query2 . "<br />";
  1672. echo "<hr />";
  1673. }
  1674. $results2 = pdoquery($this->query2);
  1675. $results = $results2;
  1676. // si pas de résultat, recherche d'une "localité" de niveau supérieur
  1677. if (count($results) == 0) {
  1678. $this->query3 = "SELECT lct_id, lct_parent_id, lct_lat, lct_long ";
  1679. $this->query3 .= "FROM " . $this->table_locality_name . " ";
  1680. $this->query3 .= "WHERE lct_id = " . $loc_tmp2["lct_parent_id"];
  1681. if ($_global["debug"] == 3) {
  1682. echo "getCoordinates() - 3<br />";
  1683. echo $this->query3 . "<br />";
  1684. echo "<hr />";
  1685. }
  1686. $results3 = pdoquery($this->query3);
  1687. $results = $results3;
  1688. }
  1689. }
  1690. return array("loc_key" => $loc_key, "latitude" => $results[0]["lct_lat"], "longitude" => $results[0]["lct_long"]);
  1691. }
  1692. }
  1693. // *** new search when cookie is empty ***
  1694. function setNewSearch($request) {
  1695. global $_global;
  1696. // adds universe
  1697. $this->search_parameters["univers"] = $_global["univers"];
  1698. // is agency search ?
  1699. $this->is_agency_search = (isset($request["id_agence"]) ? true : false);
  1700. // sets request
  1701. $this->search_request = $this->setRequest($request);
  1702. // adds date
  1703. $this->setDate();
  1704. // sets from
  1705. $this->setFrom();
  1706. // sets where
  1707. $where = array();
  1708. $this->setWhere($where, "ad_status");
  1709. $this->setWhere($where, "locality");
  1710. $this->setWhere($where, "country");
  1711. $this->setWhere($where, "ck_property_type");
  1712. $this->setWhere($where, "price");
  1713. $this->setWhere($where, "area");
  1714. $this->setWhere($where, "ck_nb_rooms");
  1715. $this->setWhere($where, "with_mmf");
  1716. /* START:RECHERCHE AVANCEE */
  1717. /*
  1718. //$this->setWhere($where, "with_mmf");
  1719. $this->setWhere($where, "recent_ads");
  1720. //if($request["property_type"][0] == 3)
  1721. $this->setWhere($where, "surf");
  1722. $this->setWhere($where, "floor");
  1723. $this->setWhere($where, "elevator");
  1724. $this->setWhere($where, "caretaker");
  1725. $this->setWhere($where, "interphone");
  1726. $this->setWhere($where, "balcony");
  1727. $this->setWhere($where, "terrace");
  1728. $this->setWhere($where, "parquet");
  1729. $this->setWhere($where, "fireside");
  1730. $this->setWhere($where, "closets");
  1731. $this->setWhere($where, "storage");
  1732. $this->setWhere($where, "parking");
  1733. $this->setWhere($where, "garden");
  1734. $this->setWhere($where, "pool");
  1735. /* STOP:RECHERCHE AVANCEE */
  1736. // common where clause
  1737. $this->where = $where;
  1738. // sets index
  1739. $force_index = array();
  1740. $this->setIndex($force_index, "locality");
  1741. // common index clause
  1742. // force index when we are doing a search on more than one locality
  1743. if (count($force_index) > 1) {
  1744. $this->force_index = $force_index;
  1745. }
  1746. // builds main query
  1747. $this->query = "SELECT COUNT(*) AS NUM ";
  1748. $this->query .= "FROM " . $this->from . " ";
  1749. if (isset($this->force_index)) {
  1750. //$this->query .= "FORCE INDEX (".implode(", ", $this->force_index).") ";
  1751. }
  1752. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  1753. // adds post code
  1754. $_start = microtime(true);
  1755. $this->setPostCodes();
  1756. $this->showTime("set post codes", $_start);
  1757. // executes the query
  1758. $_start = microtime(true);
  1759. if ($_global["debug"] == 3) {
  1760. echo "setNewSearch()<br />";
  1761. echo $this->query . "<br />";
  1762. echo "<hr />";
  1763. }
  1764. $this->search_results = pdoquery($this->query);
  1765. $this->showTime("main search", $_start);
  1766. $this->search_count = $this->search_results[0]["NUM"];
  1767. $this->showTime("main count", $_start);
  1768. // save
  1769. $this->search_parameters["count"] = $this->search_count;
  1770. $this->search_request["count"] = $this->search_count;
  1771. // sets antenna
  1772. $this->setAntenna();
  1773. }
  1774. // *** sets date ***
  1775. function setDate($skip_request = false) {
  1776. $time = time();
  1777. if ($skip_request == false) {
  1778. $this->search_request["date"] = date("Y-m-d", $time);
  1779. $this->search_request["timestamp"] = $time;
  1780. }
  1781. $this->search_parameters["date"] = date("Y-m-d", $time);
  1782. $this->search_parameters["timestamp"] = $time;
  1783. }
  1784. // *** returns select clause including all needed fields ***
  1785. function setSelect($mode = "ad", $extended = false, $deleted = false) {
  1786. global $_global;
  1787. // field list
  1788. $fields = array();
  1789. switch ($mode) {
  1790. // ad fields
  1791. case "ad" :
  1792. // ad extended
  1793. if ($extended == true) {
  1794. // ad all
  1795. $fields[] = "*";
  1796. // ad localisation
  1797. //20091202-1 (1/3) not using T_LOCALITY_LCT_FR table when select town name
  1798. $fields[] = $this->table_prfx . "_default_town_2";
  1799. $fields[] = $this->table_prfx . "_default_town_1";
  1800. $fields[] = $this->table_prfx . "_default_town_0";
  1801. /*
  1802. $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";
  1803. $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";
  1804. $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";
  1805. */
  1806. // ad dates
  1807. //20091202-2 (1/4) not using SELECT when use of DATEDIFF
  1808. if ($deleted == true) {
  1809. $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_date_deleted) AS " . $this->table_prfx . "_days_old";
  1810. } else {
  1811. $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_first_online_date) AS " . $this->table_prfx . "_days_old";
  1812. }
  1813. }
  1814. // ad standard
  1815. else {
  1816. // ad identifiers
  1817. $fields[] = "id_annonce";
  1818. $fields[] = "t." . $this->table_prfx . "_ai_id";
  1819. $fields[] = $this->table_prfx . "_reference";
  1820. $fields[] = $this->table_prfx . "_num_mandat";
  1821. // ad premium
  1822. $fields[] = $this->table_prfx . "_is_premium";
  1823. //logo_agency
  1824. $fields[] = $this->table_prfx . "_is_logo_agency";
  1825. //directory_agency
  1826. $fields[] = $this->table_prfx . "_is_directory_agency";
  1827. //website_agency
  1828. $fields[] = $this->table_prfx . "_is_website_agency";
  1829. // ad features
  1830. $fields[] = $this->table_prfx . "_type_transaction";
  1831. $fields[] = "id_bien";
  1832. $fields[] = ($_global['univers'] == 1 ? "prg_title" : "''") . " AS prg_title";
  1833. $fields[] = ($_global['univers'] == 1 ? "id_bien_programme" : "''") . " AS id_bien_programme";
  1834. $fields[] = $this->table_prfx . "_property_type_id";
  1835. $fields[] = $this->table_prfx . "_property_type_id_orig";
  1836. $fields[] = $this->table_prfx . "_property_type";
  1837. $fields[] = $this->table_prfx . "_area";
  1838. $fields[] = $this->table_prfx . "_price";
  1839. $fields[] = $this->table_prfx . "_nb_rooms";
  1840. $fields[] = $this->table_prfx . "_default_text";
  1841. //ad is exclusive
  1842. $fields[] = $this->table_prfx . "_is_exclusive";
  1843. // ad currency
  1844. $fields[] = $this->table_prfx . "_currency";
  1845. // ad pictures
  1846. $fields[] = $this->table_prfx . "_photo";
  1847. $fields[] = $this->table_prfx . "_nb_photo";
  1848. /*
  1849. $fields[] = $this->table_prfx."_photo_2";
  1850. $fields[] = $this->table_prfx."_photo_3";
  1851. $fields[] = $this->table_prfx."_photo_4";
  1852. $fields[] = $this->table_prfx."_photo_5";
  1853. $fields[] = $this->table_prfx."_photo_6";
  1854. $fields[] = $this->table_prfx."_photo_7";
  1855. $fields[] = $this->table_prfx."_photo_8";
  1856. $fields[] = $this->table_prfx."_photo_9";
  1857. $fields[] = $this->table_prfx."_photo_10";
  1858. // ad multimedia
  1859. for ($i = 1; $i < 6; $i ++)
  1860. {
  1861. $fields[] = $this->table_prfx."_mmf_".$i;
  1862. $fields[] = $this->table_prfx."_mmf_type_".$i;
  1863. }
  1864. */
  1865. // ad logicode
  1866. $fields[] = $this->table_prfx . "_logicode";
  1867. $fields[] = $this->table_prfx . "_logicode_old";
  1868. // ad localisation
  1869. $fields[] = $this->table_prfx . "_post_code";
  1870. $fields[] = $this->table_prfx . "_default_town";
  1871. //20091202-1 (2/3) not using T_LOCALITY_LCT_FR table when select town name
  1872. $fields[] = $this->table_prfx . "_default_town_2";
  1873. $fields[] = $this->table_prfx . "_default_town_1";
  1874. $fields[] = $this->table_prfx . "_default_town_0";
  1875. //if($_global['district'] == 1){
  1876. for ($i = 1; $i <= 3; $i++) {
  1877. $fields[] = $this->table_prfx . "_district_id" . $i;
  1878. $fields[] = $this->table_prfx . "_district_name" . $i;
  1879. }
  1880. //}
  1881. /*
  1882. $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";
  1883. $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";
  1884. $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";
  1885. */
  1886. $fields[] = "lgm_id";
  1887. $fields[] = "lgc_id";
  1888. $fields[] = "lgn_id";
  1889. $fields[] = $this->table_prfx . "_country";
  1890. $fields[] = $this->table_prfx . "_default_proximity";
  1891. $fields[] = $this->table_prfx . "_default_sector";
  1892. for ($i = 0; $i < 3; $i++) {
  1893. $fields[] = $this->table_prfx . "_locality_" . $i;
  1894. }
  1895. // ad dates
  1896. $fields[] = $this->table_prfx . "_first_online_date";
  1897. $fields[] = $this->table_prfx . "_update_date";
  1898. //20091202-2 (2/4) not using SELECT when use of DATEDIFF
  1899. $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_first_online_date) AS " . $this->table_prfx . "_days_old";
  1900. // ad pub
  1901. $fields[] = $this->table_prfx . "_pub_code";
  1902. // ad agency
  1903. $fields[] = "id_agence";
  1904. $fields[] = "id_presto";
  1905. $fields[] = $this->table_prfx . "_name_agency";
  1906. // $fields[] = $this->table_prfx."_address_agency";
  1907. $fields[] = $this->table_prfx . "_post_code_agency";
  1908. $fields[] = $this->table_prfx . "_town_agency";
  1909. // $fields[] = $this->table_prfx."_country_agency";
  1910. $fields[] = $this->table_prfx . "_tel_agency";
  1911. $fields[] = $this->table_prfx . "_fax_agency";
  1912. $fields[] = $this->table_prfx . "_email_agency";
  1913. $fields[] = $this->table_prfx . "_site_agency";
  1914. $fields[] = $this->table_prfx . "_rcs_agency";
  1915. $fields[] = $this->table_prfx . "_logo_agency";
  1916. $fields[] = $this->table_prfx . "_franchising_agency";
  1917. //if location/rent we must include charge details (Michel)
  1918. if ($_global["univers"] == 2) {
  1919. $fields[] = $this->table_prfx . "_property_charges";
  1920. $fields[] = $this->table_prfx . "_agency_rent_fees";
  1921. }
  1922. // vacances
  1923. if ($_global["univers"] == 13) {
  1924. $fields[] = $this->table_prfx . "_nb_bedrooms";
  1925. $fields[] = $this->table_prfx . "_nb_people";
  1926. $fields[] = $this->table_prfx . "_partner_url";
  1927. }
  1928. //ad Agency POWERSITE
  1929. $fields[] = $this->table_prfx . "_is_powersite_agency";
  1930. $fields[] = $this->table_prfx . "_powersite_url_agency";
  1931. $fields[] = $this->table_prfx . "_powersite_calltracking_agency";
  1932. /* Ad force order for proximity */
  1933. if ($this->PerimProximit > 0) {
  1934. //$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";
  1935. $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";
  1936. }
  1937. // recherche avancee
  1938. $fields[] = $this->table_prfx . "_advanced_set";
  1939. // Bandeau personnalisable
  1940. $fields[] = $this->table_prfx . "_personnalisable";
  1941. }
  1942. break;
  1943. // agency fields
  1944. case "agency" :
  1945. // agency extended
  1946. if ($extended == true) {
  1947. // agency all
  1948. $fields[] = "*";
  1949. // agency localisation
  1950. /*
  1951. $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";
  1952. $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";
  1953. $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";
  1954. */
  1955. //20100216-1 (1/2): not using T_LOCALITY_LCT_FR table when select town name for AGC
  1956. $fields[] = $this->table_prfx . "_default_town_2 AS " . $this->table_prfx . "_town_agency_2";
  1957. $fields[] = $this->table_prfx . "_default_town_1 AS " . $this->table_prfx . "_town_agency_1";
  1958. $fields[] = $this->table_prfx . "_default_town_0 AS " . $this->table_prfx . "_town_agency_0";
  1959. // agency ad counts
  1960. $fields[] = "(t." . $this->table_prfx . "_rnt_count + t." . $this->table_prfx . "_sal_count) AS " . $this->table_prfx . "_count";
  1961. }
  1962. // agency standard
  1963. else {
  1964. // agency identifiers
  1965. $fields[] = "id_agence";
  1966. $fields[] = $this->table_prfx . "_id";
  1967. $fields[] = "id_presto";
  1968. $fields[] = $this->table_prfx . "_rcs";
  1969. $fields[] = "agc_is_phonemandatory4contact";
  1970. // agency data
  1971. $fields[] = $this->table_prfx . "_name";
  1972. $fields[] = $this->table_prfx . "_franchising";
  1973. $fields[] = $this->table_prfx . "_company_name";
  1974. $fields[] = $this->table_prfx . "_description";
  1975. // agency premium
  1976. $fields[] = $this->table_prfx . "_is_premium";
  1977. // agency logo & pictures
  1978. $fields[] = $this->table_prfx . "_logo";
  1979. // agency localisation
  1980. $fields[] = $this->table_prfx . "_address";
  1981. $fields[] = $this->table_prfx . "_post_code";
  1982. $fields[] = $this->table_prfx . "_town_agency";
  1983. $fields[] = $this->table_prfx . "_country";
  1984. /*
  1985. $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";
  1986. $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";
  1987. $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";
  1988. */
  1989. //20100216-1 (2/2): not using T_LOCALITY_LCT_FR table when select town name for AGC
  1990. $fields[] = $this->table_prfx . "_default_town_2 AS " . $this->table_prfx . "_town_agency_2";
  1991. $fields[] = $this->table_prfx . "_default_town_1 AS " . $this->table_prfx . "_town_agency_1";
  1992. $fields[] = $this->table_prfx . "_default_town_0 AS " . $this->table_prfx . "_town_agency_0";
  1993. $fields[] = "lgc_id";
  1994. $fields[] = "lgn_id";
  1995. for ($i = 0; $i < 3; $i++) {
  1996. $fields[] = $this->table_prfx . "_loc_id_" . $i;
  1997. }
  1998. // agency contact
  1999. $fields[] = $this->table_prfx . "_tel";
  2000. $fields[] = $this->table_prfx . "_fax";
  2001. $fields[] = $this->table_prfx . "_email";
  2002. $fields[] = $this->table_prfx . "_site";
  2003. if (AGC_EXCLUSIVE_FRANCHISING != '') {
  2004. if (is_numeric(AGC_EXCLUSIVE_FRANCHISING) && AGC_EXCLUSIVE_FRANCHISING > 0) {
  2005. $fields[] = "(IF({$this->table_prfx}_franchising_id=" . AGC_EXCLUSIVE_FRANCHISING . ", 1, 0)) AS {$this->table_prfx}_franchising_order";
  2006. } else {
  2007. $fields[] = "(IF({$this->table_prfx}_franchising = '" . AGC_EXCLUSIVE_FRANCHISING . "', 1, 0)) AS {$this->table_prfx}_franchising_order";
  2008. }
  2009. } else {
  2010. $fields[] = "0 AS {$this->table_prfx}_franchising_order";
  2011. }
  2012. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  2013. // agency ad counts
  2014. $fields[] = "(IF((adp.adp_rnt_count IS NULL), 0, adp.adp_rnt_count)) AS " . $this->table_prfx . "_rnt_count";
  2015. $fields[] = "(IF((adp.adp_sal_count IS NULL), 0, adp.adp_sal_count)) AS " . $this->table_prfx . "_sal_count";
  2016. switch ($this->cumul_ad_for_agency_search) {
  2017. case 2:
  2018. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  2019. $fields[] = "(adp.adp_sal_count) AS " . $this->table_prfx . "_count";
  2020. break;
  2021. case 3:
  2022. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  2023. $fields[] = "(adp.adp_rnt_count) AS " . $this->table_prfx . "_count";
  2024. break;
  2025. default:
  2026. //20091007-1 : using new table T_AGENCY_DATA_PONDERING_ADP
  2027. $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";
  2028. break;
  2029. }
  2030. //POWERSITE
  2031. $fields[] = $this->table_prfx . "_is_powersite";
  2032. $fields[] = $this->table_prfx . "_powersite_url";
  2033. $fields[] = $this->table_prfx . "_powersite_calltracking";
  2034. // Projet POLCO (W.ASBAITI 14/01/10)
  2035. $fields[] = $this->table_prfx . "_is_logo";
  2036. $fields[] = $this->table_prfx . "_is_directory";
  2037. $fields[] = $this->table_prfx . "_is_website";
  2038. // Tel obligatoire ou pas
  2039. $fields[] = $this->table_prfx . "_is_phonemandatory4contact";
  2040. }
  2041. break;
  2042. case "refville" :
  2043. // ad identifiers
  2044. $fields[] = "id_annonce";
  2045. $fields[] = "id_presto";
  2046. // ad features
  2047. $fields[] = $this->table_prfx . "_reference";
  2048. $fields[] = $this->table_prfx . "_num_mandat";
  2049. $fields[] = $this->table_prfx . "_first_online_date";
  2050. $fields[] = $this->table_prfx . "_property_type";
  2051. $fields[] = $this->table_prfx . "_property_type_id";
  2052. $fields[] = $this->table_prfx . "_price";
  2053. $fields[] = $this->table_prfx . "_area";
  2054. $fields[] = $this->table_prfx . "_nb_rooms";
  2055. $fields[] = $this->table_prfx . "_photo";
  2056. $fields[] = $this->table_prfx . "_default_text";
  2057. $fields[] = $this->table_prfx . "_default_town";
  2058. $fields[] = $this->table_prfx . "_post_code";
  2059. $fields[] = $this->table_prfx . "_locality_0";
  2060. $fields[] = $this->table_prfx . "_locality_1";
  2061. $fields[] = $this->table_prfx . "_locality_2";
  2062. //20091202-1 (3/3) not using T_LOCALITY_LCT_FR table when select town name
  2063. $fields[] = $this->table_prfx . "_default_town_2";
  2064. $fields[] = $this->table_prfx . "_default_town_1";
  2065. $fields[] = $this->table_prfx . "_default_town_0";
  2066. /*
  2067. $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";
  2068. $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";
  2069. $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";
  2070. */
  2071. $fields[] = "UNIX_TIMESTAMP(" . $this->table_prfx . "_update_date) AS " . $this->table_prfx . "_update_date";
  2072. $fields[] = $this->table_prfx . "_name_agency";
  2073. $fields[] = $this->table_prfx . "_town_agency";
  2074. $fields[] = $this->table_prfx . "_tel_agency";
  2075. $fields[] = $this->table_prfx . "_email_agency";
  2076. $fields[] = "'" . $_global["univers"] . "' AS univers";
  2077. break;
  2078. }
  2079. // concatenates
  2080. $this->select = implode(", ", $fields);
  2081. //var_dump($this->select);
  2082. //die();
  2083. }
  2084. // *** returns select clause including all needed fields ***
  2085. function setGdmSelect() {
  2086. // fields
  2087. $fields = array();
  2088. // ad all
  2089. $fields[] = "*";
  2090. // ad localisation
  2091. /*
  2092. $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";
  2093. $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";
  2094. $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";
  2095. */
  2096. //20091202-2
  2097. $fields[] = $this->table_prfx . "_default_town_2 AS " . $this->table_prfx . "_default_town_2";
  2098. $fields[] = $this->table_prfx . "_default_town_1 AS " . $this->table_prfx . "_default_town_1";
  2099. $fields[] = $this->table_prfx . "_default_town_0 AS " . $this->table_prfx . "_default_town_0";
  2100. // ad dates
  2101. //20091202-2 (3/4) not using SELECT when use of DATEDIFF
  2102. $fields[] = "DATEDIFF('" . $this->search_parameters["date"] . "', " . $this->table_prfx . "_update_date) AS " . $this->table_prfx . "_days_old";
  2103. }
  2104. // *** sets query from ***
  2105. //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
  2106. function setFrom($use_data_pondering = false) {
  2107. global $_global;
  2108. $this->from = $this->table_name . " t";
  2109. if ($use_data_pondering) {
  2110. //$this->from .= ", T_AGENCY_DATA_PONDERING_ADP adp ";
  2111. $this->from .= " LEFT OUTER JOIN T_AGENCY_DATA_PONDERING_ADP adp ";
  2112. }
  2113. }
  2114. // *** sets query search criterion ***
  2115. function setIndex(&$force_index, $criterion) {
  2116. switch ($criterion) {
  2117. // AD LOCALITY
  2118. case "locality" :
  2119. if ($this->search_request["loc_key"] != "") {
  2120. $value = $this->search_request["loc_key"];
  2121. // processes
  2122. $value = explode("_", $value);
  2123. // sets index
  2124. switch ($value[1]) {
  2125. // map group
  2126. case 97 :
  2127. $force_index[] = "lgm_id";
  2128. break;
  2129. // code group
  2130. case 98 :
  2131. $force_index[] = "lgc_id";
  2132. break;
  2133. // name group
  2134. case 99 :
  2135. $force_index[] = "lgn_id";
  2136. break;
  2137. // standard
  2138. default :
  2139. $force_index[] = $this->table_prfx . "_locality_" . $value[1];
  2140. break;
  2141. }
  2142. } else {
  2143. $indexes = array();
  2144. for ($i = 1; $i < (SEARCH_FIELDS_NUMBER + 1); $i++) {
  2145. $value = $this->search_request["loc_key" . $i];
  2146. if ($value != "") {
  2147. // processes
  2148. $value = explode("_", $value);
  2149. // sets indexes
  2150. switch ($value[1]) {
  2151. // map group
  2152. case 97 :
  2153. $force_index[] = "lgm_id";
  2154. break;
  2155. // code group
  2156. case 98 :
  2157. $force_index[] = "lgc_id";
  2158. break;
  2159. // name group
  2160. case 99 :
  2161. $force_index[] = "lgn_id";
  2162. break;
  2163. // standard
  2164. default :
  2165. $force_index[] = $this->table_prfx . "_locality_" . $value[1];
  2166. break;
  2167. }
  2168. }
  2169. }
  2170. }
  2171. break;
  2172. // COUNTRY
  2173. case "country" :
  2174. // sets index
  2175. $force_index[] = $this->table_prfx . "_country";
  2176. break;
  2177. // PROPERTY TYPE
  2178. case "property_type" :
  2179. // sets index
  2180. $force_index[] = $this->table_prfx . "_property_type_id";
  2181. break;
  2182. }
  2183. }
  2184. function setWherePropertyTypeVsRoom(&$where) {
  2185. $propertyType = $this->search_request['ck_property_type'];
  2186. $nbRooms = $this->search_request['ck_nb_rooms'];
  2187. $this->search_parameters['ck_property_type'] = $propertyType;
  2188. $this->search_parameters['ck_nb_rooms'] = $nbRooms;
  2189. $sql_part = '';
  2190. if (strpos($nbRooms, '1') !== false) {
  2191. if (strpos($propertyType, '1') !== false) {
  2192. // Construire les couples type de bien / nombre de pieces
  2193. // Ajout du terrain sans pièces
  2194. if ($propertyType[3] == '1')
  2195. $sql_part .= '';
  2196. } else {
  2197. // Renseigner le nombre de pièces sans tenir compte du type de biens
  2198. $this->setWhere($where, 'ck_nb_rooms', $nbRooms);
  2199. }
  2200. } else if (strpos($propertyType, '1') !== false) {
  2201. // Renseigner le type de bien sans tenir compte du nombre de pièces
  2202. $this->setWhere($where, 'ck_nb_rooms', $nbRooms);
  2203. }
  2204. }
  2205. function setLocWhere($value, $i) {
  2206. $this->search_parameters["loc_key" . $i] = implode('_', $value);
  2207. $this->search_parameters["loc_keys"][] = implode('_', $value);
  2208. // stores parameters
  2209. $this->search_parameters["loc_ids"][] = $value[0];
  2210. $this->search_parameters["loc_levels"][] = $value[1];
  2211. switch ($value[1]) {
  2212. // map group
  2213. case 97 :
  2214. $clause = "lgm_id = " . $value[0];
  2215. break;
  2216. // code group
  2217. case 98 :
  2218. $clause = "lgc_id = " . $value[0];
  2219. break;
  2220. // name group
  2221. case 99 :
  2222. $clause = "lgn_id = " . $value[0];
  2223. break;
  2224. // standard
  2225. default :
  2226. $clause = $this->table_prfx . "_locality_" . $value[1] . " = " . $value[0];
  2227. break;
  2228. }
  2229. // add postcode
  2230. $this->addPostCode($value[0], $value[1]);
  2231. return $clause;
  2232. }
  2233. // *** sets query search criterion ***
  2234. function setWhere(&$where, $criterion, $value = "") {
  2235. global $_global;
  2236. if ($value == '' && isset($this->search_request[$criterion]))
  2237. $value = $this->search_request[$criterion];
  2238. switch ($criterion) {
  2239. case "only_old": // Uniquement dans l'ancien
  2240. $clause = $this->table_prfx . "_type_transaction <> 5";
  2241. break;
  2242. // TYPE_TRANSACTION
  2243. case "type_transaction" :
  2244. if ($value > 0) {
  2245. $this->search_parameters["type_transaction"] = $value;
  2246. $clause = $this->table_prfx . "_type_transaction = " . $value;
  2247. $this->isTtypeTransactionAlreadySetInSql = true;
  2248. }
  2249. break;
  2250. //NOM D'AGENCE
  2251. case "agc_name":
  2252. $this->search_parameters["agc_name"] = $value;
  2253. if ($this->table_prfx == 'agc') {
  2254. $value = addslashes($value);
  2255. $clause = 'UPPER(' . $this->table_prfx . "_name) LIKE UPPER('%" . $value . "%')";
  2256. } else {
  2257. $clause = $this->table_prfx . "_agc_name LIKE '%" . $value . "'";
  2258. }
  2259. break;
  2260. // DATE
  2261. case "date" :
  2262. // stores parameters
  2263. $this->search_parameters["date"] = $value;
  2264. // sets clause
  2265. $clause = $this->table_prfx . "_update_date >= '" . $value . "'";
  2266. break;
  2267. // ID
  2268. case "id" :
  2269. if ($value != "") {
  2270. // stores parameters
  2271. $this->search_parameters["id"] = $value;
  2272. // sets clause
  2273. $clause = "id_annonce = '" . $value . "'";
  2274. }
  2275. break;
  2276. // ID_AGENCE
  2277. case "id_agence" :
  2278. if ($value != "") {
  2279. // stores parameters
  2280. $this->search_parameters["id_agence"] = $value;
  2281. // sets clause
  2282. $clause = "id_agence = '" . $value . "'";
  2283. }
  2284. break;
  2285. // ID_AGENCE
  2286. case "grp_id_agence" :
  2287. if (is_array($value) && count($value) > 0) {
  2288. // stores parameters
  2289. $this->search_parameters["grp_id_agence"] = $value;
  2290. // sets clause
  2291. $val = "";
  2292. for ($cnt = 0; $cnt < count($value); $cnt++) {
  2293. $val .= "'" . $value[$cnt] . "' ";
  2294. }
  2295. $val = rtrim($val);
  2296. $val = str_replace(" ", ", ", $val);
  2297. $clause = "id_agence in (" . $val . ")";
  2298. }
  2299. break;
  2300. // LOGICODE
  2301. case "logicode" :
  2302. $clause = $this->table_prfx . "_logicode = '" . $value . "'";
  2303. // $clause .= " AND ".$this->table_prfx."_type_transaction != '3'"; // locations saisonnières
  2304. break;
  2305. // LOGICODE_OLD
  2306. case "logicode_old" :
  2307. $clause = $this->table_prfx . "_logicode_old = '" . $value . "'";
  2308. // $clause .= " AND ".$this->table_prfx."_type_transaction != '3'"; // locations saisonnières
  2309. break;
  2310. // PREMIUM
  2311. case "premium" :
  2312. $clause = $this->table_prfx . "_is_premium = 1";
  2313. break;
  2314. // PREMIUM
  2315. case "exclusive" :
  2316. if ($value > 0) {
  2317. $clause = $this->table_prfx . '_is_exclusive = ' . $value;
  2318. }
  2319. break;
  2320. // AD LOCALITY
  2321. case "locality" :
  2322. if (($this->search_request["loc_key"] != "") && ($this->search_request["loc_key"] != "_")) {
  2323. $value = $this->search_request["loc_key"];
  2324. // stores parameters
  2325. $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
  2326. // $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name"]);
  2327. $this->search_parameters["loc_key"] = $value;
  2328. $this->search_parameters["loc_keys"][] = $value;
  2329. // processes
  2330. $value = explode("_", $value);
  2331. // stores parameters
  2332. $this->search_parameters["loc_ids"][] = $value[0];
  2333. $this->search_parameters["loc_levels"][] = $value[1];
  2334. // sets clause
  2335. switch ($value[1]) {
  2336. // map group
  2337. case 97 :
  2338. $clause = "lgm_id = " . $value[0];
  2339. break;
  2340. // code group
  2341. case 98 :
  2342. $clause = "lgc_id = " . $value[0];
  2343. break;
  2344. // name group
  2345. case 99 :
  2346. $clause = "lgn_id = " . $value[0];
  2347. break;
  2348. // standard
  2349. default :
  2350. $clause = $this->table_prfx . "_locality_" . $value[1] . " = " . $value[0];
  2351. break;
  2352. }
  2353. // add postcode
  2354. $this->addPostCode($value[0], $value[1]);
  2355. } else {
  2356. $clauses = array();
  2357. for ($i = 1; $i < (SEARCH_FIELDS_NUMBER + 1); $i++) {
  2358. $value = $this->search_request["loc_key" . $i];
  2359. if ($value != "") {
  2360. $loc_names[] = $this->search_request["loc_name" . $i];
  2361. // $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name".$i]);
  2362. // processes
  2363. $values = $value;
  2364. $value = explode("_", $value);
  2365. if (($value[0] != "") && ($value[1] != "")) {
  2366. // stores parameters
  2367. $this->search_parameters["loc_key" . $i] = $values;
  2368. $this->search_parameters["loc_keys"][] = $values;
  2369. // stores parameters
  2370. $this->search_parameters["loc_ids"][] = $value[0];
  2371. $this->search_parameters["loc_levels"][] = $value[1];
  2372. // sets clause
  2373. switch ($value[1]) {
  2374. // map group
  2375. case 97 :
  2376. $clauses[] = "lgm_id = " . $value[0];
  2377. break;
  2378. // code group
  2379. case 98 :
  2380. $clauses[] = "lgc_id = " . $value[0];
  2381. break;
  2382. // name group
  2383. case 99 :
  2384. $clauses[] = "lgn_id = " . $value[0];
  2385. break;
  2386. // standard
  2387. default :
  2388. $clauses[] = $this->table_prfx . "_locality_" . $value[1] . " = " . $value[0];
  2389. break;
  2390. }
  2391. // add postcode
  2392. $this->addPostCode($value[0], $value[1]);
  2393. }
  2394. }
  2395. }
  2396. // stores parameters
  2397. if (!isset($this->search_request["loc_name"])) {
  2398. $this->search_parameters["loc_name"] = implode(", ", $loc_names);
  2399. } else {
  2400. $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
  2401. }
  2402. // reorders request parameters
  2403. for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
  2404. unset($this->search_request["loc_key" . $i]);
  2405. //unset($this->search_request["loc_name".$i]);
  2406. }
  2407. for ($i = 0; $i < count($this->search_parameters["loc_keys"]); $i++) {
  2408. $this->search_request["loc_key" . ($i + 1)] = $this->search_parameters["loc_keys"][$i];
  2409. //$this->search_request["loc_name".($i + 1)] = $this->search_parameters["loc_name".($i + 1)];
  2410. }
  2411. // sets clause
  2412. $clause = implode(" OR ", $clauses);
  2413. }
  2414. break;
  2415. // COUNTRY
  2416. case "country" :
  2417. $value = strtoupper($_global["site"]);
  2418. #if($value=='') $value = strtoupper($_global["site"]);
  2419. #else $value = strtoupper($value);
  2420. // stores parameters
  2421. $this->search_parameters["country"] = $value;
  2422. // sets clause
  2423. $clause = $this->table_prfx . "_country = '" . $value . "'";
  2424. break;
  2425. // PROPERTY TYPE
  2426. case "property_type" :
  2427. // stores parameters
  2428. $this->search_parameters["property_type"] = $value;
  2429. // sets clause
  2430. if (is_array($value)) {
  2431. $clause = $this->table_prfx . "_property_type_id IN (" . implode(", ", $value) . ")";
  2432. } elseif ($value > 0) {
  2433. $clause = $this->table_prfx . "_property_type_id = " . $value;
  2434. }
  2435. break;
  2436. // STATUS
  2437. case "ad_status" :
  2438. if ($this->table_name != "TM_SAL_FR" && $this->table_name != "TM_RNT_FR") {
  2439. $clause = $this->table_prfx . "_ad_status >= 0";
  2440. }
  2441. break;
  2442. case "ad_in_nav_lang" :
  2443. //$clause = "t.sal_ai_id=lg.sal_ai_id AND lg.tad_language='".strtoupper($_global["lang"])."' AND lg.tad_text<>''";
  2444. $clause = "lg.tad_language='" . strtoupper($_global["lang"]) . "'";
  2445. break;
  2446. // visuel photo
  2447. case "photo" :
  2448. $clause = $this->table_prfx . "_nb_photo > 0";
  2449. break;
  2450. // LEGAL TYPE
  2451. case "property_ownership_type" :
  2452. // stores parameters
  2453. $this->search_parameters["property_ownership_type"] = $value;
  2454. if (is_array($value)) {
  2455. $clause = $this->table_prfx . "_id_property_ownership_type IN (" . implode(", ", $value) . ")";
  2456. } else {
  2457. $clause = $this->table_prfx . "_id_property_ownership_type IN (" . $value . ")";
  2458. }
  2459. break;
  2460. case "perimproximit" :
  2461. /* $clause = " lct_name_fr in (SELECT * FROM (SELECT lct_name,
  2462. (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))))
  2463. as Proximite from LOC_LOOKUP_FR) AS GLO where Proximite<='$this->PerimProximit' order by Proximite"; */
  2464. $clause = $this->table_prfx . "_locality_2 IN (" . $this->list_lock_proximite . ")";
  2465. break;
  2466. // vacances
  2467. case "nb_bedrooms" :
  2468. $value = (int) $value;
  2469. if ($value >= 0) {
  2470. if ($value == 9) {
  2471. $clause = $this->table_prfx . "_nb_bedrooms >= 10";
  2472. } else {
  2473. $clause = $this->table_prfx . "_nb_bedrooms = " . ($value + 1);
  2474. }
  2475. $this->search_parameters["nb_bedrooms"] = $value;
  2476. }
  2477. break;
  2478. case "nb_people" :
  2479. if ($value != "") {
  2480. $value = (int) $value;
  2481. switch ($value) {
  2482. case 0 :
  2483. $clause = $this->table_prfx . "_nb_people BETWEEN 1 AND 5";
  2484. break;
  2485. case 1 :
  2486. $clause = $this->table_prfx . "_nb_people BETWEEN 4 AND 7";
  2487. break;
  2488. case 2 :
  2489. $clause = $this->table_prfx . "_nb_people BETWEEN 6 AND 9";
  2490. break;
  2491. case 3 :
  2492. $clause = $this->table_prfx . "_nb_people BETWEEN 8 AND 12";
  2493. break;
  2494. case 4 :
  2495. $clause = $this->table_prfx . "_nb_people > 11";
  2496. break;
  2497. }
  2498. $this->search_parameters["nb_people"] = $value;
  2499. }
  2500. break;
  2501. case "refville_field" : // champs de localisation des annonces dans T_RENTAD_RNT et T_SALESAD_SAL
  2502. $lct_value = $value["lct_val"];
  2503. if (isset($value["lct_lvl"])) { // peut être "empty"
  2504. $lct_level = $value["lct_lvl"];
  2505. // calcul du bon nom de champ en fonction du niveau
  2506. if ($lct_level == "99") {
  2507. $lct_field = "lgn_id";
  2508. } else if ($lct_level == "98") {
  2509. $lct_field = "lgc_id";
  2510. } else { // 1 ou 2 a priori
  2511. if (($lct_value == "100") && ($lct_level == "1")) { // Paris
  2512. $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . "locality_1";
  2513. } else { // autre ville
  2514. $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . "locality_" . $lct_level;
  2515. }
  2516. }
  2517. } else if (isset($value["lct_field"]) && !empty($value["lct_field"])) {
  2518. $lct_field = $value["lct_field"];
  2519. // calcul du bon nom de champ en fonction de celui qui a été donné et qui est peut-être erroné
  2520. if ($lct_field == "lct_id") {
  2521. $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . "locality_2";
  2522. }
  2523. // rajout du préfixe pour les "localiy_" si nécessaire
  2524. if (string_begins_with($lct_field, "locality_")) {
  2525. $lct_field = (($_global['univers'] == 2) || ($_global['univers'] == 8) ? "rnt" : "sal") . "_" . $lct_field;
  2526. }
  2527. }
  2528. $clause = $lct_field . " = " . $lct_value;
  2529. //echo "[clause=".$clause."]";
  2530. break;
  2531. case "refville_locality" :
  2532. $clause = $this->table_prfx . "_locality_2 > 0";
  2533. break;
  2534. case "post_code_departem" :
  2535. if ($value == "98") { // Monaco
  2536. $clause = $this->table_prfx . "_post_code = '98000'";
  2537. } else { // départements
  2538. $clause = $this->table_prfx . "_post_code LIKE '" . $value . "%'";
  2539. }
  2540. break;
  2541. // PROPERTY TYPE
  2542. case "ck_property_type" :
  2543. // stores parameters
  2544. $this->search_parameters["ck_property_type"] = $value;
  2545. $length = strlen($value);
  2546. // Traitement particulier du type viager
  2547. if ($value[$length - 1] == '1') {
  2548. $ignore_viager = false;
  2549. $value[$length - 1] = '0';
  2550. }
  2551. else
  2552. $ignore_viager = true;
  2553. if (strpos($value, '1') !== false) {
  2554. $ids = array();
  2555. for ($i = 0; $i < $length; $i++) {
  2556. if ($value[$i] == '1')
  2557. $ids[] = $i + 1;
  2558. }
  2559. //$clause = $this->table_prfx."_property_type_id_orig IN (".implode(", ", $ids).") AND ".$this->table_prfx."_type_transaction <> 4";
  2560. //if( $clause_viager!='' ) $clause .= ') OR ('.$clause_viager;
  2561. $clause = $this->table_prfx . "_property_type_id_orig IN (" . implode(", ", $ids) . ")";
  2562. if ($ignore_viager && !$this->isTtypeTransactionAlreadySetInSql)
  2563. $clause .= ") AND (" . $this->table_prfx . "_type_transaction <> 4";
  2564. }
  2565. // Sinon, pas de filtre sur les types de bien
  2566. elseif (!$ignore_viager && !$this->isTtypeTransactionAlreadySetInSql)
  2567. $clause = $this->table_prfx . "_type_transaction = 4";
  2568. break;
  2569. // CRITERES AVANCES
  2570. case "ck_advanced" :
  2571. // stores parameters
  2572. $this->search_parameters["ck_advanced"] = $value;
  2573. $length = strlen($value);
  2574. if (strpos($value, '1') !== false) {
  2575. /*
  2576. *
  2577. * Attention :
  2578. * PHP complète les valeurs par des 0 à droite avec l'opération binaire,
  2579. * contrairement à MYSQL qui complète à gauche
  2580. *
  2581. *
  2582. * Instructions :
  2583. *
  2584. * Utiliser une opération de type binaire AND
  2585. * advanced_set & X = X, où X est un nombre décimal ou binaire
  2586. *
  2587. * Utiliser une opération de type binaire OR
  2588. * advanced_set & X, où X est un nombre décimal ou binaire
  2589. *
  2590. */
  2591. $length = strlen($value);
  2592. $clause = '';
  2593. global $_MASK_ADV_OR;
  2594. foreach ($_MASK_ADV_OR as $mask_or) {
  2595. $mask_value = $value & $mask_or;
  2596. // Ajouter la clause OU du chauffage
  2597. if ($mask_value > 0) {
  2598. // Equivalent d'un NON + compléter avec des 1 pour le ET ci-dessous
  2599. $remove_mask = str_pad(strtr($mask_value, '01', '10'), $length, 1);
  2600. // Effacer les critères de chauffage du masque principal
  2601. $value = $value & $remove_mask;
  2602. // Ajouter l'opération binaire, avec la chaine dans le bon sens
  2603. $mask_value = strrev(rtrim($mask_value, '0'));
  2604. $clause .= ' AND ' . $this->table_prfx . "_advanced_set & b'{$mask_value}'";
  2605. }
  2606. }
  2607. // Traiter ensuite tout le reste comme des champs requis (ET logique)
  2608. if ($value > 0) {
  2609. // Envoyer l'opération binaire, avec la chaine dans le bon sens
  2610. $value = strrev(rtrim($value, '0'));
  2611. $clause .= ' AND ' . $this->table_prfx . "_advanced_set & b'{$value}' = b'{$value}'";
  2612. }
  2613. $clause = substr($clause, 5);
  2614. $this->isAdvancedSearch = true;
  2615. }
  2616. break;
  2617. // NB ROOMS
  2618. case "ck_nb_rooms" :
  2619. // stores parameters
  2620. $this->search_parameters["ck_nb_rooms"] = $value;
  2621. if ($_global['univers'] == 8)
  2622. $champs = '_nb_bedrooms'; else
  2623. $champs = '_nb_rooms';
  2624. if (strpos($value, '1') !== false) {
  2625. $ids = array();
  2626. // Le dernier nombre avant le "et plus"
  2627. $last_single_num = 5;
  2628. for ($i = 0; $i < $last_single_num; $i++) {
  2629. if ($value[$i] == '1')
  2630. $ids[] = $i + 1;
  2631. }
  2632. // Si aucun autre nombre est coché
  2633. if ($ids == array()) {
  2634. // Si le "et plus" est coché
  2635. if ($value[$last_single_num] == '1')
  2636. $clause .= $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
  2637. // Sinon, aucun filtre
  2638. }
  2639. // Si d'autre nombres sont cochés
  2640. else {
  2641. $clause = $this->table_prfx . $champs . " IN (" . implode(", ", $ids) . ")";
  2642. // Si le sixieme est coche, ajouter le OR
  2643. if ($value[$last_single_num] == '1')
  2644. $clause .= ' OR ' . $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
  2645. }
  2646. }
  2647. break;
  2648. // NB ROOMS
  2649. case "ck_nb_bedrooms" :
  2650. // stores parameters
  2651. $this->search_parameters["ck_nb_bedrooms"] = $value;
  2652. $champs = '_nb_bedrooms';
  2653. if (strpos($value, '1') !== false) {
  2654. $ids = array();
  2655. // Le dernier nombre avant le "et plus"
  2656. $last_single_num = 5;
  2657. for ($i = 0; $i < $last_single_num; $i++) {
  2658. if ($value[$i] == '1')
  2659. $ids[] = $i + 1;
  2660. }
  2661. // Si aucun autre nombre est coché
  2662. if ($ids == array()) {
  2663. // Si le "et plus" est coché
  2664. if ($value[$last_single_num] == '1') {
  2665. $clause .= $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
  2666. }
  2667. // Sinon, aucun filtre
  2668. }
  2669. // Si d'autre nombres sont cochés
  2670. else {
  2671. $clause = $this->table_prfx . $champs . " IN (" . implode(", ", $ids) . ")";
  2672. // Si le sixieme est coche, ajouter le OR
  2673. if ($value[$last_single_num] == '1') {
  2674. $clause .= ' OR ' . $this->table_prfx . $champs . ' >= ' . ($last_single_num + 1);
  2675. }
  2676. }
  2677. //$this->isAdvancedSearch = true;
  2678. }
  2679. break;
  2680. // SURFACE DU TERRAIN
  2681. case 'surf':
  2682. $value_min = $this->search_request["surf_min"];
  2683. $value_max = $this->search_request["surf_max"];
  2684. // stores parameters
  2685. $this->search_parameters["surf_min"] = "" . $value_min;
  2686. $this->search_parameters["surf_max"] = "" . $value_max;
  2687. // On a une valeur min ?
  2688. if ($value_min != "") {
  2689. // Et on a une valeur max ?
  2690. if ($value_max != "") {
  2691. // restores order
  2692. if ($value_min > $value_max) {
  2693. $value_tmp = $value_min;
  2694. $value_min = $value_max;
  2695. $value_max = $value_tmp;
  2696. }
  2697. $clause = $this->table_prfx . "_garden_area BETWEEN " . $value_min . " AND " . $value_max;
  2698. // Seulement le min
  2699. } else {
  2700. $clause = $this->table_prfx . "_garden_area >= " . $value_min;
  2701. }
  2702. $this->isAdvancedSearch = true;
  2703. // Seulement le max ?
  2704. } elseif ($value_max != "") {
  2705. $clause = $this->table_prfx . "_garden_area <= " . $value_max;
  2706. $this->isAdvancedSearch = true;
  2707. }
  2708. break;
  2709. // PRICE, AREA, NB_ROOMS
  2710. case 'price':
  2711. case 'area':
  2712. case 'nb_rooms':
  2713. $value_min = $this->search_request[$criterion . "_min"];
  2714. $value_max = $this->search_request[$criterion . "_max"];
  2715. // stores parameters
  2716. $this->search_parameters[$criterion] = $value;
  2717. $this->search_parameters[$criterion . "_min"] = "" . $value_min;
  2718. $this->search_parameters[$criterion . "_max"] = "" . $value_max;
  2719. // sets clause
  2720. if ($value != "") {
  2721. if ($criterion == "nb_rooms") {
  2722. if (is_array($this->search_request[$criterion])) {
  2723. $value_unique = array_unique($value); // supprime les doublons
  2724. if (count($value_unique) > 1) {
  2725. $clause = $this->table_prfx . "_" . $criterion . " IN (" . implode(", ", $value_unique) . ")";
  2726. } else if (sizeof($value_unique) == 1) {
  2727. $clause = $this->table_prfx . "_" . $criterion . " = " . $value_unique[0];
  2728. }
  2729. } else {
  2730. $clause = $this->table_prfx . "_" . $criterion . ($value == 0 ? " = " : " >= ") . ($value + 1);
  2731. }
  2732. }
  2733. } else {
  2734. if ($value_min != "" && $value_max != "") {
  2735. // restores order
  2736. if ($value_min > $value_max) {
  2737. $value_tmp = $value_min;
  2738. $value_min = $value_max;
  2739. $value_max = $value_tmp;
  2740. }
  2741. $this->search_parameters[$criterion . "_min"] = $value_min;
  2742. $this->search_parameters[$criterion . "_max"] = $value_max;
  2743. $clause = $this->table_prfx . "_" . $criterion . " BETWEEN " . $value_min . " AND " . $value_max;
  2744. } else {
  2745. if ($value_min != "") {
  2746. $clause = $this->table_prfx . "_" . $criterion . " >= " . $value_min;
  2747. } elseif ($value_max != "") {
  2748. $clause = $this->table_prfx . "_" . $criterion . " <= " . $value_max;
  2749. }
  2750. }
  2751. }
  2752. // sets price minimum, for everything else than parkings
  2753. if ($criterion == "price" && $this->search_request["property_type"][0] != 7) {
  2754. $price_clause = $this->table_prfx . "_price > " . constant("MIN_PRICE_" . strtoupper($this->table_prfx));
  2755. $clause .= ($clause != "" ? ") AND (" : "") . $price_clause;
  2756. }
  2757. break;
  2758. // AG LOCALITY
  2759. case "ag_locality" :
  2760. if (($this->search_request["loc_key"] != "") && ($this->search_request["loc_key"] != "_")) {
  2761. $value = $this->search_request["loc_key"];
  2762. // stores parameters
  2763. $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
  2764. $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name"]);
  2765. $this->search_parameters["loc_key"] = $value;
  2766. $this->search_parameters["loc_keys"][] = $value;
  2767. // processes
  2768. $value = explode("_", $value);
  2769. // stores parameters
  2770. $this->search_parameters["loc_ids"][] = $value[0];
  2771. $this->search_parameters["loc_levels"][] = $value[1];
  2772. // sets clause
  2773. switch ($value[1]) {
  2774. // map group
  2775. case 97 :
  2776. $clause = "lgm_id = " . $value[0];
  2777. break;
  2778. // code group
  2779. case 98 :
  2780. $clause = "lgc_id = " . $value[0];
  2781. break;
  2782. // name group
  2783. case 99 :
  2784. $clause = "lgn_id = " . $value[0];
  2785. break;
  2786. // standard
  2787. default :
  2788. $clause = $this->table_prfx . "_loc_id_" . $value[1] . " = " . $value[0];
  2789. break;
  2790. }
  2791. /* Patch Specifique pour Marseille(421) et Lyon(422) */
  2792. switch ($value[0]) {
  2793. case 19667:
  2794. $clause = "lgn_id = 421";
  2795. break;
  2796. case 18897:
  2797. $clause = "lgn_id = 422";
  2798. break;
  2799. default:
  2800. break;
  2801. }
  2802. // add postcode
  2803. $this->addPostCode($value[0], $value[1]);
  2804. } else {
  2805. $clauses = array();
  2806. for ($i = 1; $i < (SEARCH_FIELDS_NUMBER + 1); $i++) {
  2807. $value = $this->search_request["loc_key" . $i];
  2808. if ($value != "") {
  2809. $loc_names[] = $this->search_request["loc_name" . $i];
  2810. // $this->search_parameters["loc_names"][] = preg_replace("/( ?\([0-9]+\))/", "", $this->search_request["loc_name".$i]);
  2811. // processes
  2812. $values = $value;
  2813. $value = explode("_", $value);
  2814. if (($value[0] != "") && ($value[1] != "")) {
  2815. // stores parameters
  2816. $this->search_parameters["loc_key" . $i] = $values;
  2817. $this->search_parameters["loc_keys"][] = $values;
  2818. // stores parameters
  2819. $this->search_parameters["loc_ids"][] = $value[0];
  2820. $this->search_parameters["loc_levels"][] = $value[1];
  2821. // sets clause
  2822. switch ($value[1]) {
  2823. // map group
  2824. case 97 :
  2825. $clauses[] = "lgm_id = " . $value[0];
  2826. break;
  2827. // code group
  2828. case 98 :
  2829. $clauses[] = "lgc_id = " . $value[0];
  2830. break;
  2831. // name group
  2832. case 99 :
  2833. $clauses[] = "lgn_id = " . $value[0];
  2834. break;
  2835. // standard
  2836. default :
  2837. $clauses[] = $this->table_prfx . "_loc_id_" . $value[1] . " = " . $value[0];
  2838. break;
  2839. }
  2840. // add postcode
  2841. $this->addPostCode($value[0], $value[1]);
  2842. }
  2843. }
  2844. }
  2845. // stores parameters
  2846. if (!isset($this->search_request["loc_name"])) {
  2847. $this->search_parameters["loc_name"] = implode(", ", $loc_names);
  2848. } else {
  2849. $this->search_parameters["loc_name"] = $this->search_request["loc_name"];
  2850. }
  2851. // reorders request parameters
  2852. for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
  2853. unset($this->search_request["loc_key" . $i]);
  2854. //unset($this->search_request["loc_name".$i]);
  2855. }
  2856. for ($i = 0; $i < count($this->search_parameters["loc_keys"]); $i++) {
  2857. $this->search_request["loc_key" . ($i + 1)] = $this->search_parameters["loc_keys"][$i];
  2858. //$this->search_request["loc_name".($i + 1)] = $this->search_parameters["loc_name".($i + 1)];
  2859. }
  2860. // sets clause
  2861. $clause = implode(" OR ", $clauses);
  2862. }
  2863. break;
  2864. // AG COUNT
  2865. case "ag_count" :
  2866. //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
  2867. //$clause = $this->table_prfx."_rnt_count > 0 OR ".$this->table_prfx."_sal_count > 0";
  2868. $clause = "adp.adp_id_presto = t.id_presto AND (adp.adp_rnt_count > 0 OR adp.adp_sal_count > 0)";
  2869. /*
  2870. // FP. 03/02/11 - Disable showing exclusive agencies even if they don't have announces
  2871. if(AGC_EXCLUSIVE_FRANCHISING!='') {
  2872. if(is_numeric(AGC_EXCLUSIVE_FRANCHISING) && AGC_EXCLUSIVE_FRANCHISING>0) {
  2873. $clause .= ' OR agc_franchising_id='.AGC_EXCLUSIVE_FRANCHISING;
  2874. } else {
  2875. $clause .= " OR agc_franchising='".AGC_EXCLUSIVE_FRANCHISING."'";
  2876. }
  2877. }
  2878. */
  2879. break;
  2880. // Consommation énergétique
  2881. case "dpe" :
  2882. $this->search_parameters['dpe'] = $value;
  2883. break;
  2884. // Fraicheur des annonces
  2885. case "fresh" :
  2886. $this->search_parameters['fresh'] = $value;
  2887. break;
  2888. case "lct_post_code" :
  2889. if ($value) {
  2890. $clause = $this->table_prfx . "_lct_post_code = " . $value;
  2891. }
  2892. break;
  2893. }
  2894. // adds clause
  2895. if ($clause != "") {
  2896. $where[] = "(" . $clause . ")";
  2897. }
  2898. $this->global_where = $where;
  2899. }
  2900. /**
  2901. * Function setOrderAgencyAds : uniquement pour l'univers 9 (annonces ventes + location)
  2902. *
  2903. * @param type $sOrder : field to "order by"
  2904. */
  2905. function setOrderAgencyAds($sOrder) {
  2906. $default_order = false;
  2907. if (!empty($sOrder)) {
  2908. if ($this->PerimProximit > 0) {
  2909. $sOrder = $this->order[] = "LocalityProximity ASC";
  2910. $sOrder = $this->order[] = "DistProximity ASC";
  2911. }
  2912. $aOrders = array("update_date", "property_type", "price", "area", "nb_rooms");
  2913. if ($sOrder == "post_code") {
  2914. $aOrders[] = "post_code";
  2915. }
  2916. if (!in_array($sOrder, $aOrders)) {
  2917. $sOrder = "price";
  2918. }
  2919. } else {
  2920. // TRI PAR PRIX DESC PAR DEFAUT
  2921. $sOrder = "price";
  2922. $this->search_request['order'] = 'price';
  2923. $this->search_request['hi_order'] = 0; // DESC
  2924. $default_order = true;
  2925. }
  2926. if ($default_order) { // Si tri par defaut, on affiche les vene en premier
  2927. $this->order[] = " univ ASC";
  2928. }
  2929. // default order
  2930. $this->order[] = $sOrder . " " . ($this->search_request['hi_order'] == 1 ? 'DESC' : 'ASC');
  2931. if (($sOrder == "post_code")) {
  2932. $this->order[] = "price DESC";
  2933. }
  2934. // optional order
  2935. if (($sOrder != "update_date") && (!isset($this->search_request["order_price"]))) {
  2936. $this->order[] = "update_date DESC";
  2937. }
  2938. }
  2939. // *** sets query order clause ***
  2940. function setOrder($mode, $order, $field = "") {
  2941. global $_global;
  2942. switch ($mode) {
  2943. // ad order
  2944. case "ad" :
  2945. if ($order != "") {
  2946. if ($this->PerimProximit > 0) {
  2947. $order = $this->order[] = "LocalityProximity ASC";
  2948. $order = $this->order[] = "DistProximity ASC";
  2949. }
  2950. // array of authorized sort fields
  2951. if ($_global["univers"] == 13) {
  2952. $orders = array("update_date", "property_type", "price", "nb_bedrooms", "nb_people");
  2953. } else {
  2954. $orders = array("update_date", "property_type", "price", "area", "nb_rooms");
  2955. if ($order == "post_code") {
  2956. // array_push($orders, $order);
  2957. $orders[] = "post_code";
  2958. }
  2959. }
  2960. // only adds if required order field is allowed
  2961. if (!in_array($order, $orders)) {
  2962. $order = "price";
  2963. }
  2964. } else {
  2965. $order = "price";
  2966. $this->search_request['hi_order'] = 0; // ASC
  2967. }
  2968. $direction = ($this->search_request["hi_order"] == 1 ? "DESC" : "ASC");
  2969. // default order
  2970. $this->order[] = $this->table_prfx . "_" . $order . " " . $direction;
  2971. if (($order == "post_code") || ($_global["self"] == "resultats_refnat.php")) {
  2972. $this->order[] = $this->table_prfx . "_price " . $direction;
  2973. }
  2974. // optional order
  2975. if (($order != "update_date") && (!isset($this->search_request["order_price"]))) {
  2976. $this->order[] = $this->table_prfx . "_update_date DESC";
  2977. }
  2978. if ($_global["self"] == "resultats_refnat.php") {
  2979. $this->order = array();
  2980. $this->order[] = $this->table_prfx . "_update_date DESC";
  2981. }
  2982. break;
  2983. case "filter_ad" :
  2984. if (!isset($this->order)) {
  2985. $this->order = array();
  2986. }
  2987. $direction = ($order == 1 ? "DESC" : "ASC");
  2988. $orderthis = $this->table_prfx . "_" . $field . " " . $direction;
  2989. if (!in_array($orderthis, $this->order)) {
  2990. $this->order[] = $orderthis;
  2991. }
  2992. break;
  2993. // agency order
  2994. case "agency" :
  2995. $user_ihm = json_decode($_COOKIE[USER_DATA_IHM_COOKIE_NAME], true);
  2996. $allowedOrder = array('count', 'name');
  2997. if (isset($user_ihm['hi_order']) && in_array($user_ihm['order'], $allowedOrder)) {
  2998. $direction = ((int) $user_ihm['hi_order'] > 0 ? 'DESC' : 'ASC');
  2999. $order = $user_ihm['order'];
  3000. //order == 1 tri croissant
  3001. //order == 0 tri décroissant
  3002. } else {
  3003. if (AGC_EXCLUSIVE_FRANCHISING != '') { // ORPI en haut de list si pas de tri
  3004. $this->order[] = $this->table_prfx . '_franchising_order DESC';
  3005. }
  3006. //Tri par defaut
  3007. $direction = 'DESC';
  3008. $order = 'count';
  3009. // $this->order[] = 'agc_count DESC';
  3010. }
  3011. // default order
  3012. $this->order[] = $this->table_prfx . "_" . $order . " " . $direction;
  3013. break;
  3014. case "random" :
  3015. $this->order[] = "rand()";
  3016. break;
  3017. }
  3018. // stores parameter
  3019. if ($mode <> "filter_ad") {
  3020. $this->search_parameters["order"] = $order;
  3021. $this->search_request["order"] = $order;
  3022. }
  3023. }
  3024. // *** sets query limit ***
  3025. /**
  3026. *
  3027. * @global type $_global
  3028. * @param type $mode
  3029. * @param type $offset
  3030. * @param type $limit
  3031. */
  3032. function setLimit($mode, $offset, $limit = 5) {
  3033. global $_global;
  3034. if ($mode == "ad") {
  3035. $max_results = ($this->is_agency_search ? MAX_RESULTS_AGENCY : MAX_RESULTS);
  3036. // N° de page a afficher moins 1 pour gérer le Limit
  3037. if (!isset($_global['powersite']) || $_global['powersite'] <> 1) {
  3038. $offset = $offset - 1;
  3039. }
  3040. if ($offset < 0) {
  3041. $offset = 0;
  3042. }
  3043. } elseif ($mode == "adHomeGallery") {
  3044. $max_results = 4; //MAX_RESULTS_AGENCY;
  3045. } else {
  3046. $max_results = MAX_RESULTS_AGENCY;
  3047. }
  3048. $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
  3049. $count = $max_results_per_page;
  3050. $count = $max_results_per_page - ($this->has_premium == true ? 1 : 0) - ($this->has_exclusive == true ? 1 : 0);
  3051. //$count = $max_results_per_page;
  3052. //$offset = $offset - ($this->has_premium == true ? 1 : 0);
  3053. $start = $offset * $count;
  3054. if ($start + $count > $max_results) {
  3055. $count = $max_results - $start;
  3056. }
  3057. if ($mode == "free") {
  3058. $max_results_per_page = $limit;
  3059. $start = $offset;
  3060. }
  3061. if ($count < 0) {
  3062. $count = MAX_RESULTS_PER_PAGE;
  3063. }
  3064. //modification pierre : calcul limit
  3065. if ($_REQUEST['offset']==1) {
  3066. setcookie('nbAdFirstPage', $count);
  3067. } else if (isset($_COOKIE['nbAdFirstPage'])) {
  3068. $start = $_COOKIE['nbAdFirstPage']+($_REQUEST['offset']-2)*$count;
  3069. }
  3070. $this->limit = $start . ", " . $count;
  3071. }
  3072. // *** sets post codes ***
  3073. function setPostCodes() {
  3074. global $_global;
  3075. if (count($this->loc_keys) > 0) {
  3076. $this->search_parameters["lzip"] = array();
  3077. $i = 0;
  3078. //debug2($this->loc_keys);
  3079. foreach ($this->loc_keys as $loc_key) {
  3080. // AGU 30/09
  3081. if ($this->search_parameters["loc_levels"][$i] == 97) {
  3082. // builds the query
  3083. $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 ";
  3084. $query .= "FROM T_LOCGROUPMAP_LGM_" . strtoupper($_global["site"]) . " ";
  3085. $query .= "WHERE " . $loc_key;
  3086. } else {
  3087. // builds the query
  3088. $query = "SELECT lct_parent_id, lct_name" . $this->table_locality_lang . " AS lct_name, lct_post_code, lgc_id, lgn_id ";
  3089. $query .= "FROM " . $this->table_locality_name . " ";
  3090. $query .= "WHERE " . $loc_key;
  3091. }
  3092. // executes the query
  3093. if ($_global["debug"] == 3) {
  3094. echo "setPostCodes()<br />";
  3095. echo $query . "<br />";
  3096. echo "<hr />";
  3097. }
  3098. $locality = pdoquery($query);
  3099. // set
  3100. $this->search_parameters["loc_names"][] = $locality[0]["lct_name"];
  3101. // set post_code
  3102. if ($this->search_parameters["loc_levels"][0] == 99) {
  3103. $lzips = array();
  3104. for ($j = 0; $j < count($locality); $j++) {
  3105. $lzips[] = $locality[$j]["lct_post_code"];
  3106. }
  3107. $this->search_parameters["lzip"][] = implode(", ", $lzips);
  3108. // agu 14/08/2009
  3109. $this->search_request["lzips"][] = implode(", ", $lzips);
  3110. } else {
  3111. $this->search_parameters["lzip"][] = $locality[0]["lct_post_code"];
  3112. // agu 14/08/2009
  3113. $this->search_request["lzips"][] = $locality[0]["lct_post_code"];
  3114. }
  3115. //
  3116. $this->search_parameters["lgc_ids"][] = $locality[0]["lgc_id"];
  3117. //
  3118. $this->search_parameters["lgn_ids"][] = $locality[0]["lgn_id"];
  3119. // set department code
  3120. $this->search_parameters["szip"][] = substr($locality[0]["lct_post_code"], 0, 2);
  3121. // agu 14/08/2009
  3122. $this->search_request["szips"][] = substr($locality[0]["lct_post_code"], 0, 2);
  3123. // set parent id
  3124. $this->search_parameters["loc_parent_ids"][] = $locality[0]["lct_parent_id"];
  3125. $i++;
  3126. }
  3127. $this->search_request["szip"] = get_zip_code($this->search_parameters, "szip");
  3128. $this->search_request["lzip"] = get_zip_code($this->search_parameters, "lzip");
  3129. $this->setLocalityHierarchy();
  3130. }
  3131. }
  3132. // *** sets locality hierarchy
  3133. function setLocalityHierarchy() {
  3134. global $_global;
  3135. switch ($this->search_parameters["loc_levels"][0]) {
  3136. case 0 :
  3137. $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]);
  3138. break;
  3139. case 1 :
  3140. // builds the query
  3141. $query = "SELECT lct_level, lct_name" . $this->table_locality_lang . " lct_name, lct_post_code, lct_id ";
  3142. $query .= "FROM " . $this->table_locality_name . " ";
  3143. $query .= "WHERE lct_id = " . $this->search_parameters["loc_parent_ids"][0];
  3144. // executes the query
  3145. if ($_global["debug"] == 3) {
  3146. echo "setLocalityHierarchy()<br />";
  3147. echo $query . "<br />";
  3148. echo "<hr />";
  3149. }
  3150. $locality = pdoquery($query);
  3151. // set
  3152. $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"]);
  3153. $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]);
  3154. break;
  3155. default :
  3156. // builds the query
  3157. $query = "SELECT lct_level, lct_name" . $this->table_locality_lang . " lct_name, lct_post_code, lct_id ";
  3158. $query .= "FROM " . $this->table_locality_name . " ";
  3159. if ($this->search_parameters["loc_parent_ids"][0] != "")
  3160. $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] . ")) ";
  3161. $query .= "ORDER BY lct_level";
  3162. // executes the query
  3163. if ($_global["debug"] == 3) {
  3164. echo "setLocalityHierarchy()<br />";
  3165. echo $query . "<br />";
  3166. echo "<hr />";
  3167. }
  3168. $localities = pdoquery($query);
  3169. // set
  3170. $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"]);
  3171. $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"]);
  3172. switch ($this->search_parameters["loc_levels"][0]) {
  3173. // map group
  3174. case 97 :
  3175. $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]);
  3176. break;
  3177. // code group
  3178. case 98 :
  3179. $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]);
  3180. break;
  3181. // name group
  3182. case 99 :
  3183. $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]);
  3184. break;
  3185. // standard
  3186. default :
  3187. $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]);
  3188. break;
  3189. }
  3190. break;
  3191. }
  3192. }
  3193. // *** sets coordinates ***
  3194. function setCoordinates() {
  3195. $query = "SELECT lct_lat, lct_long ";
  3196. $query .= "FROM " . $this->table_locality_name . " ";
  3197. $query .= "WHERE lct_id = ";
  3198. }
  3199. // *** sets number of pages ***
  3200. function setPages($mode) {
  3201. global $_global;
  3202. if ($mode == "ad") {
  3203. $max_results = ($this->is_agency_search ? MAX_RESULTS_AGENCY : MAX_RESULTS);
  3204. } else {
  3205. $max_results = MAX_RESULTS_AGENCY;
  3206. }
  3207. $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
  3208. //$max_results_per_page = $max_results_per_page - ($this->has_premium == true ? 1 : 0);
  3209. //echo "<pre>"; print_r($_REQUEST);echo "</pre>";
  3210. if (isset($_REQUEST['user_data_ihm'])) {
  3211. $anbPages = json_decode($_REQUEST['user_data_ihm'], true);
  3212. $anbPages = $anbPages['nb_results'];
  3213. if ($anbPages == NULL) {
  3214. $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
  3215. } else {
  3216. $max_results_per_page = $anbPages;
  3217. }
  3218. } else {
  3219. $max_results_per_page = ($mode == "ad" ? MAX_RESULTS_PER_PAGE : MAX_RESULTS_AGENCY_PER_PAGE);
  3220. }
  3221. $count = $this->search_count;
  3222. if ($count >= $max_results) {
  3223. $count = $max_results;
  3224. }
  3225. $nbPages = ceil($count / $max_results_per_page);
  3226. if ($this->search_parameters['premiumPresente']) {
  3227. $max_results_per_page = $max_results_per_page - 1;
  3228. $nbPages = ceil($count / $max_results_per_page);
  3229. }
  3230. $this->search_parameters["pages"] = $nbPages;
  3231. $this->search_request["pages"] = $nbPages;
  3232. }
  3233. // *** sets request ***
  3234. function setRequest($http_request) {
  3235. //var_dump($http_request); die;
  3236. global $_global;
  3237. if ($this->enableSearch($http_request) == true) {
  3238. $request = array();
  3239. if ($http_request["loc_name"] != "") {
  3240. $request["loc_name"] = $http_request["loc_name"];
  3241. } else {
  3242. $loc_names = array();
  3243. for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
  3244. if ($http_request["loc_name" . $i] != "" && $http_request["loc_name" . $i] != LABEL_DEFAULT_LOCALITY) {
  3245. $loc_names[] = $http_request["loc_name" . $i];
  3246. }
  3247. $request["loc_name" . $i] = $http_request["loc_name" . $i];
  3248. }
  3249. $request["loc_name"] = implode(", ", $loc_names);
  3250. }
  3251. // loc_keys
  3252. if ($http_request["loc_key"] != "") {
  3253. $request["loc_key"] = $http_request["loc_key"];
  3254. } else {
  3255. for ($i = 1; $i <= SEARCH_FIELDS_NUMBER; $i++) {
  3256. $request["loc_key" . $i] = $http_request["loc_key" . $i];
  3257. $request["loc_name" . $i] = $http_request["loc_name" . $i];
  3258. }
  3259. }
  3260. if (empty($_REQUEST['old'])) {
  3261. if (isset($http_request["ck_property_type"]))
  3262. $request["ck_property_type"] = $http_request["ck_property_type"];
  3263. if (isset($http_request["ck_nb_rooms"]))
  3264. $request["ck_nb_rooms"] = $http_request["ck_nb_rooms"];
  3265. if (isset($http_request["ck_nb_bedrooms"]))
  3266. $request["ck_nb_bedrooms"] = $http_request["ck_nb_bedrooms"];
  3267. if (isset($http_request["ck_advanced"]))
  3268. $request["ck_advanced"] = $http_request["ck_advanced"];
  3269. }
  3270. else {
  3271. if (isset($http_request["property_type"]))
  3272. $request["ck_property_type"] = convert_property_value($http_request["property_type"], 40);
  3273. if (isset($http_request["nb_rooms"]))
  3274. $request["ck_nb_rooms"] = convert_nb_rooms($http_request["nb_rooms"], $http_request["nb_rooms_min"], $http_request["nb_rooms_max"], 40);
  3275. }
  3276. $parameters = array("area", "price", "surf");
  3277. foreach ($parameters as $parameter) {
  3278. if ($http_request[$parameter] != "") {
  3279. $request[$parameter] = $http_request[$parameter];
  3280. }
  3281. if ($http_request[$parameter . "_min"] != "") {
  3282. $request[$parameter . "_min"] = $http_request[$parameter . "_min"];
  3283. }
  3284. if ($http_request[$parameter . "_max"] != "") {
  3285. $request[$parameter . "_max"] = $http_request[$parameter . "_max"];
  3286. }
  3287. }
  3288. if ($http_request["property_ownership_type"] != "") {
  3289. $request["property_ownership_type"] = $http_request["property_ownership_type"];
  3290. }
  3291. // advanced search parameters
  3292. if ($http_request["with_mmf"] != "") {
  3293. $request["with_mmf"] = $http_request["with_mmf"];
  3294. }
  3295. if (isset($http_request["dpe"]))
  3296. $request["dpe"] = $http_request["dpe"];
  3297. if (isset($http_request["fresh"]))
  3298. $request["fresh"] = $http_request["fresh"];
  3299. // order_pages (cz)
  3300. if ($http_request["order_pages"] != "") {
  3301. $request["order_pages"] = $http_request["order_pages"];
  3302. }
  3303. // szip
  3304. if ($http_request["szip"] != "") {
  3305. $request["szip"] = $http_request["szip"];
  3306. }
  3307. // lzip
  3308. if ($http_request["lzip"] != "") {
  3309. $request["lzip"] = $http_request["lzip"];
  3310. }
  3311. // id agence
  3312. if ($http_request["id_agence"] != "") {
  3313. $request["id_agence"] = $http_request["id_agence"];
  3314. }
  3315. //use map for cz
  3316. if ($http_request["use_map"] != "") {
  3317. $request["use_map"] = $http_request["use_map"];
  3318. }
  3319. if ($http_request["agc_name"] != "") {
  3320. $request["agc_name"] = $http_request["agc_name"];
  3321. }
  3322. // order
  3323. $request["order"] = $http_request["order"];
  3324. if (isset($http_request["order_price"])) {
  3325. if ($http_request["order_price"] == "") {
  3326. $http_request["order_price"] = 1;
  3327. }
  3328. $request["order_price"] = $http_request["order_price"];
  3329. }
  3330. if ($http_request["order2"] != "") {
  3331. $request["order2"] = $http_request["order2"];
  3332. }
  3333. // offset
  3334. $request["offset"] = $http_request["offset"];
  3335. // date
  3336. $request["date"] = $http_request["date"];
  3337. // site
  3338. $request["site"] = $_global["site"];
  3339. // univers
  3340. $request["univers"] = $http_request["univers"];
  3341. //visuel annonce
  3342. $request["an_visuel"] = $http_request["an_visuel"];
  3343. //visuel annonce
  3344. $request["hi_order"] = $http_request["hi_order"];
  3345. //Nb Results par Page
  3346. //print_r($http_request["LISearchHistoryCookie"]);
  3347. //$aSearch = unserialize($http_request["LISearchHistoryCookie"]);
  3348. //$aSearch = unserialize($aSearch[0]);
  3349. // nb_results vient du cookie, qui peut avoir été modifié juste avant (voir tools.js)
  3350. $request["nb_results"] = MAX_RESULTS_PER_PAGE;
  3351. // vacances
  3352. if ($_global["univers"] == 13) {
  3353. // nb_bedrooms
  3354. $request["nb_bedrooms"] = $http_request["nb_bedrooms"];
  3355. // nb_people
  3356. $request["nb_people"] = $http_request["nb_people"];
  3357. // type_transaction
  3358. $request["type_transaction"] = $http_request["type_transaction"];
  3359. }
  3360. // returns
  3361. return $request;
  3362. } else {
  3363. /*
  3364. // Attention : on peut arriver là si l'expression reguliere dans rw.decode echoue !
  3365. // Bien regarder si le tableau request contient ce que l'on veut.
  3366. if(empty($_REQUEST['old'])) {
  3367. echo '<b>Florian</b><br />Fichier `',__FILE__,'` (l. ',__LINE__,')<hr /><pre>';
  3368. var_dump( $http_request );
  3369. die();
  3370. }
  3371. */
  3372. header("Location:/index.php", true, 301);
  3373. die();
  3374. }
  3375. }
  3376. // *** allows search ***
  3377. function enableSearch($http_request) {
  3378. if ($http_request["loc_key"] != "" || $http_request["loc_key1"] != "" || $http_request["loc_key2"] != "" || $http_request["loc_key3"] != "" || $http_request["loc_key4"] != "") {
  3379. return true;
  3380. } else {
  3381. if ($http_request["id_agence"] != "") {
  3382. return true;
  3383. }
  3384. }
  3385. return false;
  3386. }
  3387. // *** sets antenna code ***
  3388. function setAntenna() {
  3389. if ($this->search_count > 0) {
  3390. // get the first filled pub_code
  3391. for ($i = 0; $i < count($this->search_results); $i++) {
  3392. $value = get_pub_data($this->search_results[$i][$this->table_prfx . "_pub_code"], "area1");
  3393. if ($value != "") {
  3394. $this->search_parameters["antenna"] = str_pad($value, 3, "0", STR_PAD_LEFT);
  3395. $this->search_request["antenna"] = str_pad($value, 3, "0", STR_PAD_LEFT);
  3396. break;
  3397. }
  3398. }
  3399. }
  3400. }
  3401. // *** adds post code ***
  3402. function addPostCode($id, $level) {
  3403. switch ($level) {
  3404. // map group
  3405. case 97 :
  3406. $this->loc_keys[] = "(lgm_id = " . $id . ")";
  3407. break;
  3408. // code group
  3409. case 98 :
  3410. $this->loc_keys[] = "(lgc_id = " . $id . ")";
  3411. break;
  3412. // name group
  3413. case 99 :
  3414. $this->loc_keys[] = "(lgn_id = " . $id . ")";
  3415. break;
  3416. // standard
  3417. default :
  3418. $this->loc_keys[] = "(lct_id = " . $id . " AND lct_level = " . $level . ")";
  3419. break;
  3420. }
  3421. }
  3422. // *** returns search results ***
  3423. function getSearchResults($mode = "ad") {
  3424. switch ($mode) {
  3425. // ad results
  3426. case "ad" :
  3427. if ($this->has_premium) {
  3428. $this->search_results = array_merge($this->search_results_premium, $this->search_results);
  3429. }
  3430. if ($this->has_exclusive) {
  3431. $this->search_results['exclu'] = $this->search_results_exclusive;
  3432. }
  3433. $search_results = $this->search_results;
  3434. break;
  3435. // agency results
  3436. case "agency" :
  3437. $search_results = $this->search_results_agency;
  3438. break;
  3439. }
  3440. return $search_results;
  3441. }
  3442. // Ads for a locality (for cities pages, cities and arrondissement pages...)
  3443. function getAdsCities($tab_ville, $max_ads = "", $property_type = NULL, $tab_nb_rooms = NULL, $results_piece = NULL, $with_photos = true, $val_offset = "") {
  3444. if (empty($max_ads)) $max_ads = 4;
  3445. if (empty($val_offset)) $val_offset = 0;
  3446. global $_global;
  3447. //print_r($tab_ville);
  3448. if (($tab_ville["lct_val"] != "") && (($tab_ville["lct_lvl"] != "") || ($tab_ville["lct_field"] != ""))) {
  3449. // sets select
  3450. if ($results_piece != NULL) {
  3451. $this->setSelect("ad", false);
  3452. } else {
  3453. $this->setSelect("refville", false);
  3454. }
  3455. // sets from
  3456. $this->setFrom();
  3457. // sets where
  3458. $where = array();
  3459. $this->setWhere($where, "ad_status"); // ..._ad_status >= 0
  3460. $this->setWhere($where, "price"); // ..._price > 0
  3461. $this->setWhere($where, "country"); // ..._country = 'FR'
  3462. $this->setWhere($where, "refville_field", $tab_ville); // lgn_id, lgc_id ou ..._locality_2
  3463. $this->setWhere($where, "refville_locality"); // ..._locality_2 > 0
  3464. if ($property_type != NULL) {
  3465. $this->search_request["property_type"] = $property_type;
  3466. $this->setWhere($where, "property_type");
  3467. }
  3468. if ($tab_nb_rooms != NULL) {
  3469. $this->search_request["nb_rooms"] = $tab_nb_rooms;
  3470. $this->setWhere($where, "nb_rooms");
  3471. }
  3472. // common where clause
  3473. $this->where = $where;
  3474. // set order
  3475. $this->setOrder("filter_ad", 1, "update_date");
  3476. // builds the query
  3477. $this->subquery = "SELECT " . $this->select . " ";
  3478. $this->subquery .= "FROM " . $this->from . " ";
  3479. $this->subquery .= "WHERE " . implode(" AND ", $this->where) . " ";
  3480. // only ads width at least 1 photo
  3481. if ($with_photos) {
  3482. $this->subquery .= "AND (" . $_global["table_prefix"] . "_nb_photo > 0)" . " ";
  3483. }
  3484. if (isset($tab_ville['lct_locality_2_arrond']) && !empty($tab_ville['lct_locality_2_arrond'])) {
  3485. $this->subquery .= "OR " . $_global["table_prefix"] . "_locality_2 IN (" . implode(", ", $tab_ville["lct_locality_2_arrond"]) . ")";
  3486. }
  3487. // vacances
  3488. if ($_global["univers"] == 13) {
  3489. $this->subquery .= "AND (" . $_global["table_prefix"] . "_type_transaction = 3)" . " ";
  3490. } else if ($_global["univers"] == 2) {
  3491. $this->subquery .= "AND (" . $_global["table_prefix"] . "_type_transaction = 2)" . " ";
  3492. } else if ($_global["univers"] == 8) {
  3493. $this->subquery .= "AND (" . $_global["table_prefix"] . "_type_transaction = 8)" . " ";
  3494. }
  3495. $this->subquery .= "ORDER BY " . implode(", ", $this->order) . " ";
  3496. // on récupère 10 fois plus d'annonces que souhaité véritablement, pour ensuite effectuer
  3497. // un tri aléatoire sur cette première liste et n'en garder ensuite que me nombre voulu
  3498. // (permet de ne pas tout le temps avoir les mêmes annonces à chaque requête)
  3499. $this->subquery .= "LIMIT " . $val_offset . ", " . $max_ads * 10 . " ";
  3500. //die($this->subquery);
  3501. $this->query = "
  3502. SELECT SQL_CALC_FOUND_ROWS " . $this->select . "
  3503. FROM (
  3504. " . $this->subquery . ") AS sub
  3505. ORDER BY RAND()
  3506. LIMIT 0, $max_ads
  3507. ";
  3508. // Optimisation : begin (BM, 01/07/2010)
  3509. // recherche du nom de la table des annonces à utiliser
  3510. // NB: tables TM_... uniquement pour les pages résultat, pas détail !
  3511. $prfx = $_global["table_prefix"];
  3512. $sql = " SELECT ttu_" . $prfx . "_fr FROM TP_TABLE_TO_USE_TTU";
  3513. $res = pdoquery($sql);
  3514. //echo "<hr>$sql<hr>";
  3515. // table des annonces (moteur InnoDB ou MEMORY)
  3516. if (sizeof($res) > 0) {
  3517. $table_name_ads = $res[0]["ttu_" . $prfx . "_fr"];
  3518. if (in_array($_global["univers"], array(2, 8, 13))) {
  3519. $table_name_ads_old = "T_RENTAD_RNT";
  3520. } else {
  3521. $table_name_ads_old = "T_SALESAD_SAL";
  3522. }
  3523. $this_query = $this->query;
  3524. $this_query = str_replace($table_name_ads_old, $table_name_ads, $this_query);
  3525. //echo "<hr>".$this_query."<hr>";
  3526. $this->query = $this_query;
  3527. }
  3528. // Optimisation : end
  3529. //echo "select = ".$this->select."<br />";
  3530. //echo "query = ".$this->query."<br />";
  3531. // executes the query
  3532. if ($_global["debug"] == 3) {
  3533. echo "getAdsCities()<br />";
  3534. echo $this->query . "<br />";
  3535. echo "<hr />";
  3536. }
  3537. $this->search_results = pdoquery($this->query);
  3538. // --------------------------------------------
  3539. // builds the count query
  3540. $this->query_count = "SELECT FOUND_ROWS() AS NUM";
  3541. //echo "query_count = ".$this->query_count."<br />";
  3542. $this->search_count = pdoquery($this->query_count);
  3543. $this->search_count = $this->search_count[0]["NUM"];
  3544. //echo "search_count = ".$this->search_count."<br />";
  3545. }
  3546. }
  3547. // Ads for a departement
  3548. function getAdsDepartment($post_code_departem, $max_ads, $property_type = NULL, $tab_nb_rooms = NULL) {
  3549. global $_global;
  3550. if ($post_code_departem != "") {
  3551. // sets select
  3552. $this->setSelect("ad", false);
  3553. // sets from
  3554. $this->setFrom();
  3555. // sets where
  3556. $where = array();
  3557. $this->setWhere($where, "ad_status");
  3558. $this->setWhere($where, "price");
  3559. $this->setWhere($where, "country");
  3560. $this->setWhere($where, "post_code_departem", $post_code_departem);
  3561. if ($property_type != NULL) {
  3562. $this->search_request["property_type"] = $property_type;
  3563. $this->setWhere($where, "property_type");
  3564. }
  3565. if ($tab_nb_rooms != NULL) {
  3566. $this->search_request["nb_rooms"] = $tab_nb_rooms;
  3567. $this->setWhere($where, "nb_rooms");
  3568. }
  3569. // common where clause
  3570. $this->where = $where;
  3571. // set order
  3572. $this->setOrder("filter_ad", 1, "update_date");
  3573. // builds the query
  3574. $this->query = "SELECT SQL_CALC_FOUND_ROWS " . $this->select . " ";
  3575. $this->query .= "FROM " . $this->from . " ";
  3576. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  3577. $this->query .= "AND (" . $_global["table_prefix"] . "_nb_photo > 0)" . " ";
  3578. $this->query .= "AND (" . $_global["table_prefix"] . "_photo != '')" . " ";
  3579. $this->query .= "AND (" . $_global["table_prefix"] . "_type_transaction = " . $_global['univers'] . ")" . " ";
  3580. $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
  3581. $this->query .= "LIMIT 0, " . ($max_ads != "" ? $max_ads : 4);
  3582. // executes the query
  3583. if ($_global["debug"] == 3) {
  3584. echo "getAdsDepartment()<br />";
  3585. echo $this->query . "<br />";
  3586. echo "<hr />";
  3587. }
  3588. $this->search_results = pdoquery($this->query);
  3589. }
  3590. }
  3591. // Arrondissements of important french cities
  3592. function getArrondCities($city) {
  3593. //print_r($city);
  3594. $res = array();
  3595. if (isset($city["lgn_id"])) { // si lgn_id défini
  3596. $lgn_id = $city["lgn_id"];
  3597. //echo "[lgn_id = $lgn_id]"; //exit;
  3598. switch ($lgn_id) {
  3599. case "0" : // Paris
  3600. $lct_ids = array(23599, 23601, 23602, 23603, 23604, 23605, 23606, 23607, 23609, 23589, 23590, 23591, 23592, 23593, 23594, 23595, 23596, 23597, 23598, 23600);
  3601. break;
  3602. case "421" : // Marseille
  3603. $lct_ids = array(36102, 36104, 36105, 36106, 36107, 36108, 36109, 36110, 36111, 36112, 36113, 36114, 36115, 36116, 36117, 36118);
  3604. break;
  3605. case "422" : // Lyon
  3606. $lct_ids = array(36119, 36120, 36121, 36122, 36123, 36124, 36125, 36126, 36127);
  3607. break;
  3608. }
  3609. //echo "[lct_ids = ".print_r($lct_ids, true)."]"; //exit;
  3610. if (isset($lct_ids) && !empty($lct_ids)) {
  3611. $sql = "";
  3612. $sql .= " SELECT lct_id,
  3613. lct_level,
  3614. lct_name,
  3615. lct_post_code";
  3616. $sql .= " FROM T_LOCALITY_LCT_FR";
  3617. $sql .= " WHERE lct_id IN (" . implode(",", $lct_ids) . ")";
  3618. $sql .= " ORDER BY lct_post_code ASC";
  3619. if ($_global["debug"] == 3) {
  3620. echo "<hr />";
  3621. echo $sql;
  3622. echo "<hr />";
  3623. }
  3624. $res = pdoquery($sql);
  3625. }
  3626. }
  3627. return $res;
  3628. }
  3629. // Return true if the french city has arrondissements
  3630. static function hasArrondsCity($city) {
  3631. $ret = false;
  3632. if (isset($city["lgn_id"]) && !empty($city["lgn_id"])) { // si lgn_id défini
  3633. $lgn_id = $city["lgn_id"];
  3634. //echo "[lgn_id = $lgn_id]"; //exit;
  3635. $ret = (in_array($lgn_id, array(0, 421, 422)));
  3636. } else if (isset($city["lct_name"]) && !empty($city["lct_name"])) { // si lct_name défini
  3637. $lct_name = $city["lct_name"];
  3638. //echo "[lct_name = $lct_name]"; //exit;
  3639. $ret = (in_array(strtolower($lct_name), array("paris", "marseille", "lyon")));
  3640. }
  3641. return $ret;
  3642. }
  3643. // Return true if the french "city" is in fact an arrondissement of a city
  3644. static function isArrondCity($city) {
  3645. //echo "city = "; var_dump($city);
  3646. $ret = array(false, -1, "");
  3647. $lct_lkey_city_paris = "100_1";
  3648. $lct_name_city_paris = "paris";
  3649. $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);
  3650. $lct_lkey_city_marseille = "421_99";
  3651. $lct_name_city_marseille = "marseille";
  3652. $lct_ids_arronds_marseille = array(36102, 36104, 36105, 36106, 36107, 36108, 36109, 36110, 36111, 36112, 36113, 36114, 36115, 36116, 36117, 36118);
  3653. $lct_lkey_city_lyon = "422_99";
  3654. $lct_name_city_lyon = "lyon";
  3655. $lct_ids_arronds_lyon = array(36119, 36120, 36121, 36122, 36123, 36124, 36125, 36126, 36127);
  3656. if (isset($city["lct_val"]) && !empty($city["lct_val"])) { // si lct_val défini
  3657. $lct_id = $city["lct_val"];
  3658. //echo "[lct_id = $lct_id]"; //exit;
  3659. if (in_array($lct_id, $lct_ids_arronds_paris)) {
  3660. $ret = array(true, $lct_lkey_city_paris, $lct_name_city_paris);
  3661. }
  3662. if (in_array($lct_id, $lct_ids_arronds_marseille)) {
  3663. $ret = array(true, $lct_lkey_city_marseille, $lct_name_city_marseille);
  3664. }
  3665. if (in_array($lct_id, $lct_ids_arronds_lyon)) {
  3666. $ret = array(true, $lct_lkey_city_lyon, $lct_name_city_lyon);
  3667. }
  3668. }
  3669. return $ret;
  3670. }
  3671. // Major cities around important french cities
  3672. function getEnvironCities($city, $regions = "") {
  3673. //echo "city = "; var_dump($city); echo "<br>";
  3674. //echo "regions = "; var_dump($regions); echo "<br>";
  3675. $lct_name = $city["lct_name"];
  3676. //echo "[lct_name = $lct_name]"; exit;
  3677. $lct_post_code = $city["lct_post_code"];
  3678. //echo "[lct_post_code = $lct_post_code]"; exit;
  3679. $lct_ids_depart = array();
  3680. $lct_ids_region = array();
  3681. switch (strtolower($lct_name)) {
  3682. // Lot 1
  3683. case "paris" :
  3684. $lct_ids_depart = array();
  3685. $lct_ids_region = array(4285, 22198, 1104, 8802, 21595, 1625, 27495, 35588, 34526, 35588, 7878);
  3686. break;
  3687. case "marseille" :
  3688. $lct_ids_depart = array(36129, 1147, 19707, 1451, 14032);
  3689. $lct_ids_region = array(22514, 33109, 5568, 1909, 897);
  3690. break;
  3691. case "lyon" :
  3692. $lct_ids_depart = array(35343, 34302, 5413, 29852, 34092);
  3693. $lct_ids_region = array(27633, 12875, 836, 33770, 6322);
  3694. break;
  3695. case "toulouse" :
  3696. $lct_ids_depart = array(7905, 33148, 22092, 3671, 8984);
  3697. $lct_ids_region = array(21045, 32522, 408, 5864, 26107);
  3698. break;
  3699. case "nice" :
  3700. $lct_ids_depart = array(897, 5568, 12825, 5343, 16660);
  3701. $lct_ids_region = array(19667, 33109, 36129, 1909, 9442);
  3702. break;
  3703. case "nantes";
  3704. $lct_ids_depart = array(29410, 28164, 25833, 30130, 23248);
  3705. $lct_ids_region = array(767, 36157, 15380, 7498, 16440);
  3706. break;
  3707. case "strasbourg" :
  3708. $lct_ids_depart = array(13216, 31393, 13922, 31498, 3623);
  3709. $lct_ids_region = array(22063, 7862, 28813, 18202, 35954);
  3710. break;
  3711. case "montpellier" :
  3712. $lct_ids_depart = array(3478, 31792, 18797, 11897, 221);
  3713. $lct_ids_region = array(22557, 23846, 429, 22226, 5636);
  3714. break;
  3715. case "bordeaux" :
  3716. $lct_ids_depart = array(20226, 23895, 32468, 35094, 29309);
  3717. $lct_ids_region = array(23675, 796, 223, 2545, 23820);
  3718. break;
  3719. case "rennes" :
  3720. $lct_ids_depart = array(28888, 11541, 35568, 6162, 5066);
  3721. $lct_ids_region = array(4746, 25350, 18523, 33911, 27225);
  3722. break;
  3723. case "lille" :
  3724. $lct_ids_depart = array(26345, 33128, 9842, 35107, 9686);
  3725. $lct_ids_region = array(5384, 4289, 35868, 33775, 1221);
  3726. break;
  3727. case "grenoble" :
  3728. $lct_ids_depart = array(29118, 9937, 34727, 11297, 4384);
  3729. $lct_ids_region = array(18897, 27633, 35343, 33770, 34302);
  3730. break;
  3731. case "rouen" :
  3732. $lct_ids_depart = array(16853, 9423, 32131, 27673, 16829);
  3733. $lct_ids_region = array(10693, 34472, 17070, 20931, 10908);
  3734. break;
  3735. case "toulon" :
  3736. $lct_ids_depart = array(15467, 13866, 11730, 9760, 31961);
  3737. $lct_ids_region = array(19667, 22514, 36129, 1909, 897);
  3738. break;
  3739. case "nimes" :
  3740. $lct_ids_depart = array(429, 2089, 2610, 40186, 28104);
  3741. $lct_ids_region = array(21551, 23846, 3478, 22226, 5636);
  3742. break;
  3743. case "perpignan" :
  3744. $lct_ids_depart = array(5557, 27631, 1092, 27448, 5304);
  3745. $lct_ids_region = array(21551, 22557, 3478, 22226, 5636);
  3746. break;
  3747. // Lot 2
  3748. case "nancy" :
  3749. $lct_ids_depart = array(33901, 18801, 33104, 35262, 16539);
  3750. $lct_ids_region = array(20369, 32835, 10197, 21409, 31088);
  3751. break;
  3752. case "angers" :
  3753. $lct_ids_depart = array(7498, 31212, 1957, 17759, 33323);
  3754. $lct_ids_region = array(22199, 16906, 29410, 16440, 15380);
  3755. break;
  3756. case "caen" :
  3757. $lct_ids_depart = array(13588, 18238, 2542, 35510, 20799);
  3758. $lct_ids_region = array(426, 36829, 28800, 37093, 33132);
  3759. break;
  3760. case "la rochelle" :
  3761. $lct_ids_depart = array(26050, 30787, 26495, 1990, 28301);
  3762. $lct_ids_region = array(24485, 22559, 805, 6952, 30787);
  3763. break;
  3764. case "aix en provence" :
  3765. $lct_ids_depart = array(19667, 1147, 19707, 1451, 14032);
  3766. $lct_ids_region = array(22514, 33109, 1909, 897, 5568);
  3767. break;
  3768. case "metz" :
  3769. $lct_ids_depart = array(32835, 21409, 31088, 11459, 27066);
  3770. $lct_ids_region = array(22183, 10197, 33901, 39374, 18801);
  3771. break;
  3772. case "avignon" :
  3773. $lct_ids_depart = array(23094, 5688, 5954, 23886, 32110);
  3774. $lct_ids_region = array(19667, 22514, 33109, 365, 897);
  3775. break;
  3776. case "le havre" :
  3777. $lct_ids_depart = array(26356, 9423, 32131, 27673, 16829);
  3778. $lct_ids_region = array(10693, 34472, 17070, 20931, 10908);
  3779. break;
  3780. case "clermont-ferrand" :
  3781. $lct_ids_depart = array(8544, 25968, 6307, 14024, 32800);
  3782. $lct_ids_region = array(21479, 1707, 34673, 21908, 17163);
  3783. break;
  3784. case "orleans" :
  3785. $lct_ids_depart = array(11198, 23003, 28321, 28343, 12343);
  3786. $lct_ids_region = array(33174, 4374, 6925, 3793, 6781);
  3787. break;
  3788. case "versailles" :
  3789. $lct_ids_depart = array(31111, 19289, 28016, 24482, 21397);
  3790. $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
  3791. break;
  3792. case "saint-etienne" :
  3793. $lct_ids_depart = array(26018, 27282, 11085, 21116, 25990);
  3794. $lct_ids_region = array(18897, 12875, 35343, 33770, 34302);
  3795. break;
  3796. case "mulhouse" :
  3797. $lct_ids_depart = array(7862, 28813, 35954, 13926, 26014);
  3798. $lct_ids_region = array(32323, 13216, 31393, 13922, 31498);
  3799. break;
  3800. case "narbonne" :
  3801. $lct_ids_depart = array(5636, 5812, 17975, 18184, 33269);
  3802. $lct_ids_region = array(3478, 21551, 22557, 23846, 31792);
  3803. break;
  3804. case "annecy" :
  3805. $lct_ids_depart = array(837, 839, 8699, 31832, 32883);
  3806. $lct_ids_region = array(12875, 18897, 27633, 33770, 35343);
  3807. break;
  3808. case "aix les bains" :
  3809. $lct_ids_depart = array(406, 4367, 6322, 15235, 28353);
  3810. $lct_ids_region = array(12875, 18897, 27633, 33770, 35343);
  3811. break;
  3812. case "colmar" :
  3813. $lct_ids_depart = array(13926, 22064, 26014, 28813, 35954);
  3814. $lct_ids_region = array(13216, 13922, 31393, 31498, 32323);
  3815. break;
  3816. case "bourges" :
  3817. $lct_ids_depart = array(20021, 26803, 27597, 27764, 34740);
  3818. $lct_ids_region = array(3793, 6781, 6925, 23171, 33174);
  3819. break;
  3820. case "biarritz" :
  3821. $lct_ids_depart = array(796, 2545, 3568, 23675, 28350);
  3822. $lct_ids_region = array(223, 4085, 20226, 23895, 32468);
  3823. break;
  3824. case "beauvais" :
  3825. $lct_ids_depart = array(7978, 8752, 8773, 22617, 22845);
  3826. $lct_ids_region = array(132, 648, 16214, 29900, 31982);
  3827. break;
  3828. case "pontoise" :
  3829. $lct_ids_depart = array(1104, 6090, 11670, 12048, 31045);
  3830. $lct_ids_region = array(4285, 21595, 100, 27495, 34526);
  3831. break;
  3832. case "saint-denis" :
  3833. $lct_ids_depart = array(1482, 1625, 9767, 21595, 22653);
  3834. $lct_ids_region = array(1104, 4285, 21595, 100, 34526);
  3835. break;
  3836. case "saint-maur-des-fosses" :
  3837. $lct_ids_depart = array(6493, 8802, 14052, 19093, 35588);
  3838. $lct_ids_region = array(1104, 4285, 21595, 100, 27495);
  3839. break;
  3840. case "fontainebleau" :
  3841. $lct_ids_depart = array(6531, 7220, 19993, 20077, 24648);
  3842. $lct_ids_region = array(1104, 4285, 21595, 100, 27495);
  3843. break;
  3844. case "etampes" :
  3845. $lct_ids_depart = array(8152, 10698, 19795, 30637, 31349);
  3846. $lct_ids_region = array(1104, 4285, 21595, 100, 27495);
  3847. break;
  3848. // Lot 3
  3849. /*
  3850. case "cannes" :
  3851. $lct_ids_depart = array(22514, 897, 5343, 12825, 16660);
  3852. $lct_ids_region = array(19667, 33109, 36129, 1909, 15467);
  3853. break;
  3854. case "limoges" :
  3855. $lct_ids_depart = array(28575, 23509, 13991, 30471, 8671);
  3856. $lct_ids_region = array(4933, 33525, 13045, 33633, 19155);
  3857. break;
  3858. case "pau" :
  3859. $lct_ids_depart = array(2545, 796, 3496, 3568, 28350);
  3860. $lct_ids_region = array(4085, 20226, 23895, 2545, 32468);
  3861. break;
  3862. case "antibes" :
  3863. $lct_ids_depart = array(22514, 5568, 5343, 12825, 16660);
  3864. $lct_ids_region = array(19667, 33109, 36129, 1909, 15467);
  3865. break;
  3866. case "amiens" :
  3867. $lct_ids_depart = array(132, 404, 23837, 26503, 21184);
  3868. $lct_ids_region = array(29900, 2796, 7978, 8752, 31982);
  3869. break;
  3870. case "poitiers" :
  3871. $lct_ids_depart = array(6952, 5267, 18589, 7117, 27124);
  3872. $lct_ids_region = array(15386, 22559, 805, 6952, 26050);
  3873. break;
  3874. case "montreuil" :
  3875. $lct_ids_depart = array(27495, 1625, 1482, 9767, 22653);
  3876. $lct_ids_region = array(100, 4285, 1104, 34526, 22198);
  3877. break;
  3878. case "villeurbanne" :
  3879. $lct_ids_depart = array(18897, 34302, 5413, 29852, 34092);
  3880. $lct_ids_region = array(18897, 27633, 12875, 33770, 6322);
  3881. break;
  3882. case "argenteuil" :
  3883. $lct_ids_depart = array(31045, 6090, 12048, 11670, 24677);
  3884. $lct_ids_region = array(100, 4285, 21595, 27495, 34526);
  3885. break;
  3886. case "roubaix" :
  3887. $lct_ids_depart = array(18149, 33128, 9842, 35107, 9686);
  3888. $lct_ids_region = array(5384, 4289, 35868, 33775, 1221);
  3889. break;
  3890. case "tourcoing" :
  3891. $lct_ids_depart = array(5384, 4289, 35868, 33775, 1221);
  3892. $lct_ids_region = array(18149, 26345, 9842, 35107, 9686);
  3893. break;
  3894. case "colombes" :
  3895. $lct_ids_depart = array(4285, 22198, 1363, 26546, 8445);
  3896. $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
  3897. break;
  3898. case "boulogne-billancourt" :
  3899. $lct_ids_depart = array(22198, 7878, 7878, 1363, 26546);
  3900. $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
  3901. break;
  3902. case "courbevoie" :
  3903. $lct_ids_depart = array(4285, 22198, 7878, 1363, 26546);
  3904. $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
  3905. break;
  3906. case "creteil" :
  3907. $lct_ids_depart = array(35588, 6493, 29227, 19093, 14052);
  3908. $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
  3909. break;
  3910. case "nanterre" :
  3911. $lct_ids_depart = array(4285, 7878, 1363, 26546, 8445);
  3912. $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
  3913. break;
  3914. case "rueil-malmaison" :
  3915. $lct_ids_depart = array(4285, 22198, 7878, 1363, 8445);
  3916. $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
  3917. break;
  3918. case "aulnay-sous-bois" :
  3919. $lct_ids_depart = array(21595, 27495, 1482, 9767, 22653);
  3920. $lct_ids_region = array(100, 4285, 1104, 21595, 34526);
  3921. break;
  3922. case "vitry-sur-seine" :
  3923. $lct_ids_depart = array(8802, 6493, 29227, 19093, 14052);
  3924. $lct_ids_region = array(100, 4285, 1104, 21595, 27495);
  3925. break;
  3926. case "dijon" :
  3927. $lct_ids_depart = array(2747, 7292, 32463, 7380, 25312);
  3928. $lct_ids_region = array(6290, 22495, 1824, 18927, 31606);
  3929. break;
  3930. case "asnieres-sur-seine" :
  3931. $lct_ids_depart = array(4285, 22198, 7878, 26546, 8445);
  3932. $lct_ids_region = array(100, 1104, 21595, 27495, 34526);
  3933. break;
  3934. */
  3935. }
  3936. //echo "lct_ids_depart = "; var_dump($lct_ids_depart);
  3937. //echo "lct_ids_region = "; var_dump($lct_ids_region);
  3938. $res_depart = array();
  3939. if (isset($lct_ids_depart) && !empty($lct_ids_depart)) {
  3940. $sql_depart = "";
  3941. $sql_depart .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
  3942. IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
  3943. lct_name_fr,
  3944. lct_post_code";
  3945. $sql_depart .= " FROM T_LOCALITY_LCT_FR";
  3946. $sql_depart .= " WHERE lct_id IN (" . implode(",", $lct_ids_depart) . ")";
  3947. $sql_depart .= " ORDER BY lct_name_fr ASC";
  3948. if ($_global["debug"] == 3) {
  3949. echo "getEnvironCities()<br />";
  3950. echo $sql_depart . "<br />";
  3951. echo "<hr />";
  3952. }
  3953. $res_depart = pdoquery($sql_depart);
  3954. } else {
  3955. $sql = "";
  3956. $sql .= " SELECT lct_parent_id";
  3957. $sql .= " FROM T_LOCALITY_LCT_FR";
  3958. $sql .= " WHERE lct_name = '" . strtoupper(addslashes($lct_name)) . "'";
  3959. $sql .= " OR lct_name_fr = '" . strtoupper(addslashes($lct_name)) . "'";
  3960. if (isset($lct_post_code) && !empty($lct_post_code)) {
  3961. $sql .= " AND lct_post_code = '" . strtoupper(addslashes($lct_post_code)) . "'";
  3962. }
  3963. $sql .= " LIMIT 0, 1";
  3964. $res = pdoquery($sql);
  3965. if (count($res) > 0) {
  3966. $lct_dept_id = $res[0]["lct_parent_id"];
  3967. }
  3968. //echo $sql; //exit;
  3969. $sql_depart = "";
  3970. $sql_depart .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
  3971. IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
  3972. lct_name_fr,
  3973. lct_post_code";
  3974. $sql_depart .= " FROM T_LOCALITY_LCT_FR";
  3975. $sql_depart .= " WHERE lct_parent_id = '$lct_dept_id'";
  3976. $sql_depart .= " AND lct_name_fr != '" . strtoupper(addslashes($lct_name)) . "'";
  3977. $sql_depart .= " ORDER BY lct_sal_pondering DESC";
  3978. $sql_depart .= " LIMIT 0,5";
  3979. //echo $sql_depart;
  3980. $res_depart = pdoquery($sql_depart);
  3981. }
  3982. $res_region = array();
  3983. if (isset($lct_ids_region) && !empty($lct_ids_region)) {
  3984. $sql_region = "";
  3985. $sql_region .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
  3986. IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
  3987. lct_name_fr,
  3988. lct_post_code";
  3989. $sql_region .= " FROM T_LOCALITY_LCT_FR";
  3990. $sql_region .= " WHERE lct_id IN (" . implode(",", $lct_ids_region) . ")";
  3991. $sql_region .= " ORDER BY lct_sal_pondering DESC";
  3992. //echo $sql_region;
  3993. $res_region = pdoquery($sql_region);
  3994. } else {
  3995. if (isset($regions) && !empty($regions)) {
  3996. $sql_region = "";
  3997. $sql_region .= " SELECT IF (lgn_id>0, lgn_id, lct_id) AS lct_id,
  3998. IF (lct_id=100, '1', IF (lgn_id>0, '99', '2')) AS lct_level,
  3999. lct_name_fr,
  4000. lct_post_code";
  4001. $sql_region .= " FROM T_LOCALITY_LCT_FR";
  4002. $sql_region .= " WHERE lct_id IN (" . implode(",", $regions["ids_loc"]) . ")";
  4003. $sql_region .= " AND lct_name_fr != '" . strtoupper(addslashes($lct_name)) . "'";
  4004. $sql_region .= " ORDER BY lct_sal_pondering DESC";
  4005. //echo $sql_region;
  4006. $res_region = pdoquery($sql_region);
  4007. }
  4008. }
  4009. return array("depart" => $res_depart, "region" => $res_region);
  4010. }
  4011. //*** returns all localities from code group (lgc_id) ***
  4012. function getLocCodeGrp($limit = true) {
  4013. global $_global;
  4014. if ($limit) {
  4015. // limit => only when research in one locality
  4016. if (count($this->search_parameters["loc_keys"]) < 2 && count($this->search_parameters["loc_keys"]) != 0) {
  4017. if (!empty($this->search_parameters["lgc_ids"][0]) && $this->search_parameters["lgc_ids"][0] != '0') {
  4018. $sql = "SELECT lct_name, lct_id, lct_level, lct_post_code FROM TM_LOC_FR WHERE lgc_id = '" . $this->search_parameters["lgc_ids"][0] . "'";
  4019. if ($_global["debug"] == 3) {
  4020. echo "getLocCodeGrp()<br />";
  4021. echo $sql . "<br />";
  4022. echo "<hr />";
  4023. }
  4024. $results = pdoquery($sql);
  4025. return $results;
  4026. }
  4027. }
  4028. }
  4029. }
  4030. //*** returns all localities from name group (lgn_id) ***
  4031. function getLocNameGrp($limit = true) {
  4032. global $_global;
  4033. if ($limit) {
  4034. // limit => only when research in one locality
  4035. if (count($this->search_parameters["loc_keys"]) < 2 && count($this->search_parameters["loc_keys"]) != 0) {
  4036. if (!empty($this->search_parameters["lgn_ids"][0]) && $this->search_parameters["lgn_ids"][0] != '0') {
  4037. $sql = "SELECT lct_name, lct_id, lct_level, lct_post_code FROM TM_LOC_FR WHERE lgn_id = '" . $this->search_parameters["lgn_ids"][0] . "'";
  4038. if ($_global["debug"] == 3) {
  4039. echo "getLocNameGrp()<br />";
  4040. echo $sql . "<br />";
  4041. echo "<hr />";
  4042. }
  4043. $results = pdoquery($sql);
  4044. return $results;
  4045. }
  4046. }
  4047. }
  4048. }
  4049. //*** returns all localities from name or code group (lgn_id, lgc_id)
  4050. function get_locGrp($limit = true) {
  4051. global $_global;
  4052. $sql = '';
  4053. if ($limit) {
  4054. // limit => only when research in one locality
  4055. if (count($this->search_parameters["loc_keys"]) < 2 && count($this->search_parameters["loc_keys"]) > 0) {
  4056. if ($this->search_parameters["lgn_ids"][0] > 0 || $this->search_parameters["lgc_ids"][0] > 0) {
  4057. if ($this->search_parameters["lgn_ids"][0] > 0 && $this->search_parameters["lgc_ids"][0] > 0) {
  4058. //lgn_ids en priorité
  4059. $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";
  4060. } elseif ($this->search_parameters["lgn_ids"][0] > 0 && $this->search_parameters["lgc_ids"][0] == 0) {
  4061. $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";
  4062. } elseif ($this->search_parameters["lgc_ids"][0] > 0 && $this->search_parameters["lgn_ids"][0] == 0) {
  4063. $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";
  4064. }
  4065. if ($_global["debug"] == 3) {
  4066. echo "getLocGrp()<br />";
  4067. echo $sql . "<br />";
  4068. echo "<hr />";
  4069. }
  4070. if ($sql != '') {
  4071. $results = pdoquery($sql);
  4072. return $results;
  4073. }
  4074. }
  4075. }
  4076. }
  4077. }
  4078. // *** returns search count ***
  4079. function getSearchCount() {
  4080. return $this->search_count;
  4081. }
  4082. // *** returns search parameters ***
  4083. function getSearchParameters() {
  4084. return $this->search_parameters;
  4085. }
  4086. // *** returns search request ***
  4087. function getSearchRequest() {
  4088. return $this->search_request;
  4089. }
  4090. // *** returns agency locality hierarchy ***
  4091. function getSearchHierarchyAgency() {
  4092. return $this->search_hierarchy_agency;
  4093. }
  4094. // *** returns search agengy state ***
  4095. function isSearchAgency() {
  4096. return $this->is_agency_search;
  4097. }
  4098. // *** stores search parameters in the cookie ***
  4099. function saveSearch() {
  4100. global $_global;
  4101. global $aLISearchHistoryCookieValue;
  4102. if ($_global['debug'] == 1) {
  4103. echo '<hr /><p><b>[Mode debug][Cookie][' . ($this->is_agency_search ? '' : 'Non ') . 'Agence]</b> : Enregistrement de la recherche annulée (Header already sent!).</p>';
  4104. var_dump($this->search_request);
  4105. echo '<hr />';
  4106. return true;
  4107. }
  4108. $expires = time() + (86400 * COOKIE_DURATION);
  4109. $saved_searches = array();
  4110. $aLiSearchCookie_datas = array();
  4111. $aLiSearchCookie_datas = fetchcookie(SEARCH_HISTORY_COOKIE_NAME);
  4112. if (is_array($aLiSearchCookie_datas) && array_key_exists(0, $aLiSearchCookie_datas)) {
  4113. $aLiSearchCookie_datas = unserialize($aLiSearchCookie_datas[0]);
  4114. if ($aLiSearchCookie_datas != FALSE) {
  4115. $aDiff_datas = array_diff_key($this->search_request, $aLiSearchCookie_datas);
  4116. $this->search_request = array_merge($this->search_request, $aDiff_datas);
  4117. }
  4118. }
  4119. $saved_searches[0] = serialize($this->search_request);
  4120. $saved_searches[1] = serialize($this->search_parameters['loc_hierarchy']);
  4121. storecookie(SEARCH_HISTORY_COOKIE_NAME, $saved_searches, $expires);
  4122. /**
  4123. * W.ASBATITI
  4124. * 28/12/2012 :
  4125. * Le cookie USER_DATA_IHM_COOKIE_NAME est MAJ dans redirect .annuaire, pas la peine de le retraiter pour la PR AGENCEs
  4126. */
  4127. if ($_global['self'] != 'resultats_agences.php') {
  4128. // 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
  4129. if (isset($_COOKIE[USER_DATA_IHM_COOKIE_NAME])) {
  4130. $user_data_ihm_array = json_decode($_COOKIE[USER_DATA_IHM_COOKIE_NAME], true);
  4131. $user_data_ihm_array['nb_results'] = $this->search_request['nb_results'];
  4132. } else {
  4133. $user_data_ihm_array = array('nb_results' => $this->search_request['nb_results']);
  4134. }
  4135. $user_data_ihm_string = json_encode($user_data_ihm_array);
  4136. setcookie(USER_DATA_IHM_COOKIE_NAME, $user_data_ihm_string, $expires, '/');
  4137. }
  4138. foreach ($saved_searches as $saved_search) {
  4139. $aLISearchHistoryCookieValue[] = unserialize($saved_search);
  4140. }
  4141. $_global["saved_searches"] = count($aLISearchHistoryCookieValue);
  4142. }
  4143. // *** loads last search from the cookie
  4144. function loadSearch() {
  4145. $saved_searches = fetchcookie(SEARCH_HISTORY_COOKIE_NAME);
  4146. $saved_search = unserialize($saved_searches[0]);
  4147. return $saved_search;
  4148. }
  4149. // debugger
  4150. function showTime($action, $start) {
  4151. global $_global;
  4152. if ($_global["debug"] == 1) {
  4153. echo($action . " : " . (microtime(true) - $start) . " ms<br>");
  4154. }
  4155. }
  4156. // killer
  4157. function relief() {
  4158. if (isset($_global["debug"]) && ($_global["debug"] == 3)) {
  4159. echo "relief()<br />";
  4160. echo "SHOW PROCESSLIST<br />";
  4161. echo "<hr />";
  4162. }
  4163. $processes = pdoquery("SHOW PROCESSLIST");
  4164. foreach ($processes as $process) {
  4165. if ($process["User"] == "phpwebpage" && $process["Command"] == "Sleep" && $process["Time"] > 10) {
  4166. pdoquery("KILL " . $process["Id"]);
  4167. }
  4168. }
  4169. }
  4170. // search ads
  4171. function getAdsHomeGallery($request, $offset, $skip_premium = false, $simulate = false) {
  4172. global $_global;
  4173. if ($_global['univers'] == 8) {
  4174. $this->query = "SELECT * FROM T_RENTAD_RNT WHERE rnt_type_transaction=8 AND rnt_photo!='' ORDER BY rnt_creation_date DESC LIMIT 0,30";
  4175. //$res = pdoquery($sql);
  4176. $this->search_results = pdoquery($this->query);
  4177. //return $res;
  4178. return 0;
  4179. }
  4180. //var_dump($request);
  4181. if ($_global["debug"] == 1) {
  4182. //$proximite = $this->setPerimProximit(5); //5km around
  4183. //$proximite_coor = $this->getCoord($request['loc_key1']);
  4184. }
  4185. // adds universe
  4186. $this->search_parameters["univers"] = $_global["univers"];
  4187. // is agency search ?
  4188. $this->is_agency_search = false; // (isset($request["id_agence"]) ? true : false);
  4189. // sets request
  4190. $this->search_request = $this->setRequest($request);
  4191. // adds date
  4192. $this->setDate();
  4193. // sets offset
  4194. $this->search_parameters["offset"] = "" . $offset . "";
  4195. // sets select
  4196. $this->setSelect("ad", false);
  4197. // sets from
  4198. //SARA A. 04/09/09 Modified to correct the problem of number of agencies displayed on estate agency directory
  4199. $this->setFrom(false);
  4200. // sets where
  4201. $where = array();
  4202. if ($this->isGrpAgency == true) {
  4203. $this->setWhere($where, "grp_id_agence", $this->list_agency);
  4204. }
  4205. $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
  4206. $this->setWhere($where, "ad_status");
  4207. if ($this->PerimProximit > 0) {
  4208. $this->setWhere($where, "perimproximit");
  4209. } else {
  4210. $this->setWhere($where, "locality");
  4211. }
  4212. $this->setWhere($where, "country");
  4213. $this->setWhere($where, "property_type");
  4214. $this->setWhere($where, "price");
  4215. $this->setWhere($where, "area");
  4216. $this->setWhere($where, "nb_rooms");
  4217. // vacances
  4218. if ($_global["univers"] == 13) {
  4219. $this->setWhere($where, "nb_bedrooms");
  4220. $this->setWhere($where, "nb_people");
  4221. $this->setWhere($where, "type_transaction", 3);
  4222. }
  4223. if ($_global["univers"] == 2) {
  4224. $this->setWhere($where, "type_transaction", 2);
  4225. }
  4226. if ($_global["univers"] == 8) {
  4227. $this->setWhere($where, "type_transaction", 8);
  4228. }
  4229. /* We force to get only Ads with photo(s) */
  4230. $this->setWhere($where, "photo");
  4231. if ($_global["debug"] == 1) {
  4232. echo "getAdsHomeGallery - $_REQUEST<br />";
  4233. var_dump($_REQUEST);
  4234. echo "<hr />";
  4235. }
  4236. $this->setWhere($where, "with_mmf");
  4237. // common where clause
  4238. $this->where = $where;
  4239. // sets index
  4240. $force_index = array();
  4241. $this->setIndex($force_index, "locality");
  4242. // common index clause
  4243. // force index when we are doing a search on more than one locality
  4244. if (count($force_index) > 1) {
  4245. //$this->force_index = $force_index;
  4246. }
  4247. // sets order
  4248. /*
  4249. if (isset($this->search_request["order_price"])){
  4250. $this->setOrder("ad", $this->search_request["order"]);
  4251. if ($this->search_request["order_price"]==""){$this->search_request["order_price"]=1;}
  4252. $this->setOrder("filter_ad", $this->search_request["order_price"], "price");
  4253. }
  4254. */
  4255. if (isset($this->search_request["order_ads_agency"])) {
  4256. $this->setOrder("ad", $this->search_request["order"]);
  4257. if ($this->search_request["order_ads_agency"] == "") {
  4258. $this->search_request["order_ads_agency"] = "date_asc";
  4259. }
  4260. $this->setOrder("filter_ad", $this->search_request["order_ads_agency"]);
  4261. } else {
  4262. $this->setOrder("ad", $this->search_request["order"]);
  4263. }
  4264. //$this->setOrder("ad", $this->search_request["order"]);
  4265. // builds main query
  4266. //$this->query = "SELECT SQL_CALC_FOUND_ROWS ".$this->select." ";
  4267. $this->query = "SELECT " . $this->select . " ";
  4268. $this->query .= "FROM " . $this->from . " ";
  4269. if (isset($this->force_index)) {
  4270. //$this->query .= "FORCE INDEX (".implode(", ", $this->force_index).") ";
  4271. }
  4272. $query2 = $this->query;
  4273. $this->query .= "WHERE " . implode(" AND ", $this->where) . " ";
  4274. // sets limit
  4275. $this->setLimit("adHomeGallery", $offset);
  4276. //Try to join a UNION QUERY to LIMIT ZeRo Result
  4277. // sets where
  4278. $where = array();
  4279. if ($this->isGrpAgency == true) {
  4280. $this->setWhere($where, "grp_id_agence", $this->list_agency);
  4281. }
  4282. $this->setWhere($where, "id_agence", $this->search_request["id_agence"]);
  4283. $this->setWhere($where, "ad_status");
  4284. if ($this->PerimProximit > 0) {
  4285. $this->setWhere($where, "perimproximit");
  4286. } else {
  4287. $this->setWhere($where, "locality");
  4288. }
  4289. $this->setWhere($where, "property_type");
  4290. //
  4291. //$this->query .= "UNION ".$query2;
  4292. //$this->query .= "WHERE ".implode(" AND ", $this->where)." ";
  4293. //
  4294. // main query additional clause
  4295. $this->query .= "ORDER BY " . implode(", ", $this->order) . " ";
  4296. $this->query .= "LIMIT 30"; //.$this->limit;
  4297. // adds post code
  4298. $_start = microtime(true);
  4299. $this->setPostCodes();
  4300. $this->showTime("set post codes", $_start);
  4301. // executes the query
  4302. $_start = microtime(true);
  4303. if ($simulate == false) {
  4304. if ($_global["debug"] == 3) {
  4305. echo 'getAdsHomeGallery() - 1<br />';
  4306. echo $this->query . "<br />";
  4307. echo "<hr />";
  4308. }
  4309. $this->search_results = pdoquery($this->query);
  4310. $this->showTime("main search", $_start);
  4311. // builds the count query
  4312. $this->query_count = "SELECT FOUND_ROWS() AS NUM";
  4313. // executes the count query
  4314. $_start = microtime(true);
  4315. if ($_global["debug"] == 3) {
  4316. echo 'getAdsHomeGallery() - 2<br />';
  4317. echo $this->query_count . "<br />";
  4318. echo "<hr />";
  4319. }
  4320. $this->search_count = pdoquery($this->query_count);
  4321. $this->search_count = $this->search_count[0]["NUM"];
  4322. $this->showTime("main count", $_start);
  4323. // save
  4324. $this->search_parameters["count"] = $this->search_count;
  4325. $this->search_request["count"] = $this->search_count;
  4326. // calculates number of pages
  4327. $this->setPages("ad");
  4328. // sets antenna
  4329. $this->setAntenna();
  4330. }
  4331. }
  4332. /**
  4333. * Enter description here...
  4334. *
  4335. * @param unknown_type $code
  4336. * @return unknown
  4337. */
  4338. function getLongLatTown($code) {
  4339. /* $sql = "SELECT DISTINCT(".$this->table_prfx.".".$this->table_prfx."_default_town_2), lctFR.lct_lat, lctFR.lct_long
  4340. FROM ".$this->table_name." ".$this->table_prfx.", T_LOCALITY_LCT_FR lctFR
  4341. WHERE ".$this->table_prfx.".".$this->table_prfx."_default_town_2 = lctFR.lct_name_fr
  4342. AND ".$this->table_prfx.".id_annonce = '".$code."'"; */
  4343. $sql = "SELECT lctFR.lct_lat, lctFR.lct_long
  4344. FROM T_LOCALITY_LCT_FR lctFR
  4345. WHERE lctFR.lct_name_fr = '" . addslashes($code) . "'";
  4346. $result = pdoquery($sql);
  4347. return $result[0];
  4348. }
  4349. /**
  4350. * Crypte la requete et la stocke dans un cookie pour une reutilisation en ajax pour la generation
  4351. * de la navigation sur la page detail
  4352. *
  4353. * @param string $query La requête a crypter et stocker
  4354. */
  4355. function save_query($text) {
  4356. $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
  4357. $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  4358. $key = "NAV_ADS";
  4359. $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
  4360. setcookie("NAV_ADS", $crypttext);
  4361. }
  4362. }
  4363. ?>