include ("includes/header.php");
?>
//get search criteria
$action=$_REQUEST['action'];
if($action=="newsearch")
{
//UNSET PREVIOUS SESSION VARIABLES
unset($_SESSION['search_country']);
unset($_SESSION['search_city']);
unset($_SESSION['search_property']);
unset($_SESSION['search_feature']);
unset($_SESSION['saletype']);
unset($_SESSION['searchsession']);
$search_country=$_REQUEST['search_country'];
$search_city=$_REQUEST['search_city'];
$search_property=$_REQUEST['search_property'];
$search_feature=$_REQUEST['search_feature'];
$search_saletype=$_REQUEST['search_saletype'];
$_SESSION['search_country']=$search_country;
$_SESSION['search_city']=$search_city;
$_SESSION['search_property']=$search_property;
$_SESSION['search_feature']=$search_feature;
$_SESSION['search_saletype']=$search_saletype;
$_SESSION['searchsession']="set";
}
if ($action=="minisearch")
{
$mini_search_string=$_REQUEST['mini_search_string'];
$_SESSION['searchsession']="set";
$searchtext="property_id>0 AND status>10 AND (description LIKE '%$mini_search_string%' OR country LIKE '%$mini_search_string%' OR city LIKE '%$mini_search_string%' OR custom1 LIKE '%$mini_search_string%' OR custom2 LIKE '%$mini_search_string%' OR custom3 LIKE '%$mini_search_string%' OR property_id='$mini_search_string' )";
}
else
{
//if no search has been performed, go back to home page
if ($_SESSION['searchsession'] !="set")
echo "";
//get variables from session
$search_country=$_SESSION['search_country'];
$search_city=$_SESSION['search_city'];
$search_property=$_SESSION['search_property'];
$search_feature=$_SESSION['search_feature'];
$search_saletype=$_SESSION['search_saletype'];
//Now set up the search text string
$searchtext="property_id>0 AND status>10 ";
if ($search_country !="" && $search_country!=="-")
$searchtext.="AND country='$search_country' ";
if ($search_city !="" )
$searchtext.="AND city='$search_city' ";
if ($search_property !="")
$searchtext.="AND property='$search_property' ";
if ($search_feature !="")
$searchtext.="AND feature='$search_feature' ";
if ($search_saletype !="")
$searchtext.="AND saletype='$search_saletype' ";
//Remove the last comma if there is one
$len=strlen($searchtext)-1;
$lastchar=$searchtext{$len};
if ($lastchar==",")
$searchtext=substr($searchtext,0,$len);
}
if (strlen($searchtext)>1)
$result=mysql_query(" SELECT * FROM properties WHERE $searchtext ORDER BY property_id DESC");
else
$result=mysql_query(" SELECT * FROM properties LIMIT 201");
$num=mysql_numrows($result);
if ($num>199)
{
$num=200;
$over="over";
}
//work out results per page to get start and end rows
$perpage=10;
$page=$_REQUEST['page'];
$last=ceil($num/$perpage);
if (!isset($page))
{
$page=1;
$start=0;
$end=$perpage;
}
else
{
$end=$perpage*$page;
$start=$end-$perpage;
}
$startshow=$start+1;
if ($end>$num)
$endshow=$num;
else
$endshow=$end;
//Debug Only
//echo "perpage=$perpage, page=$page, start=$start, end=$end last=$last
";
if ($num==0 )
{
echo "No listings found matching those search criteria
Try searching again ";
}
else
{
echo "
";
$i=$start;
while ($i<$end && $i<$num)
{
$property_id=mysql_result($result,$i,"property_id");
$country=mysql_result($result,$i,"country");
$city=mysql_result($result,$i,"city");
$description=mysql_result($result,$i,"description");
$pic=mysql_result($result,$i,"pic");
$description=substr($description,0,185);
if (!file_exists("images/properties/$property_id/$pic"))
{
$pic="art/1.jpg";
$thumb="art/1_thumb.jpg";
}
else
$thumb="images/properties/$property_id/thumbs/$pic";
echo "
$city, $country - Property #$property_id
|
";
if ($i==$start+4)
echo "
";
//Now do navigation links
$next=$page+1;
$prev=$page-1;
$viewpages=11;
$displaylast=$page+$viewpages;
$displayfirst=$page-$viewpages;
if($displaylast>$last)
$displaylast=$last;
if($displayfirst<2)
$displayfirst=1;
if ($next>$last)
$next=$last;
if ($prev<2)
$prev=1;
echo "
";
}
?>
include ("includes/search.php");
?>
include ("includes/footer.php");
?>