<?php
class location {
    // print state list
	static function getCountyList($listName = "", $id="", $width = 250, $return_type=0, $className="" ){
  		global $db,$conn;		
		$result = $db->query("SELECT * FROM counties ORDER BY county");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['county'];
			}			
		}		
		if($return_type){
			return $dataArray;
		}else{
			print utility::createList($dataArray,$listName,$id,$width,"Select County",false,$className);
		}
		
	}
	
	static function getTownListByCounty($county){
  		global $db,$conn;		
		$result = $db->query("SELECT * FROM towns WHERE parent=$county ORDER BY town");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['town'];
			}			
		}
		return implode(",",$dataArray);
		
	}
	
	// get state by id 
	static function getStateById($id=0){
		return utility::getTableFieldById("state","state","id","$id");
  	}
	
	// print city list
	static function getCityList($listName = "", $id="", $width = 250, $return_type=0, $className="required",$state_id="" ){
  		global $db,$conn;		
		$where = " WHERE 1=1 ";
		if(isset($state_id) && $state_id !=""){
			$where .= " AND state_id = $state_id";
		}
		$result = $db->query("SELECT * FROM city $where ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['city'];
			}			
		}		
		if($return_type){
			return $dataArray;
		}else{
			print utility::createList($dataArray,$listName,$id,$width,"Select Area",false,$className);
		}
		
	}
	// get city by id 
	static function getCityById($id=0){
		return utility::getTableFieldById("city","city","id","$id");
  	}
	
	// print area list
	static function getAreaList($listName = "", $id="", $width = 250, $return_type=0, $className="required",$city_id="" ){
  		global $db,$conn;		
		$where = " WHERE 1=1 ";
		if(isset($city_id) && $city_id !=""){
			$where .= " AND city_id = $city_id";
		}
		$result = $db->query("SELECT * FROM area $where ORDER BY id");
		$dataArray = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){
				$dataArray[$row['id']] = $row['area'];
			}			
		}		
		if($return_type){
			return $dataArray;
		}else{
			print utility::createList($dataArray,$listName,$id,$width,"Select Street",false,$className);
		}
		
	}
	// get area by id 
	static function getAreaById($id=0){
		return utility::getTableFieldById("area","area","id","$id");
  	}
}
?>