]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11562 supportname and supportemail are are now initialized after admin user setup
authorskodak <skodak>
Tue, 2 Oct 2007 21:38:53 +0000 (21:38 +0000)
committerskodak <skodak>
Tue, 2 Oct 2007 21:38:53 +0000 (21:38 +0000)
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

admin/index.php
admin/settings/frontpage.php
admin/settings/server.php
admin/settings/top.php
admin/upgradesettings.php
lang/en_utf8/admin.php
lib/adminlib.php
user/editadvanced.php

index f960b74c1bbbdcf9cf768635641e8bffc652c5da..037c52e8a71f36a1f1557239c2c66dd9aebfcde8 100644 (file)
     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&amp;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
index 6522632f7d2849355ea328222d36b6dd125086d1..96693a54ec0b381a76bda98d6a68162d1208cde5 100644 (file)
@@ -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.'&amp;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.'&amp;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
index af8aab2585a5d7081376c8548b5a8107ba008a00..88b5970abd6d4affa3d581358d5001b1e260d401 100644 (file)
@@ -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));
index 2f81754b5afb32cfe835ac250aebf5fc068596f1..55938e8aa9d2bba0a81192c782ecc5b174770896 100644 (file)
@@ -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
index d6fa482908ab9cab09aa7eb131d7406034eacf57..96e1265bcc33595deca928762edb328888104ba0 100644 (file)
@@ -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') . ' <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;
     }
 
 }
@@ -64,7 +71,8 @@ admin_externalpage_print_header();
 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;
index 36d1692a6d9ea35c23eb58c981e96e3d4c47692b..f2034b65335894a24d15dae25646da7973835dad 100644 (file)
@@ -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';
index f3f30475931c1e6db75a372a6e3e6b2da3807c39..cf6e3142b2b2ad44f557512e03c20e46a29d2768 100644 (file)
@@ -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
         }
index 8bdcfa2d34b30d36cd21a101fd66afb90d4eaf25..40dbd5d7bf8136025256c00eb36a193488b22f41 100644 (file)
             }
             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 {