/DEV/DISPLAY/ajax/save_nav_det.php
PHP | 354 lines | 261 code | 55 blank | 38 comment | 99 complexity | b259d4c034aece330ec8917e7a48d444 MD5 | raw file
- <?php
- // common include
- include("../modules/includes.php");
- // plug-in
- include("json.php");
- include("../../LIB/search.class.php");
- // object instantiation
- $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
- $request = $_REQUEST;
- //echo "============>request = ";print_r($_REQUEST["json"]);
- //echo "<br/><br/>============>request decode = ";echo $request;
- $ads_pos = $json->decode($_COOKIE['ads_pos']);
- // var_dump($ads_pos);
- $univers = $request['univers'];
- $_global['univers'] = $univers;
- // TAG XITI
- switch ($_global['univers']) {
- case 1: // vente
- $xitiClickNavPrevId = 15;
- $xitiClickNavNextId = 13;
- $xitiClickNewSearchId = 17;
- break;
- case 2: // location
- $xitiClickNavPrevId = 51;
- $xitiClickNavNextId = 49;
- $xitiClickNewSearchId = 53;
- break;
- case 8: // colocation
- $xitiClickNavPrevId = 87;
- $xitiClickNavNextId = 85;
- $xitiClickNewSearchId = 89;
- break;
- }
- if ($ads_pos['param'] == "p") {
- $is_agency = false;
- $_global['is_there_premium'] = ($ads_pos['value'][0] == 'o');
- $_global['is_there_premium'] = false;
- //$num_row = (int)substr($_REQUEST['p'],1);
- //$param = '?p='.$_REQUEST['p'][0];
- $num_row = (int) substr($ads_pos['value'], 1);
- $param = 'p';
- $param_value = $ads_pos['value'][0];
- }
- // Recherche a partir des annonces d'une agence
- else {
- $is_agency = true;
- $_global['is_there_premium'] = false;
- //$num_row = (int)$_REQUEST['r'];
- //$param = '?r=';
- $num_row = (int) $ads_pos['value'];
- $param = 'r';
- }
- // recherche du nom de la table des annonces à utiliser
- // NB: tables TM_... uniquement pour les pages résultat, pas détail normalement
- if ($univers == 2 || $univers == 8) {
- $prfx = $_global["table_prefix"] = "rnt";
- } else {
- $prfx = $_global["table_prefix"] = "sal";
- }
- $sql = " SELECT ttu_" . $prfx . "_fr FROM TP_TABLE_TO_USE_TTU";
- $res = pdoquery($sql);
- //echo "<hr>"; echo $sql; echo "<hr>";
- // table des annonces (moteur InnoDB ou MEMORY ou MyISAM)
- if (sizeof($res) > 0 && strpos($request['url'], 'gallery=1') === false) {
- $table_name_ads = $res[0]["ttu_" . $prfx . "_fr"];
- } else {
- if ($univers == 2 || $univers == 8) {
- $prfx = "rnt";
- if (strpos($request['url'], 'gallery=1') === false)
- $table_name_ads = "T_RENTAD_RNT";
- else
- $table_name_ads = "T_RENTAD_BIS";
- } else {
- $prfx = "sal";
- if (strpos($request['url'], 'gallery=1') === false)
- $table_name_ads = "T_SALESAD_SAL";
- else
- $table_name_ads = "T_SALESAD_BIS";
- }
- }
- if ($univers == 2 || $univers == 8) {
- $search_nav = new search_object($table_name_ads, 'rnt'); // location && colocation
- } else if ($univers == 1) {
- $search_nav = new search_object($table_name_ads, 'sal'); // vente
- } else {
- exit();
- }
- // SI c'est une ORPI ou une PREMIUM on rejoue la requete et on cherche leur position parmis l ensemble des resultats
- if ($ads_pos['tpl_code'] == "e" || $ads_pos['tpl_code'] == "p" || $ads_pos['tpl_code'] == "o") {
- $result = $search_nav->getExcluNav($request['id_anc']);
- $num_row = array_search($request['id_anc'], $result);
- $rLink = to_url(to_nat($search_nav->search_request, 'recherche'));
- $navigation = $search_nav->getNavigateDetail(null, $num_row, $is_agency);
- $navigation['prev']['id_annonce'] = $result[$num_row - 1];
- $navigation['next']['id_annonce'] = $result[$num_row + 1];
- } elseif (is_array($ads_pos)) {
-
- $navigation = $search_nav->getNavigateDetail(null, $num_row, $is_agency);
- $rLink = to_url(to_nat($search_nav->search_request, 'recherche'));
- }
- $navigation = $search_nav->getNavigateDetail(null, $num_row, $is_agency);
- switch ($univers) {
- case '2':
- $homepage = URL_SITE . 'location-immobilier.php';
- break;
- case '8':
- $homepage = URL_SITE . 'recherche-colocation.php';
- break;
- default:
- $homepage = URL_SITE;
- break;
- }
- $request['url'] = urldecode($request['url']);
- $request['referrer'] = urldecode($request['referrer']);
- //print_r($navigation); die;
- if ($navigation != null && stripos($request['url'], 'gallery=1') === false && stripos($request['url'], 'ext=1') === false && stripos($request['url'], 'ext=2') === false && $request['referrer'] != '') {
- $url = "detail.php?" . $_SERVER["QUERY_STRING"];
- // Ajouter le lien Annonce précédente
- if ($navigation['prev']['id_annonce'] != null) {
- //$url_prev = to_nat($url.'&id='.$navigation['prev'], "detail").$param.($num_row-1);
- $url_prev = to_url(to_nat($url . '&id=' . $navigation['prev']['id_annonce'].'&type_transaction='.$univers, "detail"));
- if (isset($_REQUEST['dbg']))
- $url_prev .= '?dbg=' . $_REQUEST['dbg'];
- $title = $navigation['prev'][$prfx . '_property_type'];
- if (isset($navigation['prev'][$prfx . '_default_sector']))
- $title .= ' ' . ucwords2(strtolower($navigation['prev'][$prfx . '_default_sector']));
- if (isset($navigation['prev'][$prfx . '_post_code']))
- $title .= ' (' . $navigation['prev'][$prfx . '_post_code'] . ')';
- if (isset($navigation['prev'][$prfx . '_nb_rooms']) && $navigation['prev'][$prfx . '_nb_rooms'] > 0)
- $title .= ', ' . $navigation['prev'][$prfx . '_nb_rooms'] . ' pièce(s)';
- if (isset($navigation['prev'][$prfx . '_price']) && $navigation['prev'][$prfx . '_price'] < 1999999999)
- $title .= ', ' . n_f($navigation['prev'][$prfx . '_price']) . ' €';
- $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>';
- }else {
- $links[0] = '<div class="nav-calage-left"> </div>';
- }
- // rlink
- $links[1] = '<div class="navCenterBtn"><a class="spir_btn" href="' . $rLink . '" title="Revenir à la liste des résultats">Revenir à ma recherche</a>';
- $links[2] = '<a class="spir_btn" onclick="' . getXitiClick($xitiClickNewSearchId) . '" href="' . $homepage . '" title="Faire une nouvelle recherche">Nouvelle recherche</a></div>';
- // Ajouter le lien Annonce suivante
- if ($navigation['next']['id_annonce'] != null) {
- //$url_next = to_nat($url.'&id='.$navigation['next'], "detail").$param.($num_row+1);
- $url_next = to_url(to_nat($url . '&id=' . $navigation['next']['id_annonce'].'&type_transaction='.$univers, "detail"));
- $title = $navigation['next'][$prfx . '_property_type'];
- if (isset($navigation['next'][$prfx . '_default_sector']))
- $title .= ' ' . ucwords2(strtolower($navigation['next'][$prfx . '_default_sector']));
- if (isset($navigation['next'][$prfx . '_post_code']))
- $title .= ' (' . $navigation['next'][$prfx . '_post_code'] . ')';
- if (isset($navigation['next'][$prfx . '_nb_rooms']) && $navigation['next'][$prfx . '_nb_rooms'] > 0)
- $title .= ', ' . $navigation['next'][$prfx . '_nb_rooms'] . ' pièce(s)';
- if (isset($navigation['next'][$prfx . '_price']) && $navigation['next'][$prfx . '_price'] < 1999999999)
- $title .= ', ' . n_f($navigation['next'][$prfx . '_price']) . ' €';
- if (isset($_REQUEST['dbg']))
- $url_next .= '?dbg=' . $_REQUEST['dbg'];
- $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>';
- }else {
- $links[3] = '<div class="nav-calage-right"> </div>';
- }
- if ($navigation['prev']['id_annonce'] != null || $navigation['next']['id_annonce'] != null) {
- $js = '';
- } else {
- $js = 'if(document.getElementById("li-similaire-wrapper"))document.getElementById("li-similaire-wrapper").style.display="block";';
- $js .= 'if(document.getElementById("bloc_alerte_email_right"))document.getElementById("bloc_alerte_email_right").style.display="none";';
- }
- } else if (stripos($request['url'], 'ext=1') === false && stripos($request['url'], 'ext=2') !== false && $request['referrer'] != '') {
- $query = "SELECT *, ${prfx}_default_town_2, ${prfx}_default_town_1, ${prfx}_default_town_0
- FROM $table_name_ads
- WHERE id_annonce = '" . $request['id_anc'] . "'
- ";
-
- $res = pdoquery($query);
- list($ad, $ag) = get_ad_data("detail.php", $res[0], 0, '');
- // Annonce NEUF => univers 1
- if (!in_array($ad['type_transaction'], array(1, 2, 8)))
- $univ = 1;
- else
- $univ = $ad['type_transaction'];
- // si type de bien couplé à un autre (ou d'autres),
- // alors on mets tous les types de bien dans la recherche
- // ex: Bureau / Commerce ou encore Loft / Atelier
- $prop_type_value = getPropretyValueFromId($ad['property_type_id_orig'], $univ);
- if ($prop_type_value) {
- $prop_array_value = explode(',', $prop_type_value);
- } else {
- $prop_array_value = array();
- }
- $tab_new_query = array(
- 'univers' => $univ,
- 'loc_name1' => $ad['real_town'] . ' (' . $ad['real_zip'] . ')',
- 'loc_key1' => $ad['lct_id'] . '_' . $ad['lct_level'],
- 'price_min' => intval($ad['real_price'] - ceil($ad['real_price'] / 5)),
- 'price_max' => intval($ad['real_price'] + ceil($ad['real_price'] / 5)),
- 'ck_property_type' => $prop_array_value,
- 'site' => 'fr',
- );
- $rLink = to_url(to_nat($tab_new_query, 'recherche'));
- $id_anc = $request['id_anc'];
- $isSaveNavDet = true;
- if ($request['univers']==1) {
- $uriPrefix = 'detail-vente';
- $prefixe ="sal";
- } else {
- $uriPrefix = 'detail-location';
- $prefixe ="rnt";
- }
-
- include_once('get_annonce_fraiche_carousel.php');
- $total_annonces = count($annonces_fraiches);
- foreach ($annonces_fraiches as $key => $annonce) {
- //si annonce en cours
- if ($annonce["id_annonce"] == $id_anc) {
- //on récupère l'annonce précédente
- if ($key>0) {
- $prev = $key-1;
- $url_prev = to_url($uriPrefix.'-'.strtolower($annonces_fraiches[$prev]['id_annonce']).'.htm?ext=2');
- //gestion du title du lien
- $title = array();
- $title[] = $annonces_fraiches[$prev][$prefixe.'_default_town_2'].' ('.$annonces_fraiches[$prev][$prefixe.'_post_code'].')';
- if(isset($annonces_fraiches[$prev][$prefixe.'_property_type']) && $annonces_fraiches[$prev][$prefixe.'_property_type'] != '') {
- $title[] = $annonces_fraiches[$prev][$prefixe.'_property_type'];
- }
- if(isset($annonces_fraiches[$prev][$prefixe.'_area']) && $annonces_fraiches[$prev][$prefixe.'_area'] > 0) {
- $title[] = $annonces_fraiches[$prev][$prefixe.'_area'].' m²';
- }
- if(isset($annonces_fraiches[$prev][$prefixe.'_nb_rooms']) && $annonces_fraiches[$prev][$prefixe.'_nb_rooms'] > 0) {
- $title[] = $annonces_fraiches[$prev][$prefixe.'_nb_rooms'].' pièce'.($annonces_fraiches[$prev][$prefixe.'_nb_rooms'] > 1 ? 's' : '');
- }
-
- $title[] = n_f($annonces_fraiches[$prev][$prefixe.'_price']).' €';
- $title = implode(' - ', $title);
- $links[0] = '<a onclick="' . getXitiClick($xitiClickNavPrevId).'" href="' . $url_prev . '" class="spir_btn nav_prev" title="'.$title.'"><span>Annonce précédente</span></a>';
- } else {
- $links[0] = '<div class="nav-calage-left"> </div>';
- }
- $links[1] = '<div class="navCenterBtn"><a class="spir_btn" href="' . $rLink . '" title="Voir des annonces similaires">Annonces similaires</a>';
- $links[2] = '<a class="spir_btn" onclick="' . getXitiClick($xitiClickNewSearchId) . '" href="' . $homepage . '" title="Faire une nouvelle recherche">Nouvelle recherche</a></div>';
- //on récupère l'annonce suivante
- if ($key<($total_annonces-1)) {
- $next = $key+1;
- $url_next = to_url($uriPrefix.'-'.strtolower($annonces_fraiches[$next]['id_annonce']).'.htm?ext=2');
- //gestion du title du lien
- $title = array();
- $title[] = $annonces_fraiches[$next][$prefixe.'_default_town_2'].' ('.$annonces_fraiches[$next][$prefixe.'_post_code'].')';
- if(isset($annonces_fraiches[$next][$prefixe.'_property_type']) && $annonces_fraiches[$next][$prefixe.'_property_type'] != '') {
- $title[] = $annonces_fraiches[$next][$prefixe.'_property_type'];
- }
- if(isset($annonces_fraiches[$next][$prefixe.'_area']) && $annonces_fraiches[$next][$prefixe.'_area'] > 0) {
- $title[] = $annonces_fraiches[$next][$prefixe.'_area'].' m²';
- }
- if(isset($annonces_fraiches[$next][$prefixe.'_nb_rooms']) && $annonces_fraiches[$next][$prefixe.'_nb_rooms'] > 0) {
- $title[] = $annonces_fraiches[$next][$prefixe.'_nb_rooms'].' pièce'.($annonces_fraiches[$next][$prefixe.'_nb_rooms'] > 1 ? 's' : '');
- }
-
- $title[] = n_f($annonces_fraiches[$next][$prefixe.'_price']).' €';
- $title = implode(' - ', $title);
- $links[3] = '<a onclick="' . getXitiClick($xitiClickNavNextId) . '" href="' . $url_next . '" class="spir_btn nav_next" title="'.$title.'"><span>Annonce suivante</span></a>';
- } else {
- $links[3] = '<div class="nav-calage-right"> </div>';
- }
- break;
- }
- }
- } else {
- $query = "SELECT *, ${prfx}_default_town_2, ${prfx}_default_town_1, ${prfx}_default_town_0
- FROM $table_name_ads
- WHERE id_annonce = '" . $request['id_anc'] . "'
- ";
- $res = pdoquery($query);
- list($ad, $ag) = get_ad_data("detail.php", $res[0], 0, '');
- // Annonce NEUF => univers 1
- if (!in_array($ad['type_transaction'], array(1, 2, 8)))
- $univ = 1;
- else
- $univ = $ad['type_transaction'];
- // si type de bien couplé à un autre (ou d'autres),
- // alors on mets tous les types de bien dans la recherche
- // ex: Bureau / Commerce ou encore Loft / Atelier
- $prop_type_value = getPropretyValueFromId($ad['property_type_id_orig'], $univ);
- if ($prop_type_value) {
- $prop_array_value = explode(',', $prop_type_value);
- } else {
- $prop_array_value = array();
- }
- $tab_new_query = array(
- 'univers' => $univ,
- 'loc_name1' => $ad['real_town'] . ' (' . $ad['real_zip'] . ')',
- 'loc_key1' => $ad['lct_id'] . '_' . $ad['lct_level'],
- 'price_min' => intval($ad['real_price'] - ceil($ad['real_price'] / 5)),
- 'price_max' => intval($ad['real_price'] + ceil($ad['real_price'] / 5)),
- 'ck_property_type' => $prop_array_value,
- 'site' => 'fr',
- );
- $rLink = to_url(to_nat($tab_new_query, 'recherche'));
- $links[0] = '<div class="nav-calage-left"> </div>';
- $links[1] = '<div class="navCenterBtn"><a class="spir_btn" href="' . $rLink . '" title="Voir des annonces similaires">Annonces similaires</a>';
- $links[2] = '<a class="spir_btn" onclick="' . getXitiClick($xitiClickNewSearchId) . '" href="' . $homepage . '" title="Faire une nouvelle recherche">Nouvelle recherche</a></div>';
- $links[3] = '<div class="nav-calage-right"> </div>';
- $js = 'if(document.getElementById("li-similaire-wrapper"))document.getElementById("li-similaire-wrapper").style.display="block";';
- // $js .= 'if(document.getElementById("bloc_alerte_email_right"))document.getElementById("bloc_alerte_email_right").style.display="none";';
- }
- $str_links[] = implode('', $links);
- $str_links[] = $js;
- // if( $links!='') echo '<div id="nav_prev_next">'.$str_links.'</div>'.$js;
- echo $json->encode($str_links);