libdir.'/adminlib.php');
$return = optional_param('return', '', PARAM_ALPHA);
admin_externalpage_setup('upgradesettings'); // now hidden page
// a caveat: we're depending on only having one admin access this page at once. why? the following line
// (the function call to find_new_settings) must have the EXACT SAME RETURN VALUE both times that this
// page is loaded (i.e. both when we're displaying the form and then when we process the form's input).
// if the return values don't match, we could potentially lose changes that the admin is making.
$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 == '') {
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 ($data = data_submitted()) {
$unslashed = (array)stripslashes_recursive($data);
if (confirm_sesskey()) {
$newsettings = find_new_settings(admin_get_root());
$errors = '';
foreach($newsettings as $newsetting) {
if (isset($unslashed['s_' . $newsetting->name])) {
$errors .= $newsetting->write_setting($unslashed['s_' . $newsetting->name]);
} else {
$errors .= $newsetting->write_setting($newsetting->defaultsetting);
}
}
if (empty($errors)) {
// 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");
}
} else {
$url = "$CFG->wwwroot/$CFG->admin/upgradesettings.php?return=$return";
error(get_string('errorwithsettings', 'admin') . '
' . $errors, $url);
}
} else {
error(get_string('confirmsesskeybad', 'error'));
}
}
// and finally, if we get here, then there are new settings and we have to print a form
// to modify them
admin_externalpage_print_header();
print_simple_box(get_string('upgradesettingsintro','admin'),'','100%','',5,'generalbox','');
echo '