<?php
/**
 * This is a class file used for User 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 UserMgt.
 *
 * @category School Management System
 * @package  School Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class CustmerProductMgmt
{
    /**
     * @var public $customer_productid This is the customer_productid Id feteched from the database(lms_customerproduct).
     */
    public $customer_productid;
	
	/**
     * @var public $customer_id This is the customer_id Role of user feteched from the database(lms_customerproduct).
     */
	 
	 public $customer_id;
	  	
/**
     * @var public $product_id This is the product_id  Name of user feteched from the database(lms_customerproduct).
     */
	  public $product_id;
	
	/**
     * @var public $purchase_date This is the purchase_date Password of user feteched from the database(lms_customerproduct).
     */
	 
	 public $purchase_date;
	
	
	/**
     * @var public $company_id This is the company_id.
     */
	 public $company_id;
    
	
     /**
     * @var public $login_id This is the id of loger.
     */
	 public $createdby;
	
	/**
     * @var public $student_createdon This is the Student createdom.
     */
	public $createdon;
	
	
	 
   
    function CustmerProductMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->user_count=0;
    }

    /**
     * This function is used to get a particular record.
     *
     * @param integer $page_id This is the database banner id.
     *
     * @return array
     */
    function getRecordById($uder_id)
    {
        $qry = "select * from lms_customerproduct where lms_customerproduct.company_id= '".$_SESSION["cCompany_id"]."' ";

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

        $out=dbQuery($qry);

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

            $row=dbArray($out);
            extract($row);
			
            $this->customer_productid 				    = ($customer_productid);
			$this->customer_id				= ($customer_id);
			$this->product_id				= ($product_id);
			$this->purchase_date 			= ($purchase_date);
			$this->company_id 				= ($company_id);
			$this->createdby 				= ($createdby);
			$this->createdon 				= ($createdon);
			
			dbFreeResult($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 getAllRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->user_count=0;
		
        $qry = "SELECT * FROM lms_customerproduct 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";
        }

        $out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->user_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 getpurchaseDate($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->user_count=0;
		
        $qry = "SELECT purchase_date FROM lms_customerproduct 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";
        }

        $out=dbQuery($qry);

        if (dbRows($out)>0) {
            $result=dbArray($out);
			$record=$result['purchase_date'];
			return $record;							
        }
		return $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->user_count=0;
		
        $qry = "SELECT Count(*) AS Count 
				FROM lms_customerproduct 
				WHERE 1=1 ";
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
	
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->user_count=$Count;            
			dbFreeResult($out);
        }
		return $this->user_count;
    }
	
	
	
	
    /**
     * This is a function for adding new record for Student.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
		global $SQLDateFormat;
		
		$Qry1 = "";
		$Qry1 .= "product_id='"		   	.Escape($this->product_id)."',";
		$Qry1 .= "customer_id='"		.Escape($this->customer_id)."',";
		$Qry1 .= "purchase_date=         STR_TO_DATE('".Escape($this->purchase_date)."','$SQLDateFormat'),";	
		$Qry1 .= "company_id='"			.Escape($_SESSION["cCompany_id"])."',";	
		$Qry1 .= "createdby='"	      	.Escape($_SESSION['cUserId'])."',";			
		$Qry1 .= "createdon='"	      	.Escape(date('Y-m-d h:i:s'))."',";	
		
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
			$qry = "insert into lms_customerproduct set " . $Qry1 . " ";
			dbQuery($qry);
			$this->customer_productid=dbInsertedId();
		}
    }
	
	function edit()
    {
		$Qry1 = "";
		$Qry1 .= "product_id='"		   	.Escape($this->product_id)."',";
		$Qry1 .= "customer_id='"		.Escape($this->customer_id)."',";
		$Qry1 .= "purchase_date='"		.Escape($this->purchase_date)."',";
		$Qry1 .= "company_id='"			.Escape($_SESSION["cCompany_id"])."',";	
		$Qry1 .= "createdby='"	      	.Escape($_SESSION['cUserId'])."',";			
		$Qry1 .= "createdon='"	      	.Escape(date('Y-m-d h:i:s'))."',";		
		
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
$qry = "update lms_customerproduct set " . $Qry1 ."where customer_id=".$this->customer_id." AND product_id=".$this->product_id."  ";
			dbQuery($qry);
			$this->customer_productid=dbInsertedId();
		}
    }
	
   
	
/**
     * This is a function for deleting the User record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {
	   $qry = "delete from  lms_customerproduct 
             	where customer_id in (".$this->customer_id.") 
				and company_id='".$_SESSION["cCompany_id"]."'";
		dbQuery($qry);     
    }

	
}
?>