<?php

defined('_VALID') or die(RESTRICTED_ACCESS);
include_once('class.accesscontrol.php');
$accesscontrolObj = new accesscontrol($configObj);
$action = $_REQUEST['action'];
$view = $_REQUEST['view'];
$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('accesscontrolObj', $accesscontrolObj);
$accesscontrolObj->fk_modules = '2';
$paramMain = $configObj->AllmoduleAccess[$configObj->ModuleName];
$configObj->glTplObj->set('paramMain', $paramMain);
if ($configObj->glSessionObj->value('admin_id') != '1' || $configObj->glSessionObj->value('chr_user') == 'A')
{
    
    $configObj->glLibraryObj->header_redirect("index.php");
}
switch ($view) {

    case 'quickModuleAction':
        
        $accesscontrolObj->insertQuickModuleAction();
        exit;
        break;

    case 'insertGroupAccess':
        
        $accesscontrolObj->insertGroupAccess();
        exit;
        break;

    case 'group':
        
        switch ($action) {
            case 'add':
                
                if ($paramMain['Add'] != 'Y') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&view=group');
                }
                $accesscontrolObj->loadCount('CountRowsgroups');
                $accesscontrolObj->pagename = 'index.php?module=accesscontrol&view=group'; // Attribute of Page Name
                $accesscontrolObj->varpostdata = $_REQUEST;
                $configObj->glTplObj->set('accGroupTab', true);
                if ($accesscontrolObj->insert_groups()) {
                    if ($_POST['btnsaveandc_x'] != '') {
                        $eid = $accesscontrolObj->lastinsertid;
                        $action = 'edit';
                        $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&view=group&action=edit&msg=add&eid=' . $eid);
                    } else if ($_POST['btnsaveande_x'] != '') {
                        $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&view=group&msg=add');
                    }
                }
                $configObj->glTplObj->set('fk_modules', $accesscontrolObj->fk_modules);
                $modulecmb = $accesscontrolObj->getmodulecmb();

                //get all action with id and name
                $configObj->glTplObj->set('allAction', $accesscontrolObj->getAllAction());
                $configObj->glTplObj->set('actionmodule', $accesscontrolObj->selectAllassignAction());
                //get module id and name
                $configObj->glTplObj->set('allModule', $accesscontrolObj->getAllmodule());
                //get module related detail
                $configObj->glTplObj->set('allModuleAction', $accesscontrolObj->getAllModuleAction());
                $configObj->glTplObj->set('allCustomModule', $accesscontrolObj->getAllCustomModule());
                //get module related detail
                $configObj->glTplObj->set('allCustomModuleAction', $accesscontrolObj->getAllCustomModuleAction());
                //add code for access control
                $configObj->glTplObj->set('modulecmb', $modulecmb);
                if ($_REQUEST['msg'] == 'add') {
                    $messagebox = $accesscontrolObj->configObj->glLibraryObj->message("Congrats! The record is successfully saved.");
                    $accesscontrolObj->configObj->glTplObj->set('messagebox', $messagebox);
                }
                $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons('index.php?module=accesscontrol&view=group', 'bottom'));
                $configObj->adminContentPanel = $configObj->glTplObj->process('groups_form.tpl.php');
                break;

            case 'edit':

                if (empty($_REQUEST['eid'])) {
                    $configObj->glLibraryObj->header_redirect('index.php');
                }
                if ($paramMain['Edit'] != 'Y') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&view=group');
                }
                $accesscontrolObj->loadCount('CountRowsgroups');
                $accesscontrolObj->pagename = 'index.php?module=accesscontrol&view=group';
                $configObj->glTplObj->set('accGroupTab', true);
                $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons('index.php?module=accesscontrol&view=group', 'bottom'));

                if ($_REQUEST['h_save'] == 'T') {
                    $accesscontrolObj->varpostdata = $_REQUEST;
                    if ($accesscontrolObj->update_groups()) {
                        if ($_POST['btnsaveandc_x'] != '') {
                            $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&view=group&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                        } else if ($_POST['btnsaveande_x'] != '') {
                            $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&view=group&msg=edit');
                        }
                    }
                } else {
                    if ($_REQUEST['msg'] == 'add') {
                        $messagebox = $accesscontrolObj->configObj->glLibraryObj->message("Congrats! The record is successfully saved.");
                        $accesscontrolObj->configObj->glTplObj->set('messagebox', $messagebox);
                    } else if ($_REQUEST['msg'] == 'edit') {
                        $messagebox = $accesscontrolObj->configObj->glLibraryObj->message("Congrats! The record is successfully edited and saved.");
                        $accesscontrolObj->configObj->glTplObj->set('messagebox', $messagebox);
                    }
                    $configObj->glTplObj->set('fk_modules', $accesscontrolObj->fk_modules);
                    $row = $accesscontrolObj->select_groups($_REQUEST['eid']);
                    $configObj->glTplObj->set('row', $row);


                    //add code for access control
                    //get all action with id and name
                    $configObj->glTplObj->set('allAction', $accesscontrolObj->getAllAction());
                    $configObj->glTplObj->set('actionmodule', $accesscontrolObj->selectAllassignAction($_REQUEST['eid']));
                    //get module id and name
                    $configObj->glTplObj->set('allModule', $accesscontrolObj->getAllmodule());
                   // $configObj->glTplObj->set('allCustomModule', $accesscontrolObj->getAllCustomModule());
                    //get module related detail
                    $configObj->glTplObj->set('allModuleAction', $accesscontrolObj->getAllModuleAction());
                   // $configObj->glTplObj->set('allCustomModuleAction', $accesscontrolObj->getAllCustomModuleAction());
                    //get user access
                    $configObj->glTplObj->set('allUserAccess', $accesscontrolObj->getAllUserAccess($_REQUEST['eid']));
                    $configObj->adminContentPanel = $configObj->glTplObj->process('groups_form.tpl.php');
                }
                break;
            case 'delete':

                if ($configObj->isAjaxSet) {
                    $accesscontrolObj->is_groupsused($accesscontrolObj->fk_modules);
                }
                break;
            default:

                $configObj->glTplObj->set('accGroupTab', true);
                $accesscontrolObj->load_groups();
                break;
        }
        break;

    default:
        switch ($action) {
            case 'add':
                
                if ($paramMain['Add'] != 'Y') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol');
                }
                $accesscontrolObj->pagename = 'index.php?module=accesscontrol';
                $accesscontrolObj->loadCount('CountRowsUser');
                $accesscontrolObj->varpostdata = $_REQUEST;
                $configObj->glTplObj->set('accAddTab', true);

                if ($accesscontrolObj->insert_users()) {
                    if ($_POST['btnsaveandc_x'] != '') {
                        $eid = $accesscontrolObj->lastinsertid;
                        $action = 'edit';
                        $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&action=edit&msg=add&eid=' . $eid);
                    } else if ($_POST['btnsaveande_x'] != '') {
                        $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&msg=add');
                    }
                }

                $configObj->glTplObj->set('fk_modules', $accesscontrolObj->fk_modules);
                $groupdrp = $accesscontrolObj->groupcmbuser();
                $configObj->glTplObj->set('groupdrp', $groupdrp);
                if ($_REQUEST['msg'] == 'add') {
                    $messagebox = $accesscontrolObj->configObj->glLibraryObj->message("congrats! The record is successfully saved.");
                    $accesscontrolObj->configObj->glTplObj->set('messagebox', $messagebox);
                }
                $configObj->glTplObj->set('frmaction', $accesscontrolObj->urlwithpara . '&action=' . $_REQUEST['action']);
                $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons('index.php?module=accesscontrol', 'bottom'));
                $configObj->adminContentPanel = $configObj->glTplObj->process('staff_form.tpl.php');
                break;

            case 'edit':
                
                if (empty($_REQUEST['eid'])) {
                    $configObj->glLibraryObj->header_redirect('index.php');
                }
                if ($paramMain['Edit'] != 'Y') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol');
                }
                $configObj->glTplObj->set('accAddTab', true);
                $accesscontrolObj->pagename = 'index.php?module=accesscontrol'; // Attribute of Page Name
                $accesscontrolObj->loadCount('CountRowsUser');
                $configObj->glTplObj->set('frmaction', $accesscontrolObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid']);
                $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons('index.php?module=accesscontrol', 'bottom'));
                $configObj->glTplObj->set('accAddTab', true);


                if ($_REQUEST['h_save'] == 'T') {
                    $accesscontrolObj->varpostdata = $_REQUEST;
                    if ($accesscontrolObj->update_users()) {
                        if ($_POST['btnsaveandc_x'] != '') {
                            $configObj->glLibraryObj->header_redirect($accesscontrolObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                        } else if ($_POST['btnsaveande_x'] != '') {
                            $configObj->glLibraryObj->header_redirect('index.php?module=accesscontrol&msg=edit');
                        }
                    }
                } else {
                    if ($_REQUEST['msg']) {
                        if ($_REQUEST['msg'] == 'add') {
                            $messagebox = $accesscontrolObj->configObj->glLibraryObj->message("congrats! The record is successfully saved.");
                            $accesscontrolObj->configObj->glTplObj->set('messagebox', $messagebox);
                        } else if ($_REQUEST['msg'] == 'edit') {
                            $messagebox = $accesscontrolObj->configObj->glLibraryObj->message("congrats! The record is successfully edited and saved.");
                            $accesscontrolObj->configObj->glTplObj->set('messagebox', $messagebox);
                        }
                    }

                    $configObj->glTplObj->set('fk_modules', $accesscontrolObj->fk_modules);
                    $row = $accesscontrolObj->select_users($_REQUEST['eid']);
                    $configObj->glTplObj->set('row', $row);
                    $selid = $accesscontrolObj->groupcmbuserselect($_REQUEST['eid']);
                    $groupdrp = $accesscontrolObj->groupcmbuser($selid);
                    $configObj->glTplObj->set('groupdrp', $groupdrp);
                    $configObj->adminContentPanel = $configObj->glTplObj->process('staff_form.tpl.php');
                }
                break;

            case 'checksame':
                
                $count = $accesscontrolObj->check_sameuser();
                ob_clean();
                if ($count > 0) {
                    $same = 'Y';
                } else {
                    $same = 'N';
                }
                echo $same;
                exit();
                break;

            case 'delete':
                
                if ($configObj->isAjaxSet) {
                    $accesscontrolObj->is_usersused($accesscontrolObj->fk_modules);
                }
                break;

            case 'checkEmailid':

                ob_clean();
                echo $accesscontrolObj->checkExistedEmailid($_REQUEST['email']);
                exit();
                break;

            case 'addquickcat':
                if ($configObj->isAjaxSet) {

                    echo $configObj->glTplObj->process('quickAddgroup.tpl.php');
                    exit;
                }

            case 'insertgroupquick':

                if ($configObj->isAjaxSet) {
                    $name = $_REQUEST['var_name'];
                    $accesscontrolObj->insertgroupquick($name);
                }
                break;

            case 'popupAdd':

                if ($_REQUEST['sub'] == 'adddata') {
                    $accesscontrolObj->varpostdata = $_REQUEST;
                    $accesscontrolObj->insert_popupgroups();
                    echo $groupdrp = $accesscontrolObj->groupcmbuser($accesscontrolObj->lastinsertid);
                    exit;
                } else {
                    $configObj->glTplObj->set('fk_modules', $accesscontrolObj->fk_modules);
                    echo $configObj->glTplObj->process('popupgroups.tpl.php');
                    exit;
                }
                break;

            default:
                
                $configObj->glTplObj->set('accesscontrolTab', true);
                $accesscontrolObj->load_users();
                break;
        }
        break;
}
?>