<?php
	
	class Country
	{
		var $obj1;
		var $con;
		function __construct()
		{
			$this->obj1 = new dboperations();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getCountries($CountryID='',$sql='',$debugquery='',$fields='*')
		{
			
			
			if ($CountryID!="")
			{
				$sqltext = "Select $fields from mstcountry where Countryid='".$CountryID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "select $fields from mstcountry order by countryname";
			}
				
			$companies = $this->obj1->select_query($sqltext);
			
			$numrows=0;
			
			if ($companies)
			{
				$numrows = $this->obj1->numRows($companies);
			}
			if ($numrows ==1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}	
			}
			else if($numrows > 1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}
			}
			return $compstr;
		}
		// add company to database
		function AddCountry($CompanyData)
		{
		if (is_array($CompanyData)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($CompanyData as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into mstcountry ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		function EditProduct($applicationdata)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnamesvalues =  "set ";
				
				foreach ($applicationdata as $k => $v) 
				{
					$fieldnamesvalues .=  ($fieldnamesvalues =="set ")?"$k='$v'":",$k='$v'";
				}
				$sqltext = "update mstcountry ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteProduct($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from mstcountry where countryid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}

class City
	{
	
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getCities($CityID='',$sql='',$debugquery='',$fields='*')
		{
			if ($CityID!="")
			{
				$sqltext = "Select $fields from mstCity where Cityid='".$CityID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
				
			}
			else
			{
				$sqltext = "Select $fields from mstCity";
			}
			$companies = $this->obj1->select_query($sqltext);
			
			if ($companies)
			{
				$numrows = $this->obj1->numRows($companies);
			}
			if ($numrows ==1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}	
			}
			else if($numrows > 1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}
			}
			return $compstr;
		
		}
		// add company to database
		function AddCity($CompanyData)
		{
		if (is_array($CompanyData)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($CompanyData as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into mstCity ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		function EditCategory($applicationdata)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnamesvalues =  "set ";
				
				foreach ($applicationdata as $k => $v) 
				{
					$fieldnamesvalues .=  ($fieldnamesvalues =="set ")?"$k='$v'":",$k='$v'";
				}
				$sqltext = "update mstCity ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteCategory($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from mstCity where Categoryid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}
class State
	{
	
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getState($StateID='',$sql='',$debugquery='',$fields='*')
		{
			if ($SubCategoryID!="")
			{
				$sqltext = "Select $fields from mstState where Stateid='".$SubCategoryID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstState";
			}
				
			$companies = $this->obj1->select_query($sqltext);
			
			if ($companies)
			{
				$numrows = $this->obj1->numRows($companies);
			}
			if ($numrows ==1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}	
			}
			else if($numrows > 1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}
			}
			return $compstr;
		
		}
		// add company to database
		function AddState($CompanyData)
		{
		if (is_array($CompanyData)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($CompanyData as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into mstState ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		function EditState($applicationdata)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnamesvalues =  "set ";
				
				foreach ($applicationdata as $k => $v) 
				{
					$fieldnamesvalues .=  ($fieldnamesvalues =="set ")?"$k='$v'":",$k='$v'";
				}
				$sqltext = "update mstState ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteState($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from mstState where Stateid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}

?>