Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php get_header(); ?>
- <?php
- if(isset($_GET['author_name'])) :
- $curauth = get_userdatabylogin($author_name);
- else :
- $curauth = get_userdata(intval($author));
- endif;
- ?>
- <?php if (is_paged()) $is_paged = true; ?>
- <div class="wrapper" >
- <div class="clearfix container_border">
- <div class="breadcrumbs">
- <p><?php if ( get_option( 'ptthemes_breadcrumbs' )) { yoast_breadcrumb('',''); } ?></p>
- <span class="findproperties" onclick="show_hide_propertysearchoptions();"><a href="javascript:void(0);"><?php _e(FIND_PROPERTIES_TEXT);?></a></span>
- </div>
- </div>
- <?php require_once (TEMPLATEPATH . '/library/includes/search.php'); ?>
- <?php
- $is_search = 0;
- global $wpdb;
- $totalpost_count = 0;
- $propertycategory = get_cat_id_from_name(get_option('ptthemes_propertycategory'));
- $propertycategorys = get_sub_categories($propertycategory,'string');
- $all_pids_arr = $wpdb->get_var("SELECT group_concat(ID) FROM $wpdb->posts where post_status='publish'");
- $all_pids_arr = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_taxonomy tt join $wpdb->term_relationships tr on tr.term_taxonomy_id=tt.term_taxonomy_id where tt.term_id in ($propertycategorys)");
- if($_REQUEST['srch_location'])
- {
- $is_search = 1;
- $srch_location = $_REQUEST['srch_location'];
- //$location_pids = $wpdb->get_var("SELECT group_concat(tr.object_id) FROM $wpdb->term_taxonomy tt join $wpdb->term_relationships tr on tr.term_taxonomy_id=tt.term_taxonomy_id where tt.term_id=\"$srch_location\"");
- $location_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'add_location' and meta_value like \"$srch_location\"");
- $all_pids_arr = array_intersect($all_pids_arr,$location_pids_arr);
- }
- else if($_REQUEST['srch_price'])
- {
- $is_search = 1;
- $srch_price = $_REQUEST['srch_price'];
- /*$price = (explode("N",$_REQUEST['srch_price']));
- $price = $price[1]."".$price[2];
- $srch_price = trim($price);
- $_GET['price'] = $price;*/
- if(strstr($srch_price,'-'))
- {
- $srch_price_str = str_replace('-',' and ',$srch_price);
- $srch_price_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'price' and
- meta_value between $srch_price_str");
- }
- elseif(strstr($srch_price,'+'))
- {
- $srch_price_str = str_replace('+','',$srch_price);
- $srch_price_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'price' and
- meta_value >= $srch_price_str");
- }
- $all_pids_arr = array_intersect($all_pids_arr,$srch_price_arr);
- }
- else if($_REQUEST['srch_bedrooms'])
- {
- $is_search = 1;
- $srch_bedrooms = $_REQUEST['srch_bedrooms'];
- //$srch_bedrooms = $wpdb->get_var("select group_concat(post_id) from $wpdb->postmeta where meta_key like 'bed_rooms' and meta_value = \"$srch_bedrooms\"");
- //$srch_bedrooms_arr = explode(',',$srch_bedrooms);
- $srch_bedrooms_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'bed_rooms' and meta_value = \"$srch_bedrooms\"");
- $all_pids_arr = array_intersect($all_pids_arr,$srch_bedrooms_arr);
- }
- /*if($_REQUEST['srch_bathroom'])
- {
- $is_search = 1;
- $srch_bathroom = $_REQUEST['srch_bathroom'];
- $bathroom_pids_arr = $wpdb->get_col("select (post_id) from $wpdb->postmeta where meta_key like 'bath_rooms' and meta_value = \"$srch_bathroom\"");
- $all_pids_arr = array_intersect($all_pids_arr,$bathroom_pids_arr);
- }*/
- else if($_REQUEST['srch_type'])
- {
- $is_search = 1;
- $srch_type = $_REQUEST['srch_type'];
- $type_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'property_type' and meta_value = \"$srch_type\"");
- $all_pids_arr = array_intersect($all_pids_arr,$type_pids_arr);
- }
- else if($_REQUEST['srch_area'])
- {
- $is_search = 1;
- $srch_area = $_REQUEST['srch_area'];
- if(strstr($srch_area,'-'))
- {
- $srch_area_str = str_replace('-',' and ',$srch_area);
- $srch_area_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'area' and meta_value between $srch_area_str");
- }
- elseif(strstr($srch_area,'+'))
- {
- $srch_area_str = str_replace('+','',$srch_area);
- $srch_area_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'area' and meta_value >= $srch_area_str");
- }
- $all_pids_arr = array_intersect($all_pids_arr,$srch_area_pids_arr);
- }
- else if($_REQUEST['srch_keyword'] && $_REQUEST['srch_keyword']!=CITY_STATE_ZIP_SRCH_TEXT)
- {
- $is_search = 1;
- $srch_keyword = $_REQUEST['srch_keyword'];
- $srch_keyword_arr = explode(',',$srch_keyword);
- if(count($srch_keyword_arr)==1)
- {
- $add_city = $srch_keyword;
- $add_state = $srch_keyword;
- $add_zip_code = $srch_keyword;
- }elseif(count($srch_keyword_arr)==2)
- {
- $add_city = $srch_keyword_arr[0];
- $add_state = $srch_keyword_arr[1];
- $add_zip_code = $srch_keyword_arr[0];
- }elseif(count($srch_keyword_arr)==3)
- {
- $add_city = $srch_keyword_arr[0];
- $add_state = $srch_keyword_arr[1];
- $add_zip_code = $srch_keyword_arr[2];
- }
- $kw_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where (meta_key like 'add_city' and meta_value like \"$add_city\") or (meta_key like 'add_state' and meta_value like \"$add_state\") or (meta_key like 'add_zip_code' and meta_value like \"$add_zip_code\")");
- $all_pids_arr = array_intersect($all_pids_arr,$kw_pids_arr);
- }
- if($is_search && !$all_pids_arr)
- {
- $all_pids_arr[0] = 'nopost';
- }
- if($_REQUEST['srch_property_id'])
- {
- $post_ids_str = $_REQUEST['srch_property_id'];
- $sub_cat_sql .= " and p.ID in ($post_ids_str) ";
- }else
- {
- if($all_pids_arr)
- {
- $post_ids_str = implode(',',$all_pids_arr);
- if($post_ids_str)
- {
- $sub_cat_sql .= " and p.ID in ($post_ids_str) ";
- }
- }
- }
- $featurecat = get_cat_id_from_name(get_option('ptthemes_featuredcategory'));
- if($featurecat)
- {
- $srch_feature_pids = $wpdb->get_var("SELECT group_concat(tr.object_id) FROM $wpdb->term_taxonomy tt join $wpdb->term_relationships tr on tr.term_taxonomy_id=tt.term_taxonomy_id where tt.term_id in ($featurecat)");
- $srch_feature_pids = '';
- }
- $blogcat = get_cat_id_from_name(get_option('ptthemes_blogcategory'));
- $blogcatcatids = get_sub_categories($blogcat,'string');
- if($blogcatcatids)
- {
- $srch_blog_pids = $wpdb->get_var("SELECT group_concat(tr.object_id) FROM $wpdb->term_taxonomy tt join $wpdb->term_relationships tr on tr.term_taxonomy_id=tt.term_taxonomy_id where tt.term_id in ($blogcatcatids)");
- }
- if($srch_blog_pids && $srch_feature_pids)
- {
- $sub_cat_sql .= " and p.ID not in ($srch_blog_pids,$srch_feature_pids) ";
- }elseif($srch_blog_pids && $srch_feature_pids=='')
- {
- $sub_cat_sql .= " and p.ID not in ($srch_blog_pids) ";
- }elseif($srch_blog_pids=='' && $srch_feature_pids)
- {
- $sub_cat_sql .= " and p.ID not in ($srch_feature_pids) ";
- }
- $srch_sql = "select p.* from $wpdb->posts p $post_meta_join where p.post_status='publish' and p.post_type='post' $sub_cat_sql";
- if($srch_feature_pids)
- {
- $feature_srch_sql = "select p.* from $wpdb->posts p where p.post_status='publish' and p.post_type='post' and p.ID in ($srch_feature_pids)";
- $srch_sql = " select * from (($feature_srch_sql) union ($srch_sql))";
- }
- $totalpost_count = $wpdb->get_var("select count(p.ID) from $wpdb->posts p $post_meta_join where p.post_status='publish' and p.post_type='post' $sub_cat_sql");
- global $posts_per_page,$paged;
- if($paged==''){$paged=1;}
- $startlimit = $posts_per_page*($paged-1);
- $srch_sql .= " order by p.ID desc limit $startlimit , $posts_per_page";
- $post_info = $wpdb->get_results($srch_sql);
- ?> <!-- contentarea #end -->
- <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery.js"></script>
- <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/functions.js"></script>
- <div class="contentarea">
- <div class="content" >
- <div class="latestproperties latestproperties_<?php echo stripslashes(get_option('ptthemes_sidebar_left')); ?>">
- <h5>
- <span>
- <a href="#" class="switch_thumb">
- <?php
- if ($post_info)
- {
- _e(SWITCH_THUMB_TEXT);
- }
- ?>
- </a>
- </span>
- <?php
- if($_REQUEST['s'] == 'viewmore')
- {
- _e(LATEST_PROPERTIES_TEXT);
- }
- elseif(is_category() && $_REQUEST['search']=='')
- {
- echo single_cat_title();
- }else
- {
- //echo __(SEARCH_TEXT). get_search_param();
- echo get_search_param();
- }
- ?></h5>
- <?php if($post_info) { ?>
- <ul class="display ">
- <?php
- $count=0;
- foreach($post_info as $post_info_obj)
- {
- $count++;
- $post = $post_info_obj;
- get_property_info_li($post);
- if($count%3==0)
- {
- ?>
- <li class="blank"></li>
- <?php
- }
- }
- ?>
- </ul>
- <?php
- }else
- {
- if (!$_POST['submit'])
- {
- _e(NO_PROPERTY_AVAILABLE_MSG);
- }
- //Custom function to format price range
- function formatPrice($price)
- {
- $price = trim($price);
- if (!empty($price))
- {
- if (stristr($price,"-") == true)
- {
- $fee = explode("-",$price);
- return "N".number_format($fee[0])."-N".number_format($fee[1]);
- //echo $price;
- }
- else
- {
- $fee = substr($price,0,-1);
- return "N".number_format($fee)."+";
- }
- }
- else
- {
- echo "";
- }
- }
- $_SESSION['id'] = $current_user->data->ID;
- $srch_city = $_REQUEST['srch_city'];
- $srch_city = $wpdb->get_var("SELECT name FROM $wpdb->cities WHERE id = $srch_city");
- //Custom message to allow users save their searches.
- if ($_GET['srch_price'] == "All Price Range In =N=")
- {
- $_GET['srch_price'] = 0;
- }
- $wpdb->query("INSERT INTO $wpdb->wanted_properties
- VALUES('','$_GET[srch_price]','$_GET[srch_bedrooms]','$_GET[srch_area]','$_GET[srch_ptype]',
- '$_GET[srch_location]','$srch_city',CURDATE())");
- //echo "<br/>Omin".$current_user->data->ID;
- if (!empty($current_user->data->ID))
- {
- if (!$_POST['submit'])
- {
- echo "<br/>Save Your Search, your search terms will show up in our wanted directory so agents can view it.
- <br/><br/><h6>Below are your search criteria:</h6><br/>";
- //echo $_GET['srch_city'];
- }
- if($_POST['submit'])
- {
- if ($_GET['srch_price'] == "All Price Range In =N=")
- {
- $_GET['srch_price'] = 0;
- }
- $wpdb->query("INSERT INTO $wpdb->saved_search
- VALUES('','$_GET[srch_price]','$_GET[srch_bedrooms]','$_GET[srch_area]','$_GET[srch_ptype]',
- '$_GET[srch_location]','$srch_city','$_GET[srch_type]','$_SESSION[id]')");
- $message = "Your Search has been saved";
- }
- if ($message != "")
- {
- echo "<div class='sucess_msg'>$message</div>";
- }
- if(!$_POST['submit'])
- {
- echo "City: ".$srch_city."<br/>";
- echo "Location: ".$_GET['srch_location']."<br/>";
- echo "Type: ".$_GET['srch_type']."<br/>";
- if ($_GET['srch_price'] != "All Price Range In =N=")
- {
- echo "Price Range:".formatPrice($_GET['srch_price'])."<br/>";
- }
- else
- {
- echo "Price Range: Nill<br/>";
- }
- echo "Area(Sq. Ft): ".$_GET['srch_area']."<br/>";
- echo "Bedrooms: ".$_GET['srch_bedrooms']."<br/>";
- echo "<form method='post' action=''>
- <input type='submit' value='Save Search' name='submit'/>
- </form>";
- }
- }
- }
- ?>
- <?php if($post_info) { ?>
- <div class="pagination">
- <?php if (function_exists('wp_pagenavi')) { ?><?php wp_pagenavi(); ?><?php } ?>
- </div>
- <?php }?>
- </div>
- <?php get_sidebar(); ?> <!-- sidebar #end -->
- </div>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement