<?php
	
	/*
		This class will be used for operations on Company related data
		mainly mstCompany table
	*/
	
	class Members
	{
	
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getMembers($MemberID='',$sql='',$debugquery='',$fields='*')
		{
			if ($MemberID!="")
			{
				$sqltext = "Select $fields from mstmember where emberid='".$MemberID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstmember";
			}
				
			$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 AddMember($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 mstmember ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		function EditMember($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 mstmember ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteMember($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from mstmember where applicationid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}
	
	/*
		Registration Class : This will be used for two reasons
		1) To manage mstregistration table
		2) To Validate Login everytime
		
	*/
	
	class UserRegistration
	{
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1->dbconnect();
		}
		// get list of or single compani(es) from database
		
		function getUserInfo($UserID='',$sql='',$fields='*')
		{
			if ($UserID!="")
			{
				$sqltext = "Select $fields from memberiec where memberid='".$UserID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from memberiec";
			}
			
			$users = $this->obj1->select_query($sqltext);
			
			if ($users)
			{
				$numrows = $this->obj1->numRows($users);
			}
			if ($numrows ==1)
			{
				while ($userlist = mysqli_fetch_assoc($users))
				{
					$userstr[] = $userlist;
				}	
			}
			else if($numrows > 1)
			{
				while ($userlist = mysqli_fetch_assoc($users))
				{
					$userstr[] = $companylist;
				}
			}
			return $userstr;
		}
		
		// add company to database
		function AddUser($UserData)
		{
		if (is_array($UserData)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($UserData as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into memberiec ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		}
		
		function EditUser($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 memberiec ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		
		}
		
		function DeleteUser($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from memberiec where memberid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		// this function will be called to validate login everytime
		function ValidateLogin($username,$password,$ip='')
		{
			$returnvalue = "0";
			if (($username!='')&&($password!=''))
				{
					$userid = getUserInfo("","","select userid from mstregistration where username='".$username."' and password='".$password."' and isDeleted='0' and isActive='1'");
					if ($userid[0]['userid']!="")
					{
						return $userid[0]['userid'];
					}
					else 
					{
						return $returnvalue;
					}
				}
			else
			{
				return $returnvalue;
			}	
		}
	}
	
	
	/*
		This class will be used for operations on Company related data
		mainly trnCompanyProduct table
	*/
	class CompanyProducts
	{
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		// get Products for the Company
		function getCompanyProducts($CompanyProductID='',$sql='',$fields='*')
		{
			if ($CompanyProductID!="")
			{
				$sqltext = "Select $fields from trncompanyproduct where companyproductid='".$CompanyProductID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from trncompanyproduct limit 0,50";
			}
				
			$companyprod = $this->obj1->select_query($sqltext);
			
			if ($companyprod)
			{
				$numrows = $this->obj1->numRows($companyprod);
			}
			if ($numrows ==1)
			{
				while ($companyprodlist = mysqli_fetch_assoc($companyprod))
				{
					$compprodstr[] = $companyprodlist;
				}	
			}
			else if($numrows > 1)
			{
				while ($companyprodlist = mysqli_fetch_assoc($companyprod))
				{
					$compprodstr[] = $companyprodlist;
				}
			}
			return $compprodstr;
		
		}
		function AddCompanyProducts($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 trncompanyproduct ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		function EditCompanyProducts($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 trncompanyproduct ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function DeleteCompanyProducts($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from trncompanyproduct where companyproductid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}
	
	/*
		This class will be used for operations on Company related data
		mainly trnCompanyProfile table
	*/
	
	class CompanyProfile
	{
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		function GetCompanyProfile($CompanyProfileID='',$sql='',$debugquery='',$fields='*')
		{
			if ($CompanyProfileID!="")
			{
				$sqltext = "Select $fields from trncompanyprofile where companyprofileid='".$CompanyProfileID."'";
			}
			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;
		
		}
		function AddCompanyProfile($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 trncompanyprofile ".$fieldnames.") values ".$fieldvalues.")";
				echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		function EditCompanyProfile($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 trncompanyprofile ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function DeleteCompanyProfile($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from trncompanyprofile where companyprofileid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
		
	}
	
	/*
		This class will be used for operations on Company related data
		mainly trnCompanyOffers and mstBuySell table
	*/
	class CompanyOffers
	{
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		function getCompanyOffers($CompanyID='',$sql='',$debugquery='',$fields='*')
		{
			if ($CompanyID!="")
			{
				$sqltext = "Select $fields from trncompanyoffers where companyofferid='".$CompanyID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from trncompanyoffers limit 0,50";
			}
				
			$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;
		}
		function AddCompanyOffers($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 trncompanyoffers ".$fieldnames.") values ".$fieldvalues.")";
				echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		}
		function EditCompanyOffers($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 trncompanyoffers ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function DeleteCompanyOffers($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from trncompanyoffers where companyofferid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		}
	
	}
	/*
		This class will be used for operations on Company related data
		mainly trnCompanyWebShop
	*/
	class CompanyWebStore
	{
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this-> con = $this->obj1-> dbconnect();
		}
		function getCompanyWebStore($CompanyBusinessID='',$sql='',$debugquery='',$fields='*')
		{
			if ($CompanyBusinessID!="")
			{
				$sqltext = "Select $fields from trncompanywebstore where CompanyBusinessID='".$CompanyBusinessID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from trncompanywebstore limit 0,50";
			}
				
			$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;
		}
		function AddCompanyWebStore($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 trncompanywebstore ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		}
		function EditCompanyWebStore($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 trncompanywebstore ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function DeleteCompanyWebStore($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from trncompanywebstore where CompanyBusinessID='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		}
	
	}	
?>