forked from science-ation/science-ation
- Separte the action handler from the config emitter (but tie them together so
that the old functionality remains) - Run the action handler separately in the tour annealer and judge annealer config so that the page can be refreshed immediately after an update, so the config variables (that may have changed) are reloaded. - Skip updating config variables that haven't changed.
This commit is contained in:
parent
c8d01cb8fb
commit
984c9776ef
@ -30,14 +30,20 @@ ogram; see the file COPYING. If not, write to
|
||||
require("judges.inc.php");
|
||||
require("judges_schedulerconfig_check.inc.php");
|
||||
|
||||
$action = config_editor_handle_actions($config['FAIRYEAR'], "var");
|
||||
if($action == 'update') {
|
||||
header("Location: judges_schedulerconfig.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
send_header("Judge Scheduler Configuration",
|
||||
array('Committee Main' => 'committee_main.php',
|
||||
'Administration' => 'admin/index.php',
|
||||
'Judges' => 'admin/judges.php')
|
||||
);
|
||||
|
||||
config_editor("Judge Scheduler", $config['FAIRYEAR'], "var", $_SERVER['PHP_SELF']);
|
||||
|
||||
config_editor("Judge Scheduler", $config['FAIRYEAR'], "var", $_SERVER['PHP_SELF']);
|
||||
echo "<hr />";
|
||||
|
||||
if($_GET['action']=="reset")
|
||||
|
@ -34,7 +34,12 @@ ogram; see the file COPYING. If not, write to
|
||||
header("Location: tours_sa_status.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$action = config_editor_handle_actions( $config['FAIRYEAR'], "var");
|
||||
if($action == 'update') {
|
||||
header('Location: tours_sa_config.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
send_header("Automatic Tour Assignment Configuration",
|
||||
array('Committee Main' => 'committee_main.php',
|
||||
|
@ -114,6 +114,47 @@ function config_update_variables($fairyear=NULL, $lastfairyear=NULL)
|
||||
}
|
||||
}
|
||||
|
||||
$config_editor_actions_done = false;
|
||||
$config_editor_updated = false;
|
||||
|
||||
function config_editor_handle_actions($year, $array_name)
|
||||
{
|
||||
global $config;
|
||||
global $config_editor_actions_done;
|
||||
|
||||
$config_editor_actions_done = true;
|
||||
$updated = false;
|
||||
if($_POST['action']=="update") {
|
||||
$var = config_editor_parse_from_http_headers($array_name);
|
||||
$varkeys = array_keys($var);
|
||||
foreach($varkeys as $k) {
|
||||
if(is_array($var[$k]))
|
||||
$val = implode(',',$var[$k]);
|
||||
else
|
||||
$val = $var[$k];
|
||||
|
||||
/* If it hasn't changed, don't update it */
|
||||
if($config[$k] == $val) continue;
|
||||
// echo $config[$k]." ==? $val";
|
||||
|
||||
/* Prep for MySQL update */
|
||||
$val = mysql_escape_string($val);
|
||||
$v = mysql_escape_string(stripslashes($k));
|
||||
mysql_query("UPDATE config SET val=\"$val\"
|
||||
WHERE var=\"$v\"
|
||||
AND `year`='$year'");
|
||||
print mysql_error();
|
||||
// echo "Saving {$v} = $val<br>";
|
||||
$config_editor_updated = true;
|
||||
$updated = true;
|
||||
}
|
||||
if($updated == true) {
|
||||
$_SESSION['messages'][] = 'config_editor_updated';
|
||||
}
|
||||
return 'update';
|
||||
}
|
||||
}
|
||||
|
||||
/* A complete question editor. Just call it with the
|
||||
* section you want to edit, a year, the array_name to use for
|
||||
* POSTing and GETting the questions (so you can put more than one
|
||||
@ -125,22 +166,21 @@ function config_update_variables($fairyear=NULL, $lastfairyear=NULL)
|
||||
function config_editor($category, $year, $array_name, $self)
|
||||
{
|
||||
global $config;
|
||||
global $config_editor_actions_done, $config_editor_updated;
|
||||
|
||||
if($_POST['action']=="update") {
|
||||
if($config_editor_actions_done == false) {
|
||||
config_editor_handle_actions($year, $array_name);
|
||||
}
|
||||
|
||||
$var = config_editor_parse_from_http_headers($array_name);
|
||||
$varkeys = array_keys($var);
|
||||
foreach($varkeys as $k) {
|
||||
if(is_array($var[$k]))
|
||||
$val = mysql_escape_string(implode(',',$var[$k]));
|
||||
else
|
||||
$val = mysql_escape_string($var[$k]);
|
||||
$v = mysql_escape_string(stripslashes($k));
|
||||
mysql_query("UPDATE config SET val=\"$val\" WHERE var=\"$v\" AND `year`='$year'");
|
||||
print mysql_error();
|
||||
// echo "Saving {$v} = $val<br>";
|
||||
if(is_array($_SESSION['messages'])) {
|
||||
foreach($_SESSION['messages'] as $m) {
|
||||
switch($m) {
|
||||
case 'config_editor_updated':
|
||||
echo happy(i18n("Configuration Updated"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
echo happy(i18n("Configuration Updated"));
|
||||
$_SESSION['messages'] = array();
|
||||
}
|
||||
|
||||
/* Load questions, then handle up and down, because with up and down we
|
||||
@ -267,6 +307,9 @@ function config_editor($category, $year, $array_name, $self)
|
||||
print("<input type=\"submit\" value=\"".i18n("Save Configuration")."\" />\n");
|
||||
|
||||
echo "</form>";
|
||||
|
||||
/* Returns TRUE if config variables were updated */
|
||||
return $updated;
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user