PageRenderTime 61ms CodeModel.GetById 15ms 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

Large files files are truncated, but you can click here to view the full 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 'Requ…

Large files files are truncated, but you can click here to view the full file