<?php
Class ListLocations {
protected $locationType;
protected $locationID;
protected $locType;
protected $name;
function __construct($locationType, $locationID) {
$this->locationType = $locationType;
$this->locationID = $locationID;
if ($this->locationType == 'Category') {
$this->getCategories();
} else if ($this->locationType == 'City') {
$this->showCityEntries();
} else if ($this->locationType == 'State') {
$this->getCities();
} else if ($this->locationType == 'Country') {
$this->getStates();
} else if ($this->locationType == 'ViewAllCountries') {
$this->getCountries();
}
}
function getStates() {
$this->stateResource = mysql_query("SELECT * FROM State WHERE countryID='$this->locationID'");
$this->outputList($this->stateResource, 'State');
}
function getCities() {
$this->cityResource = mysql_query("SELECT * FROM Cities WHERE stateID='$this->locationID'");
$this->outputList($this->cityResource, 'Category');
}
function getCountries() {
$this->countryResource = mysql_query("SELECT * FROM Countries");
$this->outputList($this->countryResource, 'Country');
}
function getCategories() {
$this->categoryResource = mysql_query("SELECT * FROM Categories");
$this->outputCategories($this->categoryResource, $this->locationID);
}
function showCityEntries() {
$this->listingsResource = mysql_query("SELECT * FROM Postings WHERE CityID='$this->locationID' ORDER BY datePosted");
$this->outputEntries($this->listingsResource);
$this->postAnAddAvailable = 1;
}
function outputList($resource, $locType) {
while ($row = mysql_fetch_assoc($resource)) {
$url = LOCATION_CAT . "?locationType=$locType&id=" . $row['id'];
$name = $row['name'];
$html = '<ul>';
$html .= "<li><a href='$url' title='$name'>$name</a></li>";
$html .= '</ul>';
echo $html;
}
}
function outputCategories($resource, $cityID) {
while ($row = mysql_fetch_assoc($resource)) {
$catID = $row['id'];
$url = LOCATION_CAT . "?locationType=City&id=$cityID&catID=$catID";
$name = $row['name'];
$html = '<ul>';
$html .= "<li><a href='$url' title='$name'>$name</a></li>";
$html .= '</ul>';
echo $html;
}
}
function outputEntries($resource) {
while ($row = mysql_fetch_assoc($resource)) {
$url = VIEW_POSTING . "?id=" . $row['id'];
$name = $row['name'];
$html = '<ul>';
$html .= "<li><a href='$url' title='$name'>$name</a></li>";
$html .= '</ul>';
echo $html;
}
}
}
?>