Esempio n. 1
0
function GroupPermissionsReport()
{
    global $context, $txt, $modSettings, $smcFunc;
    if (isset($_REQUEST['groups'])) {
        if (!is_array($_REQUEST['groups'])) {
            $_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
        }
        foreach ($_REQUEST['groups'] as $k => $dummy) {
            $_REQUEST['groups'][$k] = (int) $dummy;
        }
        $_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
        $clause = 'id_group IN ({array_int:groups})';
    } else {
        $clause = 'id_group != {int:moderator_group}';
    }
    // Get all the possible membergroups, except admin!
    $request = $smcFunc['db_query']('', '
		SELECT id_group, group_name
		FROM {db_prefix}membergroups
		WHERE ' . $clause . '
			AND id_group != {int:admin_group}' . (empty($modSettings['permission_enable_postgroups']) ? '
			AND min_posts = {int:min_posts}' : '') . '
		ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name', array('admin_group' => 1, 'min_posts' => -1, 'newbie_group' => 4, 'moderator_group' => 3, 'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array()));
    if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
        $groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
    } else {
        $groups = array('col' => '');
    }
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $groups[$row['id_group']] = $row['group_name'];
    }
    $smcFunc['db_free_result']($request);
    // Make sure that every group is represented!
    setKeys('rows', $groups);
    // Create the table first.
    newTable($txt['gr_type_group_perms'], '-', 'all', 100, 'center', 200, 'left');
    // Show all the groups
    addData($groups);
    // Add a separator
    addSeparator($txt['board_perms_permission']);
    // Now the big permission fetch!
    $request = $smcFunc['db_query']('', '
		SELECT id_group, add_deny, permission
		FROM {db_prefix}permissions
		WHERE ' . $clause . (empty($modSettings['permission_enable_deny']) ? '
			AND add_deny = {int:not_denied}' : '') . '
		ORDER BY permission', array('not_denied' => 1, 'moderator_group' => 3, 'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array()));
    $lastPermission = null;
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        // If this is a new permission flush the last row.
        if ($row['permission'] != $lastPermission) {
            // Send the data!
            if ($lastPermission !== null) {
                addData($curData);
            }
            // Add the permission name in the left column.
            $curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
            $lastPermission = $row['permission'];
        }
        // Good stuff - add the permission to the list!
        if ($row['add_deny']) {
            $curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
        } else {
            $curData[$row['id_group']] = '<span style="color: red;">' . $txt['board_perms_deny'] . '</span>';
        }
    }
    $smcFunc['db_free_result']($request);
    // Flush the last data!
    addData($curData);
}
Esempio n. 2
0
 /**
  * Show the large variety of group permissions assigned to each membergroup.
  * functions ending with "Report" are responsible for generating data for reporting.
  * they are all called from action_index.
  * never access the context directly, but use the data handling
  * functions to do so.
  */
 public function action_group_perms()
 {
     global $txt;
     if (isset($_REQUEST['groups'])) {
         if (!is_array($_REQUEST['groups'])) {
             $_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
         }
         $query_groups = array_diff(array_map('intval', $_REQUEST['groups']), array(3));
         $group_clause = 'id_group IN ({array_int:groups})';
     } else {
         $query_groups = array();
         $group_clause = 'id_group != {int:moderator_group}';
     }
     // Get all the possible membergroups, except admin!
     require_once SUBSDIR . '/Reports.subs.php';
     $all_groups = allMembergroups($group_clause, $query_groups);
     if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
         $groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']) + $all_groups;
     } else {
         $groups = array('col' => '') + $all_groups;
     }
     // Make sure that every group is represented!
     setKeys('rows', $groups);
     // Create the table first.
     newTable($txt['gr_type_group_perms'], '-', 'all', 100, 'center', 200, 'left');
     // Show all the groups
     addData($groups);
     // Add a separator
     addSeparator($txt['board_perms_permission']);
     // Now the big permission fetch!
     $perms = boardPermissionsByGroup($group_clause, isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array());
     $lastPermission = null;
     $curData = array();
     foreach ($perms as $row) {
         // If this is a new permission flush the last row.
         if ($row['permission'] != $lastPermission) {
             // Send the data!
             if ($lastPermission !== null) {
                 addData($curData);
             }
             // Add the permission name in the left column.
             $curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
             $lastPermission = $row['permission'];
         }
         // Good stuff - add the permission to the list!
         if ($row['add_deny']) {
             $curData[$row['id_group']] = '<span class="success">' . $txt['board_perms_allow'] . '</span>';
         } else {
             $curData[$row['id_group']] = '<span class="alert">' . $txt['board_perms_deny'] . '</span>';
         }
     }
     // Flush the last data!
     addData($curData);
 }