createRecordset($sql); $ntown_id = $db->fetchAll($rs); $count = 0; $ntown = ""; foreach($ntown_id as $val) { if((count($ntown_id)-1) == $count) { $ntown .= "'".$val["ntown_id"]."'"; } else { $ntown .= "'".$val["ntown_id"]."'".", "; } $count++; } } if($currency != ''){ $currency_rate = $db->getField("currency", "currency_code", $currency, "currency_rate"); $rate = $currency_rate; }else{ $rate = 1; } $page = form_int("page",1)+0; $sortby = form_int("sortby", 5, 0, 5); $sortdir = form_int("sortdir",0,0,1); // echo $sortdir."
"; if (form_isset("reverse")) { $sortdir = 1-$sortdir; } switch($sortdir) { case 0 : $orderDir = "ASC"; break; case 1 : $orderDir = "DESC"; break; } switch($sortby) { case 0: $sortField = "title"; break; case 1: $sortField = "ptown"; break; case 2: $sortField = "habitable_size"; break; case 3: $sortField = "beds"; break; case 4: $sortField = "department"; break; case 5: $sortField = "price"; break; default: $sortField = "price"; break; } if($selected_view !="") { $sql = "SELECT DISTINCT(l.listing_id) FROM listings l LEFT JOIN users u ON l.user_id = u.user_id LEFT JOIN colo_agents a ON l.colo_agent_id = a.colo_agent_id LEFT JOIN listing_department d ON l.department_id = d.department_id LEFT JOIN p_town p ON l.ptown_id = p.id LEFT JOIN listing_type t ON l.type_id = t.type_id LEFT JOIN n_town n ON l.ntown_id = n.id JOIN listing_views v ON l.listing_id = v.listing_id"; $rs = $db->createRecordset($sql); $nlisting_id = $db->fetchAll($rs); $count = 0; $nlisting = ""; //print_r($nlisting_id); foreach($nlisting_id as $val) { if((count($nlisting_id)-1) == $count) { $nlisting .= "'".$val["listing_id"]."'"; } else { $nlisting .= "'".$val["listing_id"]."'".","; } $count++; } //echo $nlisting; $search_1="SELECT l.listing_id, l.title, l.user_id AS userid, l.images_count, l.habitable_size, l.beds, l.view_count as view, l.lot_size, round(l.price * $rate) AS price, l.status, SUBSTRING(l.description, 1, 100) AS description, show_price, l.friendly_link, l.ptown_id AS ptown, d.name AS department, t.name AS type, n.name AS ntown, u.username as agent, a.agent_name,v.view_id FROM listings l LEFT JOIN users u ON l.user_id = u.user_id LEFT JOIN colo_agents a ON l.colo_agent_id = a.colo_agent_id LEFT JOIN listing_department d ON l.department_id = d.department_id LEFT JOIN p_town p ON l.ptown_id = p.id LEFT JOIN listing_type t ON l.type_id = t.type_id LEFT JOIN n_town n ON l.ntown_id = n.id INNER JOIN listing_views v ON l.listing_id = v.listing_id WHERE v.listing_id IN($nlisting) "; } else { $search_1 = "SELECT l.listing_id, l.title, l.user_id AS userid, l.images_count, l.habitable_size, l.beds, l.view_count as view, l.lot_size, round(l.price * $rate) AS price, l.status, SUBSTRING(l.description, 1, 100) AS description, show_price, l.friendly_link, l.ptown_id AS ptown, d.name AS department, t.name AS type, n.name AS ntown, u.username as agent, a.agent_name FROM listings l LEFT JOIN users u ON l.user_id = u.user_id LEFT JOIN colo_agents a ON l.colo_agent_id = a.colo_agent_id LEFT JOIN listing_department d ON l.department_id = d.department_id LEFT JOIN p_town p ON l.ptown_id = p.id LEFT JOIN listing_type t ON l.type_id = t.type_id LEFT JOIN n_town n ON l.ntown_id = n.id"; } $search_2 = $search_1; $where_1 = array(); $where_2 = array(); $user = user_GetCurrent(); # Show or not show inactive listings if (!$user["is_admin"] && !$user["is_agent"]){ array_push($where_1, "l.active = 1"); array_push($where_1, "l.show_price = 1"); array_push($where_2, "l.active = 1"); array_push($where_2, "l.show_price = 0"); }else{ array_push($where_1, "l.show_price = 1"); array_push($where_1, "l.status != 3"); array_push($where_2, "l.show_price = 0"); array_push($where_2, "l.status != 3"); } # Show FR /* if ($showFr_log = user_Allowed()){ //echo $showFr_log; if (!$user["is_admin"] && !$user["is_agent"]){ switch($showFr_log) { case 'allowed': break; case 'not_allowed': array_push($where_1, "l.show_fr = 'Yes'"); array_push($where_2, "l.show_fr = 'Yes'"); break; case 'unknown': array_push($where_1, "l.show_fr = 'xx'"); array_push($where_2, "l.show_fr = 'xx'"); break; } } }*/ # Show FR if (user_FromFR()){ if (!$user["is_admin"] && !$user["is_agent"]){ array_push($where_1, "l.show_fr = 'Yes'"); array_push($where_2, "l.show_fr = 'Yes'"); } } # Show RHF if (!$user["is_admin"] && !$user["is_agent"]){ array_push($where_1, "l.show_rhf = 'Yes'"); array_push($where_2, "l.show_rhf = 'Yes'"); } if ($ref_id != '') { array_push($where_1, " l.listing_id = '" . $db->escapeSqlLike($ref_id). "'"); array_push($where_2, " l.listing_id = '" . $db->escapeSqlLike($ref_id). "'"); } if($selected_ptown && $selected_near_by_town == "") { if($ntown != "") { array_push($where_1, "(l.ntown_id IN ($ntown) OR l.ptown_id = '" . $db->escapeSqlLike($selected_ptown) . "')"); array_push($where_2, "(l.ntown_id IN ($ntown) OR l.ptown_id = '" . $db->escapeSqlLike($selected_ptown) . "')"); } else { array_push($where_1, "l.ptown_id = '" . $db->escapeSqlLike($selected_ptown) . "'"); array_push($where_2, "l.ptown_id = '" . $db->escapeSqlLike($selected_ptown) . "'"); } } if($selected_near_by_town) { array_push($where_1, "l.ntown_id = '" . $db->escapeSqlLike($selected_near_by_town) . "'"); array_push($where_2, "l.ntown_id = '" . $db->escapeSqlLike($selected_near_by_town) . "'"); } if ($price_from != '') { array_push($where_1, " l.price * $rate >= " . $db->escapeSqlLike($price_from) . ""); array_push($where_2, " l.price * $rate >= " . $db->escapeSqlLike($price_from*0.8) . ""); } if ($price_to != '') { array_push($where_1, " l.price * $rate <= " . $db->escapeSqlLike($price_to) . ""); array_push($where_2, " l.price * $rate <= " . $db->escapeSqlLike($price_to*1.2) . ""); } if ($selected_department) { array_push($where_1, " l.department_id = '" . $db->escapeSqlLike($selected_department) . "'"); array_push($where_2, " l.department_id = '" . $db->escapeSqlLike($selected_department) . "'"); } if ($selected_type) { array_push($where_1, " l.type_id = '" . $db->escapeSqlLike($selected_type) . "'"); array_push($where_2, " l.type_id = '" . $db->escapeSqlLike($selected_type) . "'"); } if ($selected_view) { array_push($where_1, " v.view_id = '" . $db->escapeSqlLike($selected_view) . "'"); array_push($where_2, " v.view_id = '" . $db->escapeSqlLike($selected_view) . "'"); } if ($selected_view) { if(sizeof($where_1) > 0){ $search_1 .= " AND ".join($where_1, " AND "); } if(sizeof($where_2) > 0){ $search_2 .= " AND ".join($where_2, " AND "); } } else { if(sizeof($where_1) > 0){ $search_1 .= " WHERE ".join($where_1, " AND "); } if(sizeof($where_2) > 0){ $search_2 .= " WHERE ".join($where_2, " AND "); } } $search = $search_1.' UNION '.$search_2; // $search .=" ORDER BY " . $sortField . " " . $orderDir; $search .=" ORDER BY " . $sortField . " " . DESC; // echo $search; $listings_rows = $db->createRecordset($search); $search_query = "&primary_town=" . html_escapeURL($selected_ptown) ."&nearby_town=" . html_escapeURL($selected_near_by_town) ."&select_department=" . html_escapeURL($selected_department) ."¤cy=" . html_escapeURL($currency) ."&select_type=" . html_escapeURL($selected_type) ."&select_view=" . html_escapeURL($selected_view) ."&price_from=" . html_escapeURL($price_from) ."&price_to=" . html_escapeURL($price_to) ; $sort_query = "sortby=" . html_escapeURL($sortby) . "&sortdir=" . html_escapeURL($sortdir); #Determine the pagination $pag = new Pagination($listings_rows, $search_query."&".$sort_query, GLOBAL_RECORDS_PER_PAGE); $pag->current_page = $page; $pagination = $pag->Process(); $smarty->assign("pagination", $pagination); for($i = 0; $i < sizeof($listings_rows); $i++) { $ptown_ids = split(",", $listings_rows[$i]["ptown"]); $count = 1; $ptown = ""; foreach($ptown_ids as $id) { if($count == 1) { $ptown = $db->getField("p_town", "id", $id, "name"); } else { $ptown .= ", ". $db->getField("p_town", "id", $id, "name"); } $count++; } $listings_rows[$i]["ptown"] = $ptown; $listing_id = $listings_rows[$i]["listing_id"]; $image = listing_GetImages($listing_id, 1); $listings_rows[$i]["thumbs"] = $image; $listings_rows[$i]["status"] = status_GetName($listings_rows[$i]["status"]); } #title $smarty->assign("title", "Search Results"); $smarty->assign("nav", "properties"); $smarty->assign("subnav", page_GetSubnav("properties")); $smarty->assign("subnav_selected", "search_properties"); #main content # left content $smarty->assign("sortby",$sortby); $smarty->assign("sortdir",$sortdir); $smarty->assign("message",$msg); $smarty->assign("page",$page); $smarty->assign("search_query",$search_query); $smarty->assign_by_ref("listings", $listings_rows); # right content $smarty->assign("select_department", $select_department); $smarty->assign("select_type", $select_type); $smarty->assign("price_from", $price_from); $smarty->assign("currency", $currency); $smarty->assign("price_to", $price_to); $smarty->assign("search", array("search2.tpl")); $smarty->assign("search1", array("search_form_two.tpl")); $smarty->assign("searchontopandbottom", "1"); if (!$user["is_admin"] && !$user["is_agent"]) { $smarty->assign("contents", array("results_new.tpl")); } else { $smarty->assign("contents", array("results3.tpl")); } $smarty->assign("callouts", array("search3.tpl", "featured_vertical3.tpl")); $smarty->display("main3.tpl"); ?>