<?php
	
	class Products
	{
	
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getProducts($ProductID='',$sql='',$debugquery='',$fields='*')
		{
			if ($ProductID!="")
			{
				$sqltext = "Select $fields from hs_code where hs_codeid='".$ProductID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from hs_code";
			}
				
			$companies = $this->obj1->select_query($sqltext);
			$compstr = "";
			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 into hs_code ".$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 mstproduct ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteProduct($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from hs_code where productid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}

class Category
	{
	
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getCategory($CategoryID='',$sql='',$debugquery='',$fields='*')
		{
			if ($CategoryID!="")
			{
				$sqltext = "Select $fields from mstcategory where Categoryid='".$CategoryID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstCategory";
			}
				
			$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 AddCategory($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 mstCategory ".$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 mstCategory ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteCategory($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from mstCategory where Categoryid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}
class SubCategory
	{
	
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getSubCategory($SubCategoryID='',$sql='',$debugquery='',$fields='*')
		{
			if ($SubCategoryID!="")
			{
				$sqltext = "Select $fields from mstsubcategory where subCategoryid='".$SubCategoryID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstSubCategory";
			}
				
			$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 AddSubCategory($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 mstSubCategory ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		function EditSubCategory($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 mstSubCategory ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteSubCategory($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from mstSubCategory where Categoryid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}

?>
