]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed up some bugs and notices when assigning roles in a user context
authormoodler <moodler>
Sat, 16 Sep 2006 12:41:47 +0000 (12:41 +0000)
committermoodler <moodler>
Sat, 16 Sep 2006 12:41:47 +0000 (12:41 +0000)
admin/roles/assign.php
admin/roles/override.php

index c868d56782ba8e707beccce4304b0fec4dd93056..6f95aa9d991c19da9d4c6c389a0c633719adbc59 100755 (executable)
 
     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");
 
     
 
             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",
                      "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
-                      <a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$participants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> ->".$straction,
+                      <a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> ->".$straction,
                       "", "", true, "&nbsp;", navmenu($course));      
         
         /// site header  
 
     } else {   // Print overview table
        
+        $userparam = (!empty($userid)) ? '&amp;userid='.$userid : '';
+
         $table->tablealign = 'center';
         $table->cellpadding = 5;
         $table->cellspacing = 0;
             if ($contextusers = get_role_users($roleid, $context)) {
                 $countusers = count($contextusers);
             }
-            $table->data[] = array('<a href="assign.php?contextid='.$context->id.'&amp;roleid='.$roleid.'">'.$rolename.'</a>', $countusers);
+            $table->data[] = array('<a href="assign.php?contextid='.$context->id.'&amp;roleid='.$roleid.$userparam.'">'.$rolename.'</a>', $countusers);
         }
     
         print_table($table);
 
     print_footer($course);
 
-?>
\ No newline at end of file
+?>
index a69609b6cc2d30ad22c7a70397d7df3a4823d594..1cf0816ff05be862ef70c592dd19d408b0678038 100755 (executable)
@@ -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');
     $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",
                      "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
-                      <a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$participants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> -> $straction",
+                      <a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname</a> -> $straction",
                       "", "", true, "&nbsp;", navmenu($course));      
         
         /// site header  
         } else {
             print_header("$course->fullname: $fullname", "$course->fullname",
-                        "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> -> $straction", "", "", true, "&nbsp;", navmenu($course));     
+                        "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname</a> -> $straction", "", "", true, "&nbsp;", navmenu($course));     
         }
         $showroles = 1;
         $currenttab = 'override';
     }
 
 
-     /*************************
-      * 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');
 
         }
 
     } else {   // Print overview table
+
+        $userparam = (!empty($userid)) ? '&amp;userid='.$userid : '';
        
         $table->tablealign = 'center';
         $table->cellpadding = 5;
         foreach ($overridableroles as $roleid => $rolename) {
             $countusers = 0;
             $overridecount = count_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id");
-            $table->data[] = array('<a href="override.php?contextid='.$context->id.'&amp;roleid='.$roleid.'">'.$rolename.'</a>', $overridecount);
+            $table->data[] = array('<a href="override.php?contextid='.$context->id.'&amp;roleid='.$roleid.$userparam.'">'.$rolename.'</a>', $overridecount);
         }
     
         print_table($table);