<?
	class Product
	{

		function Product()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getProduct($KeyID='',$sql='',$debugquery='',$fields='*',$tablename='mstproducts',$KeyFieldName='')
		{
			if (($KeyID!="") )//&&($tablename!="mstproducts"))
			{
				$sqltext = "Select $fields from mstproducts where $KeyFieldName='".$KeyID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
				
			$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 AddProduct($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 mstproducts ".$fieldnames.") values ".$fieldvalues.")";
			   //echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		function EditProduct($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 mstproducts ".$fieldnamesvalues." where ".$wherecondition ;
				
			//	echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		
		function DeleteProduct($applicationdata)
		{
			
			if($applicationdata!='')
			{
				$sqltext = "delete from mstproducts 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";
		}
	}

?>