dirroot . '/' . $CFG->admin . '/adminlib.php');
admin_externalpage_setup('adminnotifications'); // we pretend to be the adminnotifications page... don't wanna show up in the menu :)
// 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.
$newsettings = find_new_settings($ADMIN);
// first we deal with the case where there are no new settings to be set
if (count($newsettings) === 0) {
redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php', get_string('nonewsettings','admin'),1);
die;
}
// now we'll deal with the case that the admin has submitted the form with new settings
if ($data = data_submitted()) {
$data = (array)$data;
if (confirm_sesskey()) {
$errors = '';
foreach($newsettings as $newsetting) {
if (isset($data['s_' . $newsetting->name])) {
$errors .= $newsetting->write_setting($data['s_' . $newsetting->name]);
} else {
$errors .= $newsetting->write_setting($newsetting->defaultsetting);
}
}
if (empty($errors)) {
redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php', get_string('changessaved'),1);
die;
} else {
error(get_string('errorwithsettings', 'admin') . '
' . $errors);
die;
}
} else {
error(get_string('confirmsesskeybad', 'error'));
die;
}
}
// 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();
echo '