/**
  * This function actually saves modifications to a membergroup's board permissions.
  */
 public function action_modify2()
 {
     global $context;
     checkSession();
     validateToken('admin-mp');
     // We'll need to init illegal permissions, update child permissions, etc.
     require_once SUBSDIR . '/Permission.subs.php';
     require_once SUBSDIR . '/ManagePermissions.subs.php';
     loadIllegalPermissions();
     $current_group_id = (int) $_GET['group'];
     $_GET['pid'] = (int) $_GET['pid'];
     // Cannot modify predefined profiles.
     if ($_GET['pid'] > 1 && $_GET['pid'] < 5) {
         fatal_lang_error('no_access', false);
     }
     // Verify this isn't inherited.
     if ($current_group_id == -1 || $current_group_id == 0) {
         $parent = -2;
     } else {
         require_once SUBSDIR . '/Membergroups.subs.php';
         $group = membergroupById($current_group_id, true);
         $parent = $group['id_parent'];
     }
     if ($parent != -2) {
         fatal_lang_error('cannot_edit_permissions_inherited');
     }
     $givePerms = array('membergroup' => array(), 'board' => array());
     // Guest group, we need illegal, guest permissions.
     if ($current_group_id == -1) {
         loadIllegalGuestPermissions();
         $context['illegal_permissions'] = array_merge($context['illegal_permissions'], $context['non_guest_permissions']);
     }
     // Prepare all permissions that were set or denied for addition to the DB.
     if (isset($_POST['perm']) && is_array($_POST['perm'])) {
         foreach ($_POST['perm'] as $perm_type => $perm_array) {
             if (is_array($perm_array)) {
                 foreach ($perm_array as $permission => $value) {
                     if ($value == 'on' || $value == 'deny') {
                         // Don't allow people to escalate themselves!
                         if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) {
                             continue;
                         }
                         $givePerms[$perm_type][] = array($permission, $current_group_id, $value == 'deny' ? 0 : 1);
                     }
                 }
             }
         }
     }
     // Insert the general permissions.
     if ($current_group_id != 3 && empty($_GET['pid'])) {
         deleteInvalidPermissions($current_group_id, $context['illegal_permissions']);
         if (!empty($givePerms['membergroup'])) {
             replacePermission($givePerms['membergroup']);
         }
     }
     // Insert the boardpermissions.
     $profileid = max(1, $_GET['pid']);
     deleteAllBoardPermissions($current_group_id, $profileid);
     if (!empty($givePerms['board'])) {
         foreach ($givePerms['board'] as $k => $v) {
             $givePerms['board'][$k][] = $profileid;
         }
         replaceBoardPermission($givePerms['board']);
     }
     // Update any inherited permissions as required.
     updateChildPermissions($current_group_id, $_GET['pid']);
     // Clear cached privs.
     updateSettings(array('settings_updated' => time()));
     redirectexit('action=admin;area=permissions;pid=' . $_GET['pid']);
 }
示例#2
0
function loadAllPermissions($loadType = 'classic')
{
    global $context, $txt, $modSettings;
    // List of all the groups dependant on the currently selected view - for the order so it looks pretty, yea?
    // Note to Mod authors - you don't need to stick your permission group here if you don't mind SMF sticking it the last group of the page.
    $permissionGroups = array('membergroup' => array('simple' => array('view_basic_info', 'shoutbox', 'shoutbox_panel', 'use_pm_system', 'post_calendar', 'edit_profile', 'delete_account', 'use_avatar', 'moderate_general', 'administrate'), 'classic' => array('general', 'shoutbox', 'shoutbox_panel', 'pm', 'calendar', 'maintenance', 'member_admin', 'profile')), 'board' => array('simple' => array('make_posts', 'make_unapproved_posts', 'post_polls', 'participate', 'modify', 'notification', 'attach', 'moderate'), 'classic' => array('general_board', 'topic', 'post', 'poll', 'notification', 'attachment')));
    /*   The format of this list is as follows:
    		'membergroup' => array(
    			'permissions_inside' => array(has_multiple_options, classic_view_group, simple_view_group(_own)*, simple_view_group_any*),
    		),
    		'board' => array(
    			'permissions_inside' => array(has_multiple_options, classic_view_group, simple_view_group(_own)*, simple_view_group_any*),
    		);
    	*/
    $permissionList = array('membergroup' => array('view_stats' => array(false, 'general', 'view_basic_info'), 'view_mlist' => array(false, 'general', 'view_basic_info'), 'who_view' => array(false, 'general', 'view_basic_info'), 'search_posts' => array(false, 'general', 'view_basic_info'), 'karma_edit' => array(false, 'general', 'moderate_general'), 'karma_edit' => array(false, 'general', 'moderate_general'), 'shoutbox_view' => array(false, 'shoutbox', 'shoutbox'), 'shoutbox_post' => array(false, 'shoutbox', 'shoutbox'), 'shoutbox_edit' => array(false, 'shoutbox_panel', 'shoutbox_panel'), 'shoutbox_delete' => array(false, 'shoutbox_panel', 'shoutbox_panel'), 'shoutbox_prune' => array(false, 'shoutbox_panel', 'shoutbox_panel'), 'shoutbox_ban' => array(false, 'shoutbox_panel', 'shoutbox_panel'), 'pm_read' => array(false, 'pm', 'use_pm_system'), 'pm_send' => array(false, 'pm', 'use_pm_system'), 'calendar_view' => array(false, 'calendar', 'view_basic_info'), 'calendar_post' => array(false, 'calendar', 'post_calendar'), 'calendar_edit' => array(true, 'calendar', 'post_calendar', 'moderate_general'), 'admin_forum' => array(false, 'maintenance', 'administrate'), 'manage_boards' => array(false, 'maintenance', 'administrate'), 'manage_attachments' => array(false, 'maintenance', 'administrate'), 'manage_smileys' => array(false, 'maintenance', 'administrate'), 'edit_news' => array(false, 'maintenance', 'administrate'), 'access_mod_center' => array(false, 'maintenance', 'moderate_general'), 'moderate_forum' => array(false, 'member_admin', 'moderate_general'), 'manage_membergroups' => array(false, 'member_admin', 'administrate'), 'manage_permissions' => array(false, 'member_admin', 'administrate'), 'manage_bans' => array(false, 'member_admin', 'administrate'), 'manage_awards' => array(false, 'maintenance', 'administrate'), 'send_mail' => array(false, 'member_admin', 'administrate'), 'issue_warning' => array(false, 'member_admin', 'moderate_general'), 'profile_view' => array(true, 'profile', 'view_basic_info', 'view_basic_info'), 'profile_identity' => array(true, 'profile', 'edit_profile', 'moderate_general'), 'profile_extra' => array(true, 'profile', 'edit_profile', 'moderate_general'), 'profile_title' => array(true, 'profile', 'edit_profile', 'moderate_general'), 'profile_remove' => array(true, 'profile', 'delete_account', 'moderate_general'), 'profile_server_avatar' => array(false, 'profile', 'use_avatar'), 'profile_upload_avatar' => array(false, 'profile', 'use_avatar'), 'profile_remote_avatar' => array(false, 'profile', 'use_avatar')), 'board' => array('moderate_board' => array(false, 'general_board', 'moderate'), 'approve_posts' => array(false, 'general_board', 'moderate'), 'post_new' => array(false, 'topic', 'make_posts'), 'post_unapproved_topics' => array(false, 'topic', 'make_unapproved_posts'), 'post_unapproved_replies' => array(true, 'topic', 'make_unapproved_posts', 'make_unapproved_posts'), 'post_reply' => array(true, 'topic', 'make_posts', 'make_posts'), 'merge_any' => array(false, 'topic', 'moderate'), 'split_any' => array(false, 'topic', 'moderate'), 'send_topic' => array(false, 'topic', 'moderate'), 'make_sticky' => array(false, 'topic', 'moderate'), 'move' => array(true, 'topic', 'moderate', 'moderate'), 'lock' => array(true, 'topic', 'moderate', 'moderate'), 'remove' => array(true, 'topic', 'modify', 'moderate'), 'modify_replies' => array(false, 'topic', 'moderate'), 'delete_replies' => array(false, 'topic', 'moderate'), 'announce_topic' => array(false, 'topic', 'moderate'), 'delete' => array(true, 'post', 'modify', 'moderate'), 'modify' => array(true, 'post', 'modify', 'moderate'), 'report_any' => array(false, 'post', 'participate'), 'poll_view' => array(false, 'poll', 'participate'), 'poll_vote' => array(false, 'poll', 'participate'), 'poll_post' => array(false, 'poll', 'post_polls'), 'poll_add' => array(true, 'poll', 'post_polls', 'moderate'), 'poll_edit' => array(true, 'poll', 'modify', 'moderate'), 'poll_lock' => array(true, 'poll', 'moderate', 'moderate'), 'poll_remove' => array(true, 'poll', 'modify', 'moderate'), 'mark_any_notify' => array(false, 'notification', 'notification'), 'mark_notify' => array(false, 'notification', 'notification'), 'view_attachments' => array(false, 'attachment', 'participate'), 'post_unapproved_attachments' => array(false, 'attachment', 'make_unapproved_posts'), 'post_attachment' => array(false, 'attachment', 'attach')));
    // All permission groups that will be shown in the left column on classic view.
    $leftPermissionGroups = array('general', 'calendar', 'maintenance', 'member_admin', 'topic', 'post');
    // We need to know what permissions we can't give to guests.
    loadIllegalGuestPermissions();
    // Some permissions are hidden if features are off.
    $hiddenPermissions = array();
    $relabelPermissions = array();
    // Permissions to apply a different label to.
    $relabelGroups = array();
    // As above but for groups.
    if (!in_array('cd', $context['admin_features'])) {
        $hiddenPermissions[] = 'calendar_view';
        $hiddenPermissions[] = 'calendar_post';
        $hiddenPermissions[] = 'calendar_edit';
    }
    if (!in_array('w', $context['admin_features'])) {
        $hiddenPermissions[] = 'issue_warning';
    }
    // Post moderation?
    if (!$modSettings['postmod_active']) {
        $hiddenPermissions[] = 'approve_posts';
        $hiddenPermissions[] = 'post_unapproved_topics';
        $hiddenPermissions[] = 'post_unapproved_replies';
        $hiddenPermissions[] = 'post_unapproved_attachments';
    } else {
        // Relabel the topics permissions
        $relabelPermissions['post_new'] = 'auto_approve_topics';
        // Relabel the reply permissions
        $relabelPermissions['post_reply'] = 'auto_approve_replies';
        // Relabel the attachment permissions
        $relabelPermissions['post_attachment'] = 'auto_approve_attachments';
    }
    $context['permissions'] = array();
    $context['hidden_permissions'] = array();
    foreach ($permissionList as $permissionType => $permissionList) {
        $context['permissions'][$permissionType] = array('id' => $permissionType, 'view' => $loadType, 'columns' => array());
        foreach ($permissionList as $permission => $permissionArray) {
            // If this is a guest permission we don't do it if it's the guest group.
            if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions'])) {
                continue;
            }
            // What groups will this permission be in?
            $own_group = $permissionArray[$loadType == 'classic' ? 1 : 2];
            $any_group = $loadType == 'simple' && !empty($permissionArray[3]) ? $permissionArray[3] : ($loadType == 'simple' && $permissionArray[0] ? $permissionArray[2] : '');
            // First, Do these groups actually exist - if not add them.
            if (!isset($permissionGroups[$permissionType][$loadType][$own_group])) {
                $permissionGroups[$permissionType][$loadType][$own_group] = true;
            }
            if (!empty($any_group) && !isset($permissionGroups[$permissionType][$loadType][$any_group])) {
                $permissionGroups[$permissionType][$loadType][$any_group] = true;
            }
            // What column should this be located into?
            $position = $loadType == 'classic' && !in_array($own_group, $leftPermissionGroups) ? 1 : 0;
            // If the groups have not yet been created be sure to create them.
            $bothGroups = array('own' => $own_group);
            $bothGroups = array();
            /*
            			// For guests, just reset the array.
            			if (!isset($context['group']['id']) || !($context['group']['id'] == -1 && $any_group))
            				$bothGroups['own'] = $own_group;
            
            			if ($any_group)
            			{
            				$bothGroups['any'] = $any_group;
            
            			}
            */
            // For guests, just reset the array.
            if (!isset($context['group']['id']) || !($context['group']['id'] == -1 && $any_group)) {
                $bothGroups['own'] = $own_group;
            }
            if ($any_group) {
                $bothGroups['any'] = $any_group;
            }
            foreach ($bothGroups as $group) {
                if (!isset($context['permissions'][$permissionType]['columns'][$position][$group])) {
                    $context['permissions'][$permissionType]['columns'][$position][$group] = array('type' => $permissionType, 'id' => $group, 'name' => $loadType == 'simple' ? isset($txt['permissiongroup_simple_' . $group]) ? $txt['permissiongroup_simple_' . $group] : '' : $txt['permissiongroup_' . $group], 'icon' => isset($txt['permissionicon_' . $group]) ? $txt['permissionicon_' . $group] : $txt['permissionicon'], 'help' => isset($txt['permissionhelp_' . $group]) ? $txt['permissionhelp_' . $group] : '', 'hidden' => false, 'permissions' => array());
                }
            }
            // This is where we set up the permission dependant on the view.
            if ($loadType == 'classic') {
                $context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array('id' => $permission, 'name' => !isset($relabelPermissions[$permission]) ? $txt['permissionname_' . $permission] : $txt[$relabelPermissions[$permission]], 'show_help' => isset($txt['permissionhelp_' . $permission]), 'note' => isset($txt['permissionnote_' . $permission]) ? $txt['permissionnote_' . $permission] : '', 'has_own_any' => $permissionArray[0], 'own' => array('id' => $permission . '_own', 'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_own'] : ''), 'any' => array('id' => $permission . '_any', 'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_any'] : ''), 'hidden' => in_array($permission, $hiddenPermissions));
            } else {
                foreach ($bothGroups as $group_type => $group) {
                    $context['permissions'][$permissionType]['columns'][$position][$group]['permissions'][$permission . ($permissionArray[0] ? '_' . $group_type : '')] = array('id' => $permission . ($permissionArray[0] ? '_' . $group_type : ''), 'name' => isset($txt['permissionname_simple_' . $permission . ($permissionArray[0] ? '_' . $group_type : '')]) ? $txt['permissionname_simple_' . $permission . ($permissionArray[0] ? '_' . $group_type : '')] : $txt['permissionname_' . $permission], 'help_index' => isset($txt['permissionhelp_' . $permission]) ? 'permissionhelp_' . $permission : '', 'hidden' => in_array($permission, $hiddenPermissions));
                }
            }
            if (in_array($permission, $hiddenPermissions)) {
                if ($permissionArray[0]) {
                    $context['hidden_permissions'][] = $permission . '_own';
                    $context['hidden_permissions'][] = $permission . '_any';
                } else {
                    $context['hidden_permissions'][] = $permission;
                }
            }
        }
        ksort($context['permissions'][$permissionType]['columns']);
    }
    // Check we don't leave any empty groups - and mark hidden ones as such.
    foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups) {
        foreach ($groups as $id => $group) {
            if (empty($group['permissions'])) {
                unset($context['permissions'][$permissionType]['columns'][$column][$id]);
            } else {
                $foundNonHidden = false;
                foreach ($group['permissions'] as $permission) {
                    if (empty($permission['hidden'])) {
                        $foundNonHidden = true;
                    }
                }
                if (!$foundNonHidden) {
                    $context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true;
                }
            }
        }
    }
}
/**
 * Load permissions into $context['permissions'].
 *
 * @package Permissions
 * @internal
 */
function loadAllPermissions()
{
    global $context, $txt, $modSettings;
    // List of all the groups
    // Note to Mod authors - you don't need to stick your permission group here if you don't mind having it as the last group of the page.
    $permissionGroups = array('membergroup' => array('general', 'pm', 'calendar', 'maintenance', 'member_admin', 'profile'), 'board' => array('general_board', 'topic', 'post', 'poll', 'notification', 'attachment'));
    /*   The format of this list is as follows:
    		'membergroup' => array(
    			'permissions_inside' => array(has_multiple_options, view_group),
    		),
    		'board' => array(
    			'permissions_inside' => array(has_multiple_options, view_group),
    		);
    	*/
    $permissionList = array('membergroup' => array('view_stats' => array(false, 'general'), 'view_mlist' => array(false, 'general'), 'who_view' => array(false, 'general'), 'search_posts' => array(false, 'general'), 'karma_edit' => array(false, 'general'), 'disable_censor' => array(false, 'general'), 'pm_read' => array(false, 'pm'), 'pm_send' => array(false, 'pm'), 'pm_draft' => array(false, 'pm'), 'pm_autosave_draft' => array(false, 'pm'), 'send_email_to_members' => array(false, 'pm'), 'calendar_view' => array(false, 'calendar'), 'calendar_post' => array(false, 'calendar'), 'calendar_edit' => array(true, 'calendar'), 'admin_forum' => array(false, 'maintenance'), 'manage_boards' => array(false, 'maintenance'), 'manage_attachments' => array(false, 'maintenance'), 'manage_smileys' => array(false, 'maintenance'), 'edit_news' => array(false, 'maintenance'), 'access_mod_center' => array(false, 'maintenance'), 'moderate_forum' => array(false, 'member_admin'), 'manage_membergroups' => array(false, 'member_admin'), 'manage_permissions' => array(false, 'member_admin'), 'manage_bans' => array(false, 'member_admin'), 'send_mail' => array(false, 'member_admin'), 'issue_warning' => array(false, 'member_admin'), 'profile_view' => array(true, 'profile'), 'profile_identity' => array(true, 'profile'), 'profile_extra' => array(true, 'profile'), 'profile_title' => array(true, 'profile'), 'profile_remove' => array(true, 'profile'), 'profile_server_avatar' => array(false, 'profile'), 'profile_upload_avatar' => array(false, 'profile'), 'profile_remote_avatar' => array(false, 'profile'), 'approve_emails' => array(false, 'member_admin')), 'board' => array('moderate_board' => array(false, 'general_board'), 'approve_posts' => array(false, 'general_board'), 'post_new' => array(false, 'topic'), 'post_unapproved_topics' => array(false, 'topic'), 'post_unapproved_replies' => array(true, 'topic'), 'post_reply' => array(true, 'topic'), 'post_draft' => array(false, 'topic'), 'post_autosave_draft' => array(false, 'topic'), 'merge_any' => array(false, 'topic'), 'split_any' => array(false, 'topic'), 'send_topic' => array(false, 'topic'), 'make_sticky' => array(false, 'topic'), 'move' => array(true, 'topic'), 'lock' => array(true, 'topic'), 'remove' => array(true, 'topic'), 'modify_replies' => array(false, 'topic'), 'delete_replies' => array(false, 'topic'), 'announce_topic' => array(false, 'topic'), 'delete' => array(true, 'post'), 'modify' => array(true, 'post'), 'report_any' => array(false, 'post'), 'poll_view' => array(false, 'poll'), 'poll_vote' => array(false, 'poll'), 'poll_post' => array(false, 'poll'), 'poll_add' => array(true, 'poll'), 'poll_edit' => array(true, 'poll'), 'poll_lock' => array(true, 'poll'), 'poll_remove' => array(true, 'poll'), 'mark_any_notify' => array(false, 'notification'), 'mark_notify' => array(false, 'notification'), 'view_attachments' => array(false, 'attachment'), 'post_unapproved_attachments' => array(false, 'attachment'), 'post_attachment' => array(false, 'attachment'), 'postby_email' => array(false, 'topic'), 'like_posts' => array(false, 'topic')));
    // All permission groups that will be shown in the left column.
    $leftPermissionGroups = array('general', 'calendar', 'maintenance', 'member_admin', 'topic', 'post');
    // we'll need to init illegal permissions.
    require_once SUBSDIR . '/Permission.subs.php';
    // We need to know what permissions we can't give to guests.
    loadIllegalGuestPermissions();
    // Some permissions are hidden if features are off.
    $hiddenPermissions = array();
    $relabelPermissions = array();
    // Permissions to apply a different label to.
    if (!in_array('cd', $context['admin_features'])) {
        $hiddenPermissions[] = 'calendar_view';
        $hiddenPermissions[] = 'calendar_post';
        $hiddenPermissions[] = 'calendar_edit';
    }
    if (!in_array('w', $context['admin_features'])) {
        $hiddenPermissions[] = 'issue_warning';
    }
    if (!in_array('k', $context['admin_features'])) {
        $hiddenPermissions[] = 'karma_edit';
    }
    if (!in_array('l', $context['admin_features'])) {
        $hiddenPermissions[] = 'like_posts';
    }
    if (!in_array('pe', $context['admin_features'])) {
        $hiddenPermissions[] = 'approve_emails';
        $hiddenPermissions[] = 'postby_email';
    }
    if (!in_array('dr', $context['admin_features'])) {
        $hiddenPermissions[] = 'post_draft';
        $hiddenPermissions[] = 'pm_draft';
        $hiddenPermissions[] = 'post_autosave_draft';
        $hiddenPermissions[] = 'pm_autosave_draft';
    }
    // Post moderation?
    if (!$modSettings['postmod_active']) {
        $hiddenPermissions[] = 'approve_posts';
        $hiddenPermissions[] = 'post_unapproved_topics';
        $hiddenPermissions[] = 'post_unapproved_replies';
        $hiddenPermissions[] = 'post_unapproved_attachments';
    } else {
        // Relabel the topics permissions
        $relabelPermissions['post_new'] = 'auto_approve_topics';
        // Relabel the reply permissions
        $relabelPermissions['post_reply'] = 'auto_approve_replies';
        // Relabel the attachment permissions
        $relabelPermissions['post_attachment'] = 'auto_approve_attachments';
    }
    // Are attachments enabled?
    if (empty($modSettings['attachmentEnable'])) {
        $hiddenPermissions[] = 'manage_attachments';
        $hiddenPermissions[] = 'view_attachments';
        $hiddenPermissions[] = 'post_unapproved_attachments';
        $hiddenPermissions[] = 'post_attachment';
    }
    // Provide a practical way to modify permissions.
    call_integration_hook('integrate_load_permissions', array(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions));
    $context['permissions'] = array();
    $context['hidden_permissions'] = array();
    foreach ($permissionList as $permissionType => $permissionList) {
        $context['permissions'][$permissionType] = array('id' => $permissionType, 'columns' => array());
        foreach ($permissionList as $permission => $permissionArray) {
            // If this is a guest permission we don't do it if it's the guest group.
            if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions'])) {
                continue;
            }
            // What groups will this permission be in?
            $own_group = $permissionArray[1];
            // First, Do these groups actually exist - if not add them.
            if (!isset($permissionGroups[$permissionType][$own_group])) {
                $permissionGroups[$permissionType][$own_group] = true;
            }
            // What column should this be located into?
            $position = !in_array($own_group, $leftPermissionGroups) ? 1 : 0;
            // If the groups have not yet been created be sure to create them.
            $bothGroups = array();
            // Guests can have only any, registered users both
            if (!isset($context['group']['id']) || !($context['group']['id'] == -1)) {
                $bothGroups['own'] = $own_group;
            } else {
                $bothGroups['any'] = $own_group;
            }
            foreach ($bothGroups as $group) {
                if (!isset($context['permissions'][$permissionType]['columns'][$position][$group]['type'])) {
                    $context['permissions'][$permissionType]['columns'][$position][$group] = array('type' => $permissionType, 'id' => $group, 'name' => $txt['permissiongroup_' . $group], 'icon' => isset($txt['permissionicon_' . $group]) ? $txt['permissionicon_' . $group] : $txt['permissionicon'], 'help' => isset($txt['permissionhelp_' . $group]) ? $txt['permissionhelp_' . $group] : '', 'hidden' => false, 'permissions' => array());
                }
            }
            // This is where we set up the permission.
            $context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array('id' => $permission, 'name' => !isset($relabelPermissions[$permission]) ? $txt['permissionname_' . $permission] : $txt[$relabelPermissions[$permission]], 'show_help' => isset($txt['permissionhelp_' . $permission]), 'note' => isset($txt['permissionnote_' . $permission]) ? $txt['permissionnote_' . $permission] : '', 'has_own_any' => $permissionArray[0], 'own' => array('id' => $permission . '_own', 'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_own'] : ''), 'any' => array('id' => $permission . '_any', 'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_any'] : ''), 'hidden' => in_array($permission, $hiddenPermissions));
            if (in_array($permission, $hiddenPermissions)) {
                if ($permissionArray[0]) {
                    $context['hidden_permissions'][] = $permission . '_own';
                    $context['hidden_permissions'][] = $permission . '_any';
                } else {
                    $context['hidden_permissions'][] = $permission;
                }
            }
        }
        ksort($context['permissions'][$permissionType]['columns']);
        // Check we don't leave any empty groups - and mark hidden ones as such.
        foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups) {
            foreach ($groups as $id => $group) {
                if (empty($group['permissions'])) {
                    unset($context['permissions'][$permissionType]['columns'][$column][$id]);
                } else {
                    $foundNonHidden = false;
                    foreach ($group['permissions'] as $permission) {
                        if (empty($permission['hidden'])) {
                            $foundNonHidden = true;
                        }
                    }
                    if (!$foundNonHidden) {
                        $context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true;
                    }
                }
            }
        }
    }
}