<?
	class jobs
	{
		var $obj1;
		var $con;
		// constructor
		function __construct()
		{
			$this->obj1 = new dboperations();
			$this->con = $this->obj1-> dbconnect();
			
		}
		
		
		function getjobs($jobid="",$fields="*",$sql="")
		{
			if ($jobid!="")
			{
				$sqltext = "Select $fields from mstjobs where jobid='".$jobid."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstjobs";
			}
			$jobs = $this->obj1->select_query($sqltext);
			if ($jobs)
			{
				$numrows = $this->obj1->numRows($jobs);
			}
			if ($numrows ==1)
			{
				while ($jobslist = mysqli_fetch_assoc($jobs))
				{
					$jobstr[] = $jobslist;
				}
			}
			else
			{
				while ($jobslist = mysqli_fetch_assoc($jobs))
				{
					$jobstr[] = $jobslist;
				}
			}
			return $jobstr;
		}
				// example for adding product data		//            $data['productname'] = 'product1';
		//            $data['proudctdesc'] = "product desc";
		//            $data['productimagebig'] = '/images/product1.jpg';
		//            $data = $obj->addproduct($data);
		function addjob($productdata)
		{
			if (is_array($productdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($productdata as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into mstjobs ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$jobs = $this->obj1->insert_query($sqltext);
				return ($jobs == 1)?"true":"false";
				
			}
		}
		function editjob($productdata,$wherecondition)
		{
			if (is_array($productdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnamesvalues =  "set ";
				
				foreach ($productdata as $k => $v) 
				{
					$fieldnamesvalues .=  ($fieldnamesvalues =="set ")?"$k='$v'":",$k='$v'";
				}
				$sqltext = "update mstjobs ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$jobs = $this->obj1->update_query($sqltext);
				return ($jobs == 1)?"true":"false";
				
			}
		}
		function deletejob($jobid)
		{
			if($jobid)
			{
				$sqltext = "delete from mstjobs where jobid='".$jobid."'";
				$jobs = $this->obj1->delete_query($sqltext);
				return ($jobs == 1)?"true":"false";
			}
		}
		
	}
?>	