From: skodak Date: Sat, 3 Mar 2007 22:30:35 +0000 (+0000) Subject: MDL-8522 Add role reset button into role definition form; fixed single button css X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a83addc5e5dbb9247e8183104ffe65b9911f75e5;p=moodle.git MDL-8522 Add role reset button into role definition form; fixed single button css --- diff --git a/admin/roles/manage.html b/admin/roles/manage.html index ac9f8a374b..6835d0d812 100755 --- a/admin/roles/manage.html +++ b/admin/roles/manage.html @@ -4,9 +4,6 @@ case 'add': $submitlabel = get_string('addrole', 'role'); break; - case 'view': - $submitlabel = get_string('listallroles', 'role'); - break; case 'edit': default: $submitlabel = get_string('savechanges'); @@ -14,11 +11,8 @@ if ($action == 'view') { ?> -
- -
-
@@ -27,39 +21,44 @@
- - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + +
name); - } else { - echo ''; - if (isset($errors["name"])) formerr($errors["name"]); - } ?>
shortname); - } else { - echo ''; - if (isset($errors["shortname"])) formerr($errors["shortname"]); - } ?>
description); - $usehtmleditor = false; - } else { - print_textarea($usehtmleditor, 10, 50, 50, 10, 'description', $role->description); - } ?>
:name); ?>
:shortname); ?>
:description); $usehtmleditor = false; ?>
name).'" />'; + if (isset($errors["name"])) formerr($errors["name"]); + ?>
shortname).'" />'; + if (isset($errors["shortname"])) formerr($errors["shortname"]); + ?>
description); + ?>
-name]) and $defaultcaps[$capability->name] == CAP_ALLOW) ? $capclass : ''; $isprevent = (isset($defaultcaps[$capability->name]) and $defaultcaps[$capability->name] == CAP_PREVENT) ? $capclass : ''; $isprohibit = (isset($defaultcaps[$capability->name]) and $defaultcaps[$capability->name] == CAP_PROHIBIT) ? $capclass : ''; - + ?> @@ -193,11 +192,11 @@ foreach ($capabilities as $capability) { -
- +
+ -
+ diff --git a/admin/roles/manage.php b/admin/roles/manage.php index ec9ad157ef..209eafd7e1 100755 --- a/admin/roles/manage.php +++ b/admin/roles/manage.php @@ -16,9 +16,9 @@ $cancel = optional_param('cancel', 0, PARAM_BOOL); $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); - + require_capability('moodle/role:manage', $sitecontext); - + if ($cancel) { redirect('manage.php'); } @@ -192,7 +192,7 @@ case 'delete': if (in_array($roleid, $defaultroles)) { - error('This role is used as one of the default system roles, it can not be deleted'); + error('This role is used as one of the default system roles, it can not be deleted'); } if ($confirm and data_submitted() and confirm_sesskey()) { if (!delete_role($roleid)) { @@ -245,17 +245,38 @@ redirect('manage.php'); break; + case 'duplicate': + if (!array_key_exists($roleid, $roles)) { + redirect('manage.php'); + } + + if ($confirm and data_submitted() and confirm_sesskey()) { + //ok - lets duplicate! + } else { + // show confirmation + admin_externalpage_print_header($adminroot); + $optionsyes = array('action'=>'duplicate', 'roleid'=>$roleid, 'sesskey'=>sesskey(), 'confirm'=>1); + $optionsno = array('action'=>'view', 'roleid'=>$roleid); + $a = new object(); + $a->id = $roleid; + $a->name = $roles[$roleid]->name; + $a->shortname = $roles[$roleid]->shortname; + notice_yesno(get_string('duplicaterolesure', 'role', $a), 'manage.php', 'manage.php', $optionsyes, $optionsno, 'post', 'get'); + admin_externalpage_print_footer($adminroot); + die; + } + // duplicate current role $sourcerole = get_record('role','id',$roleid); - + $fullname = $sourcerole->name; $shortname = $sourcerole->shortname; $currentfullname = ""; $currentshortname = ""; $counter = 0; - - // find a name for the duplicated role + + // find a name for the duplicated role do { if ($counter) { $suffixfull = " ".get_string("copyasnoun")." ".$counter; @@ -271,14 +292,57 @@ $courseshort = get_record("role","shortname",addslashes($currentshortname)); $counter++; } while ($coursefull || $courseshort); - - $description = 'duplicate of '.$fullname; + + $description = 'duplicate of '.$fullname; if ($newrole = create_role($currentfullname, $currentshortname, $description)) { // dupilcate all the capabilities role_cap_duplicate($sourcerole, $newrole); - } + } redirect('manage.php'); break; + + case 'reset': + if (!array_key_exists($roleid, $roles)) { + redirect('manage.php'); + } + + if ($confirm and data_submitted() and confirm_sesskey()) { + $legacyroles = get_legacy_roles(); + + $defaultcaps = array(); + foreach($legacyroles as $ltype=>$lcap) { + $localoverride = get_local_override($roleid, $sitecontext->id, $lcap); + if (!empty($localoverride->permission) and $localoverride->permission == CAP_ALLOW) { + //choose first selected legacy capability + $defaultcaps = get_default_capabilities($ltype); + break; + } + } + + delete_records('role_capabilities', 'roleid', $roleid); + if (!empty($defaultcaps)) { + foreach($defaultcaps as $cap=>$permission) { + assign_capability($cap, $permission, $roleid, $sitecontext->id); + } + } + redirect('manage.php?action=view&roleid='.$roleid); + + } else { + // show confirmation + admin_externalpage_print_header($adminroot); + $optionsyes = array('action'=>'reset', 'roleid'=>$roleid, 'sesskey'=>sesskey(), 'confirm'=>1); + $optionsno = array('action'=>'view', 'roleid'=>$roleid); + $a = new object(); + $a->id = $roleid; + $a->name = $roles[$roleid]->name; + $a->shortname = $roles[$roleid]->shortname; + notice_yesno(get_string('resetrolesure', 'role', $a), 'manage.php', 'manage.php', $optionsyes, $optionsno, 'post', 'get'); + admin_externalpage_print_footer($adminroot); + die; + } + + break; + default: break; } @@ -336,13 +400,21 @@ echo '
'; if ($action == 'view') { - popup_form('manage.php?action=view&roleid=', $roleoptions, 'switchrole', $roleid, '', '', '', + popup_form('manage.php?action=view&roleid=', $roleoptions, 'switchrole', $roleid, '', '', '', false, 'self', get_string('selectrole', 'role')); + echo '
'; + $options = array(); $options['roleid'] = $roleid; $options['action'] = 'edit'; print_single_button('manage.php', $options, get_string('edit')); + $options['action'] = 'reset'; + print_single_button('manage.php', $options, get_string('reset')); + $options['action'] = 'duplicate'; + print_single_button('manage.php', $options, get_string('duplicaterole', 'role')); + print_single_button('manage.php', null, get_string('listallroles', 'role')); + echo '
'; } echo '
'; @@ -467,12 +539,12 @@ function role_cap_duplicate($sourcerole, $targetrole) { $systemcontext = get_context_instance(CONTEXT_SYSTEM); $caps = get_records_sql("SELECT * FROM {$CFG->prefix}role_capabilities WHERE roleid = $sourcerole->id - AND contextid = $systemcontext->id"); + AND contextid = $systemcontext->id"); // adding capabilities foreach ($caps as $cap) { unset($cap->id); $cap->roleid = $targetrole; insert_record('role_capabilities', $cap); - } + } } ?> diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php index 3c5421f398..110419ba36 100644 --- a/lang/en_utf8/role.php +++ b/lang/en_utf8/role.php @@ -49,7 +49,8 @@ $string['currentrole'] = 'Current role'; $string['defaultrole'] = 'Default role'; $string['defineroles'] = 'Define roles'; $string['deleterolesure'] = 'Are you sure that you want to delete role \"$a->name ($a->shortname)\"?

Currently this role is assigned to $a->count users.'; -$string['duplicaterole'] = 'Duplicate this role'; +$string['duplicaterolesure'] = 'Are you sure that you want to duplicate role \"$a->name ($a->shortname)\"?

'; +$string['duplicaterole'] = 'Duplicate role'; $string['editrole'] = 'Edit role'; $string['errorbadrolename'] = 'Incorrect role name'; $string['errorbadroleshortname'] = 'Incorrect role name'; @@ -79,6 +80,7 @@ $string['question:export'] = 'Export questions'; $string['question:import'] = 'Import questions'; $string['question:manage'] = 'Manage questions'; $string['question:managecategory'] = 'Manage question category'; +$string['resetrolesure'] = 'Are you sure that you want to reset role \"$a->name ($a->shortname)\" to defaults?

The defaults are taken from the selected legacy capability.'; $string['risks'] = 'Risks'; $string['role:assign'] = 'Assign roles to users'; $string['role:manage'] = 'Create and manage roles'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 960b2df47b..01fc36df7b 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1555,13 +1555,13 @@ function moodle_install_roles() { */ function get_legacy_roles() { return array( - 'guest' => 'moodle/legacy:guest', - 'user' => 'moodle/legacy:user', - 'student' => 'moodle/legacy:student', - 'teacher' => 'moodle/legacy:teacher', - 'editingteacher' => 'moodle/legacy:editingteacher', + 'admin' => 'moodle/legacy:admin', 'coursecreator' => 'moodle/legacy:coursecreator', - 'admin' => 'moodle/legacy:admin' + 'editingteacher' => 'moodle/legacy:editingteacher', + 'teacher' => 'moodle/legacy:teacher', + 'student' => 'moodle/legacy:student', + 'user' => 'moodle/legacy:user', + 'guest' => 'moodle/legacy:guest' ); } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 122b0aeaaa..87cb6f7dbb 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -131,6 +131,11 @@ img.grouppicture { padding: 0; } +.singlebutton form, +.singlebutton div { + display:inline; +} + .generalbox { border-width:1px; border-style:solid; @@ -775,14 +780,19 @@ body#admin-modules table.generaltable td.c0 margin-top: 1em; } -#admin-roles-manage .duplicaterole { - text-align: right; +#admin-roles-manage .buttons { + margin: 20px; + text-align:center; +} + +#admin-roles-manage .buttons .singlebutton { + display: inline; } #admin-roles-manage .singlebutton, #admin-roles-allowoverride .singlebutton, #admin-roles-allowassign .singlebutton { - padding: 10px; + padding: 5px; text-align:center; }