From 414a85ccb231db7a98513ae464de519099eeead5 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 28 Jan 2008 21:48:44 +0000 Subject: [PATCH] - Add number checking (and parsing) to the config editor - Change the type of $config['regfee'] to 'number' --- admin/judges_schedulerconfig.php | 2 +- admin/tours_sa_config.php | 2 +- config_editor.inc.php | 23 ++++++++++++++++++----- db/db.code.version.txt | 2 +- db/db.update.103.sql | 1 + 5 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 db/db.update.103.sql diff --git a/admin/judges_schedulerconfig.php b/admin/judges_schedulerconfig.php index 7d3c172..2a2496e 100644 --- a/admin/judges_schedulerconfig.php +++ b/admin/judges_schedulerconfig.php @@ -30,7 +30,7 @@ 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"); + $action = config_editor_handle_actions("Judge Scheduler", $config['FAIRYEAR'], "var"); if($action == 'update') { header("Location: judges_schedulerconfig.php"); exit; diff --git a/admin/tours_sa_config.php b/admin/tours_sa_config.php index 7049d63..4eff3a9 100644 --- a/admin/tours_sa_config.php +++ b/admin/tours_sa_config.php @@ -35,7 +35,7 @@ ogram; see the file COPYING. If not, write to exit; } - $action = config_editor_handle_actions( $config['FAIRYEAR'], "var"); + $action = config_editor_handle_actions("Tour Assigner", $config['FAIRYEAR'], "var"); if($action == 'update') { header('Location: tours_sa_config.php'); exit; diff --git a/config_editor.inc.php b/config_editor.inc.php index 8f2a954..1e71c18 100644 --- a/config_editor.inc.php +++ b/config_editor.inc.php @@ -117,11 +117,13 @@ 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) +function config_editor_handle_actions($category, $year, $array_name) { global $config; global $config_editor_actions_done; + $config_vars = config_editor_load($category, $year); + $config_editor_actions_done = true; $updated = false; if($_POST['action']=="update") { @@ -133,9 +135,20 @@ function config_editor_handle_actions($year, $array_name) else $val = $var[$k]; - /* If it hasn't changed, don't update it */ - if($config[$k] == $val) continue; -// echo $config[$k]." ==? $val"; + /* If it hasn't changed, don't update it (do a string + * compare so numbers aren't interpreted.. php thinks + * "1.0" == "1") */ + if(strcmp($config[$k], $val) == 0) continue; + + switch($config_vars[$k]['type']) { + case 'number': + if(ereg("[0-9]+(\.[0-9]+)?", $val, $regs)) { + $val = $regs[0]; + } else { + $val = 0; + } + break; + } /* Prep for MySQL update */ $val = mysql_escape_string($val); @@ -169,7 +182,7 @@ function config_editor($category, $year, $array_name, $self) global $config_editor_actions_done, $config_editor_updated; if($config_editor_actions_done == false) { - config_editor_handle_actions($year, $array_name); + config_editor_handle_actions($category, $year, $array_name); } if(is_array($_SESSION['messages'])) { diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 257e563..a9c8fe8 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -102 +103 diff --git a/db/db.update.103.sql b/db/db.update.103.sql new file mode 100644 index 0000000..b1f0bea --- /dev/null +++ b/db/db.update.103.sql @@ -0,0 +1 @@ +UPDATE `config` SET `type` = 'number' WHERE `var` = 'regfee';