-<form name="assignform" id="assignform" method="post" action="assign.php">
-<input type="hidden" name="previoussearch" value="<?php echo $previoussearch ?>" />
-<?php
-if ($userid) {
- print ('<input type="hidden" name="userid" value="'.$userid.'"/>');
-}
-?>
+<form name="assignform" id="assignform" method="post" action="">
+<input type="hidden" name="previoussearch" value="<?php p($previoussearch) ?>" />
+<input type="hidden" name="userid" value="<?php p($userid) ?>" />
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
<input type="hidden" name="contextid" value="<?php p($contextid) ?>" />
</td>
<td></td>
<td valign="top">
- <?php print_string('potentialusers', 'role', count($usercount)); ?>
+ <?php print_string('potentialusers', 'role', $usercount); ?>
</td>
</tr>
<tr>
<?php // $Id$
// Script to assign users to contexts
- require_once("../../config.php");
+ require_once('../../config.php');
require_once($CFG->dirroot.'/mod/forum/lib.php');
define("MAX_USERS_PER_PAGE", 5000);
$errors = array();
+ $baseurl = 'assign.php?contextid='.$contextid;
+ if (!empty($userid)) {
+ $baseurl .= '&userid='.$userid;
+ }
+ if (!empty($courseid)) {
+ $baseurl .= '&courseid='.$courseid;
+ }
+
if (! $context = get_context_instance_by_id($contextid)) {
error("Context ID was incorrect (can't find it)");
}
if ($context->contextlevel == CONTEXT_USER) {
/// course header
- if ($courseid!= SITEID) {
+ if ($courseid != SITEID) {
print_header("$fullname", "$fullname",
- "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
- <a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> ->".$straction,
+ "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
+ <a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$courseid\">$fullname</a> ->".$straction,
"", "", true, " ", navmenu($course));
/// site header
} else {
print_header("$course->fullname: $fullname", "$course->fullname",
- "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
+ "<a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$courseid\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
}
$showroles = 1;
choose_from_menu ($assignableroles, 'roleid', $roleid, get_string('listallroles', 'role').'...', $script='rolesform.submit()');
echo '</div></form>';
- print_simple_box_start("center");
+ print_simple_box_start('center');
include('assign.html');
print_simple_box_end();
if (!empty($errors)) {
- print_simple_box_start("center");
- foreach ($errors as $error) {
- notify($error);
+ $msg = '<p>';
+ foreach ($errors as $e) {
+ $msg .= $e.'<br />';
}
+ $msg .= '</p>';
+ print_simple_box_start('center');
+ notify($msg);
print_simple_box_end();
}
if ($inmeta) {
sync_metacourse($course);
}
- $userparam = (!empty($userid)) ? '&userid='.$userid : '';
$table->tablealign = 'center';
$table->cellpadding = 5;
if ($contextusers = get_role_users($roleid, $context)) {
$countusers = count($contextusers);
}
- $table->data[] = array('<a href="assign.php?contextid='.$context->id.'&roleid='.$roleid.$userparam.'">'.$rolename.'</a>', $countusers);
+ $table->data[] = array('<a href="'.$baseurl.'&roleid='.$roleid.'">'.$rolename.'</a>', $countusers);
}
print_table($table);
$newrole->shortname = $shortname;
$newrole->description = $description;
}
+
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
+ $capabilities = fetch_context_capabilities($sitecontext); // capabilities applicable in this context
- foreach ($data as $capname => $value) {
- if (!preg_match('|^[a-z_]+/[a-z_]+:[a-z_]+$|', $capname)) {
+ foreach ($capabilities as $cap) {
+ if (!isset($data->{$cap->name})) {
continue;
}
- $value = clean_param($value, PARAM_INT);
+ $capname = $cap->name;
+ $value = clean_param($data->{$cap->name}, PARAM_INT);
if (!in_array($value, $allowed_values)) {
continue;
}
}
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
+ $capabilities = fetch_context_capabilities($sitecontext); // capabilities applicable in this context
- foreach ($data as $capname => $value) {
- if (!preg_match('|^[a-z_]+/[a-z_]+:[a-z_]+$|', $capname)) {
+ foreach ($capabilities as $cap) {
+ if (!isset($data->{$cap->name})) {
continue;
}
- $value = clean_param($value, PARAM_INT);
+ $capname = $cap->name;
+ $value = clean_param($data->{$cap->name}, PARAM_INT);
if (!in_array($value, $allowed_values)) {
continue;
}
foreach ($errors as $e) {
$msg .= $e.'<br />';
}
+ $msg .= '</p>';
admin_externalpage_print_header($adminroot);
notify($msg);
print_continue('manage.php');
- <form action="override.php" method="post">
- <input type="hidden" name="contextid" value="<?php p($contextid) ?>">
- <input type="hidden" name="roleid" value="<?php p($roleid) ?>">
-<?php
-if ($userid) {
- print ('<input type="hidden" name="userid" value="'.$userid.'"/>');
-}
-if ($courseid) {
- print ('<input type="hidden" name="courseid" value="'.$courseid.'" />');
-}?>
- <table class="override">
- <tr>
- <td><?php print_string('capability','role') ?></td>
- <td><?php print_string('inherit','role') ?></td>
- <td><?php print_string('allow','role') ?></td>
- <td><?php print_string('prevent','role') ?></td>
- <td><?php print_string('prohibit','role') ?></td>
- <td><?php print_string('risks','role') ?></td>
- </tr>
- <?php
+<form action="override.php" method="post">
+ <input type="hidden" name="contextid" value="<?php p($contextid) ?>">
+ <input type="hidden" name="roleid" value="<?php p($roleid) ?>">
+ <input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
+ <input type="hidden" name="userid" value="<?php p($userid) ?>" />
+ <input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
+ <table class="override">
+ <tr>
+ <td><?php print_string('capability','role') ?></td>
+ <td><?php print_string('inherit','role') ?></td>
+ <td><?php print_string('allow','role') ?></td>
+ <td><?php print_string('prevent','role') ?></td>
+ <td><?php print_string('prohibit','role') ?></td>
+ <td><?php print_string('risks','role') ?></td>
+ </tr>
+ <?php
- // init these 2
- $contextlevel = 0;
- $component = '';
+ // init these 2
+ $contextlevel = 0;
+ $component = '';
- foreach ($capabilities as $capability) {
- // prints a breaker if component or name or context level
- if ($capability->component != $component or $capability->contextlevel != $contextlevel) {
- echo ('<tr><td colspan="5"><b>'.get_component_string($capability->component, $capability->contextlevel).'</b></td></tr>');
- }
+ foreach ($capabilities as $capability) {
+ // prints a breaker if component or name or context level
+ if ($capability->component != $component or $capability->contextlevel != $contextlevel) {
+ echo ('<tr><td colspan="5"><strong>'.get_component_string($capability->component, $capability->contextlevel).'</strong></td></tr>');
+ }
- // these 2 are used to see to group same mod/core capabilities together
- $contextlevel = $capability->contextlevel;
- $component = $capability->component;
+ // these 2 are used to see to group same mod/core capabilities together
+ $contextlevel = $capability->contextlevel;
+ $component = $capability->component;
- // check the capability override for this cap, this role in this context
- if (isset($localoverrides[$capability->name])) {
- $localpermission = $localoverrides[$capability->name]->permission;
- } else {
- $localpermission = 0; // Just inherit
- }
+ // check the capability override for this cap, this role in this context
+ 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;
- $isprohibit = $r_caps[$capability->name] <= -500;
- } else {
- $isallow = 0;
- $isprevent = 0;
- $isprohibit = 0;
- }
+ if (isset($r_caps[$capability->name])) {
+ $isallow = $r_caps[$capability->name] > 0;
+ $isprevent = $r_caps[$capability->name] < 0 && $r_caps[$capability->name] > -500;
+ $isprohibit = $r_caps[$capability->name] <= -500;
+ } else {
+ $isallow = 0;
+ $isprevent = 0;
+ $isprohibit = 0;
+ }
- $isdisabled = $isprohibit || islegacy($capability->name);
+ $isdisabled = $isprohibit || islegacy($capability->name);
- ?>
+ ?>
- <tr>
- <td><?php echo get_capability_string($capability->name); ?></td>
+ <tr>
+ <td><?php echo get_capability_string($capability->name); ?></td>
- <td align="center">
- <input type="radio" name="<?php echo $capability->name; ?>" value="0"
- <?php
- if ($localpermission == 0) {echo 'checked="checked"';}
- if ($isdisabled) {echo 'disabled="disabled"';}?> />
- </td>
+ <td align="center">
+ <input type="radio" name="<?php echo $capability->name; ?>" value="0"
+ <?php
+ if ($localpermission == CAP_INHERIT) {echo 'checked="checked"';}
+ if ($isdisabled) {echo 'disabled="disabled"';}?> />
+ </td>
- <td align="center" <?php if ($isallow) {echo 'class="capcurrent"';} ?>>
- <input type="radio" name="<?php echo $capability->name; ?>"
- <?php echo ' value="'.CAP_ALLOW.'"';
- if ($localpermission == CAP_ALLOW) {echo ' checked="checked"';}
- if ($isdisabled) {echo ' disabled="disabled"';}?> />
- </td>
+ <td align="center" <?php if ($isallow) {echo 'class="capcurrent"';} ?>>
+ <input type="radio" name="<?php echo $capability->name; ?>"
+ <?php echo ' value="'.CAP_ALLOW.'"';
+ if ($localpermission == CAP_ALLOW) {echo ' checked="checked"';}
+ if ($isdisabled) {echo ' disabled="disabled"';}?> />
+ </td>
- <td align="center" <?php if ($isprevent) {echo 'class="capcurrent"';} ?>>
- <input type="radio" name="<?php echo $capability->name; ?>"
- <?php echo ' value="'.CAP_PREVENT.'"';
- if ($localpermission == CAP_PREVENT) {echo ' checked="checked"';}
- if ($isdisabled) {echo ' disabled="disabled"';}?> />
- </td>
+ <td align="center" <?php if ($isprevent) {echo 'class="capcurrent"';} ?>>
+ <input type="radio" name="<?php echo $capability->name; ?>"
+ <?php echo ' value="'.CAP_PREVENT.'"';
+ if ($localpermission == CAP_PREVENT) {echo ' checked="checked"';}
+ if ($isdisabled) {echo ' disabled="disabled"';}?> />
+ </td>
- <td align="center" <?php if ($isprohibit) {echo 'class="capcurrent"';} ?>>
- <input type="radio" name="<?php echo $capability->name; ?>"
- <?php echo ' value="'.CAP_PROHIBIT.'"';
- if ($localpermission == CAP_PROHIBIT) {echo ' checked="checked"';}
- if ($isdisabled) {echo ' disabled="disabled"';}?> />
- </td>
- <td><?php
- if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
- echo "T";
- }
- if (RISK_CONFIG & (int)$capability->riskbitmask) {
- echo "C";
- }
- if (RISK_XSS & (int)$capability->riskbitmask) {
- echo "X";
- }
- if (RISK_PERSONAL & (int)$capability->riskbitmask) {
- echo "P";
- }
- if (RISK_SPAM & (int)$capability->riskbitmask) {
- echo "S";
- }
- ?></td>
- </tr>
+ <td align="center" <?php if ($isprohibit) {echo 'class="capcurrent"';} ?>>
+ <input type="radio" name="<?php echo $capability->name; ?>"
+ <?php echo ' value="'.CAP_PROHIBIT.'"';
+ if ($localpermission == CAP_PROHIBIT) {echo ' checked="checked"';}
+ if ($isdisabled) {echo ' disabled="disabled"';}?> />
+ </td>
+ <td><?php
+ if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
+ echo "T";
+ }
+ if (RISK_CONFIG & (int)$capability->riskbitmask) {
+ echo "C";
+ }
+ if (RISK_XSS & (int)$capability->riskbitmask) {
+ echo "X";
+ }
+ if (RISK_PERSONAL & (int)$capability->riskbitmask) {
+ echo "P";
+ }
+ if (RISK_SPAM & (int)$capability->riskbitmask) {
+ echo "S";
+ }
+ ?></td>
+ </tr>
- <?php } ?>
- </table>
- <br />
- <div align="center"><input type="submit" value="<?php print_string('savechanges') ?>" /></div>
- </form>
+ <?php } ?>
+ </table>
+ <br />
+ <div align="center">
+ <input type="submit" value="<?php print_string('savechanges') ?>" />
+ <input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
+ </div>
+</form>
-<?php
+<?php //$Id$
- require_once("../../config.php");
+ require_once('../../config.php');
- $contextid = required_param('contextid',PARAM_INT); // context id
- $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
+ $contextid = required_param('contextid',PARAM_INT); // context id
+ $roleid = optional_param('roleid', 0, PARAM_INT); // requested role id
+ $userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
+ $courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
+ $cancel = optional_param('cancel', 0, PARAM_BOOL);
if ($courseid) {
$course = get_record('course', 'id', $courseid);
$course = $SITE;
}
+ $context = get_record('context', 'id', $contextid);
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
if ($contextid == $sitecontext->id) {
- error ('can not override base role capabilities');
+ error ('Can not override base role capabilities');
+ }
+
+ if ($context->contextlevel == CONTEXT_COURSE) {
+ require_login($context->instanceid);
+ } else {
+ require_login();
+ }
+
+ $baseurl = 'override.php?contextid='.$contextid;
+ if (!empty($userid)) {
+ $baseurl .= '&userid='.$userid;
+ }
+ if (!empty($courseid)) {
+ $baseurl .= '&courseid='.$courseid;
}
+ if ($cancel) {
+ redirect($baseurl);
+ }
+
+
/// Get some language strings
$strroletooverride = get_string('roletooverride', 'role');
- $stroverrideusers = get_string('overrideusers', 'role');
- $strpotentialusers = get_string('potentialusers', 'role');
- $strexistingusers = get_string('existingusers', 'role');
- $straction = get_string('overrideroles', 'role');
- $strcurrentrole = get_string('currentrole', 'role');
+ $stroverrideusers = get_string('overrideusers', 'role');
+ $straction = get_string('overrideroles', 'role');
+ $strcurrentrole = get_string('currentrole', 'role');
$strcurrentcontext = get_string('currentcontext', 'role');
- $strsearch = get_string('search');
- $strshowall = get_string('showall');
- $strparticipants = get_string("participants");
- $straction = get_string('overrideroles', 'role');
-
- $context = get_record('context', 'id', $contextid);
- $overridableroles = get_overridable_roles($context);
+ $strparticipants = get_string('participants');
/// Make sure this user can override that role
if ($roleid) {
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
}
+/// Process incoming role override
+ if ($data = data_submitted() and confirm_sesskey()) {
+ $allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
+ $capabilities = fetch_context_capabilities($context); // capabilities applicable in this context
+
+ $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
+ '', 'capability, permission, id');
+
+ foreach ($capabilities as $cap) {
+ if (!isset($data->{$cap->name})) {
+ continue;
+ }
+ $capname = $cap->name;
+ $value = clean_param($data->{$cap->name}, PARAM_INT);
+ if (!in_array($value, $allowed_values)) {
+ continue;
+ }
+
+ if (isset($localoverrides[$capname])) { // Something exists, so update it
+ 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;
+ if (!update_record('role_capabilities', $localoverride)) {
+ error('Could not update a capability!');
+ }
+ }
+
+ } else { // insert a record
+ if ($value != CAP_INHERIT) { // Ignore inherits
+ $localoverride = new object();
+ $localoverride->capability = $capname;
+ $localoverride->contextid = $contextid;
+ $localoverride->roleid = $roleid;
+ $localoverride->permission = $value;
+ $localoverride->timemodified = time();
+ $localoverride->modifierid = $USER->id;
+ if (!insert_record('role_capabilities', $localoverride)) {
+ error('Could not insert a capability!');
+ }
+ }
+ }
+ }
+ redirect($baseurl);
+ }
+
+
/// Print the header and tabs
if ($context->contextlevel == CONTEXT_USER) {
/// course header
if ($course->id != SITEID) {
print_header("$fullname", "$fullname",
- "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
- <a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname</a> -> $straction",
+ "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
+ <a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$course->id\">$fullname</a> -> $straction",
"", "", true, " ", navmenu($course));
/// site header
} else {
print_header("$course->fullname: $fullname", "$course->fullname",
- "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
+ "<a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$course->id\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
}
$showroles = 1;
$currenttab = 'override';
}
-/// Process incoming role override
- if ($data = data_submitted()) {
-
- $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
- '', 'capability, permission, id');
-
- foreach ($data as $capname => $value) {
- if ($capname == 'contextid' || $capname == 'roleid' || $capname == 'userid') { // ignore contextid and roleid
- continue;
- }
-
- if (isset($localoverrides[$capname])) { // Something exists, so update it
-
- 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;
-
- if (!update_record('role_capabilities', $localoverride)) {
- debugging('Could not update a capability!');
- }
- }
-
- } else { // insert a record
-
- 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!');
- }
- }
- }
- }
- }
-
+ $overridableroles = get_overridable_roles($context);
if ($roleid) {
/// prints a form to swap roles
- echo '<form name="rolesform" action="override.php" method="post">';
+ echo '<form name="rolesform" action="override.php" method="get">';
echo '<div align="center">'.$strcurrentcontext.': '.print_context_name($context).'<br/>';
if ($userid) {
echo '<input type="hidden" name="userid" value="'.$userid.'" />';
// Get the capabilities overrideable in this context
if ($capabilities = fetch_context_capabilities($context)) {
- print_simple_box_start("center");
+ print_simple_box_start('center');
include_once('override.html');
print_simple_box_end();
} else {
notice(get_string('nocapabilitiesincontext', 'role'),
- $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$contextid);
+ $CFG->wwwroot.'/'.$CFG->admin.'/roles/'.$baseurl);
}
} else { // Print overview table
- $userparam = (!empty($userid)) ? '&userid='.$userid : '';
-
$table->tablealign = 'center';
$table->cellpadding = 5;
$table->cellspacing = 0;
foreach ($overridableroles as $roleid => $rolename) {
$countusers = 0;
$overridecount = count_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id");
- $table->data[] = array('<a href="override.php?contextid='.$context->id.'&roleid='.$roleid.$userparam.'">'.$rolename.'</a>', $overridecount);
+ $table->data[] = array('<a href="'.$baseurl.'&roleid='.$roleid.'">'.$rolename.'</a>', $overridecount);
}
print_table($table);