Functions: Modify permission_exists() function to support an array of permissions.

This commit is contained in:
fusionate 2023-02-03 18:50:56 +00:00
parent 658cb83894
commit a4c4e4c52a
No known key found for this signature in database
1 changed files with 33 additions and 5 deletions

View File

@ -261,13 +261,41 @@
} }
if (!function_exists('permission_exists')) { if (!function_exists('permission_exists')) {
function permission_exists($permission) { function permission_exists($permission, $operator = 'or') {
//set default false //set default
$result = false; $result = false;
//find the permission //permissions exist
if (is_array($_SESSION["permissions"]) && $_SESSION["permissions"][$permission] == true) { if (is_array($_SESSION["permissions"]) && @sizeof($_SESSION['permissions']) != 0) {
//array
if (is_array($permission) && @sizeof($permission) != 0) {
if ($operator == 'and') {
$exists_all = true;
foreach ($permission as $perm) {
if ($_SESSION["permissions"][$permission] != true) {
$exists_all = false;
break;
}
}
$result = $exists_all;
}
else {
$exists_one = false;
foreach ($permission as $perm) {
if ($_SESSION["permissions"][$permission] != true) {
$exists_one = true;
break;
}
}
$result = $exists_one;
}
}
//single
else {
if ($_SESSION["permissions"][$permission] == true) {
$result = true; $result = true;
} }
}
}
//return the result //return the result
return $result; return $result;
} }