Advertisement
Guest User

Main Search File

a guest
May 27th, 2012
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.03 KB | None | 0 0
  1. <?php get_header(); ?>
  2. <?php
  3. if(isset($_GET['author_name'])) :
  4.     $curauth = get_userdatabylogin($author_name);
  5. else :
  6.     $curauth = get_userdata(intval($author));
  7. endif;
  8. ?>
  9.     <?php if (is_paged()) $is_paged = true; ?>
  10.    
  11.     <div class="wrapper" >
  12.         <div class="clearfix container_border">
  13.                <div class="breadcrumbs">
  14.                 <p><?php if ( get_option( 'ptthemes_breadcrumbs' )) { yoast_breadcrumb('',''); } ?></p>
  15.                     <span class="findproperties" onclick="show_hide_propertysearchoptions();"><a href="javascript:void(0);"><?php _e(FIND_PROPERTIES_TEXT);?></a></span>
  16.                 </div>
  17.             </div>
  18.     <?php require_once (TEMPLATEPATH . '/library/includes/search.php');  ?>
  19.         <?php
  20.         $is_search = 0;
  21.         global $wpdb;
  22.         $totalpost_count = 0;
  23.         $propertycategory = get_cat_id_from_name(get_option('ptthemes_propertycategory'));
  24.         $propertycategorys = get_sub_categories($propertycategory,'string');
  25.         $all_pids_arr = $wpdb->get_var("SELECT group_concat(ID) FROM $wpdb->posts where post_status='publish'");
  26.         $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)");
  27.         if($_REQUEST['srch_location'])
  28.         {
  29.             $is_search = 1;
  30.             $srch_location = $_REQUEST['srch_location'];
  31.             //$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\"");
  32.             $location_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'add_location' and meta_value like \"$srch_location\"");
  33.             $all_pids_arr = array_intersect($all_pids_arr,$location_pids_arr);
  34.         }
  35.        
  36.         else if($_REQUEST['srch_price'])
  37.         {
  38.             $is_search = 1;
  39.             $srch_price = $_REQUEST['srch_price'];
  40.            
  41.             /*$price = (explode("N",$_REQUEST['srch_price']));
  42.             $price = $price[1]."".$price[2];
  43.             $srch_price = trim($price);
  44.             $_GET['price'] = $price;*/
  45.            
  46.             if(strstr($srch_price,'-'))
  47.             {
  48.                 $srch_price_str = str_replace('-',' and ',$srch_price);
  49.                 $srch_price_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'price' and
  50.                 meta_value between $srch_price_str");
  51.             }
  52.             elseif(strstr($srch_price,'+'))
  53.             {
  54.                 $srch_price_str = str_replace('+','',$srch_price);
  55.                 $srch_price_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'price' and
  56.                 meta_value >= $srch_price_str");
  57.             }          
  58.             $all_pids_arr = array_intersect($all_pids_arr,$srch_price_arr);
  59.         }
  60.        
  61.         else if($_REQUEST['srch_bedrooms'])
  62.         {
  63.             $is_search = 1;
  64.             $srch_bedrooms = $_REQUEST['srch_bedrooms'];
  65.             //$srch_bedrooms = $wpdb->get_var("select group_concat(post_id) from $wpdb->postmeta where meta_key like 'bed_rooms' and meta_value = \"$srch_bedrooms\"");
  66.             //$srch_bedrooms_arr = explode(',',$srch_bedrooms);
  67.             $srch_bedrooms_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'bed_rooms' and meta_value = \"$srch_bedrooms\"");
  68.             $all_pids_arr = array_intersect($all_pids_arr,$srch_bedrooms_arr);
  69.         }
  70.         /*if($_REQUEST['srch_bathroom'])
  71.         {
  72.             $is_search = 1;
  73.             $srch_bathroom = $_REQUEST['srch_bathroom'];
  74.             $bathroom_pids_arr = $wpdb->get_col("select (post_id) from $wpdb->postmeta where meta_key like 'bath_rooms' and meta_value = \"$srch_bathroom\"");
  75.             $all_pids_arr = array_intersect($all_pids_arr,$bathroom_pids_arr);
  76.         }*/
  77.         else if($_REQUEST['srch_type'])
  78.         {
  79.             $is_search = 1;
  80.             $srch_type = $_REQUEST['srch_type'];
  81.             $type_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'property_type' and meta_value = \"$srch_type\"");
  82.             $all_pids_arr = array_intersect($all_pids_arr,$type_pids_arr);
  83.         }
  84.         else if($_REQUEST['srch_area'])
  85.         {
  86.             $is_search = 1;
  87.             $srch_area = $_REQUEST['srch_area'];
  88.             if(strstr($srch_area,'-'))
  89.             {
  90.                 $srch_area_str = str_replace('-',' and ',$srch_area);
  91.                 $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");
  92.             }
  93.             elseif(strstr($srch_area,'+'))
  94.             {
  95.                 $srch_area_str = str_replace('+','',$srch_area);
  96.                 $srch_area_pids_arr = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key like 'area' and meta_value >= $srch_area_str");
  97.             }      
  98.             $all_pids_arr = array_intersect($all_pids_arr,$srch_area_pids_arr);
  99.         }
  100.         else if($_REQUEST['srch_keyword'] && $_REQUEST['srch_keyword']!=CITY_STATE_ZIP_SRCH_TEXT)
  101.         {
  102.             $is_search = 1;
  103.             $srch_keyword = $_REQUEST['srch_keyword'];
  104.             $srch_keyword_arr = explode(',',$srch_keyword);
  105.             if(count($srch_keyword_arr)==1)
  106.             {
  107.                 $add_city = $srch_keyword;
  108.                 $add_state = $srch_keyword;
  109.                 $add_zip_code = $srch_keyword;
  110.             }elseif(count($srch_keyword_arr)==2)
  111.             {
  112.                 $add_city = $srch_keyword_arr[0];
  113.                 $add_state = $srch_keyword_arr[1];
  114.                 $add_zip_code = $srch_keyword_arr[0];
  115.             }elseif(count($srch_keyword_arr)==3)
  116.             {
  117.                 $add_city = $srch_keyword_arr[0];
  118.                 $add_state = $srch_keyword_arr[1];
  119.                 $add_zip_code = $srch_keyword_arr[2];
  120.             }
  121.             $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\")");
  122.             $all_pids_arr = array_intersect($all_pids_arr,$kw_pids_arr);
  123.         }
  124.         if($is_search && !$all_pids_arr)
  125.         {
  126.             $all_pids_arr[0] = 'nopost';
  127.         }
  128.         if($_REQUEST['srch_property_id'])
  129.         {
  130.             $post_ids_str = $_REQUEST['srch_property_id'];
  131.             $sub_cat_sql .= " and p.ID in ($post_ids_str) ";
  132.         }else
  133.         {
  134.             if($all_pids_arr)
  135.             {
  136.                 $post_ids_str = implode(',',$all_pids_arr);
  137.                 if($post_ids_str)
  138.                 {
  139.                     $sub_cat_sql .= " and p.ID in ($post_ids_str) ";
  140.                 }
  141.             }  
  142.         }
  143.         $featurecat = get_cat_id_from_name(get_option('ptthemes_featuredcategory'));
  144.         if($featurecat)
  145.         {
  146.             $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)");
  147.             $srch_feature_pids = '';
  148.         }
  149.         $blogcat = get_cat_id_from_name(get_option('ptthemes_blogcategory'));
  150.         $blogcatcatids = get_sub_categories($blogcat,'string');
  151.         if($blogcatcatids)
  152.         {
  153.             $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)");
  154.         }
  155.         if($srch_blog_pids && $srch_feature_pids)
  156.         {
  157.             $sub_cat_sql .= " and p.ID not in ($srch_blog_pids,$srch_feature_pids) ";
  158.         }elseif($srch_blog_pids && $srch_feature_pids=='')
  159.         {
  160.             $sub_cat_sql .= " and p.ID not in ($srch_blog_pids) ";
  161.         }elseif($srch_blog_pids=='' && $srch_feature_pids)
  162.         {
  163.             $sub_cat_sql .= " and p.ID not in ($srch_feature_pids) ";
  164.         }
  165.         $srch_sql = "select p.* from $wpdb->posts p $post_meta_join where p.post_status='publish' and p.post_type='post'  $sub_cat_sql";
  166.         if($srch_feature_pids)
  167.         {
  168.             $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)";
  169.             $srch_sql = " select * from (($feature_srch_sql) union ($srch_sql))";
  170.         }
  171.        
  172.         $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");
  173.         global $posts_per_page,$paged;
  174.         if($paged==''){$paged=1;}
  175.         $startlimit = $posts_per_page*($paged-1);
  176.         $srch_sql .= "  order by p.ID desc limit $startlimit , $posts_per_page";
  177.         $post_info = $wpdb->get_results($srch_sql);
  178.         ?> <!-- contentarea #end -->
  179.        
  180.  
  181. <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery.js"></script>
  182. <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/functions.js"></script>
  183.  
  184. <div class="contentarea">
  185. <div class="content" >
  186.     <div class="latestproperties latestproperties_<?php echo stripslashes(get_option('ptthemes_sidebar_left'));  ?>">
  187.         <h5>
  188.             <span>
  189.                 <a href="#" class="switch_thumb">
  190.                     <?php
  191.                         if ($post_info)
  192.                         {
  193.                             _e(SWITCH_THUMB_TEXT);
  194.                         }
  195.                     ?>
  196.                 </a>
  197.             </span>
  198.         <?php
  199.         if($_REQUEST['s'] == 'viewmore')
  200.         {
  201.             _e(LATEST_PROPERTIES_TEXT);
  202.         }
  203.         elseif(is_category() && $_REQUEST['search']=='')
  204.         {
  205.             echo single_cat_title();
  206.         }else
  207.         {
  208.             //echo __(SEARCH_TEXT). get_search_param();
  209.             echo get_search_param();
  210.         }  
  211.         ?></h5>    
  212.         <?php if($post_info) { ?>              
  213.        
  214.         <ul class="display ">
  215.         <?php
  216.         $count=0;
  217.         foreach($post_info as $post_info_obj)
  218.         {
  219.             $count++;
  220.             $post = $post_info_obj;
  221.             get_property_info_li($post);
  222.             if($count%3==0)
  223.             {
  224.             ?>
  225.             <li class="blank"></li>
  226.             <?php  
  227.             }
  228.         }
  229.         ?>
  230.         </ul>
  231.         <?php
  232.             }else
  233.             {
  234.                 if (!$_POST['submit'])
  235.                 {
  236.                     _e(NO_PROPERTY_AVAILABLE_MSG);
  237.                 }
  238.                
  239.                 //Custom function to format price range
  240.                 function formatPrice($price)
  241.                 {
  242.                     $price = trim($price);
  243.                     if (!empty($price))
  244.                     {
  245.                         if (stristr($price,"-") == true)
  246.                         {
  247.                             $fee = explode("-",$price);
  248.                             return "N".number_format($fee[0])."-N".number_format($fee[1]);
  249.                             //echo $price;
  250.                         }
  251.                         else
  252.                         {
  253.                             $fee = substr($price,0,-1);
  254.                             return "N".number_format($fee)."+";
  255.                         }
  256.                     }
  257.                     else
  258.                     {
  259.                         echo "";
  260.                     }
  261.                    
  262.                 }
  263.                
  264.                
  265.                 $_SESSION['id'] = $current_user->data->ID;
  266.                
  267.                 $srch_city = $_REQUEST['srch_city'];
  268.                 $srch_city = $wpdb->get_var("SELECT name FROM $wpdb->cities WHERE id = $srch_city");
  269.                
  270.                 //Custom message to allow users save their searches.
  271.                
  272.                 if ($_GET['srch_price'] == "All Price Range In =N=")
  273.                 {
  274.                     $_GET['srch_price'] = 0;
  275.                 }
  276.                 $wpdb->query("INSERT INTO $wpdb->wanted_properties
  277.                                   VALUES('','$_GET[srch_price]','$_GET[srch_bedrooms]','$_GET[srch_area]','$_GET[srch_ptype]',
  278.                                   '$_GET[srch_location]','$srch_city',CURDATE())");
  279.                
  280.                
  281.                    
  282.                 //echo "<br/>Omin".$current_user->data->ID;
  283.                 if (!empty($current_user->data->ID))
  284.                 {
  285.                         if (!$_POST['submit'])
  286.                         {
  287.                             echo "<br/>Save Your Search,  your search terms will show up in our wanted directory so agents can view it.
  288.                             <br/><br/><h6>Below are your search criteria:</h6><br/>";
  289.                             //echo $_GET['srch_city'];
  290.                         }
  291.                         if($_POST['submit'])
  292.                         {
  293.                             if ($_GET['srch_price'] == "All Price Range In =N=")
  294.                             {
  295.                                 $_GET['srch_price'] = 0;
  296.                             }
  297.                             $wpdb->query("INSERT INTO $wpdb->saved_search
  298.                                           VALUES('','$_GET[srch_price]','$_GET[srch_bedrooms]','$_GET[srch_area]','$_GET[srch_ptype]',
  299.                                           '$_GET[srch_location]','$srch_city','$_GET[srch_type]','$_SESSION[id]')");
  300.                            
  301.                                 $message = "Your Search has been saved";
  302.                            
  303.                         }
  304.                         if ($message != "")
  305.                         {
  306.                             echo "<div class='sucess_msg'>$message</div>";
  307.                         }
  308.                        
  309.                        
  310.                         if(!$_POST['submit'])
  311.                         {
  312.                             echo "City: ".$srch_city."<br/>";
  313.                             echo "Location: ".$_GET['srch_location']."<br/>";
  314.                             echo "Type: ".$_GET['srch_type']."<br/>";
  315.                             if ($_GET['srch_price'] != "All Price Range In =N=")
  316.                             {
  317.                                 echo "Price Range:".formatPrice($_GET['srch_price'])."<br/>";
  318.                             }
  319.                             else
  320.                             {
  321.                                 echo "Price Range: Nill<br/>";
  322.                             }
  323.                             echo "Area(Sq. Ft): ".$_GET['srch_area']."<br/>";
  324.                             echo "Bedrooms: ".$_GET['srch_bedrooms']."<br/>";
  325.                            
  326.                             echo "<form method='post' action=''>
  327.                                     <input type='submit' value='Save Search' name='submit'/>
  328.                                   </form>";
  329.                            
  330.                         }
  331.                 }
  332.                
  333.                
  334.             }
  335.             ?>
  336.         <?php if($post_info) { ?>
  337.         <div class="pagination">
  338.              <?php if (function_exists('wp_pagenavi')) { ?><?php wp_pagenavi(); ?><?php } ?>
  339.          </div>
  340.         <?php }?>
  341. </div>
  342.  
  343. <?php get_sidebar(); ?>  <!-- sidebar #end -->
  344. </div>
  345.  
  346. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement