- 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:
dave 2007-12-20 08:20:29 +00:00
parent c8d01cb8fb
commit 984c9776ef
3 changed files with 70 additions and 16 deletions

View File

@ -30,14 +30,20 @@ ogram; see the file COPYING. If not, write to
require("judges.inc.php"); require("judges.inc.php");
require("judges_schedulerconfig_check.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", send_header("Judge Scheduler Configuration",
array('Committee Main' => 'committee_main.php', array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php', 'Administration' => 'admin/index.php',
'Judges' => 'admin/judges.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 />"; echo "<hr />";
if($_GET['action']=="reset") if($_GET['action']=="reset")

View File

@ -34,7 +34,12 @@ ogram; see the file COPYING. If not, write to
header("Location: tours_sa_status.php"); header("Location: tours_sa_status.php");
exit; 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", send_header("Automatic Tour Assignment Configuration",
array('Committee Main' => 'committee_main.php', array('Committee Main' => 'committee_main.php',

View File

@ -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 /* A complete question editor. Just call it with the
* section you want to edit, a year, the array_name to use for * 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 * 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) function config_editor($category, $year, $array_name, $self)
{ {
global $config; 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); if(is_array($_SESSION['messages'])) {
$varkeys = array_keys($var); foreach($_SESSION['messages'] as $m) {
foreach($varkeys as $k) { switch($m) {
if(is_array($var[$k])) case 'config_editor_updated':
$val = mysql_escape_string(implode(',',$var[$k])); echo happy(i18n("Configuration Updated"));
else break;
$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>";
} }
echo happy(i18n("Configuration Updated")); $_SESSION['messages'] = array();
} }
/* Load questions, then handle up and down, because with up and down we /* 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"); print("<input type=\"submit\" value=\"".i18n("Save Configuration")."\" />\n");
echo "</form>"; echo "</form>";
/* Returns TRUE if config variables were updated */
return $updated;
} }
?> ?>