<?
	class Client
	{
		function Client()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
			
		}
		
		// get list of or single compani(es) from database
		function getClient($sqlquery='',$KeyID='',$sql='',$debugquery='',$fields='*',$tablename='mstclients',$KeyFieldName='')
		{
			if (($KeyID!="") ) //&& ($tablename =="mstclients")
			{
				$sqltext = "Select $fields from mstclients where $KeyFieldName ='".$KeyID."'";
			//	echo $KeyID;
		  //	echo $KeyFieldName ;
		 	echo $sqltext;
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else if ($sqlquery!="")
			{
				$sqltext = "select * from mstclients";
			}
				
			$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 AddClient($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 ignore into mstclients ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		function EditClient($applicationdata,$wherecondition)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnamesvalues =  "set ";
				
				foreach ($applicationdata as $k => $v) 
				{
					$fieldnamesvalues .=  ($fieldnamesvalues =="set ")?"$k='$v'":",$k='$v'";
				}
				$sqltext = "update mstclients ".$fieldnamesvalues." where ".$wherecondition ;
				
			//	echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		
		function DeleteClient($applicationdata)
		{
			
			if($applicationdata!='')
			{
				$sqltext = "delete from mstclients where ".$applicationdata;
				//echo $sqltext;
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		function ExecuteQuery($sql)
		{
			$applications = $this->obj1->update_query($sql);
			return ($applications == 1)?"true":"false";
		}
	}

?>