PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/DEV/DISPLAY/ajax/save_nav_det.php

https://github.com/chrisbst35/LI_LEMONDE
PHP | 354 lines | 261 code | 55 blank | 38 comment | 99 complexity | b259d4c034aece330ec8917e7a48d444 MD5 | raw file
  1. <?php
  2. // common include
  3. include("../modules/includes.php");
  4. // plug-in
  5. include("json.php");
  6. include("../../LIB/search.class.php");
  7. // object instantiation
  8. $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  9. $request = $_REQUEST;
  10. //echo "============>request = ";print_r($_REQUEST["json"]);
  11. //echo "<br/><br/>============>request decode = ";echo $request;
  12. $ads_pos = $json->decode($_COOKIE['ads_pos']);
  13. // var_dump($ads_pos);
  14. $univers = $request['univers'];
  15. $_global['univers'] = $univers;
  16. // TAG XITI
  17. switch ($_global['univers']) {
  18. case 1: // vente
  19. $xitiClickNavPrevId = 15;
  20. $xitiClickNavNextId = 13;
  21. $xitiClickNewSearchId = 17;
  22. break;
  23. case 2: // location
  24. $xitiClickNavPrevId = 51;
  25. $xitiClickNavNextId = 49;
  26. $xitiClickNewSearchId = 53;
  27. break;
  28. case 8: // colocation
  29. $xitiClickNavPrevId = 87;
  30. $xitiClickNavNextId = 85;
  31. $xitiClickNewSearchId = 89;
  32. break;
  33. }
  34. if ($ads_pos['param'] == "p") {
  35. $is_agency = false;
  36. $_global['is_there_premium'] = ($ads_pos['value'][0] == 'o');
  37. $_global['is_there_premium'] = false;
  38. //$num_row = (int)substr($_REQUEST['p'],1);
  39. //$param = '?p='.$_REQUEST['p'][0];
  40. $num_row = (int) substr($ads_pos['value'], 1);
  41. $param = 'p';
  42. $param_value = $ads_pos['value'][0];
  43. }
  44. // Recherche a partir des annonces d'une agence
  45. else {
  46. $is_agency = true;
  47. $_global['is_there_premium'] = false;
  48. //$num_row = (int)$_REQUEST['r'];
  49. //$param = '?r=';
  50. $num_row = (int) $ads_pos['value'];
  51. $param = 'r';
  52. }
  53. // recherche du nom de la table des annonces à utiliser
  54. // NB: tables TM_... uniquement pour les pages résultat, pas détail normalement
  55. if ($univers == 2 || $univers == 8) {
  56. $prfx = $_global["table_prefix"] = "rnt";
  57. } else {
  58. $prfx = $_global["table_prefix"] = "sal";
  59. }
  60. $sql = " SELECT ttu_" . $prfx . "_fr FROM TP_TABLE_TO_USE_TTU";
  61. $res = pdoquery($sql);
  62. //echo "<hr>"; echo $sql; echo "<hr>";
  63. // table des annonces (moteur InnoDB ou MEMORY ou MyISAM)
  64. if (sizeof($res) > 0 && strpos($request['url'], 'gallery=1') === false) {
  65. $table_name_ads = $res[0]["ttu_" . $prfx . "_fr"];
  66. } else {
  67. if ($univers == 2 || $univers == 8) {
  68. $prfx = "rnt";
  69. if (strpos($request['url'], 'gallery=1') === false)
  70. $table_name_ads = "T_RENTAD_RNT";
  71. else
  72. $table_name_ads = "T_RENTAD_BIS";
  73. } else {
  74. $prfx = "sal";
  75. if (strpos($request['url'], 'gallery=1') === false)
  76. $table_name_ads = "T_SALESAD_SAL";
  77. else
  78. $table_name_ads = "T_SALESAD_BIS";
  79. }
  80. }
  81. if ($univers == 2 || $univers == 8) {
  82. $search_nav = new search_object($table_name_ads, 'rnt'); // location && colocation
  83. } else if ($univers == 1) {
  84. $search_nav = new search_object($table_name_ads, 'sal'); // vente
  85. } else {
  86. exit();
  87. }
  88. // SI c'est une ORPI ou une PREMIUM on rejoue la requete et on cherche leur position parmis l ensemble des resultats
  89. if ($ads_pos['tpl_code'] == "e" || $ads_pos['tpl_code'] == "p" || $ads_pos['tpl_code'] == "o") {
  90. $result = $search_nav->getExcluNav($request['id_anc']);
  91. $num_row = array_search($request['id_anc'], $result);
  92. $rLink = to_url(to_nat($search_nav->search_request, 'recherche'));
  93. $navigation = $search_nav->getNavigateDetail(null, $num_row, $is_agency);
  94. $navigation['prev']['id_annonce'] = $result[$num_row - 1];
  95. $navigation['next']['id_annonce'] = $result[$num_row + 1];
  96. } elseif (is_array($ads_pos)) {
  97. $navigation = $search_nav->getNavigateDetail(null, $num_row, $is_agency);
  98. $rLink = to_url(to_nat($search_nav->search_request, 'recherche'));
  99. }
  100. $navigation = $search_nav->getNavigateDetail(null, $num_row, $is_agency);
  101. switch ($univers) {
  102. case '2':
  103. $homepage = URL_SITE . 'location-immobilier.php';
  104. break;
  105. case '8':
  106. $homepage = URL_SITE . 'recherche-colocation.php';
  107. break;
  108. default:
  109. $homepage = URL_SITE;
  110. break;
  111. }
  112. $request['url'] = urldecode($request['url']);
  113. $request['referrer'] = urldecode($request['referrer']);
  114. //print_r($navigation); die;
  115. if ($navigation != null && stripos($request['url'], 'gallery=1') === false && stripos($request['url'], 'ext=1') === false && stripos($request['url'], 'ext=2') === false && $request['referrer'] != '') {
  116. $url = "detail.php?" . $_SERVER["QUERY_STRING"];
  117. // Ajouter le lien Annonce précédente
  118. if ($navigation['prev']['id_annonce'] != null) {
  119. //$url_prev = to_nat($url.'&id='.$navigation['prev'], "detail").$param.($num_row-1);
  120. $url_prev = to_url(to_nat($url . '&id=' . $navigation['prev']['id_annonce'].'&type_transaction='.$univers, "detail"));
  121. if (isset($_REQUEST['dbg']))
  122. $url_prev .= '?dbg=' . $_REQUEST['dbg'];
  123. $title = $navigation['prev'][$prfx . '_property_type'];
  124. if (isset($navigation['prev'][$prfx . '_default_sector']))
  125. $title .= ' ' . ucwords2(strtolower($navigation['prev'][$prfx . '_default_sector']));
  126. if (isset($navigation['prev'][$prfx . '_post_code']))
  127. $title .= ' (' . $navigation['prev'][$prfx . '_post_code'] . ')';
  128. if (isset($navigation['prev'][$prfx . '_nb_rooms']) && $navigation['prev'][$prfx . '_nb_rooms'] > 0)
  129. $title .= ', ' . $navigation['prev'][$prfx . '_nb_rooms'] . ' pièce(s)';
  130. if (isset($navigation['prev'][$prfx . '_price']) && $navigation['prev'][$prfx . '_price'] < 1999999999)
  131. $title .= ', ' . n_f($navigation['prev'][$prfx . '_price']) . ' &euro;';
  132. $links[0] = '<a onclick="' . getXitiClick($xitiClickNavPrevId) . 'set_ads_pos(\'' . $ads_pos['value'][0] . ($num_row - 1) . '\');" href="' . $url_prev . '" class="spir_btn nav_prev" title="' . $title . '"><span>Annonce précédente</span></a>';
  133. }else {
  134. $links[0] = '<div class="nav-calage-left">&nbsp;</div>';
  135. }
  136. // rlink
  137. $links[1] = '<div class="navCenterBtn"><a class="spir_btn" href="' . $rLink . '" title="Revenir à la liste des résultats">Revenir à ma recherche</a>';
  138. $links[2] = '<a class="spir_btn" onclick="' . getXitiClick($xitiClickNewSearchId) . '" href="' . $homepage . '" title="Faire une nouvelle recherche">Nouvelle recherche</a></div>';
  139. // Ajouter le lien Annonce suivante
  140. if ($navigation['next']['id_annonce'] != null) {
  141. //$url_next = to_nat($url.'&id='.$navigation['next'], "detail").$param.($num_row+1);
  142. $url_next = to_url(to_nat($url . '&id=' . $navigation['next']['id_annonce'].'&type_transaction='.$univers, "detail"));
  143. $title = $navigation['next'][$prfx . '_property_type'];
  144. if (isset($navigation['next'][$prfx . '_default_sector']))
  145. $title .= ' ' . ucwords2(strtolower($navigation['next'][$prfx . '_default_sector']));
  146. if (isset($navigation['next'][$prfx . '_post_code']))
  147. $title .= ' (' . $navigation['next'][$prfx . '_post_code'] . ')';
  148. if (isset($navigation['next'][$prfx . '_nb_rooms']) && $navigation['next'][$prfx . '_nb_rooms'] > 0)
  149. $title .= ', ' . $navigation['next'][$prfx . '_nb_rooms'] . ' pièce(s)';
  150. if (isset($navigation['next'][$prfx . '_price']) && $navigation['next'][$prfx . '_price'] < 1999999999)
  151. $title .= ', ' . n_f($navigation['next'][$prfx . '_price']) . ' &euro;';
  152. if (isset($_REQUEST['dbg']))
  153. $url_next .= '?dbg=' . $_REQUEST['dbg'];
  154. $links[3] = '<a onclick="' . getXitiClick($xitiClickNavNextId) . 'set_ads_pos(\'' . $ads_pos['value'][0] . ($num_row + 1) . '\');" href="' . $url_next . '" class="spir_btn nav_next" title="' . $title . '"><span>Annonce suivante</span></a>';
  155. }else {
  156. $links[3] = '<div class="nav-calage-right">&nbsp;</div>';
  157. }
  158. if ($navigation['prev']['id_annonce'] != null || $navigation['next']['id_annonce'] != null) {
  159. $js = '';
  160. } else {
  161. $js = 'if(document.getElementById("li-similaire-wrapper"))document.getElementById("li-similaire-wrapper").style.display="block";';
  162. $js .= 'if(document.getElementById("bloc_alerte_email_right"))document.getElementById("bloc_alerte_email_right").style.display="none";';
  163. }
  164. } else if (stripos($request['url'], 'ext=1') === false && stripos($request['url'], 'ext=2') !== false && $request['referrer'] != '') {
  165. $query = "SELECT *, ${prfx}_default_town_2, ${prfx}_default_town_1, ${prfx}_default_town_0
  166. FROM $table_name_ads
  167. WHERE id_annonce = '" . $request['id_anc'] . "'
  168. ";
  169. $res = pdoquery($query);
  170. list($ad, $ag) = get_ad_data("detail.php", $res[0], 0, '');
  171. // Annonce NEUF => univers 1
  172. if (!in_array($ad['type_transaction'], array(1, 2, 8)))
  173. $univ = 1;
  174. else
  175. $univ = $ad['type_transaction'];
  176. // si type de bien couplé à un autre (ou d'autres),
  177. // alors on mets tous les types de bien dans la recherche
  178. // ex: Bureau / Commerce ou encore Loft / Atelier
  179. $prop_type_value = getPropretyValueFromId($ad['property_type_id_orig'], $univ);
  180. if ($prop_type_value) {
  181. $prop_array_value = explode(',', $prop_type_value);
  182. } else {
  183. $prop_array_value = array();
  184. }
  185. $tab_new_query = array(
  186. 'univers' => $univ,
  187. 'loc_name1' => $ad['real_town'] . ' (' . $ad['real_zip'] . ')',
  188. 'loc_key1' => $ad['lct_id'] . '_' . $ad['lct_level'],
  189. 'price_min' => intval($ad['real_price'] - ceil($ad['real_price'] / 5)),
  190. 'price_max' => intval($ad['real_price'] + ceil($ad['real_price'] / 5)),
  191. 'ck_property_type' => $prop_array_value,
  192. 'site' => 'fr',
  193. );
  194. $rLink = to_url(to_nat($tab_new_query, 'recherche'));
  195. $id_anc = $request['id_anc'];
  196. $isSaveNavDet = true;
  197. if ($request['univers']==1) {
  198. $uriPrefix = 'detail-vente';
  199. $prefixe ="sal";
  200. } else {
  201. $uriPrefix = 'detail-location';
  202. $prefixe ="rnt";
  203. }
  204. include_once('get_annonce_fraiche_carousel.php');
  205. $total_annonces = count($annonces_fraiches);
  206. foreach ($annonces_fraiches as $key => $annonce) {
  207. //si annonce en cours
  208. if ($annonce["id_annonce"] == $id_anc) {
  209. //on récupère l'annonce précédente
  210. if ($key>0) {
  211. $prev = $key-1;
  212. $url_prev = to_url($uriPrefix.'-'.strtolower($annonces_fraiches[$prev]['id_annonce']).'.htm?ext=2');
  213. //gestion du title du lien
  214. $title = array();
  215. $title[] = $annonces_fraiches[$prev][$prefixe.'_default_town_2'].' ('.$annonces_fraiches[$prev][$prefixe.'_post_code'].')';
  216. if(isset($annonces_fraiches[$prev][$prefixe.'_property_type']) && $annonces_fraiches[$prev][$prefixe.'_property_type'] != '') {
  217. $title[] = $annonces_fraiches[$prev][$prefixe.'_property_type'];
  218. }
  219. if(isset($annonces_fraiches[$prev][$prefixe.'_area']) && $annonces_fraiches[$prev][$prefixe.'_area'] > 0) {
  220. $title[] = $annonces_fraiches[$prev][$prefixe.'_area'].' m²';
  221. }
  222. if(isset($annonces_fraiches[$prev][$prefixe.'_nb_rooms']) && $annonces_fraiches[$prev][$prefixe.'_nb_rooms'] > 0) {
  223. $title[] = $annonces_fraiches[$prev][$prefixe.'_nb_rooms'].' pièce'.($annonces_fraiches[$prev][$prefixe.'_nb_rooms'] > 1 ? 's' : '');
  224. }
  225. $title[] = n_f($annonces_fraiches[$prev][$prefixe.'_price']).' €';
  226. $title = implode(' - ', $title);
  227. $links[0] = '<a onclick="' . getXitiClick($xitiClickNavPrevId).'" href="' . $url_prev . '" class="spir_btn nav_prev" title="'.$title.'"><span>Annonce précédente</span></a>';
  228. } else {
  229. $links[0] = '<div class="nav-calage-left">&nbsp;</div>';
  230. }
  231. $links[1] = '<div class="navCenterBtn"><a class="spir_btn" href="' . $rLink . '" title="Voir des annonces similaires">Annonces similaires</a>';
  232. $links[2] = '<a class="spir_btn" onclick="' . getXitiClick($xitiClickNewSearchId) . '" href="' . $homepage . '" title="Faire une nouvelle recherche">Nouvelle recherche</a></div>';
  233. //on récupère l'annonce suivante
  234. if ($key<($total_annonces-1)) {
  235. $next = $key+1;
  236. $url_next = to_url($uriPrefix.'-'.strtolower($annonces_fraiches[$next]['id_annonce']).'.htm?ext=2');
  237. //gestion du title du lien
  238. $title = array();
  239. $title[] = $annonces_fraiches[$next][$prefixe.'_default_town_2'].' ('.$annonces_fraiches[$next][$prefixe.'_post_code'].')';
  240. if(isset($annonces_fraiches[$next][$prefixe.'_property_type']) && $annonces_fraiches[$next][$prefixe.'_property_type'] != '') {
  241. $title[] = $annonces_fraiches[$next][$prefixe.'_property_type'];
  242. }
  243. if(isset($annonces_fraiches[$next][$prefixe.'_area']) && $annonces_fraiches[$next][$prefixe.'_area'] > 0) {
  244. $title[] = $annonces_fraiches[$next][$prefixe.'_area'].' m²';
  245. }
  246. if(isset($annonces_fraiches[$next][$prefixe.'_nb_rooms']) && $annonces_fraiches[$next][$prefixe.'_nb_rooms'] > 0) {
  247. $title[] = $annonces_fraiches[$next][$prefixe.'_nb_rooms'].' pièce'.($annonces_fraiches[$next][$prefixe.'_nb_rooms'] > 1 ? 's' : '');
  248. }
  249. $title[] = n_f($annonces_fraiches[$next][$prefixe.'_price']).' €';
  250. $title = implode(' - ', $title);
  251. $links[3] = '<a onclick="' . getXitiClick($xitiClickNavNextId) . '" href="' . $url_next . '" class="spir_btn nav_next" title="'.$title.'"><span>Annonce suivante</span></a>';
  252. } else {
  253. $links[3] = '<div class="nav-calage-right">&nbsp;</div>';
  254. }
  255. break;
  256. }
  257. }
  258. } else {
  259. $query = "SELECT *, ${prfx}_default_town_2, ${prfx}_default_town_1, ${prfx}_default_town_0
  260. FROM $table_name_ads
  261. WHERE id_annonce = '" . $request['id_anc'] . "'
  262. ";
  263. $res = pdoquery($query);
  264. list($ad, $ag) = get_ad_data("detail.php", $res[0], 0, '');
  265. // Annonce NEUF => univers 1
  266. if (!in_array($ad['type_transaction'], array(1, 2, 8)))
  267. $univ = 1;
  268. else
  269. $univ = $ad['type_transaction'];
  270. // si type de bien couplé à un autre (ou d'autres),
  271. // alors on mets tous les types de bien dans la recherche
  272. // ex: Bureau / Commerce ou encore Loft / Atelier
  273. $prop_type_value = getPropretyValueFromId($ad['property_type_id_orig'], $univ);
  274. if ($prop_type_value) {
  275. $prop_array_value = explode(',', $prop_type_value);
  276. } else {
  277. $prop_array_value = array();
  278. }
  279. $tab_new_query = array(
  280. 'univers' => $univ,
  281. 'loc_name1' => $ad['real_town'] . ' (' . $ad['real_zip'] . ')',
  282. 'loc_key1' => $ad['lct_id'] . '_' . $ad['lct_level'],
  283. 'price_min' => intval($ad['real_price'] - ceil($ad['real_price'] / 5)),
  284. 'price_max' => intval($ad['real_price'] + ceil($ad['real_price'] / 5)),
  285. 'ck_property_type' => $prop_array_value,
  286. 'site' => 'fr',
  287. );
  288. $rLink = to_url(to_nat($tab_new_query, 'recherche'));
  289. $links[0] = '<div class="nav-calage-left">&nbsp;</div>';
  290. $links[1] = '<div class="navCenterBtn"><a class="spir_btn" href="' . $rLink . '" title="Voir des annonces similaires">Annonces similaires</a>';
  291. $links[2] = '<a class="spir_btn" onclick="' . getXitiClick($xitiClickNewSearchId) . '" href="' . $homepage . '" title="Faire une nouvelle recherche">Nouvelle recherche</a></div>';
  292. $links[3] = '<div class="nav-calage-right">&nbsp;</div>';
  293. $js = 'if(document.getElementById("li-similaire-wrapper"))document.getElementById("li-similaire-wrapper").style.display="block";';
  294. // $js .= 'if(document.getElementById("bloc_alerte_email_right"))document.getElementById("bloc_alerte_email_right").style.display="none";';
  295. }
  296. $str_links[] = implode('', $links);
  297. $str_links[] = $js;
  298. // if( $links!='') echo '<div id="nav_prev_next">'.$str_links.'</div>'.$js;
  299. echo $json->encode($str_links);