mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
partial rewrite of role manage script, improved notice_yesno(), other minor fixes and changes; I will work on assign and overide tomorrow ;-)
This commit is contained in:
parent
e78a3505c5
commit
b5959f3071
8 changed files with 413 additions and 133 deletions
|
@ -201,7 +201,7 @@
|
||||||
}
|
}
|
||||||
echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
|
echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
|
||||||
echo '<input type="hidden" name="contextid" value="'.$context->id.'" />'.$strroletoassign.': ';
|
echo '<input type="hidden" name="contextid" value="'.$context->id.'" />'.$strroletoassign.': ';
|
||||||
choose_from_menu ($assignableroles, 'roleid', $roleid, get_string('listallroles', 'role'), $script='rolesform.submit()');
|
choose_from_menu ($assignableroles, 'roleid', $roleid, get_string('listallroles', 'role').'...', $script='rolesform.submit()');
|
||||||
echo '</div></form>';
|
echo '</div></form>';
|
||||||
|
|
||||||
print_simple_box_start("center");
|
print_simple_box_start("center");
|
||||||
|
|
|
@ -1,25 +1,80 @@
|
||||||
<?php //$Id$
|
<?php //$Id$
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'add': $submitlabel = get_string('addrole', 'role'); break;
|
case 'add':
|
||||||
|
$submitlabel = get_string('addrole', 'role');
|
||||||
|
break;
|
||||||
|
case 'view':
|
||||||
|
$submitlabel = get_string('listallroles', 'role');
|
||||||
|
break;
|
||||||
case 'edit':
|
case 'edit':
|
||||||
default: $submitlabel = get_string('savechanges');
|
default:
|
||||||
|
$submitlabel = get_string('savechanges');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
<table cellpadding="9" cellspacing="0" >
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($action == 'view') { ?>
|
||||||
|
<tr valign="top">
|
||||||
|
<td align="right"><?php print_string('selectrole', 'role') ?>:</td>
|
||||||
|
<td><table><tr>
|
||||||
|
<td><form name="switchrole" action="manage.php" method="get">
|
||||||
|
<input type="hidden" name="action" value="view" />
|
||||||
|
<?php choose_from_menu ($roleoptions, 'roleid', $roleid, get_string('listallroles', 'role').'...', $script='switchrole.submit()') ?>
|
||||||
|
</form></td>
|
||||||
|
<td><form name="editrole" action="manage.php" method="get">
|
||||||
|
<input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
|
||||||
|
<input type="hidden" name="action" value="edit" />
|
||||||
|
<input type="submit" value="<?php print_string('edit') ?>" />
|
||||||
|
</form></td>
|
||||||
|
</tr></table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
<form name="rolesform" action="manage.php" method="post">
|
<form name="rolesform" action="manage.php" method="post">
|
||||||
<input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
|
<input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
|
||||||
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
|
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
|
||||||
<input type="hidden" name="action" value="<?php p($action) ?>" />
|
<input type="hidden" name="action" value="<?php if ($action != 'view') { echo p($action); } ?>" />
|
||||||
<input type="hidden" name="contextid" value="<?php p($contextid) ?>" />
|
|
||||||
|
<tr valign="top">
|
||||||
|
<td align="right"><?php print_string('name') ?>:</td>
|
||||||
|
<td><?php
|
||||||
|
if ($action == 'view') {
|
||||||
|
p($role->name);
|
||||||
|
} else {
|
||||||
|
echo '<input type="text" name="name" maxlength="254" size="50" value="'.s($role->name).'" />';
|
||||||
|
if (isset($errors["name"])) formerr($errors["name"]);
|
||||||
|
} ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr valign="top">
|
||||||
|
<td align="right"><?php print_string('shortname') ?>:</td>
|
||||||
|
<td><?php
|
||||||
|
if ($action == 'view') {
|
||||||
|
p($role->shortname);
|
||||||
|
} else {
|
||||||
|
echo '<input type="text" name="shortname" maxlength="20" size="15" value="'.s($role->shortname).'" />';
|
||||||
|
if (isset($errors["shortname"])) formerr($errors["shortname"]);
|
||||||
|
} ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr valign="top">
|
||||||
|
<td align="right"><?php print_string('description') ?>:</td>
|
||||||
|
<td><?php
|
||||||
|
if ($action == 'view') {
|
||||||
|
p($role->description);
|
||||||
|
$usehtmleditor = false;
|
||||||
|
} else {
|
||||||
|
print_textarea($usehtmleditor, 10, 50, 50, 10, 'description', $role->description);
|
||||||
|
} ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr valign="top">
|
||||||
|
<td align="right"><?php print_string('permissions','role') ?> :</td>
|
||||||
|
<td><table>
|
||||||
|
|
||||||
<br />
|
|
||||||
<?php print_string('rolename', 'role'); ?>: <input type="text" name="name" value="<?php p($role->name) ?>" />
|
|
||||||
<?php print_string('roleshortname', 'role'); ?>: <input type="text" name="shortname" value="<?php p($role->shortname) ?>" />
|
|
||||||
<br />
|
|
||||||
<?php print_string('roledescription', 'role'); ?>:
|
|
||||||
<?php print_textarea($usehtmleditor, 10, 50, 50, 10, 'description', $role->description); ?>
|
|
||||||
<p>
|
|
||||||
<table>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php print_string('capability','role') ?></td>
|
<td><?php print_string('capability','role') ?></td>
|
||||||
<td><?php print_string('inherit','role') ?></td>
|
<td><?php print_string('inherit','role') ?></td>
|
||||||
|
@ -46,19 +101,23 @@ foreach ($capabilities as $capability) {
|
||||||
$contextlevel = $capability->contextlevel;
|
$contextlevel = $capability->contextlevel;
|
||||||
$component = $capability->component;
|
$component = $capability->component;
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
// check the capability override for this cap, this role in this context
|
// check the capability override for this cap, this role in this context
|
||||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||||
|
|
||||||
$localoverride = get_local_override($roleid, $sitecontext->id, $capability->name);
|
$localoverride = get_local_override($roleid, $sitecontext->id, $capability->name);
|
||||||
|
} else {
|
||||||
|
$localoverride = new object();
|
||||||
|
$localoverride->permission = $role->{$capability->name};
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><span title="<?php echo $capability->name ?>"><?php echo get_capability_string($capability->name); ?></span></td>
|
<td><span title="<?php echo $capability->name ?>"><?php echo get_capability_string($capability->name); ?></span></td>
|
||||||
<td><input TYPE="radio" name="<?php echo $capability->name; ?>" value="0" <?php if (!isset($localoverride->permission) || $localoverride->permission==0){ echo 'checked="checked"'; }?> /></td>
|
<td><input type="radio" name="<?php echo $capability->name; ?>" value="<?php echo CAP_INHERIT ?>" <?php if (!isset($localoverride->permission) || $localoverride->permission==CAP_INHERIT){ echo 'checked="checked"'; }?> /></td>
|
||||||
<td><input TYPE="radio" name="<?php echo $capability->name; ?>" value="1" <?php if (isset($localoverride->permission) && $localoverride->permission==1){ echo 'checked="checked"'; }?> /></td>
|
<td><input type="radio" name="<?php echo $capability->name; ?>" value="<?php echo CAP_ALLOW ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_ALLOW){ echo 'checked="checked"'; }?> /></td>
|
||||||
<td ><input TYPE="radio" name="<?php echo $capability->name; ?>" value="-1" <?php if (isset($localoverride->permission) && $localoverride->permission==-1){ echo 'checked="checked"'; }?> /></td>
|
<td ><input type="radio" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PREVENT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PREVENT){ echo 'checked="checked"'; }?> /></td>
|
||||||
<td ><input TYPE="radio" name="<?php echo $capability->name; ?>" value="-1000" <?php if (isset($localoverride->permission) && $localoverride->permission==-1000){ echo 'checked="checked"'; }?> /></td>
|
<td ><input type="radio" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PROHIBIT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PROHIBIT){ echo 'checked="checked"'; }?> /></td>
|
||||||
<td><?php
|
<td><?php
|
||||||
if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
|
if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
|
||||||
echo "T";
|
echo "T";
|
||||||
|
@ -79,8 +138,15 @@ foreach ($capabilities as $capability) {
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
</table></td></tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td />
|
||||||
|
<td><input type="submit" value="<?php p($submitlabel) ?>" />
|
||||||
|
<?php if ($action != 'view') { ?>
|
||||||
|
<input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
|
||||||
|
<?php } ?>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</p>
|
|
||||||
<br />
|
|
||||||
<input type="submit" value="<?php p($submitlabel); ?>" />
|
|
||||||
</form>
|
|
||||||
|
|
|
@ -9,65 +9,143 @@
|
||||||
|
|
||||||
$roleid = optional_param('roleid', 0, PARAM_INT); // if set, we are editing a role
|
$roleid = optional_param('roleid', 0, PARAM_INT); // if set, we are editing a role
|
||||||
$name = optional_param('name', '', PARAM_MULTILANG); // new role name
|
$name = optional_param('name', '', PARAM_MULTILANG); // new role name
|
||||||
$shortname = optional_param('shortname', '', PARAM_SAFEDIR); // new role shortname
|
$shortname = optional_param('shortname', '', PARAM_RAW); // new role shortname, special cleaning before storage
|
||||||
$description = optional_param('description', '', PARAM_CLEAN); // new role desc
|
$description = optional_param('description', '', PARAM_CLEAN); // new role desc
|
||||||
$action = optional_param('action', '', PARAM_ALPHA);
|
$action = optional_param('action', '', PARAM_ALPHA);
|
||||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||||
|
$cancel = optional_param('cancel', 0, PARAM_BOOL);
|
||||||
|
|
||||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||||
|
|
||||||
$strmanageroles = get_string('manageroles');
|
if ($cancel) {
|
||||||
$strdelete = get_string('delete');
|
redirect('manage.php');
|
||||||
|
|
||||||
if ($roleid && $action!='delete') {
|
|
||||||
$role = get_record('role', 'id', $roleid);
|
|
||||||
$editingstr = '-> '.get_string('editinga', '', $role->name);
|
|
||||||
} else {
|
|
||||||
$editingstr ='';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
admin_externalpage_print_header($adminroot);
|
$errors = array();
|
||||||
|
$newrole = false;
|
||||||
|
|
||||||
$currenttab = 'manage';
|
$roles = get_records('role', '', '', 'sortorder ASC, id ASC');
|
||||||
include_once('managetabs.php');
|
$rolescount = count($roles);
|
||||||
|
|
||||||
// form processing, editing a role, adding a role or deleting a role
|
/// fix sort order if needed
|
||||||
if ($action && confirm_sesskey()) {
|
$rolesort = array();
|
||||||
|
$i = 0;
|
||||||
|
foreach ($roles as $rolex) {
|
||||||
|
$rolesort[] = $rolex->id;
|
||||||
|
if ($rolex->sortorder != $i) {
|
||||||
|
$r = new object();
|
||||||
|
$r->id = $rolex->id;
|
||||||
|
$r->sortorder = $i;
|
||||||
|
update_record('role', $r);
|
||||||
|
$roles[$rolex->id]->sortorder = $i;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// form processing, editing a role, adding a role, deleting a role etc.
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'add':
|
case 'add':
|
||||||
|
if ($data = data_submitted() and confirm_sesskey()) {
|
||||||
|
|
||||||
$newrole = create_role($name, $shortname, $description);
|
$shortname = moodle_strtolower(clean_param(clean_filename($shortname), PARAM_SAFEDIR)); // only lowercase safe ASCII characters
|
||||||
|
|
||||||
$ignore = array('roleid', 'sesskey', 'action', 'name', 'description', 'contextid');
|
if (empty($name)) {
|
||||||
|
$errors['name'] = get_string('errorbadrolename', 'role');
|
||||||
|
} else if (count_records('role', 'name', $name)) {
|
||||||
|
$errors['name'] = get_string('errorexistsrolename', 'role');
|
||||||
|
}
|
||||||
|
|
||||||
$data = data_submitted();
|
if (empty($shortname)) {
|
||||||
|
$errors['shortname'] = get_string('errorbadroleshortname', 'role');
|
||||||
|
} else if (count_records('role', 'shortname', $shortname)) {
|
||||||
|
$errors['shortname'] = get_string('errorexistsroleshortname', 'role');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
$newrole = create_role($name, $shortname, $description, '', $rolescount);
|
||||||
|
} else {
|
||||||
|
$newrole = new object();
|
||||||
|
$newrole->name = $name;
|
||||||
|
$newrole->shortname = $shortname;
|
||||||
|
$newrole->description = $description;
|
||||||
|
}
|
||||||
|
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
|
||||||
|
|
||||||
foreach ($data as $capname => $value) {
|
foreach ($data as $capname => $value) {
|
||||||
if (in_array($capname, $ignore)) {
|
if (!preg_match('|^[a-z_]+/[a-z_]+:[a-z_]+$|', $capname)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$value = (int)$value;
|
||||||
|
if (!in_array($value, $allowed_values)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
assign_capability($capname, $value, $newrole, $sitecontext->id);
|
assign_capability($capname, $value, $newrole, $sitecontext->id);
|
||||||
|
} else {
|
||||||
|
$newrole->$capname = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($errors)) {
|
||||||
|
redirect('manage.php');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'edit':
|
case 'edit':
|
||||||
|
if ($data = data_submitted() and confirm_sesskey()) {
|
||||||
|
|
||||||
$ignore = array('roleid', 'sesskey', 'action', 'name', 'description', 'contextid');
|
$shortname = moodle_strtolower(clean_param(clean_filename($shortname), PARAM_SAFEDIR)); // only lowercase safe ASCII characters
|
||||||
|
|
||||||
$data = data_submitted();
|
if (empty($name)) {
|
||||||
|
$errors['name'] = get_string('errorbadrolename', 'role');
|
||||||
|
} else {
|
||||||
|
if ($rs = get_records('role', 'name', $name)) {
|
||||||
|
unset($rs[$roleid]);
|
||||||
|
if (!empty($rs)) {
|
||||||
|
$errors['name'] = get_string('errorexistsrolename', 'role');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($shortname)) {
|
||||||
|
$errors['shortname'] = get_string('errorbadroleshortname', 'role');
|
||||||
|
} else {
|
||||||
|
if ($rs = get_records('role', 'shortname', $shortname)) {
|
||||||
|
unset($rs[$roleid]);
|
||||||
|
if (!empty($rs)) {
|
||||||
|
$errors['shortname'] = get_string('errorexistsroleshortname', 'role');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$newrole = new object();
|
||||||
|
$newrole->name = $name;
|
||||||
|
$newrole->shortname = $shortname;
|
||||||
|
$newrole->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
|
||||||
|
|
||||||
foreach ($data as $capname => $value) {
|
foreach ($data as $capname => $value) {
|
||||||
if (in_array($capname, $ignore)) {
|
if (!preg_match('|^[a-z_]+/[a-z_]+:[a-z_]+$|', $capname)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$value = (int)$value;
|
||||||
|
if (!in_array($value, $allowed_values)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$newrole->$capname = $value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// edit default caps
|
// edit default caps
|
||||||
$SQL = "select * from {$CFG->prefix}role_capabilities where
|
$SQL = "SELECT * FROM {$CFG->prefix}role_capabilities
|
||||||
roleid = $roleid and capability = '$capname' and contextid = $sitecontext->id";
|
WHERE roleid = $roleid AND capability = '$capname'
|
||||||
|
AND contextid = $sitecontext->id";
|
||||||
|
|
||||||
$localoverride = get_record_sql($SQL);
|
$localoverride = get_record_sql($SQL);
|
||||||
|
|
||||||
|
@ -88,6 +166,7 @@
|
||||||
|
|
||||||
// update normal role settings
|
// update normal role settings
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
$role->id = $roleid;
|
$role->id = $roleid;
|
||||||
$role->name = $name;
|
$role->name = $name;
|
||||||
$role->description = $description;
|
$role->description = $description;
|
||||||
|
@ -95,67 +174,153 @@
|
||||||
if (!update_record('role', $role)) {
|
if (!update_record('role', $role)) {
|
||||||
error('Could not update role!');
|
error('Could not update role!');
|
||||||
}
|
}
|
||||||
|
redirect('manage.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
if ($confirm) { // deletes a role
|
if ($confirm and data_submitted() and confirm_sesskey()) {
|
||||||
|
|
||||||
// check for depedencies XXX TODO
|
// first unssign all users
|
||||||
|
if (!role_unassign($roleid)) {
|
||||||
// delete all associated role-assignments? XXX TODO
|
error("Error while unassigning all users from role with ID $roleid!");
|
||||||
|
}
|
||||||
|
|
||||||
if (!delete_records('role', 'id', $roleid)) {
|
if (!delete_records('role', 'id', $roleid)) {
|
||||||
error('Could not delete role!');
|
error("Could not delete role with ID $roleid!");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else if (confirm_sesskey()){
|
||||||
echo ('<form action="manage.php" method="POST">');
|
// show confirmation
|
||||||
echo ('<input type="hidden" name="action" value="delete">');
|
admin_externalpage_print_header($adminroot);
|
||||||
echo ('<input type="hidden" name="roleid" value="'.$roleid.'">');
|
$optionsyes = new object();
|
||||||
echo ('<input type="hidden" name="sesskey" value="'.sesskey().'">');
|
$optionsyes->action = 'delete';
|
||||||
echo ('<input type="hidden" name="confirm" value="1">');
|
$optionsyes->roleid = $roleid;
|
||||||
notice_yesno(get_string('deleterolesure', 'role'),
|
$optionsyes->sesskey = sesskey();
|
||||||
'manage.php?action=delete&roleid='.$roleid.'&sesskey='.sesskey().'&confirm=1', 'manage.php');
|
$optionsyes->confirm = 1;
|
||||||
|
$a = new object();
|
||||||
|
$a->id = $roleid;
|
||||||
|
$a->name = $roles[$roleid]->name;
|
||||||
|
$a->shortname = $roles[$roleid]->shortname;
|
||||||
|
$a->count = (int)count_records('role_assignments', 'roleid', $roleid);
|
||||||
|
notice_yesno(get_string('deleterolesure', 'role', $a), 'manage.php', 'manage.php', $optionsyes, NULL, 'post', 'get');
|
||||||
admin_externalpage_print_footer($adminroot);
|
admin_externalpage_print_footer($adminroot);
|
||||||
exit;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redirect('manage.php');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/// add possible positioning switch here
|
case 'moveup':
|
||||||
|
if (array_key_exists($roleid, $roles) and confirm_sesskey()) {
|
||||||
|
$role = $roles[$roleid];
|
||||||
|
if ($role->sortorder > 0) {
|
||||||
|
$above = $roles[$rolesort[$role->sortorder - 1]];
|
||||||
|
$r = new object();
|
||||||
|
|
||||||
|
$r->id = $role->id;
|
||||||
|
$r->sortorder = $above->sortorder;
|
||||||
|
if (!update_record('role', $r)) {
|
||||||
|
$errors[] = "Can not update role with ID $r->id!";
|
||||||
|
}
|
||||||
|
|
||||||
|
$r->id = $above->id;
|
||||||
|
$r->sortorder = $role->sortorder;
|
||||||
|
if (!update_record('role', $r)) {
|
||||||
|
$errors[] = "Can not update role with ID $r->id!";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($errors)) {
|
||||||
|
$msg = '<p>';
|
||||||
|
foreach ($errors as $e) {
|
||||||
|
$msg .= $e.'<br />';
|
||||||
|
}
|
||||||
|
admin_externalpage_print_header($adminroot);
|
||||||
|
notify($msg);
|
||||||
|
print_continue('manage.php');
|
||||||
|
admin_externalpage_print_footer($adminroot);
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect('manage.php');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'movedown':
|
||||||
|
if (array_key_exists($roleid, $roles) and confirm_sesskey()) {
|
||||||
|
$role = $roles[$roleid];
|
||||||
|
if ($role->sortorder + 1 < $rolescount) {
|
||||||
|
$bellow = $roles[$rolesort[$role->sortorder + 1]];
|
||||||
|
$r = new object();
|
||||||
|
|
||||||
|
$r->id = $role->id;
|
||||||
|
$r->sortorder = $bellow->sortorder;
|
||||||
|
if (!update_record('role', $r)) {
|
||||||
|
$errors[] = "Can not update role with ID $r->id!";
|
||||||
|
}
|
||||||
|
|
||||||
|
$r->id = $bellow->id;
|
||||||
|
$r->sortorder = $role->sortorder;
|
||||||
|
if (!update_record('role', $r)) {
|
||||||
|
$errors[] = "Can not update role with ID $r->id!";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($errors)) {
|
||||||
|
$msg = '<p>';
|
||||||
|
foreach ($errors as $e) {
|
||||||
|
$msg .= $e.'<br />';
|
||||||
|
}
|
||||||
|
$msg .= '</p>';
|
||||||
|
admin_externalpage_print_header($adminroot);
|
||||||
|
notify($msg);
|
||||||
|
print_continue('manage.php');
|
||||||
|
admin_externalpage_print_footer($adminroot);
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect('manage.php');
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/// print UI now
|
||||||
|
|
||||||
$roles = get_records('role', '', '', 'sortorder ASC, id ASC');
|
admin_externalpage_print_header($adminroot);
|
||||||
|
|
||||||
if (($roleid && $action!='delete') || $action=='new') { // load the role if id is present
|
$currenttab = 'manage';
|
||||||
|
include_once('managetabs.php');
|
||||||
|
|
||||||
if ($roleid) {
|
if (($roleid and ($action == 'view' or $action == 'edit')) or $action == 'add') { // view or edit role details
|
||||||
$action='edit';
|
|
||||||
$role = get_record('role', 'id', $roleid);
|
if ($action == 'add') {
|
||||||
} else {
|
$roleid = 0;
|
||||||
$action='add';
|
if (empty($errors) or empty($newrole)) {
|
||||||
|
$role = new object();
|
||||||
$role->name='';
|
$role->name='';
|
||||||
$role->shortname='';
|
$role->shortname='';
|
||||||
$role->description='';
|
$role->description='';
|
||||||
|
} else {
|
||||||
|
$role = stripslashes_safe($newrole);
|
||||||
|
}
|
||||||
|
} else if ($action == 'edit' and !empty($errors) and !empty($newrole)) {
|
||||||
|
$role = stripslashes_safe($newrole);
|
||||||
|
} else {
|
||||||
|
if(!$role = get_record('role', 'id', $roleid)) {
|
||||||
|
error('Incorrect role ID!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($roles as $rolex) {
|
foreach ($roles as $rolex) {
|
||||||
$roleoptions[$rolex->id] = format_string($rolex->name);
|
$roleoptions[$rolex->id] = format_string($rolex->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// prints a form to swap roles
|
|
||||||
print ('<form name="rolesform1" action="manage.php" method="post">');
|
|
||||||
print ('<div align="center">'.get_string('selectrole', 'role').': ');
|
|
||||||
choose_from_menu ($roleoptions, 'roleid', $roleid, get_string('listallroles', 'role'), $script='rolesform1.submit()');
|
|
||||||
print ('</div></form>');
|
|
||||||
|
|
||||||
// this is the array holding capabilities of this role sorted till this context
|
// this is the array holding capabilities of this role sorted till this context
|
||||||
$r_caps = role_context_capabilities($roleid, $sitecontext);
|
$r_caps = role_context_capabilities($roleid, $sitecontext);
|
||||||
|
|
||||||
|
@ -163,7 +328,19 @@
|
||||||
$capabilities = fetch_context_capabilities($sitecontext);
|
$capabilities = fetch_context_capabilities($sitecontext);
|
||||||
|
|
||||||
$usehtmleditor = can_use_html_editor();
|
$usehtmleditor = can_use_html_editor();
|
||||||
print_simple_box_start();
|
|
||||||
|
switch ($action) {
|
||||||
|
case 'add':
|
||||||
|
print_heading(get_string('addrole', 'role'));
|
||||||
|
break;
|
||||||
|
case 'view':
|
||||||
|
print_heading(get_string('viewrole', 'role'));
|
||||||
|
break;
|
||||||
|
case 'edit':
|
||||||
|
print_heading(get_string('editrole', 'role'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
print_simple_box_start('center');
|
||||||
include_once('manage.html');
|
include_once('manage.html');
|
||||||
print_simple_box_end();
|
print_simple_box_end();
|
||||||
|
|
||||||
|
@ -176,15 +353,17 @@
|
||||||
$table = new object;
|
$table = new object;
|
||||||
|
|
||||||
$table->tablealign = 'center';
|
$table->tablealign = 'center';
|
||||||
$table->align = array('right', 'left', 'left');
|
$table->align = array('right', 'left', 'middle');
|
||||||
$table->wrap = array('nowrap', '', 'nowrap');
|
$table->wrap = array('nowrap', '', 'nowrap');
|
||||||
$table->cellpadding = 5;
|
$table->cellpadding = 5;
|
||||||
$table->cellspacing = 0;
|
$table->cellspacing = 0;
|
||||||
$table->width = '90%';
|
$table->width = '90%';
|
||||||
|
$table->data = array();
|
||||||
|
|
||||||
$table->head = array(get_string('roles', 'role'),
|
$table->head = array(get_string('name'),
|
||||||
get_string('description'),
|
get_string('description'),
|
||||||
get_string('delete'));
|
get_string('shortname'),
|
||||||
|
get_string('edit'));
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
* List all current roles *
|
* List all current roles *
|
||||||
|
@ -192,15 +371,40 @@
|
||||||
|
|
||||||
foreach ($roles as $role) {
|
foreach ($roles as $role) {
|
||||||
|
|
||||||
$table->data[] = array('<a href="manage.php?roleid='.$role->id.'&sesskey='.sesskey().'">'.format_string($role->name).'</a>', format_text($role->description, FORMAT_HTML), '<a href="manage.php?action=delete&roleid='.$role->id.'&sesskey='.sesskey().'">'.$strdelete.'</a>');
|
$stredit = get_string('edit');
|
||||||
|
$strdelete = get_string('delete');
|
||||||
|
$strmoveup = get_string('moveup');
|
||||||
|
$strmovedown = get_string('movedown');
|
||||||
|
|
||||||
|
$row = array();
|
||||||
|
$row[0] = '<a href="manage.php?roleid='.$role->id.'&action=view">'.format_string($role->name).'</a>';
|
||||||
|
$row[1] = format_text($role->description, FORMAT_HTML);
|
||||||
|
$row[2] = s($role->shortname);
|
||||||
|
$row[3] = '<a title="'.$stredit.'" href="manage.php?action=edit&roleid='.$role->id.'">'.
|
||||||
|
'<img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.$stredit.'" /></a> ';
|
||||||
|
$row[3] .= '<a title="'.$strdelete.'" href="manage.php?action=delete&roleid='.$role->id.'&sesskey='.sesskey().'">'.
|
||||||
|
'<img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" alt="'.$strdelete.'" /></a> ';
|
||||||
|
if ($role->sortorder != 0) {
|
||||||
|
$row[3] .= '<a title="'.$strmoveup.'" href="manage.php?action=moveup&roleid='.$role->id.'&sesskey='.sesskey().'">'.
|
||||||
|
'<img src="'.$CFG->pixpath.'/t/up.gif" height="11" width="11" border="0" alt="'.$strmoveup.'" /></a> ';
|
||||||
|
} else {
|
||||||
|
$row[3] .= '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" height="11" width="11" border="0" alt="" /> ';
|
||||||
|
}
|
||||||
|
if ($role->sortorder+1 < $rolescount) {
|
||||||
|
$row[3] .= '<a title="'.$strmovedown.'" href="manage.php?action=movedown&roleid='.$role->id.'&sesskey='.sesskey().'">'.
|
||||||
|
'<img src="'.$CFG->pixpath.'/t/down.gif" height="11" width="11" border="0" alt="'.$strmovedown.'" /></a> ';
|
||||||
|
} else {
|
||||||
|
$row[3] .= '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" height="11" width="11" border="0" alt="" /> ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->data[] = $row;
|
||||||
|
|
||||||
}
|
}
|
||||||
print_table($table);
|
print_table($table);
|
||||||
|
|
||||||
$options = new object;
|
$options = new object();
|
||||||
$options->sesskey = sesskey();
|
$options->action = 'add';
|
||||||
$options->action = 'new';
|
print_single_button('manage.php', $options, get_string('addrole', 'role'), 'get');
|
||||||
print_single_button('manage.php', $options, get_string('addrole', 'role'), 'POST');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
admin_externalpage_print_footer($adminroot);
|
admin_externalpage_print_footer($adminroot);
|
||||||
|
|
|
@ -130,7 +130,7 @@
|
||||||
echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
|
echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
|
||||||
}
|
}
|
||||||
echo '<input type="hidden" name="contextid" value="'.$context->id.'" />'.$strroletooverride.': ';
|
echo '<input type="hidden" name="contextid" value="'.$context->id.'" />'.$strroletooverride.': ';
|
||||||
choose_from_menu ($overridableroles, 'roleid', $roleid, get_string('listallroles', 'role'), $script='rolesform.submit()');
|
choose_from_menu ($overridableroles, 'roleid', $roleid, get_string('listallroles', 'role').'...', $script='rolesform.submit()');
|
||||||
echo '</div></form>';
|
echo '</div></form>';
|
||||||
|
|
||||||
$parentcontexts = get_parent_contexts($context);
|
$parentcontexts = get_parent_contexts($context);
|
||||||
|
|
|
@ -11,9 +11,15 @@ $string['capabilities'] = 'Capabilities';
|
||||||
$string['currentrole'] = 'Current role';
|
$string['currentrole'] = 'Current role';
|
||||||
$string['currentcontext'] = 'Current context';
|
$string['currentcontext'] = 'Current context';
|
||||||
$string['defineroles'] = 'Define roles';
|
$string['defineroles'] = 'Define roles';
|
||||||
|
$string['deleterolesure'] = '<p>Are you sure, that you want to delete role \"$a->name ($a->shortname)\"?</p><p>Currently this role is assigned to $a->count users.</p>';
|
||||||
|
$string['editrole'] = 'Edit role';
|
||||||
|
$string['errorbadrolename'] = 'Incorrect role name';
|
||||||
|
$string['errorexistsrolename'] = 'Role name already exists';
|
||||||
|
$string['errorbadroleshortname'] = 'Incorrect role name';
|
||||||
|
$string['errorexistsroleshortname'] = 'Role name already exists';
|
||||||
$string['existingusers'] = '$a existing users';
|
$string['existingusers'] = '$a existing users';
|
||||||
$string['inherit'] = 'Inherit';
|
$string['inherit'] = 'Inherit';
|
||||||
$string['listallroles'] = 'List all roles...';
|
$string['listallroles'] = 'List all roles';
|
||||||
$string['manageroles'] = 'Manage roles';
|
$string['manageroles'] = 'Manage roles';
|
||||||
$string['metaassignerror'] = 'Can not assign this role to user \"$a\" because Manage metacourse capability is needed.';
|
$string['metaassignerror'] = 'Can not assign this role to user \"$a\" because Manage metacourse capability is needed.';
|
||||||
$string['metaunassignerror'] = 'Role of user \"$a\" was automatically reassigned, please unassign the role in child courses instead.';
|
$string['metaunassignerror'] = 'Role of user \"$a\" was automatically reassigned, please unassign the role in child courses instead.';
|
||||||
|
@ -26,13 +32,11 @@ $string['prevent'] = 'Prevent';
|
||||||
$string['prohibit'] = 'Prohibit';
|
$string['prohibit'] = 'Prohibit';
|
||||||
$string['risks'] = 'Risks';
|
$string['risks'] = 'Risks';
|
||||||
$string['roleassignments'] = 'Role assignments';
|
$string['roleassignments'] = 'Role assignments';
|
||||||
$string['roledescription'] = 'Role description';
|
|
||||||
$string['rolename'] = 'Role name';
|
|
||||||
$string['roleshortname'] = 'Role short name (ASCII)';
|
|
||||||
$string['roletoassign'] = 'Role to assign';
|
$string['roletoassign'] = 'Role to assign';
|
||||||
$string['roletooverride'] = 'Role to override';
|
$string['roletooverride'] = 'Role to override';
|
||||||
$string['roles'] = 'Roles';
|
$string['roles'] = 'Roles';
|
||||||
$string['selectrole'] = 'Select a role';
|
$string['selectrole'] = 'Select a role';
|
||||||
|
$string['viewrole'] = 'View role details';
|
||||||
|
|
||||||
$string['site:doanything'] = 'Allowed to do everything';
|
$string['site:doanything'] = 'Allowed to do everything';
|
||||||
$string['legacy:guest'] = 'LEGACY ROLE: Guest';
|
$string['legacy:guest'] = 'LEGACY ROLE: Guest';
|
||||||
|
|
|
@ -1188,7 +1188,7 @@ function get_local_override($roleid, $contextid, $capability) {
|
||||||
* @param legacy - optional legacy capability
|
* @param legacy - optional legacy capability
|
||||||
* @return id or false
|
* @return id or false
|
||||||
*/
|
*/
|
||||||
function create_role($name, $shortname, $description, $legacy='') {
|
function create_role($name, $shortname, $description, $legacy='', $sortorder = -1) {
|
||||||
|
|
||||||
// check for duplicate role name
|
// check for duplicate role name
|
||||||
|
|
||||||
|
@ -1200,10 +1200,17 @@ function create_role($name, $shortname, $description, $legacy='') {
|
||||||
error('there is already a role with this shortname!');
|
error('there is already a role with this shortname!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$role = new object();
|
||||||
$role->name = $name;
|
$role->name = $name;
|
||||||
$role->shortname = $shortname;
|
$role->shortname = $shortname;
|
||||||
$role->description = $description;
|
$role->description = $description;
|
||||||
|
|
||||||
|
if ($sortorder = -1) {
|
||||||
|
$role->sortorder = count_records('role');
|
||||||
|
} else {
|
||||||
|
$role->sortorder = $sortorder;
|
||||||
|
}
|
||||||
|
|
||||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||||
|
|
||||||
if ($id = insert_record('role', $role)) {
|
if ($id = insert_record('role', $role)) {
|
||||||
|
|
|
@ -381,7 +381,6 @@ function upgrade_activity_modules($return) {
|
||||||
|
|
||||||
if ($updated_modules) {
|
if ($updated_modules) {
|
||||||
print_continue($return);
|
print_continue($return);
|
||||||
print_footer();
|
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4600,7 +4600,7 @@ function notice ($message, $link='') {
|
||||||
* @param string $linkyes The link to take the user to if they choose "Yes"
|
* @param string $linkyes The link to take the user to if they choose "Yes"
|
||||||
* @param string $linkno The link to take the user to if they choose "No"
|
* @param string $linkno The link to take the user to if they choose "No"
|
||||||
*/
|
*/
|
||||||
function notice_yesno ($message, $linkyes, $linkno) {
|
function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
|
||||||
|
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
|
@ -4611,9 +4611,9 @@ function notice_yesno ($message, $linkyes, $linkno) {
|
||||||
print_simple_box_start('center', '60%', '', 5, 'generalbox', 'notice');
|
print_simple_box_start('center', '60%', '', 5, 'generalbox', 'notice');
|
||||||
echo '<p align="center">'. $message .'</p>';
|
echo '<p align="center">'. $message .'</p>';
|
||||||
echo '<table align="center" cellpadding="20"><tr><td>';
|
echo '<table align="center" cellpadding="20"><tr><td>';
|
||||||
print_single_button($linkyes, NULL, get_string('yes'), 'post', $CFG->framename);
|
print_single_button($linkyes, $optionsyes, get_string('yes'), $methodyes, $CFG->framename);
|
||||||
echo '</td><td>';
|
echo '</td><td>';
|
||||||
print_single_button($linkno, NULL, get_string('no'), 'post', $CFG->framename);
|
print_single_button($linkno, $optionsno, get_string('no'), $methodno, $CFG->framename);
|
||||||
echo '</td></tr></table>';
|
echo '</td></tr></table>';
|
||||||
print_simple_box_end();
|
print_simple_box_end();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue