BBnepal-Accounts/account/application/helpers/permission_helper.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

99 lines
1.9 KiB
PHP

<?php
function isSuperAdmin()
{
$ci =& get_instance();
if ($ci->session->has_userdata('superAdmin')) {
return true;
}
return false;
}
function isPermitted($value, $level = 0)
{
$ci =& get_instance();
if (isSuperAdmin()) {
return true;
} else {
//echo $level;die;
$privilege = $ci->session->userdata('privilege');
if (!empty($privilege[$value]) && ($privilege[$value] > $level || $privilege[$value] == $level)) {
return true;
}
return false;
}
}
function getPrivilege($value)
{
$ci =& get_instance();
$privilege = $ci->session->userdata('privilege');
if (!empty($privilege[$value])) {
return $privilege[$value];
}
return false;
}
function isViewable($level = 0)
{
$urlArray = getUrlArray();
if (!empty($urlArray[1]) && $level == 0) {
$level = getLevel($urlArray[1]);
}
else if (!is_numeric($level)){
$level = getLevel($level);
}
if (isSuperAdmin()) {
return true;
} elseif (isPermitted($urlArray[0], $level)) {
return true;
} else {
return false;
}
}
function isViewPermitted($level = '')
{
$urlArray = getUrlArray();
//pre($urlArray,1);
if (!empty($urlArray[1]) && $level == '') {
$level = $urlArray[1];
}
$level = getLevel($level);
if (isViewable($level)) {
return true;
} else {
show_404();
}
}
function getLevel($val)
{
switch ($val) {
case 'view':
return 1;
break;
case '':
return 1;
break;
case 'add':
return 2;
break;
case 'edit':
return 2;
break;
case 'update':
return 2;
break;
case 'delete':
return 3;
break;
default:
return 1;
}
}