<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  $libraryPath = '/cms/lib/viewer_functions.php';
  $dirsToCheck = array('/home/property/public_html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  list($propertiesRecords, $propertiesMetaData) = getRecords(array(
    'tableName'   => 'properties',
    'loadUploads' => true,
    'allowSearch' => true,
	'useSeoUrls'  => true,
    'perPage'     => '20',	
	'where'       => "hide_property != 1",			
  ));
  
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-img-width="1600" data-img-height="1064">
<head>
<title>Property for sale</title>

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Find your ideal property, search a wide range of properties for sale." />

<link rel="shortcut icon" href="/css/villas.ico" /> 
<link rel="stylesheet" href="/css/villas.css" type="text/css" />

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="/js/villas.js"></script>

<link rel="stylesheet" href="/heapbox/themes/belize_hole/css/belize_hole.css" type="text/css" media="screen" />
<script src="/heapbox/src/jquery.heapbox-0.9.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#price_min").heapbox();
$("#price_max").heapbox();
$("#property_type").heapbox();
$("#bedrooms").heapbox();
$("#bathrooms").heapbox();
$("#town").heapbox();
});
</script>
</head>
<body>
<? include "header.php" ?>

<div class="container">	
<? include "menu.php" ?>

<div class="content">
<h1>
<?php echo $propertiesMetaData['totalRecords'] ?>
<? if (@$_REQUEST['property_type']): {echo " ";} ?><?php endif ?>
<? if (@$_REQUEST['property_type']): {echo @$_REQUEST['property_type'];} ?><?php endif ?>
<?php if($propertiesMetaData['totalRecords'] == '1'): ?> Listing<?php endif ?>
<?php if($propertiesMetaData['totalRecords'] != '1'): ?> Listings<?php endif ?>
</h1>
<span class="yellowline"></span>

<form name="myform" action="/properties-for-sale.php" method="get">

<select name="price_min" id="price_min">
<option value="">Minimum Price</option>
<option value="50000"<?php if($_GET['price_min']=='50000') echo 'selected="selected"';?>>50.000</option>
<option value="100000"<?php if($_GET['price_min']=='100000') echo 'selected="selected"';?>>100.000</option>
<option value="150000"<?php if($_GET['price_min']=='150000') echo 'selected="selected"';?>>150.000</option>
<option value="200000"<?php if($_GET['price_min']=='200000') echo 'selected="selected"';?>>200.000</option>
<option value="250000"<?php if($_GET['price_min']=='250000') echo 'selected="selected"';?>>250.000</option>
<option value="300000"<?php if($_GET['price_min']=='300000') echo 'selected="selected"';?>>300.000</option>
<option value="400000"<?php if($_GET['price_min']=='400000') echo 'selected="selected"';?>>400.000</option>
<option value="600000"<?php if($_GET['price_min']=='600000') echo 'selected="selected"';?>>500.000</option>
</select>

<select name="price_max" id="price_max">
<option value="">Maximum Price</option>
<option value="100000"<?php if($_GET['price_max']=='100000') echo 'selected="selected"';?>>100.000</option>
<option value="150000"<?php if($_GET['price_max']=='150000') echo 'selected="selected"';?>>150.000</option>
<option value="200000"<?php if($_GET['price_max']=='200000') echo 'selected="selected"';?>>200.000</option>
<option value="250000"<?php if($_GET['price_max']=='250000') echo 'selected="selected"';?>>250.000</option>
<option value="300000"<?php if($_GET['price_max']=='300000') echo 'selected="selected"';?>>300.000</option>
<option value="400000"<?php if($_GET['price_max']=='400000') echo 'selected="selected"';?>>400.000</option>
<option value="600000"<?php if($_GET['price_max']=='600000') echo 'selected="selected"';?>>500.000</option>
</select>>

<select name="property_type" id="property_type">
<option value = "" <?php selectedIf($value, @$_REQUEST['property_type']);?>>Property Type</option>
<?php foreach (getListOptions('properties', 'property_type') as $value => $label): ?>
<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['property_type']);?>><?php echo $label; ?></option>
<?php endforeach ?>
</select>

<select name="bedrooms" id="bedrooms">
<option value = "" <?php selectedIf($value, @$_REQUEST['bedrooms']);?>>Bedrooms</option>
<?php foreach (getListOptions('properties', 'bedrooms') as $value => $label): ?>
<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['bedrooms']);?>><?php echo $label; ?></option>
<?php endforeach ?>
</select>

<select name="bathrooms" id="bathrooms">
<option value = "" <?php selectedIf($value, @$_REQUEST['bathrooms']);?>>Bathrooms</option>
<?php foreach (getListOptions('properties', 'bathrooms') as $value => $label): ?>
<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['bathrooms']);?>><?php echo $label; ?></option>
<?php endforeach ?>
</select>
<span class="whiteline"></span>
<select name="town" id="town">
<option value = "" <?php selectedIf($value, @$_REQUEST['town']);?>>All Towns</option>
<?php foreach (getListOptions('properties', 'town') as $value => $label): ?>
<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['town']);?>><?php echo $label; ?></option>
<?php endforeach ?>
</select>
<span class="whiteline"></span>
<input type="submit" name="submit" value="Search" class="search">
</form>

<span class="yellowline"></span>

<?php foreach ($propertiesRecords as $record): ?>
<div class="property">

<div class="left-text">
<h4><?php echo htmlencode($record['title']) ?></h4>
<p><?php echo $record['bedrooms'] ?> bedroom <? $str = $record['type']; $str = strtolower($str); echo $str; ?> <? $str = $record['location']; $str = strtolower($str); echo $str; ?> <? $str = $record['property_type']; $str = strtolower($str); echo $str; ?> for sale in <?php echo $record['town'] ?>, <?php echo $record['province'] ?>.</p>

<ul>
<li><strong>Bedrooms:</strong> <?php echo $record['bedrooms'] ?></li>
<li><strong>Bathrooms:</strong> <?php echo $record['bathrooms'] ?></li>
</ul>

<ul>
<li><strong><?php if($record['exact_price_or_price_from'] == 'Price From'): ?>Price from: <?php endif ?><?php if($record['exact_price_or_price_from'] == 'Exact Price'): ?>Price: <?php endif ?></strong><?php
$number = htmlencode($record['price']);
setlocale(LC_MONETARY,"de_DE");
echo money_format("%.0n", $number);
?></li>
</ul>

<ul><li><a href="<?php echo $record['_link'] ?>" title="<?php echo $record['bedrooms'] ?> bedroom <? $str = $record['property_type']; $str = strtolower($str); echo $str; ?> for sale in <?php echo $record['town'] ?>">Read more about this <?php echo $record['bedrooms'] ?> bedroom <? $str = $record['property_type']; $str = strtolower($str); echo $str; ?> for sale in <?php echo $record['town'] ?></a></li></ul>

<ul>
<li><strong>Reference:</strong> <?php echo htmlencode($record['reference']) ?></li>
</ul>
</div>

</div>
<?php foreach ($record['photos'] as $index => $upload): ?>

<div class="photos">
<a href="<?php echo $record['_link'] ?>" title="<?php echo $record['bedrooms'] ?> bedroom <? $str = $record['property_type']; $str = strtolower($str); echo $str; ?> for sale in <?php echo $record['town:label'] ?>">
<img src="<?php echo $upload['urlPath'] ?>" alt="<?php echo htmlencode($upload['info1']) ?>" class="property-photos" />  
</a>
</div>

<?php break ?>
<?php endforeach ?>
<span class="yellowline"></span>

<?php endforeach ?>

<?php if (!$propertiesRecords): ?>
<h2>No properties matched your search criteria</h2>
<?php endif ?>

<?php if ($propertiesMetaData['prevPage']): ?>
<a href="<?php echo $propertiesMetaData['prevPageLink'] ?>" title="Property for sale">&lt;&lt; Previous page</a> 
<?php endif ?>
<?php if ($propertiesMetaData['prevPage']&&$propertiesMetaData['nextPage']): ?>
| 
<?php endif ?>
<?php if ($propertiesMetaData['nextPage']): ?>
<a href="<?php echo $propertiesMetaData['nextPageLink'] ?>" title="Property for sale">Next page &gt;&gt;</a>
<?php endif ?>
<?php if ($propertiesMetaData['prevPage']||$propertiesMetaData['nextPage']): ?>
<span class="yellowline"></span>
<p>Page <?php echo $propertiesMetaData['page'] ?> of <?php echo $propertiesMetaData['totalPages'] ?> - <?php echo $propertiesMetaData['totalRecords'] ?> Properties</p>
<?php endif ?>
</div>
</div>
<? include "menu-js.php" ?>

</body>
</html>