| Server IP : 103.48.194.25 / Your IP : 216.73.216.74 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 8.2.20 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/zomuaban.com/public_html/site/helpers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
#########################################################################################
#
# XỬ LÝ CÁC QUYỀN TRUY CẬP - QUẢN TRỊ CỦA USER
#
#########################################################################################
# Hàm này kiểm tra xem user có quyền truy cập vào một Controller hay ko
function is_allow_ctr($controller, $action = null) {
$CI = & get_instance();
# Truy cập HOOK
$accessHook = $CI->accessHook;
# Mọi Editor trở lên tới ADmin đều có quyền truy cập index
$action = !isset($action) ? 'index' : $action;
return $accessHook->isAllowed(get_my_role(), $controller, $action);
}
# Hàm này kiểm tra xem user có quyền truy cập vào action của một controller hay ko
function is_allow_action($action, $controller = null) {
$CI = & get_instance();
$directory = $this->CI->router->fetch_directory();
# Controller mặc định là Controller đang thực thi
$controller = !isset($controller) ? $directory.$CI->controllerName : $controller;
$accessHook = $CI->accessHook;
return $accessHook->isAllowed(get_my_role(), $controller, $action);
}
# Hàm này kiểm tra xem user có phải quản trị (EDITOR, MOD, ADMIN) hay không - Nếu ko truyền biến thì check cả EDITOR
# Hàm này dùng được cả ở Backend lẫn Frontend
# Cách dùng:
# + is_manager() : Check xem có phải là quản trị (EDITOR, MOD, ADMIN) hay không đối với Ctrller đang thực thi - Chỉ dùng trên Frontend
# + is_manager(MOD) : Check xem user có quyền từ MOD trở lên hay ko - Sử dụng ở Backend lẫn Frontend
# + is_manager(FRONT_ITEM) : Check xem user có quyền quản trị một Ctrller nào đó hay ko - Sử dụng ở Frontend
function is_manager($controller = null) {
$CI = & get_instance();
# Kiểm tra xem có quyền mod hoặc admin
if($controller=='is_mod' || $controller=='is_admin' || $controller=='is_site_admin' ){
return is_allow_ctr(BACK_ADMIN, $controller); # Xem có quyền truy cập vào action mod hoặc admin trong backend/admin hay ko
}
# Là frontend/controller : Kiểm tra xem có phải là manager ( từ Editor trở lên)
else {
$controller = !isset($controller) ? 'frontend/'.$CI->controllerName : $controller; # Controller mặc định là Controller đang thực thi
return is_allow_ctr(BACK_ADMIN) && is_allow_ctr($controller);
}
}
function is_admin($moduleName = 'itemad') {
if (!isLogin()) return false;
$mrole = my_module_role();
return module_list($mrole['M']) == $moduleName && get_module_role_list($mrole['M']) == 'admin' ? true :false;
}
function is_mod($module='itemad'){
if (!isLogin()) return false;
$mrole = my_module_role();
return module_list($mrole['M']) == $moduleName && get_module_role_list($mrole['M']) == 'mod' ? true :false;
}
function is_editor($module='itemad'){
if (!isLogin()) return false;
$mrole = my_module_role();
return module_list($mrole['M']) == $moduleName && get_module_role_list($mrole['M']) == 'editor' ? true :false;
}
function get_module_role_list($mroleID) {
switch ($mroleID) {
case 3 : return 'editor'; break;
case 5 : return 'mod'; break;
case 7 : return 'admin'; break;
default : return 'guest';
}
}
# Hàm này trả về ID của một module
function module_list($moduleId = null) {
$module = array( 1 => 'adv'
,2 => 'keyword'
,3 => 'itemad'
,4 => 'itemvip'
,5 => 'post'
,6 => 'profile'
,7 => 'event'
,8 => 'transaction'
,9 => 'allsite' );
return isset($moduleId) ? $module[$moduleId] : $module;
}
function my_module_role(){
$role = get_my_role();
$mrole = [];
$mrole['R'] = (int)role%10;
$mrole['M'] = (int)role/10;
return $mrole;
}