$this->get_row_classes($capability)))) . '">';
/// Table cell for the capability name.
- echo '<td class="name"><span class="cap-desc">' . get_capability_docs_link($capability) .
+ echo '<th scope="row" class="name"><span class="cap-desc">' . get_capability_docs_link($capability) .
'<span class="cap-name">' . $capability->name . '</span></span></td>';
/// Add the cells specific to this table.
}
protected function add_header_cells() {
- echo '<th class="risk" colspan="' . $this->num_extra_columns() . '" scope="col">' . get_string('risks','role') . '</th>';
+ echo '<th class="risk" colspan="' . count($this->allrisks) . '" scope="col">' . get_string('risks','role') . '</th>';
}
protected function num_extra_columns() {
}
}
-class override_permissions_capability_table extends capability_table_with_risks {
+class override_permissions_table_advanced extends capability_table_with_risks {
protected $roleid;
protected $inheritedcapabilities;
+ protected $displaypermissions;
+ protected $strnotset;
protected $localoverrides;
protected $changed = array(); // $localoverrides that were changed by the submitted data, and so need to be saved.
protected $haslockedcapabiltites = false;
global $DB;
parent::__construct($context, 'overriderolestable');
$this->roleid = $roleid;
+ $this->displaypermissions = $this->allpermissions;
+ $this->strnotset = get_string('notset', 'role');
/// Get the capabiltites from the parent context, so that can be shown in the interface.
$parentcontext = get_context_instance_by_id(get_parent_contextid($context));
}
protected function add_header_cells() {
- foreach ($this->strperms as $permname => $strpermname) {
- echo '<th class="' . $permname . '" scope="col">' . $strpermname . '</th>';
- }
+ echo '<th colspan="' . count($this->displaypermissions) . '" scope="col">' . get_string('permission', 'role') . '</th>';
parent::add_header_cells();
}
protected function num_extra_columns() {
- return count($this->strperms) + parent::num_extra_columns();
+ return count($this->displaypermissions) + parent::num_extra_columns();
}
protected function skip_row($capability) {
}
protected function add_row_cells($capability) {
+ $this->add_permission_cells($capability);
+ parent::add_row_cells($capability);
+ }
+
+ protected function add_permission_cells($capability) {
$disabled = '';
if ($capability->locked || $this->inheritedcapabilities[$capability->name] == CAP_PROHIBIT) {
$disabled = ' disabled="disabled"';
}
/// One cell for each possible permission.
- foreach ($this->allpermissions as $perm => $permname) {
+ foreach ($this->displaypermissions as $perm => $permname) {
+ $strperm = $this->strperms[$permname];
$extraclass = '';
if ($perm != CAP_INHERIT && $perm == $this->inheritedcapabilities[$capability->name]) {
$extraclass = ' capcurrent';
$checked = ' checked="checked"';
}
echo '<td class="' . $permname . $extraclass . '">';
- echo '<input type="radio" title="' . $this->strperms[$permname] . '" name="' . $capability->name .
- '" value="' . $perm . '"' . $checked . $disabled . ' />';
+ echo '<label><input type="radio" name="' . $capability->name .
+ '" value="' . $perm . '"' . $checked . $disabled . ' /> ';
+ if ($perm == CAP_INHERIT) {
+ $inherited = $this->inheritedcapabilities[$capability->name];
+ if ($inherited == CAP_INHERIT) {
+ $inherited = $this->strnotset;
+ } else {
+ $inherited = $this->strperms[$this->allpermissions[$inherited]];
+ }
+ $strperm .= ' (' . $inherited . ')';
+ }
+ echo '<span class="note">' . $strperm . '</span>';
+ echo '</label></td>';
+ }
+ }
+}
+
+class override_permissions_table_basic extends override_permissions_table_advanced {
+ protected $stradvmessage;
+
+ public function __construct($context, $roleid, $safeoverridesonly) {
+ global $DB;
+ parent::__construct($context, $roleid, $safeoverridesonly);
+ unset($this->displaypermissions[CAP_PROHIBIT]);
+ $this->stradvmessage = get_string('useshowadvancedtochange', 'role');
+ }
+
+ protected function add_permission_cells($capability) {
+ if ($this->localoverrides[$capability->name] == CAP_PROHIBIT) {
+ $permname = $this->allpermissions[CAP_PROHIBIT];
+ echo '<td class="' . $permname . '" colspan="' . count($this->displaypermissions) . '">';
+ echo '<input type="hidden" name="' . $capability->name . '" value="' . CAP_PROHIBIT . '" />';
+ echo $this->strperms[$permname] . '<span class="note">' . $this->stradvmessage . '</span>';
echo '</td>';
+ } else {
+ parent::add_permission_cells($capability);
}
- parent::add_row_cells($capability);
}
}
}
protected function get_options() {
+ global $CFG;
$options = parent::get_options();
+ $options['file'] = $CFG->admin . '/roles/lib.php';
$options['roleid'] = $this->roleid;
$options['contextid'] = $this->context->id;
return $options;
}
}
-/// get all cababilities
+/// If we are actually overriding a role, create the table object, and save changes if appropriate.
if ($roleid) {
- $overridestable = new override_permissions_capability_table($context, $roleid, $safeoverridesonly);
+ if ($showadvanced) {
+ $overridestable = new override_permissions_table_advanced($context, $roleid, $safeoverridesonly);
+ } else {
+ $overridestable = new override_permissions_table_basic($context, $roleid, $safeoverridesonly);
+ }
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$overridestable->save_changes();
$showadvancedlabel = get_string('showadvanced', 'form');
}
?>
-<form id="overrideform" action="<?php echo $baseurl; ?>" method="post"><div>
+<form id="overrideform" action="<?php echo $baseurl . '&roleid=' . $roleid; ?>" method="post"><div>
<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
- <input type="hidden" name="roleid" value="<?php p($roleid); ?>" />
<div class="advancedbutton">
<input type="submit" name="toggleadvanced" value="<?php echo $showadvancedlabel ?>" />
</div>
<?php
+ echo '<p class="overridenotice">' . get_string('highlightedcellshowsinherit', 'role') . ' </p>';
$overridestable->display();
if ($overridestable->has_locked_capabiltites()) {
- echo '<div class="sefeoverridenotice">' . get_string('safeoverridenotice', 'role') . "</div>\n";
+ echo '<p class="overridenotice">' . get_string('safeoverridenotice', 'role') . "</p>\n";
}
?>
$string['grade:viewall'] = 'View grades of other users';
$string['grade:viewhidden'] = 'View hidden grades for owner';
$string['hidden'] = 'Hidden';
+$string['highlightedcellshowsinherit'] = 'The highlighted cells in the table below show the permission (if any) that will be inherited. Apart from the capabilties whose permission you actually want to alter, you should leave everything set to Inherit.';
+$string['highlightedcellshowsdefault'] = 'The highlighted cells in the table below show the default permission for this type of role.';
$string['inactiveformorethan'] = 'inactive for more than $a->timeperiod';
$string['ingroup'] = 'in the group \"$a->group\"';
$string['inherit'] = 'Inherit';
$string['overriderolesin'] = 'Override roles in $a';
$string['overrides'] = 'Overrides';
$string['overridesbycontext'] = 'Overrides (by context)';
+$string['permission'] = 'Permission';
$string['permissions'] = 'Permissions';
$string['permissionsforuser'] = 'Permissions for user $a';
$string['potentialusers'] = '$a potential users';
$string['userhashiddenassignments'] = 'This user has one or more hidden role assignments in this course';
$string['userswiththisrole'] = 'Users with role';
$string['userswithrole'] = 'All users with a role';
+$string['useshowadvancedtochange'] = 'Use \'Show advanced\' to change';
$string['viewrole'] = 'View role details';
$string['whydoesuserhavecap'] = 'Why does $a->fullname have capability $a->capability in context $a->context?';
$string['whydoesusernothavecap'] = 'Why does $a->fullname not have capability $a->capability in context $a->context?';