some more UI stuff

This commit is contained in:
toyomoyo
2006-08-15 08:29:29 +00:00
parent 6006c31d28
commit 0a8a95c91e
11 changed files with 168 additions and 38 deletions
+2 -2
View File
@@ -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 = '';
+7
View File
@@ -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>
+40 -20
View File
@@ -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 ('<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");
+1
View File
@@ -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) {
-1
View File
@@ -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);
+1 -1
View 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" :
+66
View 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? ;-)
}
?>
+17 -4
View File
@@ -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, ', ');
}
?>
+8 -4
View 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)) {
@@ -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 ':'';
+17 -4
View File
@@ -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.'&amp;userid='.$user->id.'&amp;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.'&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)) {
+9 -2
View 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;
@@ -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 "<table width=\"80%\" align=\"center\" border=\"0\" cellspacing=\"0\" class=\"userinfobox\">";
@@ -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