MDL-11566 only site shortname, fullname and desc are required/displayed during installation
MDL-11567 fixed upgradesettings redirects if error in settings
MDL-11143 defaultfrontpageroleid moved to Frontpage settings page (easier to find), speedup
require_capability('moodle/site:config', $context);
/// check that site is properly customized
- if (empty($site->shortname) or empty($site->shortname)) {
- redirect('settings.php?section=frontpagesettings&return=site');
+ if (empty($site->shortname)) {
+ // probably new installation - lets return to frontpage after this step
+ redirect('upgradesettings.php?return=site');
}
/// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
if (get_site()) { //do not use during installation
$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
- $frontpagecontextid = $frontpagecontext->id;
-} else {
- $frontpagecontext = NULL;
- $frontpagecontextid = 0;
-}
-// "frontpage" settingpage
-$temp = new admin_settingpage('frontpagesettings', get_string('frontpagesettings','admin'), 'moodle/course:update', false, $frontpagecontext);
-$temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', ''));
-$temp->add(new admin_setting_sitesettext('shortname', get_string('shortsitename'), '', ''));
-$temp->add(new admin_setting_special_frontpagedesc());
-$temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
-$temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
-$temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'), get_string('sitesectionhelp','admin'), 1));
-$temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'), '', 3,
- array('0' => '0',
- '1' => '1',
- '2' => '2',
- '3' => '3',
- '4' => '4',
- '5' => '5',
- '6' => '6',
- '7' => '7',
- '8' => '8',
- '9' => '9',
- '10' => '10')));
-$temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
-$temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0));
-$ADMIN->add('frontpage', $temp);
-
-$ADMIN->add('frontpage', new admin_externalpage('frontpageroles', get_string('frontpageroles', 'admin'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . $frontpagecontextid, 'moodle/role:assign', false, $frontpagecontext));
-
-$ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/site:backup', false, $frontpagecontext));
-
-$ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
-
-// front page default role
-$temp = new admin_settingpage('frontpagedefaultrole', get_string('frontpagedefaultrole', 'admin'), 'moodle/site:config', false, get_context_instance(CONTEXT_SYSTEM));
-$roleoptions = array(0=>'N/A'); // roles to choose from
-if ($roles = get_records('role')) {
- foreach ($roles as $role) {
- $roleoptions[$role->id] = $role->name;
+ if (has_capability('moodle/site:config', $systemcontext)
+ or has_capability('moodle/course:update', $frontpagecontext)
+ or has_capability('moodle/role:assign', $frontpagecontext)
+ or has_capability('moodle/site:restore', $frontpagecontext)
+ or has_capability('moodle/site:backup', $frontpagecontext)
+ or has_capability('moodle/course:managefiles', $frontpagecontext)
+ ) {
+ // "frontpage" settingpage
+ $temp = new admin_settingpage('frontpagesettings', get_string('frontpagesettings','admin'), 'moodle/course:update', false, $frontpagecontext);
+ $temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', NULL)); // no default
+ $temp->add(new admin_setting_sitesettext('shortname', get_string('shortsitename'), '', NULL)); // no default
+ $temp->add(new admin_setting_special_frontpagedesc());
+ $temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
+ $temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
+ $temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'), get_string('sitesectionhelp','admin'), 1));
+ $temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'), '', 3,
+ array('0' => '0',
+ '1' => '1',
+ '2' => '2',
+ '3' => '3',
+ '4' => '4',
+ '5' => '5',
+ '6' => '6',
+ '7' => '7',
+ '8' => '8',
+ '9' => '9',
+ '10' => '10')));
+ $temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
+ $temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0));
+
+ // front page default role
+ $roleoptions = array(0=>get_string('none')); // roles to choose from
+ if ($roles = get_records('role')) {
+ foreach ($roles as $role) {
+ $roleoptions[$role->id] = $role->name;
+ }
+ $temp->add(new admin_setting_configselect('defaultfrontpageroleid', get_string('frontpagedefaultrole', 'admin'), '', 0, $roleoptions));
+ }
+
+ $ADMIN->add('frontpage', $temp);
+
+ $ADMIN->add('frontpage', new admin_externalpage('frontpageroles', get_string('frontpageroles', 'admin'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . $frontpagecontext->id, 'moodle/role:assign', false, $frontpagecontext));
+
+ $ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/site:backup', false, $frontpagecontext));
+
+ $ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
+
+ $ADMIN->add('frontpage', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID, 'moodle/course:managefiles', false, $frontpagecontext));
}
}
-$temp->add(new admin_setting_configselect('defaultfrontpageroleid', get_string('frontpagedefaultrole', 'admin'), '', '', $roleoptions));
-$ADMIN->add('frontpage', $temp);
-
-$ADMIN->add('frontpage', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID, 'moodle/course:managefiles', false, $frontpagecontext));
-
?>
\ No newline at end of file
// This file defines settingpages and externalpages under the "server" category
-global $USER;
-
// "systempaths" settingpage
$temp = new admin_settingpage('systempaths', get_string('systempaths','admin'));
$temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','admin'), get_string('configgdversion', 'admin'), check_gd_version(), array('0' => get_string('gdnot'),
$options = array_merge($options, $charsets);
$temp->add(new admin_setting_configselect('sitemailcharset', get_string('sitemailcharset', 'admin'), get_string('configsitemailcharset','admin'), '', $options));
$temp->add(new admin_setting_configcheckbox('allowusermailcharset', get_string('allowusermailcharset', 'admin'), get_string('configallowusermailcharset', 'admin'), 0));
-if (empty($USER->email)) {
- if ($mainadmin = get_admin()) {
- $primaryadminemail = $mainadmin->email;
- $primaryadminname = fullname($mainadmin);
- } else {
- $primaryadminemail = '';
- $primaryadminname = '';
- }
-} else {
+if (isloggedin()) {
+ global $USER;
$primaryadminemail = $USER->email;
- $primaryadminname = fullname($USER);
+ $primaryadminname = fullname($USER, true);
+
+} else {
+ // no defaults during installation - admin user must be created first
+ $primaryadminemail = NULL;
+ $primaryadminname = NULL;
}
$temp->add(new admin_setting_configtext('supportname', get_string('supportname', 'admin'), get_string('configsupportname', 'admin'), $primaryadminname, PARAM_NOTAGS));
$temp->add(new admin_setting_configtext('supportemail', get_string('supportemail', 'admin'), get_string('configsupportemail', 'admin'), $primaryadminemail, PARAM_NOTAGS));
// since they need to exist *before* settingpages and externalpages
// are added to them.
+$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+
$ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
// hidden upgrade script
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
+$return = optional_param('return', '', PARAM_ALPHA);
+
// Technically, we shouldn't need it, but during the
// v1.9 accesslib upgrade _sometimes_ USER->access
// isn't set.
// first we deal with the case where there are no new settings to be set
if ($newsettingshtml == '') {
- redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
- die;
+ if ($return == 'site') {
+ redirect("$CFG->wwwroot/");
+ } else {
+ redirect("$CFG->wwwroot/$CFG->admin/index.php");
+ }
}
// now we'll deal with the case that the admin has submitted the form with new settings
if (empty($errors)) {
// there must be either redirect without message or continue button or else upgrade would be sometimes broken
- redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
- die;
+ if ($return == 'site') {
+ redirect("$CFG->wwwroot/");
+ } else {
+ redirect("$CFG->wwwroot/$CFG->admin/index.php");
+ }
} else {
- error(get_string('errorwithsettings', 'admin') . ' <br />' . $errors);
- die;
+ $url = "$CFG->wwwroot/$CFG->admin/upgradesettings.php?return=$return";
+ error(get_string('errorwithsettings', 'admin') . ' <br />' . $errors, $url);
}
} else {
error(get_string('confirmsesskeybad', 'error'));
- die;
}
}
print_simple_box(get_string('upgradesettingsintro','admin'),'','100%','',5,'generalbox','');
echo '<form action="upgradesettings.php" method="post" id="adminsettings">';
-echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
+echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+echo '<input type="hidden" name="return" value="'.$return.'" />';
echo '<fieldset>';
echo '<div class="clearer"><!-- --></div>';
echo $newsettingshtml;
$string['framename'] = 'Frame name';
$string['frontpage'] = 'Front Page';
$string['frontpagebackup'] = 'Front Page backup';
+$string['frontpagedefaultrole'] = 'Default frontpage role';
$string['frontpageloggedin'] = 'Front page items when logged in';
$string['frontpagerestore'] = 'Front Page restore';
$string['frontpageroles'] = 'Front Page roles';
return NULL; // has to be overridden
}
+ function get_defaultsetting() {
+ return $this->defaultsetting;
+ }
+
function write_setting($data) {
return; // has to be overridden
}
function get_setting() {
$site = get_site();
- return (isset($site->{$this->name}) ? $site->{$this->name} : NULL);
+ return $site->{$this->name};
}
function write_setting($data) {
function get_setting() {
$site = get_site();
- return (isset($site->{$this->name}) ? $site->{$this->name} : NULL);
+ return $site->{$this->name} != '' ? $site->{$this->name} : NULL;
}
function validate($data) {
function get_setting() {
$site = get_site();
- return (isset($site->{$this->name}) ? $site->{$this->name} : NULL);
+ return $site->{$this->name} != '' ? $site->{$this->name} : NULL;
}
return $ADMIN;
}
-/// settings utiliti functions
+/// settings utility functions
-// n.b. this function unconditionally applies default settings
-function apply_default_settings(&$node) {
+/**
+ * This function applies default settings.
+ * @param object $node
+ * @param bool $uncoditional if true overrides all values with defaults
+ * @return void
+ */
+function apply_default_settings(&$node, $unconditional=true) {
global $CFG;
if (is_a($node, 'admin_settingpage')) {
foreach ($node->settings as $setting) {
- $CFG->{$setting->name} = $setting->defaultsetting;
- $setting->write_setting($setting->defaultsetting);
+ if (!$unconditional and !is_null($setting->get_setting)) {
+ //do not override existing defaults
+ continue;
+ }
+ $defaultsetting = $setting->get_defaultsetting();
+ if (is_null($defaultsetting)) {
+ // no value yet - default maybe applied after admin user creation or in upgradesettings
+ continue;
+ }
+ $CFG->{$setting->name} = $defaultsetting;
+ $setting->write_setting($defaultsetting);
unset($setting); // needed to prevent odd (imho) reference behaviour
// see http://www.php.net/manual/en/language.references.whatdo.php#AEN6399
}
}
if (!empty($USER->newadminuser)) {
unset($USER->newadminuser);
+ // try to apply defaults again - some of them might depend on admin user info
+ $adminroot = admin_get_root();
+ apply_default_settings($adminroot, false);
// redirect to admin/ to continue with installation
redirect("$CFG->wwwroot/$CFG->admin/");
} else {