From 6d3c57f409461e2678a210fe69b2fe3b52212bc6 Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 20 Nov 2006 20:47:17 +0000 Subject: [PATCH] Minor problems with roles selection in participants list MDL-7630 --- user/index.php | 54 +++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/user/index.php b/user/index.php index ef7361c4e5..77c7294c49 100644 --- a/user/index.php +++ b/user/index.php @@ -42,24 +42,38 @@ require_login($course->id); + if (!has_capability('moodle/course:viewparticipants', $context) + && !has_capability('moodle/site:viewparticipants', $context)) { + print_error('nopermissions'); + } + + $rolenames = array(); + + if ($roles = get_roles_used_in_context($context, true)) { + // We should exclude "admin" users (those with "doanything" at site level) because + // Otherwise they appear in every participant list + + $sitecontext = get_context_instance(CONTEXT_SYSTEM); + $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext); - if ($roles = get_roles_used_in_context($context)) { foreach ($roles as $role) { - $options[$role->id] = $role->name; + if (isset($doanythingroles[$role->id])) { // Avoid this role (ie admin) + unset($roles[$role->id]); + continue; + } + $rolenames[$role->id] = strip_tags(format_string($role->name)); // Used in menus etc later on } - } else { // no roles yet + } + + // no roles to display yet? + if (empty($rolenames)) { if (has_capability('moodle/user:assign', $context)) { redirect($CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id); } else { - error ('no participants found for this course'); + error ('No participants found for this course'); } } - if (!has_capability('moodle/course:viewparticipants', $context) - && !has_capability('moodle/site:viewparticipants', $context)) { - print_error('nopermissions'); - } - if ($course->id == SITEID) { if (!has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_SYSTEM, SITEID))) { print_header("$course->shortname: ".get_string('participants'), $course->fullname, @@ -254,24 +268,6 @@ } - if ($roles = get_roles_used_in_context($context, true)) { - - // We should exclude "admin" users (those with "doanything" at site level) because - // Otherwise they appear in every participant list - - $sitecontext = get_context_instance(CONTEXT_SYSTEM); - $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext); - - foreach ($roles as $role) { - if (isset($doanythingroles[$role->id])) { // Avoid this role (ie admin) - unset($roles[$role->id]); - continue; - } - $rolenames[$role->id] = strip_tags(format_string($role->name)); // Used in menus etc later on - } - } - - /// Define a table showing a list of users in the current role selection $tablecolumns = array('userpic', 'fullname'); @@ -390,11 +386,11 @@ /// If there are multiple Roles in the course, then show a drop down menu for switching - if (!empty($rolenames)) { + if (count($rolenames) > 1) { echo '
'; echo get_string('currentrole', 'role').': '; $rolenames = array(0 => get_string('all')) + $rolenames; - popup_form('index.php?contextid='.$context->id.'&sifirst=&silast=&roleid=', $rolenames, + popup_form("$CFG->wwwroot/user/index.php?contextid=$context->id&sifirst=&silast=&roleid=", $rolenames, 'rolesform', $roleid, ''); echo '
'; } -- 2.39.5