/** * Internal function - returns arrays of html pages with uninitialised settings * * @param object $node Instance of admin_category or admin_settingpage * @return array */ function admin_output_new_settings_by_page($node) { global $OUTPUT; $return = array(); if ($node instanceof admin_category) { $entries = array_keys($node->children); foreach ($entries as $entry) { $return += admin_output_new_settings_by_page($node->children[$entry]); } } else { if ($node instanceof admin_settingpage) { $newsettings = array(); foreach ($node->settings as $setting) { if (is_null($setting->get_setting())) { $newsettings[] = $setting; } } if (count($newsettings) > 0) { $adminroot = admin_get_root(); $page = $OUTPUT->heading(get_string('upgradesettings', 'admin') . ' - ' . $node->visiblename, 2, 'main'); $page .= '<fieldset class="adminsettings">' . "\n"; foreach ($newsettings as $setting) { $fullname = $setting->get_full_name(); if (array_key_exists($fullname, $adminroot->errors)) { $data = $adminroot->errors[$fullname]->data; } else { $data = $setting->get_setting(); if (is_null($data)) { $data = $setting->get_defaultsetting(); } } $page .= '<div class="clearer"><!-- --></div>' . "\n"; $page .= $setting->output_html($data); } $page .= '</fieldset>'; $return[$node->name] = $page; } } } return $return; }
require_once '../config.php'; require_once $CFG->libdir . '/adminlib.php'; $return = optional_param('return', '', PARAM_ALPHA); /// no guest autologin require_login(0, false); $adminroot = admin_get_root(); // need all settings admin_externalpage_setup('upgradesettings'); // now hidden page // now we'll deal with the case that the admin has submitted the form with new settings if ($data = data_submitted() and confirm_sesskey()) { $count = admin_write_settings($data); $adminroot = admin_get_root(true); //reload tree } $newsettings = admin_output_new_settings_by_page($adminroot); if (isset($newsettings['frontpagesettings'])) { $frontpage = $newsettings['frontpagesettings']; unset($newsettings['frontpagesettings']); array_unshift($newsettings, $frontpage); } $newsettingshtml = implode($newsettings); unset($newsettings); $focus = ''; if (empty($adminroot->errors) and $newsettingshtml === '') { // there must be either redirect without message or continue button or else upgrade would be sometimes broken if ($return == 'site') { redirect("{$CFG->wwwroot}/"); } else { redirect("{$CFG->wwwroot}/{$CFG->admin}/index.php"); }