<?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 UserAccessMgmt
 *
 * @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 UserAccessMgmt
{
    /**
     * @var public $useraccess_id This is the User Access id.
     */
    public $useraccess_id;

    /**
     * @var public $user_id This is the user Id.
     */
    public $user_id;

    /**
     * @var public $user_id This is the user Id.
     */
    public $menu_id;
    public $module_id;

    /**
     * @var public $page_id This is the Page Id feteched from the database(sms_pagemaster).
     */
    public $page_id;

    /**
     * @var public $useraccess_add This is the user right to add.
     */
    public $useraccess_add;

    /**
     * @var public $useraccess_edit This is the user right to edit.
     */
    public $useraccess_edit;

    /**
     * @var public $useraccess_delete This is the user right to delete.
     */
    public $useraccess_delete;

    /**
     * @var public $useraccess_delete This is the user right to delete.
     */
    public $useraccess_view;

    /**
     * @var public $createdby This is the login id.
     */
    public $createdby;

    /**
     * @var public $createdon This is the creation date.
     */
    public $createdon;

    /**
     * @var public $useraccess_msg This is the message.
     */
    public $useraccess_msg;

    /**
     * @var public $useraccess_redirectfile This is file name to be redirected on after the operation.
     */
    public $useraccess_redirectfile;


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

    }

    /**
     * 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_id='" . Escape($this->user_id) . "',";
        $Qry1 .= "page_id='" . Escape($this->page_id) . "',";
        $Qry1 .= "menu_id='" . Escape($this->menu_id) . "',";
        $Qry1 .= "module_id='" . Escape($this->module_id) . "',";
        $Qry1 .= "useraccess_add='" . Escape($this->useraccess_add) . "',";
        $Qry1 .= "useraccess_edit='" . Escape($this->useraccess_edit) . "',";
        $Qry1 .= "useraccess_delete='" . Escape($this->useraccess_delete) . "',";
        $Qry1 .= "useraccess_view='" . Escape($this->useraccess_view) . "',";
        $Qry1 .= "login_id='" . Escape($_SESSION['aUserId']) . "',";
        $Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";

        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "insert into cms_useraccess set " . $Qry1 . " ";
            dbQuery($qry);
            $this->useraccess_id = 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  cms_useraccess 
             	where user_id in (" . $this->deleteUser_Id . ")";

        dbQuery($qry);
    }

    /**
     * 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 cms_useraccess 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;
        $out = dbQuery($qry);

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

    }

    function getuseraccess($condition)
    {
   

        $qry = "SELECT * FROM cms_useraccess where 1=1 ";
			
        if ($condition != "") {
            $qry .= $condition;
        }
//echo $qry;
        $out = dbQuery($qry);

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