From: skodak Date: Tue, 2 Oct 2007 21:38:53 +0000 (+0000) Subject: MDL-11562 supportname and supportemail are are now initialized after admin user setup X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8e5da17a4457734b73b8e72bb83f4026751d4208;p=moodle.git MDL-11562 supportname and supportemail are are now initialized after admin user setup 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 --- diff --git a/admin/index.php b/admin/index.php index f960b74c1b..037c52e8a7 100644 --- a/admin/index.php +++ b/admin/index.php @@ -527,8 +527,9 @@ 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 diff --git a/admin/settings/frontpage.php b/admin/settings/frontpage.php index 6522632f7d..96693a54ec 100644 --- a/admin/settings/frontpage.php +++ b/admin/settings/frontpage.php @@ -4,53 +4,55 @@ 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 diff --git a/admin/settings/server.php b/admin/settings/server.php index af8aab2585..88b5970abd 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -2,8 +2,6 @@ // 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'), @@ -56,17 +54,15 @@ $options['0'] = get_string('none'); $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)); diff --git a/admin/settings/top.php b/admin/settings/top.php index 2f81754b5a..55938e8aa9 100644 --- a/admin/settings/top.php +++ b/admin/settings/top.php @@ -5,6 +5,8 @@ // 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 diff --git a/admin/upgradesettings.php b/admin/upgradesettings.php index d6fa482908..96e1265bcc 100644 --- a/admin/upgradesettings.php +++ b/admin/upgradesettings.php @@ -6,6 +6,8 @@ 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. @@ -23,8 +25,11 @@ $newsettingshtml = output_new_settings_by_page(admin_get_root()); // 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 @@ -44,15 +49,17 @@ if ($data = data_submitted()) { 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') . '
' . $errors); - die; + $url = "$CFG->wwwroot/$CFG->admin/upgradesettings.php?return=$return"; + error(get_string('errorwithsettings', 'admin') . '
' . $errors, $url); } } else { error(get_string('confirmsesskeybad', 'error')); - die; } } @@ -64,7 +71,8 @@ admin_externalpage_print_header(); print_simple_box(get_string('upgradesettingsintro','admin'),'','100%','',5,'generalbox',''); echo '
'; -echo ''; +echo ''; +echo ''; echo '
'; echo '
'; echo $newsettingshtml; diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 36d1692a6d..f2034b6533 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -318,6 +318,7 @@ $string['forcetimezone'] = 'Force default timezone'; $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'; diff --git a/lib/adminlib.php b/lib/adminlib.php index f3f3047593..cf6e3142b2 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1400,6 +1400,10 @@ class admin_setting { return NULL; // has to be overridden } + function get_defaultsetting() { + return $this->defaultsetting; + } + function write_setting($data) { return; // has to be overridden } @@ -1792,7 +1796,7 @@ class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox { function get_setting() { $site = get_site(); - return (isset($site->{$this->name}) ? $site->{$this->name} : NULL); + return $site->{$this->name}; } function write_setting($data) { @@ -1819,7 +1823,7 @@ class admin_setting_sitesettext extends admin_setting_configtext { 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) { @@ -1877,7 +1881,7 @@ class admin_setting_special_frontpagedesc extends admin_setting { function get_setting() { $site = get_site(); - return (isset($site->{$this->name}) ? $site->{$this->name} : NULL); + return $site->{$this->name} != '' ? $site->{$this->name} : NULL; } @@ -2929,10 +2933,15 @@ function admin_get_root() { 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; @@ -2946,8 +2955,17 @@ function apply_default_settings(&$node) { 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 } diff --git a/user/editadvanced.php b/user/editadvanced.php index 8bdcfa2d34..40dbd5d7bf 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -141,6 +141,9 @@ } 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 {