<?php
/**
 * This is a class file used for Operator 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 EmployeeMgmt.
 *
 * @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 OperatorMgmt
{
    /**
     * @var public $operator_id This is the Employee Id feteched from the database(employee_master).
     */
    public $operator_id;
	
	/**
     * @var public $operator_name This is the Employee name.
     */
	public $operator_name;
	
	/**
     * @var public $employee_curaddress This is the Employee current address.
     */
	public $operator_address;
	
	/**
     * @var public $operator_phone This is the Employee phone.
     */
	public $operator_phone;

	/**
     * @var public $operator_mobile This is the Employee mobile.
     */
	public $operator_mobile;

	/**
     * @var public $operator_email This is the Employee email id.
     */
	public $operator_email;

	/**
     * @var public $operator_panno This is the Employee Basic salary.
     */
	public $operator_panno;
	
	/**
     * @var public $operator_photo This is the Employee Photo.
     */
	public $operator_photo;

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

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

	/**
     * @var public $operator_otherid This is the Employee designation.
     */
	public $operator_otherid;

	/**
     * @var public $company_id This is the school id.
     */
	public $company_id;
	
	/**
     * @var public $login_id This is the Employee login id.
     */
	public $createdby;
	
	/**
     * @var public $createdon This is the Employee createdon.
     */
	public $createdon;
	
	/**
     * Constructor to inialize operator_count to zero
     *
     */
    function OperatorMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->operator_count=0;
    }

    /**
     * This function is used to get a particular record.
     *
     * @param integer $operator_id This is the database operator_id.
     *
     * @return array
     */
    /*function getRecordById($operator_id,$company_id)
    {
        $qry = "select * from employee_master where 1=1 ";

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

        $out=dbQuery($qry);

		if(dbRows($out)>0) {
            $this->operator_count=1;

            $row=dbArray($out);
            extract($row);

			$this->operator_id			= ($operator_id);
			$this->company_id			= ($company_id);
			$this->operator_name		= ($operator_name);
			$this->operator_otherid		= ($operator_otherid);
			$this->operator_aadharno	= ($operator_aadharno);
			$this->employee_joindate	= ($employee_joindate);
			$this->operator_panno		= ($operator_panno);
			$this->operator_address		= ($operator_address);
			$this->operator_mobile		= ($operator_mobile);
			$this->operator_phone		= ($operator_phone);
			$this->operator_email		= ($operator_email);

			dbFreeResult($out);
        }
    }*/
		
	/**
     * This is a function for getting the total no of 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 Total Records Found
     */
    /*function getCountRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->operator_count=0;
		
       	$qry = "SELECT COUNT(*) AS Count
				FROM employee_master em 
				WHERE em.company_id   = '".$_SESSION["cCompany_id"]."' ";
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->operator_count=$Count;            
			dbFreeResult($out);	
        }
		return $this->operator_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->operator_count=0;
		
		$qry = "SELECT 
					lm.*
				FROM 
			  		lms_operator lm 			  
			  	WHERE    							
					lm.company_id   = '".$_SESSION["cCompany_id"]."' "; 
					   					   				
		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->operator_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
		
		
		
	/**
     * 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 operatorGridFilter($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->operator_count=0;
		
	  $qry = "SELECT 	
	  			lm.*		  
			  FROM 
			  	lms_operator as lm
			  WHERE    							
				lm.company_id   = '".$_SESSION["cCompany_id"]."' "; 
		
		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";
        }
		
		//echo $qry;
		$out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->operator_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
		
	function operatorGridFilterCount($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->operator_count=0;
		
	  $qry = "SELECT 	
	  			Count(*) AS Count	  
			  FROM 
			  	lms_operator as lm
			  WHERE    							
				lm.company_id   = '".$_SESSION["cCompany_id"]."' "; 
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		 $out=dbQuery($qry);

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

    /**
     * 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 .= "operator_name='"	  .Escape($this->operator_name)."',";
		$Qry1 .= "operator_address='" .replaceHtmlEditor(Escape($this->operator_address))."',";	
		$Qry1 .= "operator_phone='"	  .Escape($this->operator_phone)."',";	
		$Qry1 .= "operator_mobile='"  .Escape($this->operator_mobile)."',";	
		$Qry1 .= "operator_email='"	  .Escape($this->operator_email)."',";
		$Qry1 .= "operator_panno='"  .Escape($this->operator_panno)."',";
		$Qry1 .= "operator_aadharno='"  .Escape($this->operator_aadharno)."',";
		$Qry1 .= "operator_joindate=  STR_TO_DATE('".Escape($this->operator_joindate)."','$SQLDateFormat'),";			
		$Qry1 .= "operator_otherid='"   .Escape($this->operator_otherid)."',";		
		$Qry1 .= "company_id='"	      .Escape($this->company_id)."',";			
		$Qry1 .= "createdby='"	      .Escape($_SESSION['cUserId'])."',";			
		$Qry1 .= "createdon='"	      .Escape(date('Y-m-d h:i:s'))."',";
					
		$Qry1 .= "operator_code='"	  .Escape($this->operator_code)."',";	
		$Qry1 .= "account_no='"  .Escape($this->account_no)."',";	
		$Qry1 .= "bank_name='"	  .Escape($this->bank_name)."',";
		$Qry1 .= "branch_name='"  .Escape($this->branch_name)."',";
		$Qry1 .= "ifsc_code='"  .Escape($this->ifsc_code)."',";
		
		
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
			$qry = "insert into lms_operator set " . $Qry1 . " ";
					
			dbQuery($qry);
			$this->operator_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 .= "operator_name='"	  .Escape($this->operator_name)."',";
		$Qry1 .= "operator_address='" .replaceHtmlEditor(Escape($this->operator_address))."',";	
		$Qry1 .= "operator_phone='"	  .Escape($this->operator_phone)."',";	
		$Qry1 .= "operator_mobile='"  .Escape($this->operator_mobile)."',";	
		$Qry1 .= "operator_email='"	  .Escape($this->operator_email)."',";
		$Qry1 .= "operator_panno='"  .Escape($this->operator_panno)."',";
		$Qry1 .= "operator_aadharno='"  .Escape($this->operator_aadharno)."',";
		$Qry1 .= "operator_joindate=  STR_TO_DATE('".Escape($this->operator_joindate)."','$SQLDateFormat'),";			
		$Qry1 .= "operator_otherid='"   .Escape($this->operator_otherid)."',";		
		$Qry1 .= "company_id='"	      .Escape($this->company_id)."',";			
		$Qry1 .= "createdby='"	      .Escape($_SESSION['cUserId'])."',";			
		$Qry1 .= "createdon='"	      .Escape(date('Y-m-d h:i:s'))."',";
					
		$Qry1 .= "operator_code='"	  .Escape($this->operator_code)."',";	
		$Qry1 .= "account_no='"  .Escape($this->account_no)."',";	
		$Qry1 .= "bank_name='"	  .Escape($this->bank_name)."',";
		$Qry1 .= "branch_name='"  .Escape($this->branch_name)."',";
		$Qry1 .= "ifsc_code='"  .Escape($this->ifsc_code)."',";
		
            if ($Qry1 != "") {
                $Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
                $qry = "update lms_operator set " . $Qry1 . " where operator_id=".$this->operator_id. " and company_id = '".$_SESSION['cCompany_id']."' ";
                dbQuery($qry);
            }
	}
	
	/**
     * 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_operator 
             	where operator_id in (".$this->operator_id.") 
				and company_id='".$_SESSION["cCompany_id"]."'";
        dbQuery($qry);
   	}
	
	/**
     * This is a function for update the Employee Photo.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function updatePhoto()
    {		
		$qry = "update lms_operator 
				set operator_photo = '".$this->operator_photo."'
             	where operator_id =   ".$this->operator_id." and company_id='".$_SESSION["cCompany_id"]."'";
        dbQuery($qry);
   	}
	
	/**
     * This function is used to remove duplication of Designation.
     *
     * @param integer $company_id This is the database school id.
     *
     * @return array
     */
   /* function getDistinctDesignation()
    {
        $this->trustee_count=0;
		
        $qry = "SELECT DISTINCT operator_otherid 
				FROM employee_master where company_id='".$_SESSION['cCompany_id']."' ";
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->operator_count=dbRows($out);
			return $out;							
        }
		return $out;
	
	}*/
}
?>