2006-08-28 06:02:00 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
2006-09-20 21:00:45 +00:00
|
|
|
// detects settings that were added during an upgrade, displays a screen for the admin to
|
2006-08-28 06:02:00 +00:00
|
|
|
// modify them, and then processes modifications
|
|
|
|
|
|
|
|
require_once('../config.php');
|
2006-09-02 13:14:57 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2006-08-28 06:02:00 +00:00
|
|
|
|
2006-09-04 21:38:23 +00:00
|
|
|
$adminroot = admin_get_root();
|
2006-09-25 18:21:59 +00:00
|
|
|
admin_externalpage_setup('upgradesettings', $adminroot); // now hidden page
|
2006-08-28 06:02:00 +00:00
|
|
|
|
|
|
|
// 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.
|
2006-09-02 13:14:57 +00:00
|
|
|
|
2006-09-04 21:38:23 +00:00
|
|
|
$newsettingshtml = output_new_settings_by_page(admin_get_root());
|
2006-08-28 06:02:00 +00:00
|
|
|
|
|
|
|
// first we deal with the case where there are no new settings to be set
|
2006-09-04 21:38:23 +00:00
|
|
|
if ($newsettingshtml == '') {
|
2006-09-20 21:00:45 +00:00
|
|
|
redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
|
2006-08-28 06:02:00 +00:00
|
|
|
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()) {
|
2006-09-04 21:38:23 +00:00
|
|
|
$newsettings = find_new_settings(admin_get_root());
|
2006-08-28 06:02:00 +00:00
|
|
|
$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)) {
|
2006-09-07 19:18:48 +00:00
|
|
|
// there must be either redirect without message or continue button or else upgrade would be sometimes broken
|
|
|
|
redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
|
2006-08-28 06:02:00 +00:00
|
|
|
die;
|
|
|
|
} else {
|
|
|
|
error(get_string('errorwithsettings', 'admin') . ' <br />' . $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
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_header($adminroot);
|
2006-08-28 06:02:00 +00:00
|
|
|
|
2006-09-27 07:49:34 +00:00
|
|
|
print_simple_box(get_string('upgradesettingsintro','admin'),'','100%','',5,'generalbox','');
|
2006-09-26 20:51:28 +00:00
|
|
|
|
2006-09-27 07:49:34 +00:00
|
|
|
echo '<form action="upgradesettings.php" method="post" name="mainform" id="adminsettings">';
|
|
|
|
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
|
|
|
echo '<fieldset>';
|
|
|
|
echo '<div class="clearer"><!-- --></div>';
|
2006-09-04 21:38:23 +00:00
|
|
|
echo $newsettingshtml;
|
2006-09-26 20:51:28 +00:00
|
|
|
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
|
2006-08-28 06:02:00 +00:00
|
|
|
echo '</form>';
|
|
|
|
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_footer($adminroot);
|
2006-08-28 06:02:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find settings that have not been initialized (e.g. during initial install or an upgrade).
|
2006-09-20 21:00:45 +00:00
|
|
|
*
|
2006-08-28 06:02:00 +00:00
|
|
|
* Tests each setting's get_setting() method. If the result is NULL, we consider the setting
|
|
|
|
* to be uninitialized.
|
|
|
|
*
|
|
|
|
* @param string &$node The node at which to start searching. Should be $ADMIN for all external calls to this function.
|
|
|
|
* @return array An array containing admin_setting objects that haven't yet been initialized
|
|
|
|
*/
|
|
|
|
function find_new_settings(&$node) {
|
|
|
|
|
|
|
|
if (is_a($node, 'admin_category')) {
|
|
|
|
$return = array();
|
|
|
|
$entries = array_keys($node->children);
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
$return = array_merge($return, find_new_settings($node->children[$entry]));
|
|
|
|
}
|
|
|
|
return $return;
|
2006-09-20 21:00:45 +00:00
|
|
|
}
|
2006-08-28 06:02:00 +00:00
|
|
|
|
2006-09-20 21:00:45 +00:00
|
|
|
if (is_a($node, 'admin_settingpage')) {
|
2006-08-28 06:02:00 +00:00
|
|
|
$return = array();
|
|
|
|
foreach ($node->settings as $setting) {
|
|
|
|
if ($setting->get_setting() === NULL) {
|
|
|
|
$return[] =& $setting;
|
|
|
|
}
|
|
|
|
unset($setting); // needed to prevent odd (imho) reference behaviour
|
|
|
|
// see http://www.php.net/manual/en/language.references.whatdo.php#AEN6399
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-09-04 21:38:23 +00:00
|
|
|
function output_new_settings_by_page(&$node) {
|
|
|
|
|
|
|
|
if (is_a($node, 'admin_category')) {
|
|
|
|
$entries = array_keys($node->children);
|
|
|
|
$return = '';
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
$return .= output_new_settings_by_page($node->children[$entry]);
|
|
|
|
}
|
|
|
|
return $return;
|
2006-09-20 21:00:45 +00:00
|
|
|
}
|
2006-09-04 21:38:23 +00:00
|
|
|
|
2006-09-20 21:00:45 +00:00
|
|
|
if (is_a($node, 'admin_settingpage')) {
|
2006-09-04 21:38:23 +00:00
|
|
|
$newsettings = array();
|
|
|
|
foreach ($node->settings as $setting) {
|
|
|
|
if ($setting->get_setting() === NULL) {
|
|
|
|
$newsettings[] =& $setting;
|
|
|
|
}
|
|
|
|
unset($setting); // needed to prevent odd (imho) reference behaviour
|
|
|
|
// see http://www.php.net/manual/en/language.references.whatdo.php#AEN6399
|
|
|
|
}
|
|
|
|
$return = '';
|
|
|
|
if (count($newsettings) > 0) {
|
2006-09-26 20:51:28 +00:00
|
|
|
$return .= print_heading(get_string('upgradesettings','admin').' - '.$node->visiblename, '', 2, 'main', true);
|
2006-09-26 20:54:05 +00:00
|
|
|
$return .= '<fieldset class="adminsettings">' . "\n";
|
2006-09-04 21:38:23 +00:00
|
|
|
foreach ($newsettings as $newsetting) {
|
2006-09-26 20:51:28 +00:00
|
|
|
$return .= '<div class="clearer"><!-- --></div>' . "\n";
|
2006-09-04 21:38:23 +00:00
|
|
|
$return .= $newsetting->output_html();
|
2006-09-20 21:00:45 +00:00
|
|
|
}
|
2006-09-26 20:54:05 +00:00
|
|
|
$return .= '</fieldset>';
|
2006-09-04 21:38:23 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-09-27 07:49:34 +00:00
|
|
|
?>
|