mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
ROLES AND PERMISSIONS - FIRST CHECK-IN
======================================= WARNING: DEV IS CURRENTLY VERY UNSTABLE. This is a mega-checkin of the new Roles system. A lot of changes have been made in core and modules. Currently there are a lot of rough edges and known problems. We are working hard on these .. .the reason for getting this into HEAD at this stage is enable us to move faster (our branch was diverging from HEAD too much). Please keep an eye on http://docs.moodle.org/en/Roles for current status and information for developers on how to use the new Roles system.
This commit is contained in:
parent
394577c3e4
commit
bbbf2d4015
139 changed files with 40452 additions and 2001 deletions
119
admin/roles/override.php
Executable file
119
admin/roles/override.php
Executable file
|
@ -0,0 +1,119 @@
|
|||
<?
|
||||
/* interface page for writing role overrides */
|
||||
|
||||
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()) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
||||
}
|
||||
|
||||
$stroverrides = get_string('roleoverries');
|
||||
/*
|
||||
if ($course && $course->id != SITEID) { // course header
|
||||
print_header("$course->shortname: $stroverrides",
|
||||
"$site->fullname",
|
||||
"<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $stroverrides");
|
||||
} else { // site header
|
||||
print_header("$site->shortname: $stroverrides",
|
||||
"$site->fullname",
|
||||
"$stroverrides");
|
||||
}
|
||||
*/
|
||||
$context = get_record('context', 'id', $contextid);
|
||||
$straction = get_string('editoverride');
|
||||
$currenttab = '';
|
||||
$tabsmode = 'override';
|
||||
include_once('tabs.php');
|
||||
/*************************
|
||||
* form processing here *
|
||||
*************************/
|
||||
if ($data = data_submitted()) {
|
||||
// add or update
|
||||
foreach ($data as $capname => $value) {
|
||||
// ignore contextid and roleid
|
||||
if ($capname == "contextid" || $capname == "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 ($value == 0) { // inherit = delete
|
||||
|
||||
delete_records('role_capabilities', 'roleid', $roleid, 'contextid', $contextid, 'capability', $capname);
|
||||
|
||||
} else {
|
||||
|
||||
$localoverride->permission = $value;
|
||||
$localoverride->timemodified = time();
|
||||
$localoverride->modifierid = $USER->id;
|
||||
update_record('role_capabilities', $localoverride);
|
||||
|
||||
}
|
||||
|
||||
} 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
* drop down for swapping between roles *
|
||||
*****************************************/
|
||||
|
||||
// this needs to check capability too
|
||||
$role = get_records('role');
|
||||
foreach ($role as $rolex) {
|
||||
$options[$rolex->id] = $rolex->name;
|
||||
}
|
||||
|
||||
print ('<form name="rolesform" action="override.php" method="post">');
|
||||
print ('<div align="center">Current Context: '.print_context_name($contextid).'<br/>');
|
||||
print ('<input type="hidden" name="contextid" value="'.$contextid.'">Select a Role: ');
|
||||
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);
|
||||
|
||||
// this is the available capabilities assignable in this context
|
||||
$capabilities = fetch_context_capabilities($contextid);
|
||||
|
||||
print_simple_box_start("center");
|
||||
|
||||
include_once('override.html');
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
}
|
||||
|
||||
print_footer($course);
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue