<?php

class accesscontrol {

    var $int_glcode;
    var $chr_read;
    var $chr_star;
    var $chr_publish;
    var $intdisplayorder;
    var $chr_delete = 'Y';
    var $dt_createdate;
    var $dt_modifydate;
    var $oldint_displayorder;
    var $numofrows;
    var $numofpages;
    var $orderby = 'int_glcode';
    var $ordertype = 'desc';
    var $searchby = '0';
    var $searchtxt;
    var $start = 1;
    var $pagesize = DEFAULT_PAGESIZE;
    var $pagenumber = '1';
    var $lastinsertid;
    var $urlwithpara = '';
    var $urlwithpoutsearch = '';
    var $urlwithoutsort = '';
    var $urlwithoutpaging = '';
    var $configObj;
    var $filterby = '0';
    var $urlwithoutfilter = '';
    var $display_limit_array = array(5, 10, 15, 30);
    var $varpostdata = array();

    function accesscontrol($configObj) {
        $this->sortvar = '<img alt="sorting" src="' . GLOBAL_ADMIN_IMAGES_PATH . 'arrow-up.png" style="vertical-align:middle;">';
        $this->configObj = $configObj;
    }

    function intitialize() {
        $this->searchby = (isset($_REQUEST['searchby'])) ? $_REQUEST['searchby'] : $this->searchby;
        $_REQUEST['searchtxt'] = ($_REQUEST['type'] == 'autosearch') ? $_REQUEST['term'] : $_REQUEST['searchtxt'];
        $this->searchbyVal = (isset($_REQUEST['searchbyVal'])) ? $_REQUEST['searchbyVal'] : $this->searchbyVal;
        $this->searchtxt = (isset($_REQUEST['searchtxt'])) ? urldecode($_REQUEST['searchtxt']) : '';
        $this->searchtxtjs = (isset($_REQUEST['searchtxt'])) ? urlencode($_REQUEST['searchtxt']) : '';
        $this->orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : $this->orderby;
        $this->ordertype = (isset($_REQUEST['ordertype'])) ? $_REQUEST['ordertype'] : $this->ordertype;
        $this->filterby = (isset($_REQUEST['filterby'])) ? $_REQUEST['filterby'] : $this->filterby;
        if (isset($_REQUEST['sorting'])) {
            if ($this->ordertype == "asc") {   // This is for sort image     
                $this->ordertype = "desc";
                $this->sortvar = "<img alt=\"sorting\" src=\"" . GLOBAL_ADMIN_IMAGES_PATH . "arrow-down.png\" style=\"vertical-align:middle;\">";
            } else if ($this->ordertype == "desc") {   // This is for sort image       
                $this->ordertype = "asc";
                $this->sortvar = "<img alt=\"sorting\" src=\"" . GLOBAL_ADMIN_IMAGES_PATH . "arrow-up.png\" style=\"vertical-align:middle;\">";
            }
        }
        $this->pagesize = (isset($_REQUEST['pagesize'])) ? $_REQUEST['pagesize'] : $this->pagesize;
        $this->pagenumber = (isset($_REQUEST['pagenumber'])) ? $_REQUEST['pagenumber'] : $this->pagenumber;
        $this->start = ($this->pagenumber - 1 ) * $this->pagesize;
    }

    function select_groups($id) {
        $this->configObj->glDbObj->resetfields(); // Reset the object     
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table    
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'groups');
        $this->configObj->glDbObj->addColumn('*');
        $this->configObj->glDbObj->setWhere('int_glcode =' . $id);
        $row = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
        return $row;
    }

    function select_users($id) {
        $this->configObj->glDbObj->resetfields(); // Reset the object  
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table    
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'users');
        $this->configObj->glDbObj->addColumn('*');
        $this->configObj->glDbObj->setWhere('int_glcode =' . $id);
        $row = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
        return $row;
    }

    function CountRowsUser() {
        $this->intitialize();
        if (trim($this->searchtxt) != '') {
            $whereclause .= ($this->searchby == '0') ? " and ((var_fname like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (var_lname like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (concat(var_fname,' ',var_lname) like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (var_emailid like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (var_phoneno like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'))  " : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
        } if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);
            $whereclause .=" and $filterarray[0] = '$filterarray[1]'";
        } $sqlCountPages = "select count(1) as total from " . DB_PREFIX . "users where chr_delete = 'N' and chr_usertype = 'S' $whereclause ";
        $rs = $this->configObj->glDbObj->get_sql_row($sqlCountPages);
        $this->numofrows = $rs['total'];
        return $rs['total'];
    }

    function CountRowsgroups() {
        $this->intitialize();
        $this->Generateurl();
        if (trim($this->searchtxt) != '') {
            $whereclause .= ($this->searchby == '0') ? " and var_name like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'" : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
        } if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);
            $whereclause .=" and $filterarray[0] = '$filterarray[1]'";
        } $sqlCountPages = "select count(1) as total from " . DB_PREFIX . "groups where chr_delete = 'N' and chr_powerpanel_group = 'Y' $whereclause ";
        $rs = $this->configObj->glDbObj->get_sql_row($sqlCountPages);
        $this->numofrows = $rs['total'];
        return $rs['total'];
    }

    function selectall_groups() {
        $this->configObj->glDbObj->resetfields(); // Reset the object       
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table  

        $this->configObj->glDbObj->setTable(DB_PREFIX . 'groups');
        $this->configObj->glDbObj->addColumn('*');
        $whereclause = "chr_delete = 'N' and chr_powerpanel_group = 'Y'";
        if (trim($this->searchtxt) != '') {
            $whereclause .= ($this->searchby == '0') ? " and var_name like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'" : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
        } if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);
            $whereclause .=" and $filterarray[0] = '$filterarray[1]'";
        } if ($_REQUEST['type'] == 'autosearch') {
            $orderby = (isset($_REQUEST['orderby'])) ? 'order by ' . $this->orderby . ' ' . $this->ordertype : 'order by int_displayorder';
            $searchbyVal = (!empty($this->searchbyVal)) ? "  chr_delete = 'N' and chr_powerpanel_group = 'Y' and {$this->searchbyVal} like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%' " : " {$whereclause} ";
            if ($this->searchbyVal == '0') {
                $this->searchbyVal = "var_name";
            } if ($this->filterby != '0' && $this->filterby != '') {
                $filterarray = explode('-', $this->filterby);
                $whereclauseauto = " and $filterarray[0] = '$filterarray[1]'";
            } $autoSearchQry = "select int_glcode ,{$this->searchbyVal} as AutoVal  FROM " . DB_PREFIX . "groups where $searchbyVal $whereclauseauto group by var_name $orderby";
            $this->configObj->glLibraryObj->GetAutoSearch($autoSearchQry);
        } $this->configObj->glDbObj->setWhere($whereclause);
        $this->configObj->glDbObj->setOrderBy($this->orderby . ' ' . $this->ordertype);
        $this->configObj->glDbObj->setLimit($this->start . ', ' . $this->pagesize);
        $rs = $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        return $rs;
    }

    function selectall_users() {
        $this->configObj->glDbObj->resetfields(); // Reset the object    
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table   
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'users u left join ' . DB_PREFIX . 'groups g on u.fk_groups=g.int_glcode');
        $this->configObj->glDbObj->addColumn('u.*,g.var_name as var_name');
        if ($_REQUEST['view'] == 'users') {
            $whereclause = "u.chr_delete = 'N' and u.chr_usertype in('U','V')";
        } else {
            $whereclause = "u.chr_delete = 'N' and u.chr_usertype = 'S'";
        } if (trim($this->searchtxt) != '') {
//$whereclause .= ($this->searchby == '0') ? " and concat(u.var_fname,' ',u.var_lname) like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'" : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";     
            $whereclause .= ($this->searchby == '0') ? " and u.var_fname like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'" : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
        } if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);
            $whereclause .=" and u.$filterarray[0] = '$filterarray[1]'";
        } if ($_REQUEST['type'] == 'autosearch') {
            $orderby = (isset($_REQUEST['orderby'])) ? 'order by ' . $this->orderby . ' ' . $this->ordertype : 'order by var_name';
            $searchbyVal = (!empty($this->searchbyVal)) ? "  u.chr_delete = 'N' and  u.chr_usertype = 'S' and {$this->searchbyVal} like '%" . $this->searchtxt . "%' " : " {$whereclause} ";
            if ($this->searchbyVal == '0') {
                $this->searchbyVal = "var_fname";
            } if ($this->filterby != '0' && $this->filterby != '') {
                $filterarray = explode('-', $this->filterby);
                $whereclauseauto = " and u.$filterarray[0] = '$filterarray[1]'";
            } $autoSearchQry = "select u.int_glcode ,{$this->searchbyVal} as AutoVal  FROM " . DB_PREFIX . "users u where $searchbyVal $whereclauseauto group by u.var_fname $orderby";
            $this->configObj->glLibraryObj->GetAutoSearch($autoSearchQry);
        } $this->configObj->glDbObj->setWhere($whereclause);
        $this->configObj->glDbObj->setOrderBy($this->orderby . ' ' . $this->ordertype);
        $this->configObj->glDbObj->setLimit($this->start . ', ' . $this->pagesize);
        $rs = $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());        //echo ($this->configObj->glDbObj->buildQuery());       
        return $rs;
    }

    function insert_users() {
        if ($this->varpostdata['h_save'] == 'T') {
            $this->configObj->glLibraryObj->updatedisplay_order('users', $this->varpostdata['int_displayorder']);
            $this->int_glcode = ""; // clear key for autoincrement      
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable(DB_PREFIX . 'users');
            $this->configObj->glDbObj->setQueryType('insert');            // Set the Columns        
            $this->configObj->glDbObj->addColumn('var_fname');
            $this->configObj->glDbObj->addColumn('var_lname');
            $this->configObj->glDbObj->addColumn('var_emailid');
            $this->configObj->glDbObj->addColumn('var_password');
            $this->configObj->glDbObj->addColumn('chr_gender');
            $this->configObj->glDbObj->addColumn('var_address1');
            $this->configObj->glDbObj->addColumn('var_phoneno');
            $this->configObj->glDbObj->addColumn('var_address2');
            $this->configObj->glDbObj->addColumn('var_city');
            $this->configObj->glDbObj->addColumn('var_emailid1');
            $this->configObj->glDbObj->addColumn('var_emailid2');
            $this->configObj->glDbObj->addColumn('chr_usertype');
            $this->configObj->glDbObj->addColumn('int_displayorder');
            $this->configObj->glDbObj->addColumn('chr_publish');
            $this->configObj->glDbObj->addColumn('chr_read');
            $this->configObj->glDbObj->addColumn('chr_star');
            $this->configObj->glDbObj->addColumn('chr_delete');
            $this->configObj->glDbObj->addColumn('dt_createdate');
            $this->configObj->glDbObj->addColumn('dt_modifydate');
            $this->configObj->glDbObj->addColumn('fk_groups');            // Set the Columns Value      
            $this->configObj->glDbObj->addValue($this->varpostdata['var_fname']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_lname']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_emailid']);
            $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->cryptPass($this->varpostdata['var_password']));
            $this->configObj->glDbObj->addValue($this->varpostdata['chr_gender']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_address1']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_phoneno']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_address2']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_city']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_emailid1']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_emailid2']);
            $this->configObj->glDbObj->addValue('S');
            $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
            $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue($this->varpostdata['groupcmbuser']);
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            $this->lastinsertid = mysql_insert_id();
            $this->configObj->glLibraryObj->insertinlogmanager($this->varpostdata['fk_modules'], DB_PREFIX . 'users', 'var_fname', $this->lastinsertid, 'I'); // entry in user_group 
            if ($view != 'users') {
                $this->configObj->glLibraryObj->updatedisplay_order('users_groups', $this->varpostdata['int_displayorder']);
                $this->int_glcode = ""; // clear key for autoincrement  
                $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setTable(DB_PREFIX . 'users_groups');
                $this->configObj->glDbObj->setQueryType('insert');
                $this->configObj->glDbObj->addColumn('fk_groups');
                $this->configObj->glDbObj->addColumn('fk_users');
                $this->configObj->glDbObj->addColumn('int_displayorder');
                $this->configObj->glDbObj->addColumn('chr_publish');
                $this->configObj->glDbObj->addColumn('chr_read');
                $this->configObj->glDbObj->addColumn('chr_star');
                $this->configObj->glDbObj->addColumn('chr_delete');
                $this->configObj->glDbObj->addColumn('dt_createdate');
                $this->configObj->glDbObj->addColumn('dt_modifydate');
                $this->configObj->glDbObj->addValue($this->varpostdata['groupcmbuser']);
                $this->configObj->glDbObj->addValue($this->lastinsertid);
                $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
                $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
                $this->configObj->glDbObj->addValue('N');
                $this->configObj->glDbObj->addValue('N');
                $this->configObj->glDbObj->addValue('N');
                $this->configObj->glDbObj->addValue('NOW()');
                $this->configObj->glDbObj->addValue('NOW()');
                $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            } return true;
        }
    }

    function insert_groups() {
        if ($this->varpostdata['h_save'] == 'T') {
            $this->int_glcode = "";
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable(DB_PREFIX . 'groups');
            $this->configObj->glDbObj->setQueryType('insert');
            $this->configObj->glDbObj->addColumn('var_name');
            $this->configObj->glDbObj->addColumn('chr_publish');
            $this->configObj->glDbObj->addColumn('chr_read');
            $this->configObj->glDbObj->addColumn('chr_star');
            $this->configObj->glDbObj->addColumn('chr_delete');
            $this->configObj->glDbObj->addColumn('dt_createdate');
            $this->configObj->glDbObj->addColumn('dt_modifydate');
            $this->configObj->glDbObj->addValue($this->varpostdata['var_name']);
            $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            $this->lastinsertid = mysql_insert_id();
            $this->configObj->glLibraryObj->insertinlogmanager($this->varpostdata['fk_modules'], DB_PREFIX . 'groups', 'var_name', $this->lastinsertid, 'I');
            $this->addAccessToGroup($this->lastinsertid, $this->varpostdata['access']);
            return true;
        }
    }

    function addAccessToGroup($id, $access) {
        if (!empty($id)) {
            $sql = "select count(1) as total from " . DB_PREFIX . "useraccess where fk_groups=" . $id;
            $group = $this->configObj->glDbObj->get_sql_row($sql);
            if ($group['total'] > 0) {
                $sql = "update " . DB_PREFIX . "useraccess set chr_assign='N' where fk_groups=" . $id;
                $this->configObj->glDbObj->query($sql);
            } foreach ($access as $value) {
                $sql = "select count(1) as total from " . DB_PREFIX . "useraccess where fk_groups=" . $id . " and fk_module_useraction=" . $value;
                $result = $this->configObj->glDbObj->get_sql_row($sql);
                if ($result['total'] > 0) {
                    $sql = "update " . DB_PREFIX . "useraccess set chr_assign='Y' where fk_groups=" . $id . " and fk_module_useraction=" . $value;
                } else {
                    $sql = "insert into " . DB_PREFIX . "useraccess(fk_groups, fk_module_useraction, chr_assign, chr_delete, dt_modifydate) values($id,$value,'Y','N',NOW())";
                } $this->configObj->glDbObj->query($sql);
            }
        }
    }

    function insertgroupquick($name) {
        $this->int_glcode = "";
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'groups');
        $this->configObj->glDbObj->setQueryType('insert');
        $this->configObj->glDbObj->addColumn('var_name');
        $this->configObj->glDbObj->addColumn('chr_read');
        $this->configObj->glDbObj->addColumn('chr_star');
        $this->configObj->glDbObj->addColumn('chr_delete');
        $this->configObj->glDbObj->addColumn('dt_createdate');
        $this->configObj->glDbObj->addColumn('dt_modifydate');
        $this->configObj->glDbObj->addValue($name);
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->lastinsertid = mysql_insert_id();
        echo $this->groupcmbuser($this->lastinsertid);
        exit;
    }

    function update_users() {
        if ($this->varpostdata['int_displayorder'] != $this->varpostdata['old_displayorder']) {
            $this->update_display_order($this->varpostdata['eid'], $this->varpostdata['int_displayorder'], $this->varpostdata['old_displayorder']);
        } $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'users');
        $this->configObj->glDbObj->addColumn('var_fname');
        $this->configObj->glDbObj->addColumn('var_lname');
        $this->configObj->glDbObj->addColumn('var_emailid');
        if ($this->varpostdata['var_password'] != '') {
            $this->configObj->glDbObj->addColumn('var_password');
        } $this->configObj->glDbObj->addColumn('chr_gender');
        $this->configObj->glDbObj->addColumn('var_address1');
        $this->configObj->glDbObj->addColumn('var_phoneno');
        $this->configObj->glDbObj->addColumn('var_address2');
        $this->configObj->glDbObj->addColumn('var_city');
        $this->configObj->glDbObj->addColumn('var_emailid1');
        $this->configObj->glDbObj->addColumn('var_emailid2');
        $this->configObj->glDbObj->addColumn('chr_usertype');
        $this->configObj->glDbObj->addColumn('int_displayorder');
        $this->configObj->glDbObj->addColumn('chr_publish');
        $this->configObj->glDbObj->addColumn('chr_read');
        $this->configObj->glDbObj->addColumn('chr_star');
        $this->configObj->glDbObj->addColumn('chr_delete');
        $this->configObj->glDbObj->addColumn('dt_modifydate');
        $this->configObj->glDbObj->addColumn('fk_groups');
        $this->configObj->glDbObj->addValue($this->varpostdata['var_fname']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_lname']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_emailid']);
        if ($this->varpostdata['var_password'] != '') {
            $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->cryptPass($this->varpostdata['var_password']));
        } $this->configObj->glDbObj->addValue($this->varpostdata['chr_gender']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_address1']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_phoneno']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_address2']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_city']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_emailid1']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_emailid2']);
        $this->configObj->glDbObj->addValue('S');
        $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
        $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
        $this->configObj->glDbObj->addValue('Y');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue($this->varpostdata['groupcmbuser']);
        $this->configObj->glDbObj->setWhere('int_glcode=' . $this->varpostdata['eid']);
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->lastinsertid = $this->varpostdata['eid'];
        $this->configObj->glLibraryObj->insertinlogmanager($this->varpostdata['fk_modules'], DB_PREFIX . 'users', 'var_fname', $this->lastinsertid, 'U');
        $this->configObj->glLibraryObj->updatedisplay_order('users_groups', $this->varpostdata['int_displayorder']);
        if ($view != 'users') {
            $this->int_glcode = "";
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable(DB_PREFIX . 'users_groups');
            $this->configObj->glDbObj->setQueryType('update');
            $this->configObj->glDbObj->addColumn('fk_groups');
            $this->configObj->glDbObj->addColumn('fk_users');
            $this->configObj->glDbObj->addColumn('int_displayorder');
            $this->configObj->glDbObj->addColumn('chr_publish');
            $this->configObj->glDbObj->addColumn('chr_read');
            $this->configObj->glDbObj->addColumn('chr_star');
            $this->configObj->glDbObj->addColumn('chr_delete');
            $this->configObj->glDbObj->addColumn('dt_createdate');
            $this->configObj->glDbObj->addColumn('dt_modifydate');
            $this->configObj->glDbObj->addValue($this->varpostdata['groupcmbuser']);
            $this->configObj->glDbObj->addValue($this->lastinsertid);
            $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
            $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->setWhere('fk_users =' . $this->varpostdata['eid']);
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        } return true;
    }

    function update_groups() {
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'groups');
        $this->configObj->glDbObj->addColumn('var_name');
        $this->configObj->glDbObj->addColumn('chr_publish');
        $this->configObj->glDbObj->addColumn('chr_read');
        $this->configObj->glDbObj->addColumn('chr_star');
        $this->configObj->glDbObj->addColumn('chr_delete');
        $this->configObj->glDbObj->addColumn('dt_createdate');
        $this->configObj->glDbObj->addColumn('dt_modifydate');
        $this->configObj->glDbObj->addValue($this->varpostdata['var_name']);
        $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->setWhere('int_glcode=' . $this->varpostdata['eid']);
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->lastinsertid = $this->varpostdata['eid'];
        $this->configObj->glLibraryObj->insertinlogmanager($this->varpostdata['fk_modules'], DB_PREFIX . 'groups', 'var_name', $this->lastinsertid, 'U');
        $this->addAccessToGroup($this->varpostdata['eid'], $this->varpostdata['access']);
        return true;
    }

    function Generateurl() {
        $this->urlwithpara = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&numofrows=' . $this->numofrows . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&pagenumber=' . $this->pagenumber . '&filterby=' . $this->filterby;
        $this->urlwithpoutsearch = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&filterby=' . $this->filterby;
        $this->urlwithoutsort = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&numofrows=' . $this->numofrows . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&pagenumber=' . $this->pagenumber . '&ordertype=' . $this->ordertype . '&filterby=' . $this->filterby;
        $this->urlwithoutpaging = $this->pagename . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&filterby=' . $this->filterby;
        $this->urlwithoutfilter = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs;
        $this->configObj->AutoSearchUrl = $this->urlwithpara . "&type=autosearch&searchbyVal=" . $this->searchbyVal;
    }

    function generateParam($view = 'groups', $actionurl = 'index.php?module=groups&action=add', $searchArray = array("groups" => "groups"), $table = 'DB_PREFIX.groups', $position = 'top', $otheraction = '') {
        $filterPos = ($position == 'top') ? 'FT' : 'FB';
        if ($this->configObj->glSessionObj->value('admin_id') == '1') {
            $filterstar = array('filterarray' => array('chr_read-Y' => 'Read Only', 'chr_read-N' => 'Unread Only', 'chr_star-Y' => 'Star Only', 'chr_star-N' => 'Unstar Only'), 'filterurl' => $this->urlwithoutfilter, 'filterposition' => $filterPos, 'filterby' => $this->filterby);
        } else {
            $filterstar = array();
        } return array(
            'pageurl' => $this->pagename,
            'heading' => $view,
            'listImage' => 'add-new-user-icon.png',
            'tablename' => $table,
            'position' => $position,
            'actionImage' => 'add-new-button-blue.gif',
            'actionImageHover' => 'add-new-button-blue-hover.gif',
            'otheractionImage' => 'back-button-blue.gif',
            'actionUrl' => $actionurl, 'otheractionUrl' => $otheraction,
            'search' => array('searchArray' => $searchArray,
                'searchBy' => $this->searchby,
                'searchText' => $this->searchtxt,
                'searchUrl' => $this->urlwithpoutsearch), 'filter' => $filterstar, 'paging' => array('pagenumber' => $this->pagenumber, 'noofpages' => $this->noofpages, 'numofrows' => $this->numofrows, 'pagingurl' => $this->urlwithpara), 'display' => array('displayurl' => $this->urlwithoutpaging, 'pagesize' => $this->pagesize, 'limitarray' => $this->configObj->glLibraryObj->PagingArray(),));
    }

    function groupcmbuserselect($eid) {
        $sql = "select fk_groups from " . DB_PREFIX . "users_groups where fk_users = " . $eid . " and chr_publish = 'Y' and chr_delete = 'N'";
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        return $rs['fk_groups'];
    }

    function groupcmbuser($ids = '') {
        $returndata = '';
        $sql = "select int_glcode,var_name from " . DB_PREFIX . "groups where chr_publish='Y' and chr_delete='N' and chr_powerpanel_group = 'Y' order by int_displayorder asc";
        $rs = $this->configObj->glDbObj->query($sql);
        $returndata.='<select name="groupcmbuser" id="groupcmbuser" style="width:321px;">';
        $returndata.='<option value="0">Select Group</option>';
        while ($row = $this->configObj->glDbObj->fetch_array($rs)) {
            $returndata.='<option value="' . $row['int_glcode'] . '" ' . ($row['int_glcode'] == $ids ? 'selected' : '') . ' >' . $row['var_name'] . '</option>';
        } $returndata.='</select>';
        return $returndata;
    }

    function getmodulecmb($ids = '') {
        $selected_array = $ids['fk_modules'];
        if (!empty($selected_array)) {
            $i = 0;
            foreach ($selected_array as $value) {
                if ($i != 0)
                    $orderDetail.=",";
                $orderDetail.="'$value'";
                $i++;
            } $order = " ORDER BY FIELD(int_glcode,$orderDetail) desc";
        } else {
            $order = " order by int_glcode asc";
        } $returndata = '';
        $sql = "select int_glcode,var_modulename from " . DB_PREFIX . "modules where chr_publish='Y' and chr_delete='N' and chr_powerpanel_module = 'Y' $order";
        $rs = $this->configObj->glDbObj->query($sql);
        $returndata.='<select name="modulecmb[]" id="modulecmb" multiple size="10" style="width:250px">';
        $returndata.='<option value="0">Select Modules</option>';
        while ($row = $this->configObj->glDbObj->fetch_array($rs)) {
            if (!empty($selected_array)) {
                $returndata.='<option value="' . $row['int_glcode'] . '" ' . (in_array($row['int_glcode'], $selected_array) ? 'selected' : '') . '>' . $row['var_modulename'] . '</option>';
            } else {
                $returndata.='<option value="' . $row['int_glcode'] . '">' . $row['var_modulename'] . '</option>';
            }
        } $returndata.='</select>';
        return $returndata;
    }

    function getuserscmb() {
        $returndata = '';
        $gsql = "select fk_users from " . DB_PREFIX . "users_groups where fk_groups=" . $_REQUEST['gid'] . " and chr_delete='N'";
        $gres = $this->configObj->glDbObj->query($gsql);
        $gcount = $this->configObj->glDbObj->num_rows($gres);
        if ($gcount > 0) {
            while ($grow = $this->configObj->glDbObj->fetch_array($gres)) {
                $garray[] = $grow['fk_users'];
            } $string = implode(',', $garray);
            $whereclause = ' and int_glcode not in (' . $string . ')';
        } else {
            $whereclause = '';
        } $sql = "select int_glcode,var_fname,var_lname from " . DB_PREFIX . "users where chr_publish='Y' and chr_delete='N' and chr_usertype='S'" . $whereclause . " order by int_displayorder asc";
        $rs = $this->configObj->glDbObj->query($sql);
        $returndata.='<select name="userscmb[]" id="userscmb" multiple>';
        $returndata.='<option value="" disabled >Select Users</option>';
        while ($row = $this->configObj->glDbObj->fetch_array($rs)) {
            $returndata.='<option value="' . $row['int_glcode'] . '">' . $row['var_fname'] . '  ' . $row['var_lname'] . '</option>';
        } $returndata.='</select>';
        return $returndata;
    }

    function is_usersused($fk_modules) {
        $deleteids = $_REQUEST['dids'];
        $deletearray = explode(',', $deleteids);
        $totaldeletedrecords = count($deletearray);
        for ($i = 0; $i < $totaldeletedrecords; $i++) {
            $sql = "Update " . DB_PREFIX . "users set chr_delete='Y', dt_modifydate=NOW(),var_ipaddress='" . $_SERVER['REMOTE_ADDR'] . "',var_adminuser='" . ADMIN_NAME . "'  where int_glcode='$deletearray[$i]'";
            $this->configObj->glDbObj->query($sql);
            $this->configObj->glLibraryObj->insertinlogmanager($fk_modules, DB_PREFIX . 'users', 'var_fname', $deletearray[$i], 'D');
        } $this->load_users();
        exit;
    }

    function is_groupsused($fk_modules) {
        $deleteids = $_REQUEST['dids'];
        $deletearray = explode(',', $deleteids);
        $totaldeletedrecords = count($deletearray);
        for ($i = 0; $i < $totaldeletedrecords; $i++) {
            $sql = "Update " . DB_PREFIX . "groups set chr_delete='Y', dt_modifydate=NOW() where int_glcode='$deletearray[$i]'";
            $this->configObj->glDbObj->query($sql);
            $this->configObj->glLibraryObj->insertinlogmanager($fk_modules, DB_PREFIX . 'groups', 'var_name', $deletearray[$i], 'D');
        } $this->load_groups();
        exit;
    }

    function load_groups() {
        $this->pagename = 'index.php?module=accesscontrol&view=group'; // Attribute of Page Name   
        $this->loadCount('CountRowsgroups');
        $result = $this->selectall_groups();
        $this->configObj->glTplObj->set('result', $result);
        $view = 'Manage Group Access';
        $actionurl = 'index.php?module=accesscontrol&view=group&action=add';
        $searchArray = array("var_name" => "Name");
        $table = DB_PREFIX . 'groups';
        $parmas = $this->generateParam($view, $actionurl, $searchArray, $table);
        $this->configObj->glTplObj->set('headerpanel', $this->configObj->glLibraryObj->generateHeaderPanel($parmas));
        $this->configObj->glTplObj->set('pagingTop', $this->configObj->glLibraryObj->generatePagingPannel($parmas));
        $this->configObj->glTplObj->set('pagingBottom', $this->configObj->glLibraryObj->generatePagingPannel($this->generateParam($view, $actionurl, $searchArray, $table, 'bottom')));
        $finalsortvar = 'setsortimg' . $this->orderby;
        $this->configObj->glTplObj->set($finalsortvar, $this->sortvar);
        if ($_REQUEST['msg'] == 'add') {
            $messagebox = $this->configObj->glLibraryObj->message("The record is successfully saved");
            $this->configObj->glTplObj->set('messagebox', $messagebox);
        } else if ($_REQUEST['msg'] == 'edit') {
            $messagebox = $this->configObj->glLibraryObj->message("The record is successfully saved");
            $this->configObj->glTplObj->set('messagebox', $messagebox);
        } $notemessagebox = $this->configObj->glLibraryObj->notemessage("Note : ", "Adding groups  are incremental, once you add a new group it will display as first group and previous groups will move down in the order.");
        $this->configObj->glTplObj->set('notemessagebox', $notemessagebox);
        if ($this->configObj->isAjaxSet) {
            echo $this->configObj->glTplObj->process('groups.tpl.php');
            exit;
        } else {
            $this->configObj->adminContentPanel = $this->configObj->glTplObj->process('groups.tpl.php');
        }
    }

    function load_users() {
        if ($_REQUEST['task'] == 'orderupdate') {
            $updateids = $_REQUEST['uids'];
            $updatevalues = $_REQUEST['uvals'];
            $updateoldvalues = $_REQUEST['uoldvals'];
            $upidsarray = explode(',', $updateids);
            $upvalsarray = explode(',', $updatevalues);
            $upoldvalsarray = explode(',', $updateoldvalues);
            $this->update_display_order($upidsarray, $upvalsarray, $upoldvalsarray);
        } $this->pagename = 'index.php?module=accesscontrol';
        $this->loadCount('CountRowsUser');
        $this->configObj->glTplObj->set('setsortimg' . $this->orderby, $this->sortvar);
        $result = $this->selectall_users();
        $this->configObj->glTplObj->set('result', $result);
        $table = DB_PREFIX . 'users';
        $view = 'Manage Staff';
        $actionurl = 'index.php?module=accesscontrol&action=add';
//$searchArray = array("concat(u.var_fname,' ',u.var_lname)" => "Name", "var_emailid" => "Email id");  
        $searchArray = array("var_fname" => "Name", "var_emailid" => "Email id");
        $parmas = $this->generateParam($view, $actionurl, $searchArray, $table);
        $this->configObj->glTplObj->set('headerpanel', $this->configObj->glLibraryObj->generateHeaderPanel($parmas));
        $this->configObj->glTplObj->set('pagingTop', $this->configObj->glLibraryObj->generatePagingPannel($parmas));
        $this->configObj->glTplObj->set('pagingBottom', $this->configObj->glLibraryObj->generatePagingPannel($this->generateParam($view, $actionurl, $searchArray, $table, 'bottom')));
        if ($_REQUEST['msg'] == 'add') {
            $messagebox = $this->configObj->glLibraryObj->message("The record is successfully saved");
            $this->configObj->glTplObj->set('messagebox', $messagebox);
        } else if ($_REQUEST['msg'] == 'edit') {
            $messagebox = $this->configObj->glLibraryObj->message("The record is successfully saved");
            $this->configObj->glTplObj->set('messagebox', $messagebox);
        } $notemessagebox = $this->configObj->glLibraryObj->notemessage("Note : ", "Adding users are incremental, once you add a new user it will display as first user and previous user will move down in the order.");
        $this->configObj->glTplObj->set('notemessagebox', $notemessagebox);
        $page = $this->configObj->glTplObj->process('staff.tpl.php');
        if ($this->configObj->isAjaxSet) {
            echo $page;
            exit;
        } else {
            $this->configObj->adminContentPanel = $page;
        }
    }

    function loadCount($function) {
        $this->intitialize();
        $this->numofrows = (isset($_REQUEST['numofrows'])) ? $_REQUEST['numofrows'] : $this->{$function}();
        $this->numofrows = $this->{$function}();
        $this->noofpages = intval($this->numofrows / $this->pagesize);
        $this->noofpages = (($this->numofrows % $this->pagesize) > 0) ? ($this->noofpages + 1) : ($this->noofpages);
        $this->configObj->glTplObj->set('numofrows', $this->numofrows);
        $this->Generateurl();
    }

    function check_sameuser() {
        $usertype = " and chr_usertype ='S' ";
        if ($_REQUEST['eid'] != '') {
            $sql = "select count(1) as total from " . DB_PREFIX . "users where var_emailid='" . $_REQUEST['userid'] . "' and chr_publish='Y' " . $usertype . " and chr_delete='N' and int_glcode!=" . $_REQUEST['eid'];
            $rs = $this->configObj->glDbObj->get_sql_row($sql);
            return $rs['total'];
        } else {
            $sql = "select count(1) as total from " . DB_PREFIX . "users where var_emailid='" . $_REQUEST['userid'] . "' and chr_publish='Y'  " . $usertype . " and chr_delete='N'";
            $rs = $this->configObj->glDbObj->get_sql_row($sql);
            return $rs['total'];
        }
    }

    function update_display_order($ids, $values, $oldvalues, $table = 'users') {
        $tablename = "" . DB_PREFIX . $table;
        for ($i = 0; $i < count($ids); $i++) {
            if ($values[$i] != $oldvalues[$i]) {
                $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setQueryType('select');
                $this->configObj->glDbObj->setTable($tablename);
                $this->configObj->glDbObj->addColumn('count(1) as total');
                $this->configObj->glDbObj->setWhere("int_displayorder=" . $values[$i] . " and chr_delete = 'N'");
                $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
                if ($rs['total'] > 0) {
                    if ($values[$i] > $oldvalues[$i]) {
                        $this->configObj->glDbObj->resetfields();
                        $this->configObj->glDbObj->setTable($tablename);
                        $this->configObj->glDbObj->setQueryType('update');
                        $this->configObj->glDbObj->addColumn('int_displayorder');
                        $this->configObj->glDbObj->UnsetQuotes();
                        $this->configObj->glDbObj->addValue('int_displayorder - 1');
                        $this->configObj->glDbObj->SetQuotes();
                        $this->configObj->glDbObj->setWhere('int_displayorder > ' . $oldvalues[$i] . ' and int_displayorder <= ' . $values[$i] . '');
                        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                    } else {
                        $this->configObj->glDbObj->resetfields();
                        $this->configObj->glDbObj->setTable($tablename);
                        $this->configObj->glDbObj->setQueryType('update');
                        $this->configObj->glDbObj->addColumn('int_displayorder');
                        $this->configObj->glDbObj->UnsetQuotes();
                        $this->configObj->glDbObj->addValue('int_displayorder + 1');
                        $this->configObj->glDbObj->SetQuotes();
                        $this->configObj->glDbObj->setWhere('int_displayorder >= ' . $values[$i] . ' and  int_displayorder < ' . $oldvalues[$i] . '');
                        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                    }
                } $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setTable($tablename);
                $this->configObj->glDbObj->setQueryType('update');
                $this->configObj->glDbObj->addColumn('int_displayorder');
                $this->configObj->glDbObj->addValue($values[$i]);
                $this->configObj->glDbObj->setWhere('int_glcode=' . $ids[$i] . '');
                $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            }
        }
    }

    function insertQuickModuleAction() {
        $sql = "select GROUP_CONCAT(int_glcode) as action from " . DB_PREFIX . "useraction where chr_delete='N'";
        $result = $this->configObj->glDbObj->get_sql_row($sql);
        $action = explode(",", $result['action']);
        $sql = "select int_glcode from imac_modules where chr_powerpanel_module='Y'";
        $result = $this->configObj->glDbObj->query($sql);
        $sql = "insert into " . DB_PREFIX . "module_useraction ( `fk_modules`, `fk_useraction`, `chr_delete`, `dt_modifydate`) values";
        $mainvalue = "";
        while ($row = $this->configObj->glDbObj->fetch_array($result)) {
            $sqlvalue = "";
            foreach ($action as $value) {
                if (!empty($sqlvalue) || !empty($mainvalue))
                    $sqlvalue.=",";
                $sqlvalue.="(" . $row['int_glcode'] . "," . $value . ",'N',NOW())";
            } $mainvalue = $mainvalue . $sqlvalue;
        } echo $sql = $sql . $mainvalue;
    }

    /* quick inser for group and access control */

    function insertGroupAccess() {
        $sql = "select GROUP_CONCAT(int_glcode) as userGroup from " . DB_PREFIX . "groups where chr_delete='N'";
        $result = $this->configObj->glDbObj->get_sql_row($sql);
        $userGroup = explode(",", $result['userGroup']);
        $sql = "select int_glcode from " . DB_PREFIX . "module_useraction where chr_delete='N'";
        $result = $this->configObj->glDbObj->query($sql);
        $sql = "insert into " . DB_PREFIX . "useraccess (`fk_groups`, `fk_module_useraction`, `chr_assign`, `chr_delete`, `dt_modifydate`) VALUES";
        $mainvalue = "";
        while ($row = $this->configObj->glDbObj->fetch_array($result)) {
            $sqlvalue = "";
            foreach ($userGroup as $value) {
                if (!empty($sqlvalue) || !empty($mainvalue))
                    $sqlvalue.=",";
                $sqlvalue.="($value, " . $row['int_glcode'] . ",'Y','N',NOW())";
            } $mainvalue = $mainvalue . $sqlvalue;
        } echo $sql = $sql . $mainvalue;
    }

    function getAllAction() {
        $sql = "select GROUP_CONCAT(int_glcode) as action,GROUP_CONCAT(var_action) as actionName from " . DB_PREFIX . "useraction where chr_delete='N'";
        $result = $this->configObj->glDbObj->get_sql_row($sql);
        $tempAction = explode(",", $result['action']);
        $tempActionName = explode(",", $result['actionName']);
        for ($i = 0; $i < count($tempAction); $i++) {
            $action[$i]['actionId'] = $tempAction[$i];
            $action[$i]['actionName'] = $tempActionName[$i];
        } return $action;
    }

    function getAllmodule() {
        $sql = "select int_glcode as moduleId,var_modulename as moduleName,chr_pro_modulename, 'N' as chrcustom,var_modulename as orderfield from " . DB_PREFIX . "modules where chr_powerpanel_module='Y' and int_glcode NOT IN(8,11)               ORDER BY moduleId";
        $result = $this->configObj->glDbObj->query($sql);
        $module = array();
        while ($row = $this->configObj->glDbObj->fetch_array($result)) {
            $temp['moduleId'] = $row['moduleId'];
            $temp['moduleName'] = $row['moduleName'];
            $temp['chr_pro_modulename'] = $row['chr_pro_modulename'];
            $temp['chrcustom'] = $row['chrcustom'];
            array_push($module, $temp);
        } return $module;
    }

    function getAllCustomModule() {
        $sql = "select int_glcode as moduleId,var_pagename as moduleName,var_pagename as chr_pro_modulename,'Y' as chrcustom,int_glcode as orderfield from " . DB_PREFIX . "pages where  chr_delete='N' and chr_publish='Y'  ORDER BY orderfield";
        $result = $this->configObj->glDbObj->query($sql);
        $module = array();
        while ($row = $this->configObj->glDbObj->fetch_array($result)) {
            $temp['moduleId'] = $row['moduleId'];
            $temp['moduleName'] = $row['moduleName'];
            $temp['chr_pro_modulename'] = $row['chr_pro_modulename'];
            array_push($module, $temp);
        } return $module;
    }

    function getAllModuleAction() {
        $allAction = $this->getAllAction();
        $allModule = $this->getAllmodule();
        $mainArray = array();
        foreach ($allModule as $moduleValue) {
            foreach ($allAction as $actionValue) {
                $sql = "select int_glcode,chr_delete from " . DB_PREFIX . "module_useraction where fk_modules=" . $moduleValue['moduleId'] . " and fk_useraction='" . $actionValue['actionId'] . " '";
                $result = $this->configObj->glDbObj->get_sql_row($sql);
                if ($result['chr_delete'] == 'Y') {
                    $mainArray[$moduleValue['moduleId']][$actionValue['actionId']] = 0;
                } else {
                    $mainArray[$moduleValue['moduleId']][$actionValue['actionId']] = $result['int_glcode'];
                }
            }
        } return $mainArray;
    }

    function getAllCustomModuleAction() {
        $allAction = $this->getAllAction();
        $allCustomModule = $this->getAllCustomModule();
        $mainArray = array();
        foreach ($allCustomModule as $moduleValue) {
            foreach ($allAction as $actionValue) {
                $sql = "select int_glcode,chr_delete from " . DB_PREFIX . "module_useraction where fk_modules=" . $moduleValue['moduleId'] . " and fk_useraction='" . $actionValue['actionId'] . " '";
                $result = $this->configObj->glDbObj->get_sql_row($sql);
                if ($result['chr_delete'] == 'Y') {
                    $mainArray[$moduleValue['moduleId']][$actionValue['actionId']] = 0;
                } else {
                    $mainArray[$moduleValue['moduleId']][$actionValue['actionId']] = $result['int_glcode'];
                }
            }
        } return $mainArray;
    }

    /** get all the user access     * @param <type> $id */
    function getAllUserAccess($id) {
        $sql = "select GROUP_CONCAT(fk_module_useraction) as userAccess from " . DB_PREFIX . "useraccess where fk_groups=$id and chr_assign='Y' and chr_delete='N'";
        $result = $this->configObj->glDbObj->get_sql_row($sql);
        $userAccess = explode(",", $result['userAccess']);
        return $userAccess;
    }

    function selectAllassignAction($id = '') {
        $sql = "select mu.int_glcode,mu.fk_modules,mu.fk_useraction,mu.chr_delete as chrdelete,ua.chr_assign from " . DB_PREFIX . "module_useraction mu left join " . DB_PREFIX . "useraccess ua on mu.int_glcode = ua.fk_module_useraction and ua.chr_delete='N' and ua.fk_groups = '$id'";
        $result = $this->configObj->glDbObj->query($sql);
        $actionassign = array();
        while ($row = $this->configObj->glDbObj->fetch_array($result)) {
            $actionmodule[$row['fk_modules']][$row['fk_useraction']] = $row['int_glcode'];
            $actionassign[$row['fk_modules']][$row['fk_useraction']] = $row['chr_assign'];
            $actiondisable[$row['fk_modules']][$row['fk_useraction']] = $row['chrdelete'];
        } $this->actiondisable = $actiondisable;
        $this->actionassign = $actionassign;
        return $actionmodule;
    }

    function checkExistedEmailid($varemail) {
        $Sql = "SELECT int_glcode FROM " . DB_PREFIX . "users where chr_delete='N' and var_emailid='" . $varemail . "'";
        return $this->configObj->glDbObj->get_sql_number($Sql);
    }

////end of class
}

?>