<?php
/**
 * This is a class file used for Employee operations.
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */

/**
 * This is a class named clsMgmt.
 *
 * @category Employee Management System
 * @package  Employee Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class clsMgmt
{
	/**
	 * @var public $supportinquiry_id This is the Employee Id feteched from the database(employee_master).
	 */
	/*public $supportinquiry_id;
	   
	   /**
		* @var public $customer_id This is the Employee Basic salary.
	  
	   public $customer_id;

	   public $supportinquiry_problem;
	   /**
		* @var public $supportinquiry_date This is the Employee birthdate.
		
	   public $supportinquiry_date;

	   /**
		* @var public $employee_schooljoindate This is the Employee school join date.
		
	   public $supportinquiry_time;

	   /**
		* @var public $company_id This is the school id.
		
	   public $company_id;*/

	/**
	 * @var public $login_id This is the Employee login id.
	 */
	public $cust_id;
	public $customer_id;
	public $date1;
	public $customer_orgname;
	public $address;
	public $commu_person;
	public $mobno;
	public $phoneNo;
	public $cp_mobno;
	public $problem_det;
	public $completed_det;
	public $company_id;
	public $pending_reason;
	public $pending_work;
	public $status;
	public $user_id;

	public $support_sdate;
	public $support_edate;
	public $support_timefrom;
	public $support_timeto;


	/**
	 * @var public $createdon This is the Employee createdon.
	 */

	function clsMgmt()
	{
		$this->bullet = "<font size='2'>&raquo;</font>";
		$this->bullet = htmlentities($this->bullet);
		$this->inquiry_count = 0;
	}

	/**
	 * This is a function for getting the all records with/without condition
	 *
	 * @param integer $limit This is the limit of number or records.
	 * @param integer $start This is the starting location of records.
	 * @param string  $condition This is the condition for fetching records.	 
	 * @param string  $order_field This is the field for fetching records orderby.	 
	 * @param string  $order_type This is the order direction to fetch records orderby.	 	 
	 *
	 * @return Mix Result Set
	 */
	function getCountRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->employee_count = 0;

		$qry = "SELECT 	
	  			Count(*) AS Count	  
			  FROM 
			  lms_cust ls Left Join lms_customer c 
			  ON ls.customer_id=c.customer_id 		  
			  WHERE    							
				1=1 ";

		if ($condition != "") {
			$qry .= $condition;
		}

		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			$row = dbArray($out);
			extract($row);
			$this->employee_count = $Count;
			dbFreeResult($out);
		}
		return $this->employee_count;
	}


	/**
	 * This is a function for getting the all records with/without condition
	 *
	 * @param integer $limit This is the limit of number or records.
	 * @param integer $start This is the starting location of records.
	 * @param string  $condition This is the condition for fetching records.	 
	 * @param string  $order_field This is the field for fetching records orderby.	 
	 * @param string  $order_type This is the order direction to fetch records orderby.	 	 
	 *
	 * @return Mix Result Set
	 */
	/*function getAllRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
	   {
		   $this->inquiry_count=0;
		   
		   $qry = "SELECT * 
				   FROM 
				   lms_cust 
				   WHERE 1=1 ";
		   
		   
																 
		   if ($condition != "" ) {
			   $qry.= $condition;
		   }
		   
		   if ($order_field !="" && $order_type !="") {
			   $qry.= " order by $order_field $order_type";
		   }

		   if (intval($limit) > 0 && intval($start) >=0) {
			   $qry.= " Limit $start , $limit";
		   }
		   
		   //print $qry;
		   $out=dbQuery($qry);
		   
		   if (dbRows($out)>0) {
			   $this->inquiry_count=dbRows($out);
			   return $out;							
		   }
		   return $out;		
	   }*/


	/*  function getAllRecords11($limit=0,$start=0,$condition="",$order_field="",$order_type="")
		  {
			  $this->inquiry_count=0;
			  
			  //echo $customer_orgname;
			  
			  
			  //$qry = "SELECT lc.*,(select ld.designation_name from  
	  //				lms_designation ld	
	  //				where ld.designation_id = lc.customer_cpdesignation1)as designation_name
	  //		     from
	  //				lms_customer lc		  
	  //			 WHERE 
	  //				lc.company_id   = '".$_SESSION["cCompany_id"]."' "; 
				  //$qry = "SELECT * FROM `lms_customer`";// where customer_id
				  
			  $qry = "SELECT * FROM lms_cust WHERE cust_id in (SELECT customer_id from lms_cust) ";		
					   
									 
			  if ($condition != "" ) {
				  $qry.= $condition;
			  }
			  
			  if ($order_field !="" && $order_type !="") {
				  $qry.= " order by $order_field $order_type";
			  }

			  if (intval($limit) > 0 && intval($start) >=0) {
				  $qry.= " Limit $start , $limit";
			  }
			  
			  //print $qry;
			  $out=dbQuery($qry);
			  echo "            " .$qry;
			  //echo "dbQuery($qry)";
			  
			  //echo $out;
			  if (dbRows($out)>0) {
			  
			  //echo $out;
				  $this->inquiry_count=dbRows($out);
				  return $out;							
			  }
			  return $out;		
		  }*/
	function getAllRecords1($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->inquiry_count = 0;

		/*$qry = "SELECT lc.*,(select ld.designation_name from  
						   lms_designation ld	
						   where ld.designation_id = lc.customer_cpdesignation1)as designation_name
						from
						   lms_customer lc		  
						WHERE 
						   lc.company_id   = '".$_SESSION["cCompany_id"]."' "; */
		//$qry = "SELECT * FROM `lms_customer`";// where customer_id

		//$qry = "SELECT * FROM lms_cust WHERE customer_id in (SELECT customer_id from lms_customer) ";	

		//$qry = "SELECT lc.* , (SELECT ld.`customer_orgname` FROM lms_customer ld WHERE ld.`customer_id` = lc.`customer_id` ) AS `customer_orgname` FROM lms_cust lc";
//LIMIT 0 , 30



		$qry = "SELECT * FROM lms_cust WHERE customer_id in (SELECT customer_id from lms_customer) ";


		if ($condition != "") {
			$qry .= $condition;
		}

		if ($order_field != "" && $order_type != "") {
			$qry .= " order by $order_field $order_type";
		}

		if (intval($limit) > 0 && intval($start) >= 0) {
			$qry .= " Limit $start , $limit";
		}


		$out = dbQuery($qry);
		if (dbRows($out) > 0) {


			$this->inquiry_count = dbRows($out);
			return $out;
		}
		return $out;
	}


	/**
	 * This is a function for adding new record for Employee.
	 *
	 * @return void The redirect file name and the message are passed.
	 *
	 */
	function add()
	{

		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "cust_id='" . (Escape($this->cust_id)) . "',";
		$Qry1 .= "date1=    STR_TO_DATE('" . Escape($this->date1) . "','$SQLDateFormat'),";

		$Qry1 .= "address='" . (Escape($this->address)) . "',";
		$Qry1 .= "commu_person='" . (Escape($this->commu_person)) . "',";
		$Qry1 .= "mobno='" . (Escape($this->mobno)) . "',";
		$Qry1 .= "phoneNo='" . (Escape($this->phoneNo)) . "',";
		$Qry1 .= "cp_mobno='" . (Escape($this->cp_mobno)) . "',";
		$Qry1 .= "problem_det='" . (Escape($this->problem_det)) . "',";

		$Qry1 .= "completed_det='" . Escape($this->completed_det) . "',";
		$Qry1 .= "status='" . Escape($this->status) . "',";

		$Qry1 .= "pending_reason='" . Escape($this->pending_reason) . "',";
		$Qry1 .= "pending_work='" . Escape($this->pending_work) . "',";

		$Qry1 .= "user_id='" . Escape($this->user_id) . "',";
		$Qry1 .= "assign_user_id='" . Escape($this->assign_user_id) . "',";
		$Qry1 .= "customer_id='" . (Escape($this->customer_id)) . "',";
		$Qry1 .= "company_id='" . Escape($_SESSION['cCompany_id']) . "',";

		$Qry1 .= "support_sdate=    STR_TO_DATE('" . Escape($this->support_sdate) . "','$SQLDateFormat'),";
		$Qry1 .= "support_edate=    STR_TO_DATE('" . Escape($this->support_edate) . "','$SQLDateFormat'),";
		$Qry1 .= "support_timefrom='" . Escape($this->support_timefrom) . "',";
		$Qry1 .= "support_timeto='" . Escape($this->support_timeto) . "',";
		$Qry1 .= "cpmail1='" . Escape($this->cpmail1) . "',";
		$Qry1 .= "ticket='" . Escape($this->ticket) . "',";
		$Qry1 .= "time='" . date('dd-mm-yyyy hh:mm:ss') . "',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into lms_cust set " . $Qry1 . " ";
		//	echo $qry;
			dbQuery($qry);
			$this->cust_id = dbInsertedId();
		}
	}

	/**
	 * This is a function for editing a Employee record.
	 *
	 * @return void The redirect file name and the message are passed.
	 *
	 */
	function edit()
	{
		global $SQLDateFormat;

		$Qry1 = "";

		$Qry1 .= "cust_id='" . (Escape($this->cust_id)) . "',";
		$Qry1 .= "date1=    STR_TO_DATE('" . Escape($this->date1) . "','$SQLDateFormat'),";

		$Qry1 .= "address='" . (Escape($this->address)) . "',";
		$Qry1 .= "commu_person='" . (Escape($this->commu_person)) . "',";

		$Qry1 .= "mobno='" . (Escape($this->mobno)) . "',";
		$Qry1 .= "phoneNo='" . (Escape($this->phoneNo)) . "',";
		$Qry1 .= "cp_mobno='" . (Escape($this->cp_mobno)) . "',";
		$Qry1 .= "problem_det='" . (Escape($this->problem_det)) . "',";

		$Qry1 .= "completed_det='" . Escape($this->completed_det) . "',";
		$Qry1 .= "status='" . Escape($this->status) . "',";

		$Qry1 .= "pending_reason='" . Escape($this->pending_reason) . "',";
		$Qry1 .= "pending_work='" . Escape($this->pending_work) . "',";

		$Qry1 .= "user_id='" . Escape($this->user_id) . "',";
		$Qry1 .= "assign_user_id='" . Escape($this->assign_user_id) . "',";
		$Qry1 .= "customer_id='" . (Escape($this->customer_id)) . "',";
		$Qry1 .= "company_id='" . Escape($_SESSION['cCompany_id']) . "',";

		$Qry1 .= "support_sdate=    STR_TO_DATE('" . Escape($this->support_sdate) . "','$SQLDateFormat'),";
		$Qry1 .= "support_edate=    STR_TO_DATE('" . Escape($this->support_edate) . "','$SQLDateFormat'),";
		$Qry1 .= "support_timefrom='" . Escape($this->support_timefrom) . "',";
		$Qry1 .= "support_timeto='" . Escape($this->support_timeto) . "',";
		$Qry1 .= "cpmail1='" . Escape($this->cpmail1) . "',";
		$Qry1 .= "ticket='" . Escape($this->ticket) . "',";
		$Qry1 .= "time='" . Escape(date('Y-m-d h:i:s')) . "',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "update lms_cust set " . $Qry1 . " where cust_id=" . $this->cust_id;

			//   echo $qry; exit;

			dbQuery($qry);
		}
	}

	//$qry = "update studetnmaster set " . $Qry1 . " where  student_id=".$this->student_id;

	/**
	 * This is a function for deleting the Employee record.
	 *
	 * @return void The redirect file name and the message are passed.
	 *
	 */
	function delete()
	{
		$qry = "delete from lms_cust 
             	where cust_id in (" . $this->cust_id . ")";
		//and company_id='".$_SESSION["cCompany_id"]."'";
		dbQuery($qry);
	}


}
?>