mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-40337 cleanup role manage UI
This commit is contained in:
parent
bb061951a0
commit
06a0a2955e
@ -22,7 +22,6 @@
|
||||
* delete - delete a role (with are-you-sure)
|
||||
* moveup - change the sort order
|
||||
* movedown - change the sort order
|
||||
* reset - set a role's permissions back to the default for that legacy role type.
|
||||
*
|
||||
* For all but the first two of those, you also need a roleid parameter, and
|
||||
* possibly some other data.
|
||||
@ -32,187 +31,187 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
|
||||
require_once(dirname(__FILE__) . '/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
if ($action) {
|
||||
$roleid = required_param('roleid', PARAM_INT);
|
||||
}
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
if ($action) {
|
||||
$roleid = required_param('roleid', PARAM_INT);
|
||||
} else {
|
||||
$roleid = 0;
|
||||
}
|
||||
|
||||
/// Get the base URL for this and related pages into a convenient variable.
|
||||
$baseurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/manage.php';
|
||||
$defineurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/define.php';
|
||||
// Get the base URL for this and related pages into a convenient variable.
|
||||
$baseurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/manage.php';
|
||||
$defineurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/define.php';
|
||||
|
||||
/// Check access permissions.
|
||||
$systemcontext = context_system::instance();
|
||||
require_login();
|
||||
require_capability('moodle/role:manage', $systemcontext);
|
||||
admin_externalpage_setup('defineroles');
|
||||
// Check access permissions.
|
||||
$systemcontext = context_system::instance();
|
||||
require_login();
|
||||
require_capability('moodle/role:manage', $systemcontext);
|
||||
admin_externalpage_setup('defineroles');
|
||||
|
||||
/// Get some basic data we are going to need.
|
||||
$roles = role_fix_names(get_all_roles(), $systemcontext, ROLENAME_ORIGINAL);
|
||||
// Get some basic data we are going to need.
|
||||
$roles = role_fix_names(get_all_roles(), $systemcontext, ROLENAME_ORIGINAL);
|
||||
|
||||
$undeletableroles = array();
|
||||
$undeletableroles[$CFG->notloggedinroleid] = 1;
|
||||
$undeletableroles[$CFG->guestroleid] = 1;
|
||||
$undeletableroles[$CFG->defaultuserroleid] = 1;
|
||||
$undeletableroles = array();
|
||||
$undeletableroles[$CFG->notloggedinroleid] = 1;
|
||||
$undeletableroles[$CFG->guestroleid] = 1;
|
||||
$undeletableroles[$CFG->defaultuserroleid] = 1;
|
||||
|
||||
///.Process submitted data.
|
||||
$confirmed = optional_param('confirm', false, PARAM_BOOL) && data_submitted() && confirm_sesskey();
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
if (isset($undeletableroles[$roleid])) {
|
||||
print_error('cannotdeletethisrole', '', $baseurl);
|
||||
}
|
||||
if (!$confirmed) {
|
||||
// show confirmation
|
||||
echo $OUTPUT->header();
|
||||
$optionsyes = array('action'=>'delete', 'roleid'=>$roleid, 'sesskey'=>sesskey(), 'confirm'=>1);
|
||||
$a = new stdClass();
|
||||
$a->id = $roleid;
|
||||
$a->name = $roles[$roleid]->name;
|
||||
$a->shortname = $roles[$roleid]->shortname;
|
||||
$a->count = $DB->count_records('role_assignments', array('roleid'=>$roleid));
|
||||
// Process submitted data.
|
||||
$confirmed = (optional_param('confirm', false, PARAM_BOOL) && data_submitted() && confirm_sesskey());
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
if (isset($undeletableroles[$roleid])) {
|
||||
print_error('cannotdeletethisrole', '', $baseurl);
|
||||
}
|
||||
if (!$confirmed) {
|
||||
// Show confirmation.
|
||||
echo $OUTPUT->header();
|
||||
$optionsyes = array('action'=>'delete', 'roleid'=>$roleid, 'sesskey'=>sesskey(), 'confirm'=>1);
|
||||
$a = new stdClass();
|
||||
$a->id = $roleid;
|
||||
$a->name = $roles[$roleid]->name;
|
||||
$a->shortname = $roles[$roleid]->shortname;
|
||||
$a->count = $DB->count_records('role_assignments', array('roleid'=>$roleid));
|
||||
|
||||
$formcontinue = new single_button(new moodle_url($baseurl, $optionsyes), get_string('yes'));
|
||||
$formcancel = new single_button(new moodle_url($baseurl), get_string('no'), 'get');
|
||||
echo $OUTPUT->confirm(get_string('deleterolesure', 'role', $a), $formcontinue, $formcancel);
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
}
|
||||
if (!delete_role($roleid)) {
|
||||
// The delete failed, but mark the context dirty in case.
|
||||
mark_context_dirty($systemcontext->path);
|
||||
print_error('cannotdeleterolewithid', 'error', $baseurl, $roleid);
|
||||
}
|
||||
// Deleted a role sitewide...
|
||||
mark_context_dirty($systemcontext->path);
|
||||
add_to_log(SITEID, 'role', 'delete', 'admin/roles/manage.php', $roles[$roleid]->localname, '', $USER->id);
|
||||
redirect($baseurl);
|
||||
break;
|
||||
$formcontinue = new single_button(new moodle_url($baseurl, $optionsyes), get_string('yes'));
|
||||
$formcancel = new single_button(new moodle_url($baseurl), get_string('no'), 'get');
|
||||
echo $OUTPUT->confirm(get_string('deleterolesure', 'core_role', $a), $formcontinue, $formcancel);
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
}
|
||||
if (!delete_role($roleid)) {
|
||||
// The delete failed, but mark the context dirty in case.
|
||||
$systemcontext->mark_dirty();
|
||||
print_error('cannotdeleterolewithid', 'error', $baseurl, $roleid);
|
||||
}
|
||||
// Deleted a role sitewide...
|
||||
$systemcontext->mark_dirty();
|
||||
add_to_log(SITEID, 'role', 'delete', 'admin/roles/manage.php', $roles[$roleid]->localname, '', $USER->id);
|
||||
redirect($baseurl);
|
||||
break;
|
||||
|
||||
case 'moveup':
|
||||
if (confirm_sesskey()) {
|
||||
$prevrole = null;
|
||||
$thisrole = null;
|
||||
foreach ($roles as $role) {
|
||||
if ($role->id == $roleid) {
|
||||
$thisrole = $role;
|
||||
break;
|
||||
} else {
|
||||
$prevrole = $role;
|
||||
}
|
||||
}
|
||||
if (is_null($thisrole) || is_null($prevrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
}
|
||||
if (!switch_roles($thisrole, $prevrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
case 'moveup':
|
||||
if (confirm_sesskey()) {
|
||||
$prevrole = null;
|
||||
$thisrole = null;
|
||||
foreach ($roles as $role) {
|
||||
if ($role->id == $roleid) {
|
||||
$thisrole = $role;
|
||||
break;
|
||||
} else {
|
||||
$prevrole = $role;
|
||||
}
|
||||
}
|
||||
if (is_null($thisrole) || is_null($prevrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
}
|
||||
if (!switch_roles($thisrole, $prevrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
}
|
||||
}
|
||||
|
||||
redirect($baseurl);
|
||||
break;
|
||||
redirect($baseurl);
|
||||
break;
|
||||
|
||||
case 'movedown':
|
||||
if (confirm_sesskey()) {
|
||||
$thisrole = null;
|
||||
$nextrole = null;
|
||||
foreach ($roles as $role) {
|
||||
if ($role->id == $roleid) {
|
||||
$thisrole = $role;
|
||||
} else if (!is_null($thisrole)) {
|
||||
$nextrole = $role;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_null($nextrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
}
|
||||
if (!switch_roles($thisrole, $nextrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
case 'movedown':
|
||||
if (confirm_sesskey()) {
|
||||
$thisrole = null;
|
||||
$nextrole = null;
|
||||
foreach ($roles as $role) {
|
||||
if ($role->id == $roleid) {
|
||||
$thisrole = $role;
|
||||
} else if (!is_null($thisrole)) {
|
||||
$nextrole = $role;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_null($nextrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
}
|
||||
if (!switch_roles($thisrole, $nextrole)) {
|
||||
print_error('cannotmoverolewithid', 'error', '', $roleid);
|
||||
}
|
||||
}
|
||||
|
||||
redirect($baseurl);
|
||||
break;
|
||||
redirect($baseurl);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// Print the page header and tabs.
|
||||
echo $OUTPUT->header();
|
||||
// Print the page header and tabs.
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$currenttab = 'manage';
|
||||
include_once('managetabs.php');
|
||||
$currenttab = 'manage';
|
||||
require('managetabs.php');
|
||||
|
||||
/// Initialise table.
|
||||
$table = new html_table();
|
||||
$table->colclasses = array('leftalign', 'leftalign', 'leftalign', 'leftalign');
|
||||
$table->id = 'roles';
|
||||
$table->attributes['class'] = 'admintable generaltable';
|
||||
$table->head = array(
|
||||
get_string('role') . ' ' . $OUTPUT->help_icon('roles', 'role'),
|
||||
get_string('description'),
|
||||
get_string('roleshortname', 'role'),
|
||||
get_string('edit')
|
||||
// Initialise table.
|
||||
$table = new html_table();
|
||||
$table->colclasses = array('leftalign', 'leftalign', 'leftalign', 'leftalign');
|
||||
$table->id = 'roles';
|
||||
$table->attributes['class'] = 'admintable generaltable';
|
||||
$table->head = array(
|
||||
get_string('role') . ' ' . $OUTPUT->help_icon('roles', 'core_role'),
|
||||
get_string('description'),
|
||||
get_string('roleshortname', 'core_role'),
|
||||
get_string('edit')
|
||||
);
|
||||
|
||||
// Get some strings outside the loop.
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
$strmoveup = get_string('moveup');
|
||||
$strmovedown = get_string('movedown');
|
||||
|
||||
// Print a list of roles with edit/copy/delete/reorder icons.
|
||||
$table->data = array();
|
||||
$firstrole = reset($roles);
|
||||
$lastrole = end($roles);
|
||||
foreach ($roles as $role) {
|
||||
// Basic data.
|
||||
$row = array(
|
||||
'<a href="' . $defineurl . '?action=view&roleid=' . $role->id . '">' . $role->localname . '</a>',
|
||||
role_get_description($role),
|
||||
s($role->shortname),
|
||||
'',
|
||||
);
|
||||
|
||||
/// Get some strings outside the loop.
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
$strmoveup = get_string('moveup');
|
||||
$strmovedown = get_string('movedown');
|
||||
|
||||
/// Print a list of roles with edit/copy/delete/reorder icons.
|
||||
$table->data = array();
|
||||
$firstrole = reset($roles);
|
||||
$lastrole = end($roles);
|
||||
foreach ($roles as $role) {
|
||||
|
||||
/// Basic data.
|
||||
$row = array(
|
||||
'<a href="' . $defineurl . '?action=view&roleid=' . $role->id . '">' . $role->localname . '</a>',
|
||||
role_get_description($role),
|
||||
s($role->shortname),
|
||||
'',
|
||||
);
|
||||
|
||||
/// Icons:
|
||||
// move up
|
||||
if ($role->sortorder != $firstrole->sortorder) {
|
||||
$row[3] .= get_action_icon($baseurl . '?action=moveup&roleid=' . $role->id . '&sesskey=' . sesskey(), 'up', $strmoveup, $strmoveup);
|
||||
} else {
|
||||
$row[3] .= get_spacer();
|
||||
}
|
||||
// move down
|
||||
if ($role->sortorder != $lastrole->sortorder) {
|
||||
$row[3] .= get_action_icon($baseurl . '?action=movedown&roleid=' . $role->id . '&sesskey=' . sesskey(), 'down', $strmovedown, $strmovedown);
|
||||
} else {
|
||||
$row[3] .= get_spacer();
|
||||
}
|
||||
// edit
|
||||
$row[3] .= get_action_icon($defineurl . '?action=edit&roleid=' . $role->id,
|
||||
'edit', $stredit, get_string('editxrole', 'role', $role->localname));
|
||||
// delete
|
||||
if (isset($undeletableroles[$role->id])) {
|
||||
$row[3] .= get_spacer();
|
||||
} else {
|
||||
$row[3] .= get_action_icon($baseurl . '?action=delete&roleid=' . $role->id,
|
||||
'delete', $strdelete, get_string('deletexrole', 'role', $role->localname));
|
||||
}
|
||||
|
||||
$table->data[] = $row;
|
||||
// Move up.
|
||||
if ($role->sortorder != $firstrole->sortorder) {
|
||||
$row[3] .= get_action_icon($baseurl . '?action=moveup&roleid=' . $role->id . '&sesskey=' . sesskey(), 'up', $strmoveup, $strmoveup);
|
||||
} else {
|
||||
$row[3] .= get_spacer();
|
||||
}
|
||||
// Move down.
|
||||
if ($role->sortorder != $lastrole->sortorder) {
|
||||
$row[3] .= get_action_icon($baseurl . '?action=movedown&roleid=' . $role->id . '&sesskey=' . sesskey(), 'down', $strmovedown, $strmovedown);
|
||||
} else {
|
||||
$row[3] .= get_spacer();
|
||||
}
|
||||
// Edit.
|
||||
$row[3] .= get_action_icon($defineurl . '?action=edit&roleid=' . $role->id,
|
||||
'edit', $stredit, get_string('editxrole', 'core_role', $role->localname));
|
||||
// Delete.
|
||||
if (isset($undeletableroles[$role->id])) {
|
||||
$row[3] .= get_spacer();
|
||||
} else {
|
||||
$row[3] .= get_action_icon($baseurl . '?action=delete&roleid=' . $role->id,
|
||||
'delete', $strdelete, get_string('deletexrole', 'core_role', $role->localname));
|
||||
}
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->container_start('buttons');
|
||||
echo $OUTPUT->single_button(new moodle_url($defineurl, array('action' => 'add')), get_string('addrole', 'role'), 'get');
|
||||
echo $OUTPUT->container_end();
|
||||
$table->data[] = $row;
|
||||
}
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
echo $OUTPUT->container_start('buttons');
|
||||
echo $OUTPUT->single_button(new moodle_url($defineurl, array('action' => 'add')), get_string('addrole', 'core_role'), 'get');
|
||||
echo $OUTPUT->container_end();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
|
||||
function get_action_icon($url, $icon, $alt, $tooltip) {
|
||||
global $OUTPUT;
|
||||
|
@ -22,15 +22,13 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
|
||||
}
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$toprow = array();
|
||||
$toprow[] = new tabobject('manage', new moodle_url('/admin/roles/manage.php'), get_string('manageroles', 'role'));
|
||||
$toprow[] = new tabobject('assign', new moodle_url('/admin/roles/allow.php', array('mode'=>'assign')), get_string('allowassign', 'role'));
|
||||
$toprow[] = new tabobject('override', new moodle_url('/admin/roles/allow.php', array('mode'=>'override')), get_string('allowoverride', 'role'));
|
||||
$toprow[] = new tabobject('switch', new moodle_url('/admin/roles/allow.php', array('mode'=>'switch')), get_string('allowswitch', 'role'));
|
||||
$toprow[] = new tabobject('manage', new moodle_url('/admin/roles/manage.php'), get_string('manageroles', 'core_role'));
|
||||
$toprow[] = new tabobject('assign', new moodle_url('/admin/roles/allow.php', array('mode'=>'assign')), get_string('allowassign', 'core_role'));
|
||||
$toprow[] = new tabobject('override', new moodle_url('/admin/roles/allow.php', array('mode'=>'override')), get_string('allowoverride', 'core_role'));
|
||||
$toprow[] = new tabobject('switch', new moodle_url('/admin/roles/allow.php', array('mode'=>'switch')), get_string('allowswitch', 'core_role'));
|
||||
|
||||
echo $OUTPUT->tabtree($toprow, $currenttab);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user