2006-08-08 05:13:06 +00:00
|
|
|
<?php //$Id$
|
|
|
|
///dummy field names are used to help adding and dropping indexes. There's only 1 case now, in scorm_scoes_track
|
|
|
|
//testing
|
|
|
|
require_once('../../config.php');
|
|
|
|
|
2006-09-02 13:14:57 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
|
|
|
$adminroot = admin_get_root();
|
|
|
|
admin_externalpage_setup('manageroles', $adminroot);
|
2006-08-18 07:25:17 +00:00
|
|
|
// require_login();
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-13 09:29:33 +00:00
|
|
|
$roleid = optional_param('roleid', 0, PARAM_INT); // if set, we are editing a role
|
2006-08-09 13:18:33 +00:00
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
$name = optional_param('name', '', PARAM_ALPHA); // new role name
|
|
|
|
$description = optional_param('description', '', PARAM_NOTAGS); // new role desc
|
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
$stradministration = get_string('administration');
|
|
|
|
$strmanageroles = get_string('manageroles');
|
2006-08-08 08:31:21 +00:00
|
|
|
|
|
|
|
if ($roleid && $action!='delete') {
|
2006-08-09 13:18:33 +00:00
|
|
|
$role = get_record('role', 'id', $roleid);
|
2006-08-08 08:31:21 +00:00
|
|
|
|
2006-08-13 09:29:33 +00:00
|
|
|
$editingstr = '-> '.get_string('editinga', '', $role->name);
|
2006-08-08 08:31:21 +00:00
|
|
|
} else {
|
2006-08-13 09:29:33 +00:00
|
|
|
$editingstr ='';
|
2006-08-08 08:31:21 +00:00
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_header($adminroot);
|
2006-08-18 07:25:17 +00:00
|
|
|
// print_header("$site->shortname: $strmanageroles",
|
|
|
|
// "$site->fullname",
|
|
|
|
// "<a href=\"../index.php\">$stradministration</a> -> <a href=\"manage.php\">$strmanageroles</a>
|
|
|
|
// $editingstr
|
|
|
|
// ");
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-18 08:01:16 +00:00
|
|
|
$currenttab = 'manage';
|
|
|
|
include_once('managetabs.php');
|
|
|
|
|
2006-08-13 09:29:33 +00:00
|
|
|
// form processing, editing a role, adding a role or deleting a role
|
2006-08-09 13:18:33 +00:00
|
|
|
if ($action && confirm_sesskey()) {
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'add':
|
|
|
|
|
|
|
|
$newrole = create_role($name, $description);
|
2006-08-14 05:55:40 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
$ignore = array('roleid', 'sesskey', 'action', 'name', 'description', 'contextid');
|
2006-08-14 05:55:40 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
$data = data_submitted();
|
2006-08-14 05:55:40 +00:00
|
|
|
|
|
|
|
foreach ($data as $capname => $value) {
|
|
|
|
if (in_array($capname, $ignore)) {
|
|
|
|
continue;
|
2006-08-09 13:18:33 +00:00
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
assign_capability($capname, $value, $newrole, $sitecontext->id);
|
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit':
|
|
|
|
|
|
|
|
$ignore = array('roleid', 'sesskey', 'action', 'name', 'description', 'contextid');
|
|
|
|
|
|
|
|
$data = data_submitted();
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
foreach ($data as $capname => $value) {
|
|
|
|
if (in_array($capname, $ignore)) {
|
|
|
|
continue;
|
2006-08-09 13:18:33 +00:00
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
// edit default caps
|
|
|
|
$SQL = "select * from {$CFG->prefix}role_capabilities where
|
2006-08-14 05:55:40 +00:00
|
|
|
roleid = $roleid and capability = '$capname' and contextid = $sitecontext->id";
|
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
$localoverride = get_record_sql($SQL);
|
2006-08-14 05:55:40 +00:00
|
|
|
|
|
|
|
if ($localoverride) { // update current overrides
|
|
|
|
|
|
|
|
if ($value == 0) { // inherit = delete
|
|
|
|
|
|
|
|
unassign_capability($capname, $roleid, $sitecontext->id);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$localoverride->permission = $value;
|
|
|
|
$localoverride->timemodified = time();
|
|
|
|
$localoverride->modifierid = $USER->id;
|
|
|
|
update_record('role_capabilities', $localoverride);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
} else { // insert a record
|
2006-08-14 05:55:40 +00:00
|
|
|
|
|
|
|
assign_capability($capname, $value, $roleid, $sitecontext->id);
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update normal role settings
|
|
|
|
|
|
|
|
$role->id = $roleid;
|
|
|
|
$role->name = $name;
|
|
|
|
$role->description = $description;
|
|
|
|
|
|
|
|
update_record('role', $role);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
if ($confirm) { // deletes a role
|
|
|
|
echo ('deleting...');
|
|
|
|
|
|
|
|
// check for depedencies
|
|
|
|
|
|
|
|
// delete all associated role-assignments?
|
|
|
|
delete_records('role', 'id', $roleid);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
echo ('<form action="manage.php" method="POST">');
|
|
|
|
echo ('<input type="hidden" name="action" value="delete">');
|
|
|
|
echo ('<input type="hidden" name="roleid" value="'.$roleid.'">');
|
|
|
|
echo ('<input type="hidden" name="sesskey" value="'.sesskey().'">');
|
|
|
|
echo ('<input type="hidden" name="confirm" value="1">');
|
|
|
|
echo ('are you sure?');
|
|
|
|
echo ('<input type="submit" value="yes">');
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_footer($adminroot);
|
2006-08-18 07:25:17 +00:00
|
|
|
// print_footer($course);
|
2006-08-09 13:18:33 +00:00
|
|
|
exit;
|
|
|
|
|
|
|
|
// prints confirmation form
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/// add possible positioning switch here
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
$roles = get_records('role');
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
if (($roleid && $action!='delete') || $action=='new') { // load the role if id is present
|
|
|
|
|
|
|
|
if ($roleid) {
|
|
|
|
$action='edit';
|
|
|
|
$role = get_record('role', 'id', $roleid);
|
|
|
|
} else {
|
|
|
|
$action='add';
|
|
|
|
$role->name='';
|
|
|
|
$role->description='';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($roles as $rolex) {
|
2006-08-23 08:11:43 +00:00
|
|
|
$roleoptions[$rolex->id] = $rolex->name;
|
2006-08-09 13:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prints a form to swap roles
|
|
|
|
print ('<form name="rolesform1" action="manage.php" method="post">');
|
|
|
|
print ('<div align="center">Select a Role: ');
|
2006-08-23 08:11:43 +00:00
|
|
|
choose_from_menu ($roleoptions, 'roleid', $roleid, 'choose', $script='rolesform1.submit()');
|
2006-08-09 13:18:33 +00:00
|
|
|
print ('</div></form>');
|
|
|
|
|
|
|
|
// this is the array holding capabilities of this role sorted till this context
|
2006-08-14 05:55:40 +00:00
|
|
|
$r_caps = role_context_capabilities($roleid, $sitecontext);
|
2006-08-09 13:18:33 +00:00
|
|
|
|
|
|
|
// this is the available capabilities assignable in this context
|
2006-08-14 05:55:40 +00:00
|
|
|
$capabilities = fetch_context_capabilities($sitecontext);
|
2006-08-09 13:18:33 +00:00
|
|
|
|
|
|
|
print_simple_box_start();
|
|
|
|
include_once('manage.html');
|
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$table->tablealign = "center";
|
|
|
|
$table->align = array ("middle", "left");
|
|
|
|
$table->wrap = array ("nowrap", "nowrap");
|
|
|
|
$table->cellpadding = 5;
|
|
|
|
$table->cellspacing = 0;
|
|
|
|
$table->width = '40%';
|
|
|
|
/*************************
|
|
|
|
* List all current roles *
|
|
|
|
**************************/
|
|
|
|
|
|
|
|
$table->data[] = array('roles', 'description', 'delete');
|
|
|
|
foreach ($roles as $role) {
|
|
|
|
|
|
|
|
$table->data[] = array('<a href="manage.php?roleid='.$role->id.'&sesskey='.sesskey().'">'.$role->name.'</a>', $role->description, '<a href="manage.php?action=delete&roleid='.$role->id.'&sesskey='.sesskey().'">delete</a>');
|
|
|
|
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
|
|
|
|
echo ('<form action="manage.php" method="POST">');
|
|
|
|
echo ('<input type="hidden" name="sesskey" value="'.sesskey().'">');
|
|
|
|
echo ('<input type="hidden" name="action" value="new">');
|
|
|
|
echo ('<input type="submit" value="add new role">');
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-09 13:18:33 +00:00
|
|
|
use_html_editor("description");
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_footer($adminroot);
|
2006-08-18 07:25:17 +00:00
|
|
|
// print_footer($course);
|
2006-08-08 05:13:06 +00:00
|
|
|
?>
|