]> git.mjollnir.org Git - moodle.git/commitdiff
some more UI stuff
authortoyomoyo <toyomoyo>
Tue, 15 Aug 2006 08:29:29 +0000 (08:29 +0000)
committertoyomoyo <toyomoyo>
Tue, 15 Aug 2006 08:29:29 +0000 (08:29 +0000)
admin/roles/assign.php
admin/roles/override.html
admin/roles/override.php
blog/header.php
blog/index.php
course/user.php
grade/lib.php
lib/accesslib.php
user/index.php
user/tabs.php
user/view.php

index f52f664443213dc95050ab104ac9cf85ce22664d..89b69df3d2f7f74aafe355bc961fc84f92dd5096 100755 (executable)
@@ -58,8 +58,8 @@
     // we got a few tabs there
     if ($context->level == CONTEXT_USERID) {
         print_header();
-      
-        $currenttab = 'roles';
+        $showroles = 1;
+        $currenttab = 'assign';
         include_once($CFG->dirroot.'/user/tabs.php');
     } else {
         $currenttab = '';
index df1fc211c586570b1a15b13537ce2b54831aca64..f4a46030212859e1caf127fcabf7b080f47006ee 100755 (executable)
@@ -1,6 +1,13 @@
              <form action="override.php" method="post">     
             <input type="hidden" name="contextid" value="<?php echo $contextid; ?>">
             <input type="hidden" name="roleid" value="<?php echo $roleid; ?>">
+<?php
+if ($userid) {
+    print ('<input type="hidden" name="userid" value="'.$userid.'"/>');
+}
+if ($course->id) {
+    print ('<input type="hidden" name="courseid" value="'.$courseid.'" />');
+}?>
             <table class="override">
             <tr>
                 <td>Capability Name</td>
index edce2ce0d9f9767909861f45e473c7c35ea81efd..54c816b8bbc1520676e02e14c57cf4cc607501a2 100755 (executable)
@@ -3,14 +3,20 @@
     require_once("../../config.php");
     
     $contextid      = required_param('contextid',PARAM_INT); // context id
-    $roleid            = optional_param('roleid', 0, PARAM_INT); // required role id
-     
-     $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
-     if ($contextid == $sitecontext->id) {
-           error ('can not override base role capabilities');
-     }
-     
-     if (! $site = get_site()) {
+    $roleid         = optional_param('roleid', 0, PARAM_INT); // required role id
+    $userid         = optional_param('userid', 0, PARAM_INT); // needed for user tabs
+    $courseid       = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
+    
+    if ($courseid) {
+        $course = get_record('course', 'id', $courseid);  
+    }
+    
+    $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+    if ($contextid == $sitecontext->id) {
+        error ('can not override base role capabilities');
+    }
+
+    if (! $site = get_site()) {
         redirect("$CFG->wwwroot/$CFG->admin/index.php");
     }
 
     $context = get_record('context', 'id', $contextid);
 
     $straction = get_string('overrideroles', 'role');
-    $currenttab = '';
-
-    $tabsmode = 'override';
-    include_once('tabs.php');
+    
+    // we got a few tabs there
+    if ($context->level == CONTEXT_USERID) {
+        print_header();
+        $showroles = 1;
+        $currenttab = 'override';
+        include_once($CFG->dirroot.'/user/tabs.php');
+    } else {
+        $currenttab = '';
+        $tabsmode = 'override';
+        include_once('tabs.php');
+    }
 
 
      /*************************
@@ -77,7 +91,7 @@
          }
        
     }
-    
+
     /*****************************************
       * drop down for swapping between roles  *
       *****************************************/
     foreach ($role as $rolex) {
         $options[$rolex->id] = $rolex->name;
     }
-    
+
     print ('<form name="rolesform" action="override.php" method="post">');
-    print ('<div align="center">'.$strcurrentcontext.': '.print_context_name($contextid).'<br/>');
+    print ('<div align="center">'.$strcurrentcontext.': '.print_context_name($context).'<br/>');
     print ('<input type="hidden" name="contextid" value="'.$contextid.'">'.$strcurrentrole.': ');
+    if ($userid) {
+        print ('<input type="hidden" name="userid" value="'.$userid.'" />');
+    }
+    if ($course->id) {
+        print ('<input type="hidden" name="courseid" value="'.$courseid.'" />');
+    }
     choose_from_menu ($options, 'roleid', $roleid, 'choose', $script='rolesform.submit()');
     print ('</div></form>');
-        
+   
     /**************************************
       * print html for editting overrides  *
       **************************************/
 
     if ($roleid) {
-      
+     
           // this is the array holding capabilities of this role sorted till this context
-          $r_caps = role_context_capabilities($roleid, $contextid);
-          
+        $r_caps = role_context_capabilities($roleid, $context);
+      
         // this is the available capabilities assignable in this context
-        $capabilities = fetch_context_capabilities($contextid);
+        $capabilities = fetch_context_capabilities($context);
         
         print_simple_box_start("center");
     
index ba97373cb73b5b940bb52ba5eaa6cdf4bf26f5ab..5c37590504af3762b44a83046bc20d88dc9c22f2 100755 (executable)
@@ -184,6 +184,7 @@ if ($ME == $CFG->wwwroot.'/blog/edit.php') {  /// We are in edit mode, print the
 } /// close switch
 
 // prints the tabs
+$showroles = 1;
 $currenttab = 'blogs';
 $user = $USER;
 if (!$course) {
index 73f4e2abd50776d25aa0e175e2ff366cd986d3c5..323761736e087d4f2146dd34a8f4ff81827a49c5 100755 (executable)
@@ -150,7 +150,6 @@ $user = $USER;
 if (!$course) {
     $course = get_record('course', 'id', optional_param('courseid', SITEID, PARAM_INT));
 }
-require_once($CFG->dirroot .'/user/tabs.php');
 
 $blogpage = optional_param('blogpage', 0, PARAM_INT);
 
index 1390d6e66903b1f7c856dbb0f69f704207b6d9be..a9c4b5a6d28f675a79d8211d03b6d96693b169b4 100644 (file)
@@ -65,7 +65,7 @@
         case "grade":
             $course = get_record('course', 'id', required_param('id', PARAM_INT));
             require_once($CFG->dirroot.'/grade/lib.php');
-            grade_view_all_grades($user->id, 'user');
+            print_student_grade($user, $course);
             break;
       
         case "todaylogs" :
index 6ee47b8209bc431cd043648d58338aab5bb12fdb..5ff0fa809c1c03b42b7c05ea2588eea5c80e0b01 100644 (file)
@@ -2920,4 +2920,70 @@ function grade_download_form($type='both') {
     }
 }
 
+
+
+
+
+/** 
+ * Simply prints all grade of one student from all modules from a given course
+ * @param int $userid;
+ * @param int $courseid;
+ */
+function print_student_grade($user, $course) {
+    
+    global $CFG;
+  
+    if (!empty($user)) {
+        $grades[$user->id] = array();    // Collect all grades in this array
+        $gradeshtml[$user->id] = array(); // Collect all grades html formatted in this array
+        $totals[$user->id] = array();    // Collect all totals in this array
+    }
+  
+    $strmax = get_string("maximumshort");
+  /// Collect modules data
+    get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
+
+/// Search through all the modules, pulling out grade data
+    $sections = get_all_sections($course->id); // Sort everything the same as the course
+    for ($i=0; $i<=$course->numsections; $i++) {
+        if (isset($sections[$i])) {   // should always be true
+            $section = $sections[$i];
+            if ($section->sequence) {
+                $sectionmods = explode(",", $section->sequence);
+                foreach ($sectionmods as $sectionmod) {
+                    $mod = $mods[$sectionmod];
+                    $instance = get_record("$mod->modname", "id", "$mod->instance");
+                    $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";    
+                    
+                    if (file_exists($libfile)) {
+                        require_once($libfile);
+                        $gradefunction = $mod->modname."_grades";
+                        if (function_exists($gradefunction)) {   // Skip modules without grade function
+                            if ($modgrades = $gradefunction($mod->instance)) {
+                                if (!empty($modgrades->maxgrade)) {
+                                    if ($mod->visible) {
+                                        $maxgrade = "$modgrades->maxgrade";
+                                    } else {
+                                        $maxgrade = "$modgrades->maxgrade";
+                                    }
+                                } else {
+                                    $maxgrade = "";
+                                }
+                                
+                                if ($maxgrade) { 
+                                    echo "<br/>";
+                                    if (!empty($modgrades->grades[$user->id])) {
+                                        $currentgrade = $modgrades->grades[$user->id];
+                                        echo "$mod->modfullname: ".format_string($instance->name,true)." - $currentgrade/$maxgrade";            } else {
+                                        echo "$mod->modfullname: ".format_string($instance->name,true)." - ".get_string('nograde')."/$maxgrade";                                        
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    } // a new Moodle nesting record? ;-) 
+}
 ?>
index d744b97481031833d72c736285c74805ec61bb3b..a69641872631773a13f0d7ac915218041d298337 100755 (executable)
@@ -1228,7 +1228,6 @@ function capabilities_cleanup($component, $newcapdef=NULL) {
 function print_context_name($context) {
 
     $name = '';
-
     switch ($context->level) {
 
         case CONTEXT_SYSTEM: // by now it's a definite an inherit
@@ -1286,7 +1285,6 @@ function print_context_name($context) {
             return false;
 
     }
-
     return $name;
 }
 
@@ -1318,9 +1316,11 @@ function fetch_context_capabilities($context) {
         break;
 
         case CONTEXT_PERSONAL:
+            $SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_PERSONAL;
         break;
         
         case CONTEXT_USERID:
+            $SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_USERID;
         break;
         
         case CONTEXT_COURSECAT: // all
@@ -1364,7 +1364,7 @@ function fetch_context_capabilities($context) {
  * This function pulls out all the resolved capabilities (overrides and
  * defaults) of a role used in capability overrieds in contexts at a given
  * context.
- * @param int $context
+ * @param obj $context
  * @param int $roleid
  * @return array
  */
@@ -1585,5 +1585,18 @@ function get_roles_used_in_context($context) {
                              ORDER BY r.sortorder ASC');
 }
 
-
+// this function is used to print roles column in user profile page. 
+function get_user_roles_in_context($userid, $contextid){
+    global $CFG;
+    
+    $rolestring = '';
+    $SQL = 'select * from '.$CFG->prefix.'role_assignments ra, '.$CFG->prefix.'role r where ra.userid='.$userid.' and ra.contextid='.$contextid.' and ra.roleid = r.id';
+    if ($roles = get_records_sql($SQL)) {
+        foreach ($roles as $userrole) {
+            $rolestring .= '<a href="'.$CFG->wwwroot.'/user/index.php?contextid='.$userrole->contextid.'&amp;roleid='.$userrole->roleid.'">'.$userrole->name.'</a>, ';
+        }   
+        
+    }
+    return rtrim($rolestring, ', ');
+}
 ?>
index 0467e5224244c9b4b3a00793f03defb05e800af5..2c082c45582695716b986af4cdb0de7887714af4 100644 (file)
@@ -25,6 +25,7 @@
 
     if ($contextid) {
         if (! $context = get_context_instance_by_id($contextid)) {
+            
             error("Context ID is incorrect");
         }
         if (! $course = get_record('course', 'id', $context->instanceid)) {
             $options[$role->id] = $role->name;
         }
     }
-    
+
     if (!$roleid) {
         if ($options) {
             $roleid = array_shift(array_keys($options)); // get first element
@@ -360,9 +361,12 @@ function checkchecked(form) {
     if ($roleid) {
       
         // we are looking for all users with this role assigned in this context or higher
-        $usercontexts = get_parent_contexts($context);      
-        $listofcontexts = '('.implode(',', $usercontexts).')';
-
+        if ($usercontexts = get_parent_contexts($context)) {
+            $listofcontexts = '('.implode(',', $usercontexts).')';
+        } else {
+            $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+            $listofcontexts = '('.$sitecontext->id.')'; // must be site  
+        }
         $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country, 
                           u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, u.lastaccess AS lastaccess '; // s.lastaccess
         //$select .= $course->enrolperiod?', s.timeend ':'';
index 979f3f6b5669b47d99697f260ce093bd99c04472..bda6e745c157cc1214dc6102b9b7a487e034fab5 100644 (file)
 
 
     /// this needs permission checkings
-    
-    $context = get_context_instance(CONTEXT_USERID, $user->id);
-    $toprow[] = new tabobject('roles', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$context->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
+
+    if (!empty($showroles)) { // this variable controls whether this roles is showed, or not, so only user/view page should set this flag
+        $usercontext = get_context_instance(CONTEXT_USERID, $user->id);
+        $toprow[] = new tabobject('roles', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
                               ,get_string('roles'));
+                              
+        if (in_array($currenttab, array('assign', 'override'))) {
+            $inactive = array('roles');
+            $activetwo = array('roles');
 
+            $secondrow = array();
+            $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
+                              ,get_string('assign'));
+            $secondrow[] = new tabobject('override', $CFG->wwwroot.'/admin/roles/override.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
+                              ,get_string('override'));
+                                
+        }                                                                                                       
+    }
 /// Add second row to display if there is one
 
     if (!empty($secondrow)) {
index 28aee8dc41a33f4f1df73e6514a86ac23e50b650..d25ce02dfae81ff44198f2834e35f1083bdc37a3 100644 (file)
@@ -8,7 +8,9 @@
     $enable  = optional_param('enable', '');                  // enable email
     $disable = optional_param('disable', '');                 // disable email
 
-
+    if ($course) {
+        $coursecontext = get_context_instance(CONTEXT_COURSE, $course); 
+    }
     if (empty($id)) {         // See your own profile by default
         require_login();
         $id = $USER->id;
 ///     /user/view.php
 ///     /user/edit.php
 ///     /course/user.php
+    $context = get_context_instance(CONTEXT_USERID, $user->id);
     $currenttab = 'profile';
+    $showroles = 1;
     include('tabs.php');
 
     echo "<table width=\"80%\" align=\"center\" border=\"0\" cellspacing=\"0\" class=\"userinfobox\">";
         }
         print_row(get_string("lastaccess").":", $datestring);
     }
-
+/// printing roles
+    
+    $rolestring = get_user_roles_in_context($id, $coursecontext->id);
+    print_row(get_string("roles").":", $rolestring);
 
 /// Printing groups
     $isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and