### Eclipse Workspace Patch 1.0 #P moodle Index: admin/settings/users.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/settings/users.php,v retrieving revision 1.18 diff -u -r1.18 users.php --- admin/settings/users.php 26 Jan 2007 21:45:50 -0000 1.18 +++ admin/settings/users.php 31 Jan 2007 15:53:21 -0000 @@ -33,6 +33,7 @@ if (!$guestrole = get_guest_role()) { $guestrole->id = 0; } + if ($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) { $studentrole = array_shift($studentroles); /// Take the first one } else { @@ -40,6 +41,8 @@ } $assignableroles = get_assignable_roles($context); +$temp->add(new admin_setting_guestselect('guestroleid', get_string('guestroleid', 'admin'), + get_string('configguestroleid', 'admin'), $guestrole->id, $assignableroles)); $temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'), get_string('confignotloggedinroleid', 'admin'), $guestrole->id, $assignableroles )); $temp->add(new admin_setting_configselect('defaultuserroleid', get_string('defaultuserroleid', 'admin'), Index: lang/en_utf8/admin.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/admin.php,v retrieving revision 1.99 diff -u -r1.99 admin.php --- lang/en_utf8/admin.php 29 Jan 2007 21:29:28 -0000 1.99 +++ lang/en_utf8/admin.php 31 Jan 2007 15:53:24 -0000 @@ -103,6 +103,7 @@ $string['configfullnamedisplay'] = 'This defines how names are shown when they are displayed in full. For most mono-lingual sites the most efficient setting is the default \"Given names + Surname\", but you may choose to hide surnames altogether, or to leave it up to the current language pack to decide (some languages have different conventions).'; $string['configgdversion'] = 'Indicate the version of GD that is installed. The version shown by default is the one that has been auto-detected. Don\'t change this unless you really know what you\'re doing.'; $string['configgradebookroles'] = 'This setting allows you to control who appears on the gradebook. Users need to have at least one of these roles in a course to be shown in the gradebook for that course.'; +$string['configguestroleid'] = 'This role is automatically assigned to the guest user. It is also temporarily assigned to not enrolled users when they enter course that allows guests without password. You can only choose role with moodle/legacy:guest capability.'; $string['confighiddenuserfields'] = 'Select which user infomation fields you wish to hide from other users other than course teachers/admins. This will increase student privacy. Hold CTRL key to select multiple fields.'; $string['confightmleditor'] = 'Choose whether or not to allow use of the embedded HTML text editor. Even if you choose allow, this editor will only appear when the user is using a compatible web browser. Users can also choose not to use it.'; $string['configidnumber'] = 'This option specifies whether (a) Users are not be asked for an ID number at all, (b) Users are asked for an ID number but can leave it blank or (c) Users are asked for an ID Number and cannot leave it blank. If given the User\'s ID number is displayed in their Profile.'; @@ -290,6 +291,7 @@ $string['gotofirst'] = 'Go to first missing string'; $string['gradebook'] = 'Gradebook'; $string['gradebookroles'] = 'Graded roles'; +$string['guestroleid'] = 'Role for guest'; $string['helpadminseesall'] = 'Do admins see all calendar events or just those that apply to themselves?'; $string['helpcalendarsettings'] = 'Configure various calendar and date/time-related aspects of Moodle'; $string['helpforcetimezone'] = 'You can allow users to individually select their timezone, or force a timezone for everyone.'; Index: lib/accesslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v retrieving revision 1.216 diff -u -r1.216 accesslib.php --- lib/accesslib.php 30 Jan 2007 10:10:25 -0000 1.216 +++ lib/accesslib.php 31 Jan 2007 15:53:29 -0000 @@ -187,10 +187,25 @@ * @return object role */ function get_guest_role() { - if ($roles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { - return array_shift($roles); // Pick the first one + global $CFG; + + if (empty($CFG->guestroleid)) { + if ($roles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { + $guestrole = array_shift($roles); // Pick the first one + set_config('guestroleid', $guestrole->id); + return $guestrole; + } else { + debugging('Can not create guest role'); + return false; + } } else { - return false; + if ($guestrole = get_record('role','id', $CFG->guestroleid)) { + return $guestrole; + } else { + //somebody is messing with guest roles, remove incorrect setting and try to find a new one + set_config('guestroleid', ''); + return get_guest_role(); + } } } Index: lib/adminlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/adminlib.php,v retrieving revision 1.115 diff -u -r1.115 adminlib.php --- lib/adminlib.php 30 Jan 2007 10:33:09 -0000 1.115 +++ lib/adminlib.php 31 Jan 2007 15:53:38 -0000 @@ -1468,6 +1468,10 @@ } function write_setting($data) { + if (!$this->validate($data)) { + return get_string('validateerror', 'admin') . $this->visiblename . '
'; + } + // check that what we got was in the original choices // or that the data is the default setting - needed during install when choices can not be constructed yet if ($data != $this->defaultsetting and ! in_array($data, array_keys($this->choices))) { @@ -1477,6 +1481,10 @@ return (set_config($this->name, $data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); } + function validate($data) { + return true; + } + function output_html() { if ($this->get_setting() === NULL) { $current = $this->defaultsetting; @@ -2125,6 +2133,20 @@ } +class admin_setting_guestselect extends admin_setting_configselect { + function admin_setting_guestselect($name, $visiblename, $description, $default, $choices) { + parent::admin_setting_configselect($name, $visiblename, $description, $default, $choices); + } + + function validate($data) { + $guestroles = get_roles_with_capability('moodle/legacy:guest'); + if (array_key_exists($data, $guestroles)) { + return true; + } else { + return false; // this is not a guest role! + } + } +} class admin_setting_backupselect extends admin_setting_configselect { function admin_setting_backupselect($name, $visiblename, $description, $default, $choices) {