<?php
function DoEvents($this) {
global $_CONF, $_PAGE, $_TSM , $base;
$jpp = (int)$this->vars->data["ipp"];
$confirm = array("1" => "yes" , "0" => "no");
$tmp = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[areas]} ");
if (is_array($tmp)) {
foreach ($tmp as $key => $val)
$cache["area"][$val["area_id"]] = $val["area_name"];
}
$tmp = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[types]} ");
if (is_array($tmp)) {
foreach ($tmp as $key => $val)
$cache["type"][$val["type_id"]] = $val["type_name"];
}
$tmp = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[schools]} ");
if (is_array($tmp)) {
foreach ($tmp as $key => $val)
$cache["school"][$val["school_id"]] = $val["school_name"];
}
$tmp = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[photos]} ");
if (is_array($tmp)) {
foreach ($tmp as $key => $val)
if (!$cache["images"][$val["property"]]) {
if (is_file("upload/tn_photo_" . $val["id"] . ".jpg")) {
$cache["images"][$val["property"]] = $val["id"];
}
}
}
/* * Area
* Price Range
* City
* State/Province
* Zip/Postal Code
* Bedrooms Range
* Bathroom Range
* School District
* Square Feet
* WaterFront
*/
switch ($_GET["sub"]) {
case "error":
return $this->templates["error"]->output;
break;
case "search":
$data = $_GET;
$_states = $this->db->QFetchRowArray("SELECT * FROM states");
foreach ($_states as $key => $val)
$states[$val["code"]] = $val["name"];
$data["state"] = $base->html->FormSelect("state" , $states, $this->templates["search"] , "Select" , $_GET["state"]);
$_areas = $this->db->QFetchRowArray("SELECT * FROM site_areas");
foreach ($_areas as $key => $val)
$areas[$val["area_id"]] = $val["area_name"];
$data["area_drop"] = $base->html->FormSelect("area" , $areas, $this->templates["search"] , "Select" , $_GET["area"]);
$_schools = $this->db->QFetchRowArray("SELECT * FROM site_schools");
foreach ($_schools as $key => $val)
$schools[$val["school_id"]] = $val["school_name"];
$data["school"] = $base->html->FormSelect("school" , $schools, $this->templates["search"] , "Select" , $_GET["school"]);
$data["water_checked"] = $_GET["water"] ? "checked" : "";
$this->templates["search"]->blocks["Search"]->Replace($data , false);
$form = $this->templates["search"]->blocks["Search"]->EmptyVars();
//check if there was tried a search
if ($_GET["area"] || $_GET["pf"] || $_GET["pt"] || $_GET["city"] || $_GET["state"] || $_GET["zip"] || $_GET["bf"] || $_GET["bt"] || $_GET["b1f"] || $_GET["b1t"] || $_GET["school"] || $_GET["square"]) {
//ok, this was a search
//build the search query
if ($_GET["area"])
$query[] = " `area`='{$_GET[area]}' ";
if ($_GET["pf"] || $_GET["pt"])
$query[] = " (price >= " . (int) $_GET["pf"] . "" . ($_GET["pt"] ? " AND price <= " . (int) $_GET["pt"] . "" : "") . ") ";
if ($_GET["city"])
$query[] = " city = '{$_GET[city]}' ";
if ($_GET["state"])
$query[] = " state = '{$_GET[state]}' ";
if ($_GET["zip"])
$query[] = " zip = '{$_GET[zip]}' ";
if ($_GET["bf"] || $_GET["bt"])
$query[] = " (beds >= " . (int) $_GET["bf"] . "" . ($_GET["bt"] ? " AND beds <= " . (int) $_GET["bt"] . "" : "") . ") ";
if ($_GET["b1f"] || $_GET["b1t"])
$query[] = " (bath >= " . (int) $_GET["b1f"] . "" . ($_GET["b1t"] ? " AND bath <= " . (int) $_GET["b1t"] . "" : "") . ") ";
if ($_GET["school"])
$query[] = " school = '{$_GET[school]}' ";
if ($_GET["square"])
$query[] = " square = '{$_GET[square]}' ";
if ($_GET["water"])
$query[] = " water = '" . (int)$_GET["water"] . "' ";
if (is_array($query)) {
$page = $_GET["page"] ? ($_GET["page"] - 1) * $jpp : 0;
$properties = $this->db->QFetchRowArray("SELECT * FROM site_properties WHERE" . implode(" AND " , $query) . " AND status=1 LIMIT $page,$jpp");
$count = $this->db->RowCount($this->tables["properties"] , "WHERE " . implode(" AND " , $query) . " AND status=1");
} else
return $form;
} else
return $form;
break;
case "details":
$property = $this->db->QFetchArray("SELECT * FROM {$this->tables[properties]} WHERE id='{$_GET[id]}'");
if (is_array($property)) {
$property["type"] = $cache["type"][$property["type"]];
$property["area"] = $cache["area"][$property["area"]];
$property["school"] = $cache["school"][$property["school"]];
$property["garage"] = $confirm[$property["garage"]];
$property["water"] = $confirm[$property["water"]];
$property["price"] = number_format($property["price"] , 2);
$property["referer"] = $_SERVER["HTTP_REFERER"] ? $_SERVER["HTTP_REFERER"] : "list.php";
//read the images if are any
$images = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[photos]} WHERE property='{$_GET[id]}'");
if (is_array($images)) {
foreach ($images as $key => $image) {
$images["$key"]["source"] = $image["image"] ? "upload/photo_" . $image["id"] . ".jpg" : "upload/tn_photo_" . $image["id"] . ".jpg";
$images["$key"]["source1"] = $image["tn"] ? "upload/tn_photo_" . $image["id"] . ".jpg" : "upload/photo_" . $image["id"] . ".jpg";
}
$images = $base->html->Table($this->templates["details"],"List",$images);
} else
$images = "";
return $this->templates["details"]->blocks["Main"]->Replace($property) . $images;
} else {
header("Location: error.php");
exit;
}
break;
default:
$page = $_GET["page"] ? ($_GET["page"] - 1) * $jpp : 0;
$properties = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[properties]} WHERE status=1 LIMIT $page , $jpp ");
$count = $this->db->RowCount($this->tables["properties"] , "WHERE status=1");
break;
}
$alternance = 1;
if (is_array($properties)) {
foreach ($properties as $key => $val) {
$properties[$key]["type"] = $cache["type"][$val["type"]];
$properties[$key]["area"] = $cache["area"][$val["area"]];
$properties[$key]["school"] = $cache["school"][$val["school"]];
$properties[$key]["garage"] = $confirm[$val["garage"]];
$properties[$key]["water"] = $confirm[$val["water"]];
$properties[$key]["price"] = number_format($val["price"] , 2);
//also add the alternance template
$properties[$key]["alternance"] = $this->templates["list"]->blocks["Alternance" . $alternance]->output;
if ($cache["images"][$val["id"]]) {
$properties[$key]["image"] = $this->templates["list"]->blocks["Image"]->Replace(array("SOURCE" => "upload/tn_photo_" . $cache["images"][$val["id"]] . ".jpg"));
} else {
$properties[$key]["image"] = "";
}
//switch
$alternance = !$alternance;
}
}
//build a table with the results;
//well ok, now show the list with the templates
if (is_array($_GET)) {
foreach ($_GET as $key => $val) {
if ($key != "page")
$out[] = "$key=" . urlencode($val);
}
$extra = is_array($out) ? implode("&" , $out) . "&" : "";
}
return $form . $base->html->Table($this->templates["list"],"List",$properties,true,$count,$jpp,$_GET["page"],$this->templates["paging"],array(
"base" => in_array($_GET["sub"] , array ("department" , "category" , "search")) ? $_GET["sub"] . ".php" : "list.php" ,
"extra" => $extra,
"what" => $_GET["what"] ? "what=" . $_GET["what"] . "&" : ""
));
}
?>