Update group_permissions.php

This commit is contained in:
FusionPBX
2020-04-05 00:50:26 -06:00
committed by GitHub
parent 1dabf28b4a
commit bac885cc96

View File

@@ -67,12 +67,15 @@
//process the user data and save it to the database
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//get the list
$sql = "select * from v_group_permissions ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$sql = "select p.*, ";
$sql .= "exists(select from v_group_permissions where permission_name = p.permission_name and group_name = :group_name) as permission_assigned ";
$sql .= "from v_permissions as p ";
$parameters['group_name'] = $group_name;
//$sql = "select * from v_group_permissions ";
//$sql .= "where group_uuid = :group_uuid ";
//$parameters['group_uuid'] = $group_uuid;
$database = new database;
$group_permissions = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//add or remove permissions from the group
$x = 0;
@@ -81,7 +84,7 @@
//check to see if the group has been assigned the permission
$in_database = false;
foreach($group_permissions as $field) {
if ($field['permission_name'] === $row['permission']) {
if ($field['permission_name'] === $row['permission_name'] && $field['permission_assigned'] === true) {
$in_database = true;
break;
}
@@ -90,9 +93,9 @@
//add - checked on html form and not in the database
if ($row['checked'] === 'true') {
if (!$in_database) {
if (isset($row['permission']) && strlen($row['permission']) > 0) {
if (isset($row['permission_name']) && strlen($row['permission_name']) > 0) {
$array['add']['group_permissions'][$x]['group_permission_uuid'] = uuid();
$array['add']['group_permissions'][$x]['permission_name'] = $row['permission'];
$array['add']['group_permissions'][$x]['permission_name'] = $row['permission_name'];
$array['add']['group_permissions'][$x]['group_uuid'] = $group_uuid;
$array['add']['group_permissions'][$x]['group_name'] = $group_name;
//$array['add']['group_permissions'][$x]['permission_uuid'] = $row['uuid'];
@@ -104,10 +107,10 @@
//delete - unchecked on the form and in the database
if ($row['checked'] !== 'true') {
if ($in_database) {
if (isset($row['permission']) && strlen($row['permission']) > 0) {
$array['delete']['group_permissions'][$x]['permission_name'] = $row['permission'];
if (isset($row['permission_name']) && strlen($row['permission_name']) > 0) {
$array['delete']['group_permissions'][$x]['permission_name'] = $row['permission_name'];
$array['delete']['group_permissions'][$x]['group_uuid'] = $group_uuid;
//$array['delete']['group_permissions'][$x]['group_name'] = $group_name;
$array['delete']['group_permissions'][$x]['group_name'] = $group_name;
//$array['delete'][$x]['permission_uuid'] = $row['uuid'];
}
$x++;
@@ -230,7 +233,6 @@
if (is_array($group_permissions) && @sizeof($group_permissions) != 0) {
$x = 0;
foreach ($group_permissions as $row) {
$checked = ($row['permission_assigned'] === true) ? " checked=\"checked\"" : $checked = '';
$application_name = strtolower($row['application_name']);
$label_application_name = ucwords(str_replace(['_','-'], " ", $row['application_name']));
@@ -261,8 +263,8 @@
if (permission_exists('group_permission_add') || permission_exists('group_permission_edit') || permission_exists('group_permission_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='group_permissions[$x][checked]' id='checkbox_".$x."' class='checkbox_".$application_name."' value='true' ".$checked." onclick=\"if (!this.checked) { document.getElementById('checkbox_all_".$application_name."').checked = false; }\">\n";
echo " <input type='hidden' name='group_permissions[$x][uuid]' value='".escape($row['permission_uuid'])."' />\n";
echo " <input type='hidden' name='group_permissions[$x][permission]' value='".escape($row['permission_name'])."' />\n";
echo " <input type='hidden' name='group_permissions[$x][permission_uuid]' value='".escape($row['permission_uuid'])."' />\n";
echo " <input type='hidden' name='group_permissions[$x][permission_name]' value='".escape($row['permission_name'])."' />\n";
echo " </td>\n";
}
echo " <td class='no-wrap' onclick=\"if (document.getElementById('checkbox_".$x."').checked) { document.getElementById('checkbox_".$x."').checked = false; document.getElementById('checkbox_all_".$application_name."').checked = false; } else { document.getElementById('checkbox_".$x."').checked = true; }\">".escape($row['permission_name'])."</td>\n";