From f4af29c5a4caba59139c7b6dcb565e4baff89186 Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 16 Sep 2006 12:41:47 +0000 Subject: [PATCH] Fixed up some bugs and notices when assigning roles in a user context --- admin/roles/assign.php | 28 ++++++++++++++++------------ admin/roles/override.php | 38 +++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/admin/roles/assign.php b/admin/roles/assign.php index c868d56782..6f95aa9d99 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -22,21 +22,21 @@ if ($courseid) { $course = get_record('course', 'id', $courseid); + } else { + $course = $SITE; } - if (! $site = get_site()) { - redirect("$CFG->wwwroot/$CFG->admin/index.php"); - } - if (! $context = get_context_instance_by_id($contextid)) { error("Context ID was incorrect (can't find it)"); } - require_capability('moodle/role:assign', $context); $assignableroles = get_assignable_roles($context); + +/// Get some language strings + $strassignusers = get_string('assignusers', 'role'); $strpotentialusers = get_string('potentialusers', 'role'); $strexistingusers = get_string('existingusers', 'role'); @@ -45,6 +45,7 @@ $strcurrentcontext = get_string('currentcontext', 'role'); $strsearch = get_string('search'); $strshowall = get_string('showall'); + $strparticipants = get_string("participants"); @@ -55,10 +56,11 @@ error ('you can not override this role in this context'); } } - - $participants = get_string("participants"); - $user = get_record('user', 'id', $userid); - $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); + + if ($userid) { + $user = get_record('user', 'id', $userid); + $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); + } /// Print the header and tabs @@ -68,7 +70,7 @@ if ($courseid!= SITEID) { print_header("$fullname", "$fullname", "id\">$course->shortname -> - wwwroot."/user/index.php?id=$course->id\">$participants -> wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname ->".$straction, + wwwroot."/user/index.php?id=$course->id\">$strparticipants -> wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname ->".$straction, "", "", true, " ", navmenu($course)); /// site header @@ -173,6 +175,8 @@ } else { // Print overview table + $userparam = (!empty($userid)) ? '&userid='.$userid : ''; + $table->tablealign = 'center'; $table->cellpadding = 5; $table->cellspacing = 0; @@ -186,7 +190,7 @@ if ($contextusers = get_role_users($roleid, $context)) { $countusers = count($contextusers); } - $table->data[] = array(''.$rolename.'', $countusers); + $table->data[] = array(''.$rolename.'', $countusers); } print_table($table); @@ -194,4 +198,4 @@ print_footer($course); -?> \ No newline at end of file +?> diff --git a/admin/roles/override.php b/admin/roles/override.php index a69609b6cc..1cf0816ff0 100755 --- a/admin/roles/override.php +++ b/admin/roles/override.php @@ -9,6 +9,8 @@ if ($courseid) { $course = get_record('course', 'id', $courseid); + } else { + $course = $SITE; } $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); @@ -16,9 +18,7 @@ error ('can not override base role capabilities'); } - if (! $site = get_site()) { - redirect("$CFG->wwwroot/$CFG->admin/index.php"); - } +/// Get some language strings $strroletooverride = get_string('roletooverride', 'role'); $stroverrideusers = get_string('overrideusers', 'role'); @@ -29,38 +29,39 @@ $strcurrentcontext = get_string('currentcontext', 'role'); $strsearch = get_string('search'); $strshowall = get_string('showall'); + $strparticipants = get_string("participants"); + $straction = get_string('overrideroles', 'role'); $context = get_record('context', 'id', $contextid); $overridableroles = get_overridable_roles($context); - // role overriding permission checking +/// Make sure this user can override that role if ($roleid) { if (!user_can_override($context, $roleid)) { error ('you can not override this role in this context'); } } - $participants = get_string("participants"); - $user = get_record('user', 'id', $userid); - $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); - $straction = get_string('overrideroles', 'role'); - - + if ($userid) { + $user = get_record('user', 'id', $userid); + $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); + } - // we got a few tabs there +/// Print the header and tabs + if ($context->aggregatelevel == CONTEXT_USER) { /// course header - if ($courseid!= SITEID) { + if ($course->id != SITEID) { print_header("$fullname", "$fullname", "id\">$course->shortname -> - wwwroot."/user/index.php?id=$course->id\">$participants -> wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname -> $straction", + wwwroot."/user/index.php?id=$course->id\">$strparticipants -> wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname -> $straction", "", "", true, " ", navmenu($course)); /// site header } else { print_header("$course->fullname: $fullname", "$course->fullname", - "wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname -> $straction", "", "", true, " ", navmenu($course)); + "wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname -> $straction", "", "", true, " ", navmenu($course)); } $showroles = 1; $currenttab = 'override'; @@ -72,12 +73,9 @@ } - /************************* - * form processing here * - *************************/ +/// Process incoming role override if ($data = data_submitted()) { - $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id", '', 'capability, permission, id'); @@ -151,6 +149,8 @@ } } else { // Print overview table + + $userparam = (!empty($userid)) ? '&userid='.$userid : ''; $table->tablealign = 'center'; $table->cellpadding = 5; @@ -163,7 +163,7 @@ foreach ($overridableroles as $roleid => $rolename) { $countusers = 0; $overridecount = count_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id"); - $table->data[] = array(''.$rolename.'', $overridecount); + $table->data[] = array(''.$rolename.'', $overridecount); } print_table($table); -- 2.39.5