<?php

/**
 * This is a class file used for Student Library Management.
 *
 * 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 Member Management.
 *
 * @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 MemberMgmt
{
    /**
     * @var public $member_id This is the Member id.
     */
    public $member_id;
	
	/**
     * @var public $member_group This is the Member Group.
     */
	public $member_group;
	
	/**
     * @var public $member_registerno This is the Member Register No.
     */
	public $member_registerno;
	
	/**
     * @var public $member_name This is the Member Name.
     */
	public $member_name;
	
	/**
     * @var public $member_address This is the Member Address.
     */
	public $member_address;
	
	/**
     * @var public $member_phone This is the Member Phone.
     */
	public $member_phone;
	
	/**
     * @var public $member_mobileno This is the Member Mobile No.
     */
	public $member_mobileno;
	
	/**
     * @var public $member_refby This is the Member Reference By Name.
     */
	public $member_refby;
	
	/**
     * @var public $member_refaddress This is the Member Reference Address.
     */
	public $member_refaddress;
	
	/**
     * @var public $member_refphone This is the Member Reference Phone.
     */
	public $member_refphone;
	
	/**
     * @var public $member_active This is the Member Active.
     */
	public $member_active;
	
	/**
     * @var public $member_approvedfrom This is the Member Approved from Date.
     */
	public $member_approvedfrom;
	
	/**
     * @var public $member_approvedto This is the Member Approved to Date.
     */
	public $member_approvedto;
	
	/**
     * @var public $member_maxissuelimit This is the Member Max member Issue Limit.
     */
	public $member_maxissuelimit;
	
	/**
     * @var public $member_remark This is the Member Remark/Comment.
     */
	public $member_remark;
	
    /**
     * @var public $member_count This is a counter.
     */
    public $member_count;
    /**
     * @var public $member_redirectfile This is file name to be redirected on after the operation.
     */
    public $member_redirectfile;
  
  	/**
     * @var public $bullet This is bullet.
     */
    public $bullet;
	
	/**
     * @var public $student_msg This is the message.
     */
    public $member_msg;
    /**
     * Constructor to inialize member_count to zero
     *
     */
    function MemberMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->member_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($member_id)
    {
        $qry = "SELECT * FROM lms_membermaster where 1=1 ";

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

        }

        $out=dbQuery($qry);

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

            $row=dbArray($out);
            extract($row);
			
			$this->member_id= ($member_id);
			$this->member_group= ($member_group);
			$this->member_name= ($member_name);
			$this->member_address= ($member_address);
			$this->member_phone= ($member_phone);
			$this->member_mobileno= ($member_mobileno);
			$this->member_refby= ($member_refby);
			$this->member_refaddress= ($member_refaddress);
			$this->member_refphone= ($member_refphone);
			$this->member_active= ($member_active);
			$this->member_approvedfrom= ($member_approvedfrom);
			$this->member_approvedto= ($member_approvedto);
			$this->member_maxissuelimit= ($member_maxissuelimit);
			$this->member_remark= ($member_remark);
			
            dbResult($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->member_count=0;
		
        $qry = "SELECT * FROM lms_membermaster 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->member_count=dbRows($out);            
			dbResult($out);
        }
		return $this->member_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->member_count=0;
		
		$qry = "SELECT * FROM lms_membermaster  where school_id= '".$_SESSION["aCollegeId"]."' "; 
		
		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->member_count=dbRows($out);
			return $out;							
        }
		return ;		
    }
	
	/**
     * 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 getDistinctGroup()
    {
		$this->member_count=0;
		
		$qry = "SELECT Distinct member_group FROM lms_membermaster  where school_id= 1"; 
		
		$out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->member_count=dbRows($out);
			return $out;							
        }
		return ;		
    }
	
	/**
     * This is a function for adding new record for member.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
	    global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "member_registerno='"	    .Escape($this->member_registerno)."',";
		$Qry1 .= "member_group='"	        .Escape($this->member_group)."',";
		$Qry1 .= "member_name='"	        .Escape($this->member_name)."',";
		$Qry1 .= "member_address='"	    	.replaceHtmlEditor(Escape($this->member_address))."',";
		$Qry1 .= "member_phone='"	        .Escape($this->member_phone)."',";
		$Qry1 .= "member_mobileno='"	    .Escape($this->member_mobileno)."',";
		$Qry1 .= "member_refby='"	        .Escape($this->member_refby)."',";
		$Qry1 .= "member_refaddress='"	    .replaceHtmlEditor(Escape($this->member_refaddress))."',";
		$Qry1 .= "member_refphone='"	    .Escape($this->member_refphone)."',";
		$Qry1 .= "member_approvedfrom = STR_TO_DATE('".Escape($this->member_approvedfrom)."','$SQLDateFormat'),";	
		$Qry1 .= "member_approvedto = STR_TO_DATE('".Escape($this->member_approvedto)."','$SQLDateFormat'),";
		$Qry1 .= "member_maxissuelimit='"	.Escape($this->member_maxissuelimit)."',";
		$Qry1 .= "member_remark='"	    	.replaceHtmlEditor(Escape($this->member_remark))."',";
		$Qry1 .= "school_id='"	    		.$_SESSION['aCollegeId']."',";
		$Qry1 .= "blnBackup = '0',";
	    $Qry1 .= "member_active='"	        .Escape($this->member_active)."',";
						
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
			$qry = "insert into lms_membermaster set " . $Qry1 ." "; /* member_active='1'   */
			dbQuery($qry);
			$this->member_id =dbInsertedId();
		}
	}
	
	/**
     * This is a function for editing a Student record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function edit()
    {
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "member_group='"	        .Escape($this->member_group)."',";
		$Qry1 .= "member_name='"	        .Escape($this->member_name)."',";
		$Qry1 .= "member_address='"	    	.replaceHtmlEditor(Escape($this->member_address))."',";
		$Qry1 .= "member_phone='"	        .Escape($this->member_phone)."',";
		$Qry1 .= "member_mobileno='"	    .Escape($this->member_mobileno)."',";
		$Qry1 .= "member_refby='"	        .Escape($this->member_refby)."',";
		$Qry1 .= "member_refaddress='"	    .replaceHtmlEditor(Escape($this->member_refaddress))."',";
		$Qry1 .= "member_refphone='"	    .Escape($this->member_refphone)."',";
		$Qry1 .= "member_approvedfrom = STR_TO_DATE('".Escape($this->member_approvedfrom)."','$SQLDateFormat'),";	
		$Qry1 .= "member_approvedto = STR_TO_DATE('".Escape($this->member_approvedto)."','$SQLDateFormat'),";
		$Qry1 .= "member_maxissuelimit='"	.Escape($this->member_maxissuelimit)."',";
		$Qry1 .= "member_remark='"	    	.replaceHtmlEditor(Escape($this->member_remark))."',";
		$Qry1 .= "blnBackup = '0',";
		$Qry1 .= "member_active='"	        .Escape($this->member_active)."',";
		
						
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
            $qry = "update lms_membermaster set " . $Qry1 . " where member_id=".$this->member_id;
            dbQuery($qry);
        }
	}
	
	/**
     * This is a function for deleting the Student record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {
	    $qry = "delete from  lms_membermaster 
             	where member_id in (".$this->member_id.") 
				and school_id='".$_SESSION["aCollegeId"]."'";
		dbQuery($qry);
     
    }
	
	/**
     * This is a function for getting the max no of records with/without condition
     *
     * @param string  $condition This is the condition for fetching records.	 
     * @return Total Records Found
     */
    function getMaxRecordNumber()
    {
		$qry = "SELECT MAX(member_registerno) as mxcode 
				FROM lms_membermaster 
				WHERE school_id='".$_SESSION["aCollegeId"]."'";	
				
		$out = dbQuery($qry);
		if(dbRows($out)>0){
			$result = dbArray($out);
			$num =$result['mxcode'];
			$num =$num + 1;
			return $num;
		}
		else{
			return '1';
		}
    }
	
	/**
     * This is a function for getting the max no of records with/without condition
     *
     * @param string  $condition This is the condition for fetching records.	 
     * @return Total Records Found
     */
    function getTotalNoofIssueBook($memberid,$category)
    {
		$qry = "SELECT 
					COUNT(im.issue_id) as count
				FROM 
					lms_issuemaster im,
					lms_issuedetail ldm

				WHERE 
					im.member_type = '".$category."' AND 
					im.issue_id=ldm.issue_id AND
					im.member_id='".$memberid."' AND 
					ldm.issue_isreturned=0 AND 
					im.school_id='".$_SESSION['aCollegeId']."'
					";
		
		$out = dbQuery($qry);
		$result = dbArray($out);
		$num =$result['count'];
		return $num;
    }
	
	//Employee 
	/**
     * 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 getEmployeeRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$qry = "SELECT * FROM cms_employeemaster WHERE school_id='".$_SESSION['aCollegeId']."'";
					   					   				
		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) {
            return $out;							
        }
		return ;		
    }
	
	//Student
	/**
     * 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 getStudentRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$qry = "SELECT * 
				FROM cms_studentmaster cm 
				WHERE cm.college_id= '".$_SESSION["aCollegeId"]."' ";
		
		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) {
            return $out;							
        }
		
		return ;		
    }
	
	function getStudentId($student_gturegno){
		
		$qry = "SELECT student_id 
				FROM cms_studentmaster cm 
				WHERE cm.college_id= '".$_SESSION["aCollegeId"]."' and student_gturegno = ".$student_gturegno;
		$out=dbQuery($qry);
		
		if (dbRows($out)>0) {
			$student_rec = dbArray($out);
            return $student_rec['student_id'];							
        }
		return '';				
	}
}
?>