'.$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 ba97373cb73..5c37590504a 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 73f4e2abd50..323761736e0 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 1390d6e6690..a9c4b5a6d28 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 6ee47b8209b..5ff0fa809c1 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 d744b974810..a6964187263 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 0467e522424..2c082c45582 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 979f3f6b566..bda6e745c15 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
- ,get_string('roles'));
+ 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 28aee8dc41a..d25ce02dfae 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 "
";
@@ -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