From: moodler Date: Fri, 15 Sep 2006 06:04:10 +0000 (+0000) Subject: Cleaning up assign and override interfaces X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4934c497197efab6bfa19c676f1a2e07884af148;p=moodle.git Cleaning up assign and override interfaces --- diff --git a/admin/roles/assign.php b/admin/roles/assign.php index afed977df9..105dcc5765 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -154,28 +154,45 @@ } - // prints a form to swap roles - print ('
'); - print ('
'.$strcurrentcontext.': '.print_context_name($context).'
'); - if ($userid) { - print (''); - } - if ($courseid) { - print (''); - } - print (''.$strroletoassign.': '); - choose_from_menu ($assignableroles, 'roleid', $roleid, 'choose', $script='rolesform.submit()'); - print ('
'); - if ($roleid) { + /// prints a form to swap roles + echo '
'; + echo '
'.$strcurrentcontext.': '.print_context_name($context).'
'; + if ($userid) { + echo ''; + } + if ($courseid) { + echo ''; + } + echo ''.$strroletoassign.': '; + choose_from_menu ($assignableroles, 'roleid', $roleid, 'choose', $script='rolesform.submit()'); + echo '
'; print_simple_box_start("center"); - include('assign.html'); - print_simple_box_end(); + } else { // Print overview table + + $table->tablealign = 'center'; + $table->cellpadding = 5; + $table->cellspacing = 0; + $table->width = '20%'; + $table->head = array(get_string('roles', 'role'), get_string('users')); + $table->wrap = array('nowrap', 'nowrap'); + $table->align = array('right', 'center'); + + foreach ($assignableroles as $roleid => $rolename) { + $countusers = 0; + if ($contextusers = get_role_users($roleid, $context)) { + $countusers = count($contextusers); + } + $table->data[] = array(''.$rolename.'', $countusers); + } + + print_table($table); } + print_footer($course); ?> diff --git a/admin/roles/override.html b/admin/roles/override.html index c5cfc89f3c..03c1144fa0 100755 --- a/admin/roles/override.html +++ b/admin/roles/override.html @@ -10,18 +10,18 @@ if ($courseid) { }?> - - - - - + + + + + component != $component or $capability->contextlevel != $contextlevel) { @@ -33,12 +33,12 @@ if ($courseid) { $component = $capability->component; // check the capability override for this cap, this role in this context - - $SQL = "select * from {$CFG->prefix}role_capabilities where - roleid = $roleid and capability = '$capability->name' and contextid = $contextid"; - - $localoverride = get_record_sql($SQL); - + if (isset($localoverrides[$capability->name])) { + $localpermission = $localoverrides[$capability->name]->permission; + } else { + $localpermission = 0; // Just inherit + } + if (isset($r_caps[$capability->name])) { $isallow = $r_caps[$capability->name] > 0; $isprevent = $r_caps[$capability->name] < 0 && $r_caps[$capability->name] > -500; @@ -48,18 +48,45 @@ if ($courseid) { $isprevent = 0; $isprohibit = 0; } + + $isdisabled = $isprohibit || islegacy($capability->name); ?> - - - - + + + + + + + +
Capability NameInheritAllowPreventProhibit
name); ?>permission) || $localoverride->permission==0){ echo 'checked="checked"';} if ($isprohibit || islegacy($capability->name)) {echo 'disabled="disabled"'; }?>>>permission) && $localoverride->permission==1){ echo 'checked="checked"'; } if ($isprohibit || islegacy($capability->name)) {echo 'disabled="disabled"'; }?>>>permission) && $localoverride->permission==-1){ echo 'checked="checked"'; } if ($isprohibit || islegacy($capability->name)) {echo 'disabled="disabled"'; }?>>>permission) && $localoverride->permission==-1000){ echo 'checked="checked"'; } if ($isprohibit || islegacy($capability->name)) {echo 'disabled="disabled"'; }?>> + > + > + > + > + > + > + > +
- +
+
diff --git a/admin/roles/override.php b/admin/roles/override.php index c2d515c8e7..7b1d8c5508 100755 --- a/admin/roles/override.php +++ b/admin/roles/override.php @@ -20,10 +20,11 @@ redirect("$CFG->wwwroot/$CFG->admin/index.php"); } - $strassignusers = get_string('assignusers', 'role'); + $strroletooverride = get_string('roletooverride', 'role'); + $stroverrideusers = get_string('overrideusers', 'role'); $strpotentialusers = get_string('potentialusers', 'role'); $strexistingusers = get_string('existingusers', 'role'); - $straction = get_string('assignroles', 'role'); + $straction = get_string('overrideroles', 'role'); $strcurrentrole = get_string('currentrole', 'role'); $strcurrentcontext = get_string('currentcontext', 'role'); $strsearch = get_string('search'); @@ -75,74 +76,71 @@ * form processing here * *************************/ if ($data = data_submitted()) { - // add or update + + + $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id", + '', 'capability, permission, id'); + foreach ($data as $capname => $value) { - // ignore contextid and roleid - if ($capname == "contextid" || $capname == "roleid") { + if ($capname == 'contextid' || $capname == 'roleid') { // ignore contextid and roleid continue; } - $SQL = "select * from {$CFG->prefix}role_capabilities where - roleid = $roleid and capability = '$capname' and contextid = $contextid"; - - $localoverride = get_record_sql($SQL); - - if ($localoverride) { // update current overrides + if (isset($localoverrides[$capname])) { // Something exists, so update it - if ($value == 0) { // inherit = delete - - delete_records('role_capabilities', 'roleid', $roleid, 'contextid', $contextid, 'capability', $capname); - + if ($value == CAP_INHERIT) { // inherit = delete + delete_records('role_capabilities', 'roleid', $roleid, 'contextid', $contextid, + 'capability', $capname); } else { - + $localoverride = new object; + $localoverride->id = $localoverrides[$capname]->id; $localoverride->permission = $value; $localoverride->timemodified = time(); $localoverride->modifierid = $USER->id; - update_record('role_capabilities', $localoverride); - + if (!update_record('role_capabilities', $localoverride)) { + debugging('Could not update a capability!'); + } } } else { // insert a record - $override->capability = $capname; - $override->contextid = $contextid; - $override->roleid = $roleid; - $override->permission = $value; - $override->timemodified = time(); - $override->modifierid = $USER->id; - insert_record('role_capabilities', $override); + if ($value != CAP_INHERIT) { // Ignore inherits + $override->capability = $capname; + $override->contextid = $contextid; + $override->roleid = $roleid; + $override->permission = $value; + $override->timemodified = time(); + $override->modifierid = $USER->id; + if (!insert_record('role_capabilities', $override)) { + debugging('Could not insert a capability!'); + } + } } - - } - + } } - /***************************************** - * drop down for swapping between roles * - *****************************************/ - - print ('
'); - print ('
'.$strcurrentcontext.': '.print_context_name($context).'
'); - print (''.$strcurrentrole.': '); - if ($userid) { - print (''); - } - if ($courseid) { - print (''); - } - choose_from_menu ($overridableroles, '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 + /// prints a form to swap roles + echo '
'; + echo '
'.$strcurrentcontext.': '.print_context_name($context).'
'; + if ($userid) { + echo ''; + } + if ($courseid) { + echo ''; + } + echo ''.$strroletooverride.': '; + choose_from_menu ($overridableroles, 'roleid', $roleid, 'choose', $script='rolesform.submit()'); + echo '
'; + $r_caps = role_context_capabilities($roleid, $context); + + $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id", + '', 'capability, permission, id'); - // Get the capabilities assignable in this context + // Get the capabilities overrideable in this context if ($capabilities = fetch_context_capabilities($context)) { print_simple_box_start("center"); include_once('override.html'); @@ -151,8 +149,26 @@ notice(get_string('nocapabilitiesincontext', 'role'), $CFG->wwwroot.'/admin/roles/override.php?contextid='.$contextid); } + + } else { // Print overview table + + $table->tablealign = 'center'; + $table->cellpadding = 5; + $table->cellspacing = 0; + $table->width = '20%'; + $table->head = array(get_string('roles', 'role'), get_string('overrides', 'role')); + $table->wrap = array('nowrap', 'nowrap'); + $table->align = array('right', 'center'); + + foreach ($overridableroles as $roleid => $rolename) { + $countusers = 0; + $overridecount = count_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id"); + $table->data[] = array(''.$rolename.'', $overridecount); + } + + print_table($table); } print_footer($course); -?> \ No newline at end of file +?> diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php index b72402af87..4c5b825b5f 100755 --- a/admin/roles/tabs.php +++ b/admin/roles/tabs.php @@ -1,69 +1,70 @@ -aggregatelevel) { - + case CONTEXT_SYSTEM: $stradministration = get_string('administration'); print_header($site->fullname, "$site->fullname","$stradministration -> $straction"); - break; - + break; + case CONTEXT_PERSONAL: - break; - + break; + case CONTEXT_USERID: print_header(); - break; - + break; + case CONTEXT_COURSECAT: $category = get_record('course_categories', 'id', $context->instanceid); $strcategories = get_string("categories"); $strcategory = get_string("category"); $strcourses = get_string("courses"); print_header("$site->shortname: $category->name", "$site->fullname: $strcourses", - "wwwroot/course/index.php\">$strcategories -> wwwroot/course/category.php?id=$category->id\">$category->name -> $straction", "", "", true); - break; - + "wwwroot/course/index.php\">$strcategories -> wwwroot/course/category.php?id=$category->id\">$category->name -> $straction", "", "", true); + break; + case CONTEXT_COURSE: $streditcoursesettings = get_string("editcoursesettings"); - + $course = get_record('course', 'id', $context->instanceid); print_header($streditcoursesettings, "$course->fullname", - "wwwroot/course/view.php?id=$course->id\">$course->shortname - -> wwwroot/course/edit.php?id=$course->id\">$streditcoursesettings -> $straction"); - break; - + "wwwroot/course/view.php?id=$course->id\">$course->shortname + -> wwwroot/course/edit.php?id=$course->id\">$streditcoursesettings -> $straction"); + break; + case CONTEXT_GROUP: - break; - + break; + case CONTEXT_MODULE: // get module type? $cm = get_record('course_modules','id',$context->instanceid); $module = get_record('modules','id',$cm->module); //$module->name; $course = get_record('course','id',$cm->course); - + if (! $form = get_record($module->name, "id", $cm->instance)) { error("The required instance of this module doesn't exist"); } - + $strnav = "wwwroot/mod/$module->name/view.php?id=$cm->id\">$form->name ->"; $fullmodulename = get_string("modulename", $module->name); $streditinga = get_string("editinga", "moodle", $fullmodulename); $strmodulenameplural = get_string("modulenameplural", $module->name); - + if ($module->name == "label") { $focuscursor = ""; } else { $focuscursor = "form.name"; } - + print_header_simple($streditinga, '', - "wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural -> - $strnav wwwroot/course/mod.php?update=$cm->id&sesskey=".sesskey()."\">$streditinga -> $straction", $focuscursor, "", false); - - break; - + "wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural -> + $strnav wwwroot/course/mod.php?update=$cm->id&sesskey=".sesskey()."\">$streditinga -> $straction", $focuscursor, "", false); + + break; + case CONTEXT_BLOCK: if ($blockinstance = get_record('block_instance', 'id', $context->instanceid)) { if ($block = get_record('block', 'id', $blockinstance->blockid)) { @@ -74,86 +75,90 @@ if ($currenttab != 'update') { case 'course-view': if ($course = get_record('course', 'id', $blockinstance->pageid)) { if ($course->id != SITEID) { - $navigation = "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $navigation"; + $navigation = "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $navigation"; } print_header("$straction: $blockname", $course->fullname, $navigation); } - break; + break; case 'blog-view': $strblogs = get_string('blogs','blog'); $navigation = ''. - $strblogs.' -> '.$navigation; + $strblogs.' -> '.$navigation; print_header("$straction: $strblogs", $SITE->fullname, $navigation); - break; + break; default: print_header("$straction: $blockname", $SITE->fullname, $navigation); - break; + break; } } } - break; - + break; + default: error ('This is an unknown context!'); - return false; - + return false; + } } - // Printing the tabs +if ($context->aggregatelevel != CONTEXT_SYSTEM) { // Print tabs for anything except SYSTEM context + if ($context->aggregatelevel == CONTEXT_MODULE) { // only show update button if module? - - $toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.$context->instanceid.'&return=true&sesskey='.sesskey(), get_string('update')); - + + $toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='. + $context->instanceid.'&return=true&sesskey='.sesskey(), get_string('update')); + } - - $toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id, get_string('roles')); + + $toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='. + $context->id, get_string('roles')); if (isset($tabsmode)) { - + if (!isset($assignableroles)) { $assignableroles = get_assignable_roles($context); } if (!isset($overridableroles)) { $overridableroles = get_overridable_roles($context); - } - - + } + $inactive[] = 'roles'; if (!empty($assignableroles)) { - $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id, get_string('assignroles', 'role')); + $secondrow[] = new tabobject('assign', + $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id, + get_string('assignroles', 'role'), + get_string('showallroles', 'role'), + true); } - + if (!empty($overridableroles)) { - if ($context->aggregatelevel == CONTEXT_SYSTEM) { - $secondrow[] = new tabobject('override', '', get_string('overrideroles', 'role')); - } else { - $secondrow[] = new tabobject('override', $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id, - get_string('overrideroles', 'role')); - } + $secondrow[] = new tabobject('override', + $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id, + get_string('overrideroles', 'role'), + get_string('showallroles', 'role'), + true); } - + if ($tabsmode == 'override') { $currenttab = 'override'; } elseif ($tabsmode == 'assign') { $currenttab = 'assign'; } - + } else { $inactive[] = ''; } - + if (!empty($secondrow)) { $tabs = array($toprow, $secondrow); } else { $tabs = array($toprow); } - - if ($context->aggregatelevel != CONTEXT_SYSTEM) { // do not show tabs otherwise - print_tabs($tabs, $currenttab, $inactive); - } + + print_tabs($tabs, $currenttab, $inactive); +} ?> diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php index fba358d56a..e96ba7580e 100644 --- a/lang/en_utf8/role.php +++ b/lang/en_utf8/role.php @@ -7,6 +7,7 @@ $string['allow'] = 'Allow'; $string['allowassign'] = 'Allow role assignments'; $string['allowoverride'] = 'Allow role overrides'; $string['capability'] = 'Capability'; +$string['capabilities'] = 'Capabilities'; $string['currentrole'] = 'Current role'; $string['currentcontext'] = 'Current context'; $string['defineroles'] = 'Define roles'; @@ -15,11 +16,13 @@ $string['inherit'] = 'Inherit'; $string['manageroles'] = 'Manage roles'; $string['nocapabilitiesincontext'] = 'No capabilities available in this context'; $string['overrideroles'] = 'Override roles'; +$string['overrides'] = 'Overrides'; $string['permissions'] = 'Permissions'; $string['potentialusers'] = '$a potential users'; $string['prevent'] = 'Prevent'; $string['prohibit'] = 'Prohibit'; $string['roletoassign'] = 'Role to assign'; +$string['roletooverride'] = 'Role to override'; $string['roles'] = 'Roles'; $string['site:doanything'] = 'Allowed to do everything'; diff --git a/theme/standard/styles_color.css b/theme/standard/styles_color.css index d2243081bc..d6233094fe 100644 --- a/theme/standard/styles_color.css +++ b/theme/standard/styles_color.css @@ -954,3 +954,7 @@ body#mod-quiz-report table#attempts .r1 { color:#ff0000; } +#admin-roles-override .capcurrent { + background-color:#FFFFFF; + border: 1px solid #cecece; +}