<?php
// Script to generate the dynamic page content
// print '<div class="debug">Start of script</div>' . "\n";
require 'listing.inc';
function displayNavigation($pageCount, $curPage)
{
// Is there more than one page?
if ($pageCount > 1)
{
// Yes - build the page navigation display
if ($curPage > 1)
{
$prevPage = $curPage - 1;
// Not on page 1: the "<" should be a link
print "<a href=\"Properties.php?page={$prevPage}\"><</a> ";
}
else
{
// Page 1: static "<"
print '< ';
$curPage = 1;
}
// Page links before the current page
for ($index = 1; $index < $curPage; $index++)
{
print "<a href=\"Properties.php?page={$index}\">{$index}</a> ";
}
// Current page
print "{$curPage} ";
// Page links following the current page
for ($index = $curPage + 1; $index <= $pageCount; $index++)
{
print "<a href=\"Properties.php?page={$index}\">{$index}</a> ";
}
$nextPage = $curPage + 1;
if ($nextPage < $pageCount)
{
// Not on last page: the ">" should be a link
print " <a href=\"Properties.php?page={$nextPage}\">></a>";
}
else
{
// Last page: static ">"
print ' >';
}
}
}
function displayProperties($result, $currentProperty, $propertyCount)
{
$curRow = 0;
while (($row = @ mysql_fetch_array($result)) && ($currentProperty < $propertyCount) && ($curRow < 5))
{
if (0 != $curRow)
{
insertSpacer();
}
$imageFile = "photos/tBRANCH_{$row["PropertyID"]}.jpg";
// print '<div class="debug">Raw row:';
// print "{$row}";
// print '</div>' . "\n";
// Display the data for one entry
print ' <tr>' . "\n";
print ' <td height="22" bgcolor="#01009A"> </td>' . "\n";
print ' <td colspan="3" bgcolor="#01009A"><span class="style42">';
print "{$row["PropertyName"]}";
print '</span></td>' . "\n";
print ' <td bgcolor="#01009A"><span class="style26"><span class="style24">£';
print "{$row["Price"]}";
print ' PCM</span></span></td>' . "\n";
print ' <td bgcolor="#01009A"><span class="style26"></span></td>' . "\n";
print ' </tr>' . "\n";
print ' <tr>' . "\n";
print ' <td height="90" bgcolor="#CCCCCC"> </td>' . "\n";
print "\n";
print ' <td bgcolor="#CCCCCC"><span class="style26"><a href="javascript:;">';
print "<img src=\"{$imageFile}\"";
print ' width="170" height="128" border="0" onclick="';
print "MM_openBrWindow('pop_up.php?propID={$row["PropertyID"]}','Details1','scrollbars=yes,resizable=yes,width=900,height=650')";
print '" /></a></span></td>' . "\n";
print ' <td bgcolor="#336699"><span class="style26"><br /></span></td>' . "\n";
print ' <td bgcolor="#336699"><div align="justify"><span class="style39">';
print "{$row["ShortDescription"]}";
print '</span></div></td>' . "\n";
print ' <td bgcolor="#336699"> </td>' . "\n";
print ' </tr>' . "\n";
print ' <tr>' . "\n";
print "\n";
print ' <td height="19" bgcolor="#01009A"> </td>' . "\n";
print ' <td bgcolor="#01009A"><div align="center" class="style25"><a href="javascript:;" class="style43" onclick="';
print "MM_openBrWindow('pop_up.php?propID={$row["PropertyID"]}','Details1','scrollbars=yes,resizable=yes,width=845,height=600')";
print '">Details</a></div></td>' . "\n";
print ' <td bgcolor="#01009A"> </td>' . "\n";
print ' <td bgcolor="#01009A"><div align="center"></div></td>' . "\n";
print ' <td bgcolor="#01009A"><span class="style30"><a href="mailto:?subject=';
print "{$row["PropertyName"]}";
print '" >Send Enquiry</a> </span></td>' . "\n";
print ' </tr>' . "\n";
$currentProperty++;
$curRow++;
}
// Generate any missing table cells
for ( ; ($curRow < 5) && ($currentProperty >= $propertyCount); $curRow++)
{
print ' <tr>' . "\n";
print ' <td height="22" bgcolor="#547CAD"> </td>' . "\n";
print ' <td colspan="2" bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' </tr>' . "\n";
print ' <tr>' . "\n";
print ' <td height="90" bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' </tr>' . "\n";
print ' <tr>' . "\n";
print ' <td height="19" bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' <td bgcolor="#547CAD"> </td>' . "\n";
print ' </tr>' . "\n";
}
}
function insertSpacer()
{
print ' <tr>' . "\n";
print "\n";
print ' <td height="19"> </td>' . "\n";
print ' <td> </td>' . "\n";
print ' <td> </td>' . "\n";
print ' <td> </td>' . "\n";
print ' <td> </td>' . "\n";
print ' <tr>' . "\n";
}
if (array_key_exists("page", $_GET))
$currentPage = $_GET["page"];
else
$currentPage = 0; // Indicates request for first page
// print '<div class="debug">Page number=' . $currentPage . "\n";
$query = "SELECT PropertyID, PropertyName, Price, ShortDescription FROM listings";
// print '<div class="debug">Connecting to server</div>' . "\n";
// Connect to the server
if (!($connection = @ mysql_connect($hostName, $userName, $password)))
die("Cannot connect to server {$hostName}");
// print '<div class="debug">Opening database</div>' . "\n";
// Select the database
if (!(mysql_select_db($databaseName, $connection)))
showDbError();
// print '<div class="debug">Issuing query</div>' . "\n";
if (!($result = @ mysql_query($query, $connection)))
showDbError();
// How many properties must be displayed?
$propertyCount = mysql_num_rows($result);
// Set current property to index of first property to display (0-based)
if (0 == $currentPage)
$currentProperty = 0;
else
$currentProperty = ($currentPage - 1) * 5;
// Number of properties to skip to get to this page
if ($currentProperty > 4)
$seekCount = $currentProperty;
else
$seekCount = 0;
$pageCount = ($propertyCount + 4) / 5;
// print '<div class="debug">Property count=' . "{$propertyCount} Current property={$currentProperty} Seek count={$seekCount}</div>\n";
// Skip properties that belong on previous pages
if (0 != $seekCount)
{
if (!(mysql_data_seek($result, $seekCount)))
showDbError();
}
// print '<div class="debug">Displaying output</div>' . "\n";
print ' <tr>' . "\n";
print "\n";
print ' <td width="10" height="33" bgcolor="#547CAD"> </td>' . "\n";
print ' <td width="176" bgcolor="#547CAD"> </td>' . "\n";
print ' <td width="35" bgcolor="#547CAD"> </td>' . "\n";
print ' <td width="270" bgcolor="#547CAD"><div align="center"><span class="style46">';
displayNavigation($pageCount, $currentPage);
print '</span></div></td>' . "\n";
print ' <td width="110" bgcolor="#547CAD"> </td>' . "\n";
print ' </tr>' . "\n";
displayProperties($result, $currentProperty, $propertyCount);
print ' <tr>' . "\n";
print "\n";
print ' <td height="57"> </td>' . "\n";
print ' <td> </td>' . "\n";
print ' <td> </td>' . "\n";
print ' <td width="270" bgcolor="#547CAD"><div align="center"><span class="style46">';
displayNavigation($pageCount, $currentPage);
print '</span></div></td>' . "\n";
print ' <td> </td>' . "\n";
print ' </tr>' . "\n";
?>