// 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 = '';
<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>
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');
+ }
/*************************
}
}
-
+
/*****************************************
* 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");
} /// close switch
// prints the tabs
+$showroles = 1;
$currenttab = 'blogs';
$user = $USER;
if (!$course) {
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);
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" :
}
}
+
+
+
+
+/**
+ * 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? ;-)
+}
?>
function print_context_name($context) {
$name = '';
-
switch ($context->level) {
case CONTEXT_SYSTEM: // by now it's a definite an inherit
return false;
}
-
return $name;
}
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
* 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
*/
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.'&roleid='.$userrole->roleid.'">'.$userrole->name.'</a>, ';
+ }
+
+ }
+ return rtrim($rolestring, ', ');
+}
?>
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
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 ':'';
/// 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)) {
$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