From 0a8a95c91ea357f83ce072a0bc07468800fdd468 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Tue, 15 Aug 2006 08:29:29 +0000 Subject: [PATCH] some more UI stuff --- admin/roles/assign.php | 4 +-- admin/roles/override.html | 7 +++++ admin/roles/override.php | 60 +++++++++++++++++++++++------------ blog/header.php | 1 + blog/index.php | 1 - course/user.php | 2 +- grade/lib.php | 66 +++++++++++++++++++++++++++++++++++++++ lib/accesslib.php | 21 ++++++++++--- user/index.php | 12 ++++--- user/tabs.php | 19 +++++++++-- user/view.php | 11 +++++-- 11 files changed, 167 insertions(+), 37 deletions(-) diff --git a/admin/roles/assign.php b/admin/roles/assign.php index f52f664443..89b69df3d2 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -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 = ''; diff --git a/admin/roles/override.html b/admin/roles/override.html index df1fc211c5..f4a4603021 100755 --- a/admin/roles/override.html +++ b/admin/roles/override.html @@ -1,6 +1,13 @@
+'); +} +if ($course->id) { + print (''); +}?> diff --git a/admin/roles/override.php b/admin/roles/override.php index edce2ce0d9..54c816b8bb 100755 --- a/admin/roles/override.php +++ b/admin/roles/override.php @@ -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"); } @@ -26,10 +32,18 @@ $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 * *****************************************/ @@ -87,24 +101,30 @@ foreach ($role as $rolex) { $options[$rolex->id] = $rolex->name; } - + print (''); - print ('
'.$strcurrentcontext.': '.print_context_name($contextid).'
'); + print ('
'.$strcurrentcontext.': '.print_context_name($context).'
'); print (''.$strcurrentrole.': '); + if ($userid) { + print (''); + } + if ($course->id) { + print (''); + } choose_from_menu ($options, 'roleid', $roleid, 'choose', $script='rolesform.submit()'); print ('
'); - + /************************************** * 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"); diff --git a/blog/header.php b/blog/header.php index ba97373cb7..5c37590504 100755 --- a/blog/header.php +++ b/blog/header.php @@ -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) { diff --git a/blog/index.php b/blog/index.php index 73f4e2abd5..323761736e 100755 --- a/blog/index.php +++ b/blog/index.php @@ -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); diff --git a/course/user.php b/course/user.php index 1390d6e669..a9c4b5a6d2 100644 --- a/course/user.php +++ b/course/user.php @@ -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" : diff --git a/grade/lib.php b/grade/lib.php index 6ee47b8209..5ff0fa809c 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -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 "
"; + 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? ;-) +} ?> diff --git a/lib/accesslib.php b/lib/accesslib.php index d744b97481..a696418726 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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 .= ''.$userrole->name.', '; + } + + } + return rtrim($rolestring, ', '); +} ?> diff --git a/user/index.php b/user/index.php index 0467e52242..2c082c4558 100644 --- a/user/index.php +++ b/user/index.php @@ -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)) { @@ -154,7 +155,7 @@ $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 ':''; diff --git a/user/tabs.php b/user/tabs.php index 979f3f6b56..bda6e745c1 100644 --- a/user/tabs.php +++ b/user/tabs.php @@ -171,11 +171,24 @@ /// 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.'&userid='.$user->id.'&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.'&userid='.$user->id.'&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.'&userid='.$user->id.'&courseid='.$course->id + ,get_string('assign')); + $secondrow[] = new tabobject('override', $CFG->wwwroot.'/admin/roles/override.php?contextid='.$usercontext->id.'&userid='.$user->id.'&courseid='.$course->id + ,get_string('override')); + + } + } /// Add second row to display if there is one if (!empty($secondrow)) { diff --git a/user/view.php b/user/view.php index 28aee8dc41..d25ce02dfa 100644 --- a/user/view.php +++ b/user/view.php @@ -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; @@ -127,7 +129,9 @@ /// /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 "
Capability Name
"; @@ -268,7 +272,10 @@ } 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 -- 2.39.5