<?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 UserMgmt
{
    /**
     * @var public $user_id This is the user_id Id feteched from the database(lms_usermaster).
     */
    public $user_id;

    /**
     * @var public $user_role This is the user_role Role of user feteched from the database(lms_usermaster).
     */

    public $user_role;

    /**
     * @var public $user_name This is the user_name  Name of user feteched from the database(lms_usermaster).
     */
    public $user_name;

    /**
     * @var public $user_password This is the user_password Password of user feteched from the database(lms_usermaster).
     */

    public $user_password;


    /**
     * @var public $company_id This is the company_id.
     */
    public $company_id;
    /**
     * @var public $menu_ids This is the menu_ids Name of user feteched from the database(sms_usermaster).
     */
    public $menu_ids;


    /**
     * @var public $page_ids This is the page_ids Name of user feteched from the database(sms_usermaster).
     */
    public $page_ids;


    public $subpage_ids;
    /**
     * @var public $login_id This is the id of loger.
     */
    public $createdby;

    /**
     * @var public $student_createdon This is the Student createdom.
     */
    public $createdon;
    public $user_count;




    function UserMgmt()
    {
        $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_usermaster where lms_usermaster.company_id= '" . $_SESSION["cCompany_id"] . "' ";

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

        $out = dbQuery($qry);

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

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

            $this->user_id = ($user_id);
            $this->user_role = ($user_role);
            $this->user_name = ($user_name);
            $this->user_password = ($user_password);
            $this->company_id = ($company_id);
            $this->module_ids = ($module_ids);
            $this->menu_ids = ($menu_ids);
            $this->page_ids = ($page_ids);
            $this->subpage_ids = ($subpage_ids);
            $this->createdby = ($createdby);
            $this->createdon = ($createdon);
            $this->user_lastlogin = ($user_lastlogin);
            $this->user_currentlogin = ($user_currentlogin);

            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 
				lu.*,lc.*
				FROM 
			  		 lms_usermaster lu LEFT JOIN lms_companymaster lc 
					ON lc.company_id=lu.company_id	
					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";
        }

        // echo $qry;
        // exit;
        $out = dbQuery($qry);

        if (dbRows($out) > 0) {
            $this->user_count = dbRows($out);
            return $out;
        }
        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_usermaster 
				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 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 getExistingRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
    {
        $this->user_count = 0;

        $qry = "SELECT Count(*) AS Count FROM lms_usermaster 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()
    {
        $Qry1 = "";
        $Qry1 .= "user_name='" . Escape($this->user_name) . "',";
        $Qry1 .= "user_password='" . Escape($this->user_password) . "',";
        $Qry1 .= "company_id='" . Escape($this->company_id) . "',";
        $Qry1 .= "menu_ids='" . Escape($this->menu_ids) . "',";
        $Qry1 .= "page_ids='" . Escape($this->page_ids) . "',";
        $Qry1 .= "subpage_ids='" . Escape($this->subpage_ids) . "',";
        $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_usermaster set " . $Qry1 . " ";
            dbQuery($qry);
            $this->user_id = dbInsertedId();
        }
    }

    /*function edit()
       {
           $Qry1 = "";
           $Qry1 .= "user_name='"		   	.Escape($this->user_name)."',";
           $Qry1 .= "user_password='"		.Escape($this->user_password)."',";
           $Qry1 .= "company_id='"			.Escape($this->company_id)."',";	
           $Qry1 .= "menu_ids='"			.Escape($this->menu_ids)."',";			
           $Qry1 .= "page_ids='"			.Escape($this->page_ids)."',";
           $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_usermaster set " . $Qry1 ."where user_id=".$this->user_id."  ";
               dbQuery($qry);
               $this->user_id=dbInsertedId();
           }
       }*/


    function editLogin()
    {
        $Qry1 = "";

        $Qry1 .= "user_name='" . Escape($this->user_name) . "',";
        $Qry1 .= "user_password='" . Escape($this->user_password) . "',";
        $Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";


        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "update lms_usermaster set " . $Qry1 . " where user_id=" . $this->user_id . " And lms_usermaster.company_id= '" . $_SESSION["cCompany_id"] . "' ";
            dbQuery($qry);
        }
    }

    function editRight()
    {
        $Qry1 = "";

        $Qry1 .= "menu_ids='" . Escape($this->menu_ids) . "',";
        $Qry1 .= "page_ids='" . Escape($this->page_ids) . "',";
        $Qry1 .= "subpage_ids='" . Escape($this->subpage_ids) . "',";
        $Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";


        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "update lms_usermaster set " . $Qry1 . " where user_id=" . $this->user_id . " And lms_usermaster.company_id= '" . $_SESSION["cCompany_id"] . "' ";
            dbQuery($qry);
        }
    }


    /**
     * 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_usermaster 
             	where user_id in (" . $this->user_id . ") 
				and company_id='" . $_SESSION["cCompany_id"] . "'";
        dbQuery($qry);
    }


}
?>