From b7f327454388bee051290d66f9e6ba7c83e2b024 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 22 Jun 2010 21:32:03 +0000 Subject: [PATCH] Massive overhaul of the configuration variables - split into system variables and conference variables - rely on conference_id instead of year --- config/index.php | 6 +- config/systemvariables.php | 83 +++++++++++++++++++++++++ config/variables.php | 56 ++++------------- config_editor.inc.php | 120 +++++++++++++++++++++---------------- db/db.code.version.txt | 2 +- db/db.update.190.php | 32 ++++++++++ db/db.update.190.sql | 104 ++++++++++++++++++++++++++++++++ db/db_update.php | 68 ++++++++++----------- 8 files changed, 337 insertions(+), 134 deletions(-) create mode 100644 config/systemvariables.php create mode 100644 db/db.update.190.php create mode 100644 db/db.update.190.sql diff --git a/config/index.php b/config/index.php index 8db05549..0ea0ae98 100644 --- a/config/index.php +++ b/config/index.php @@ -34,7 +34,8 @@ if($conference['type']=='scienceolympics') { echo ""; echo " "; - echo " "; + echo " "; + echo " "; echo " "; //echo " "; echo " "; @@ -45,7 +46,8 @@ else { echo "
".theme_icon("configuration_variables")."
".i18n("Configuration Variables")."
".theme_icon("configuration_variables")."
".i18n("System Configuration Variables")."
".theme_icon("configuration_variables")."
".i18n("Conference Configuration Variables")."
".theme_icon("important_dates")."
".i18n("Important Dates")."
".theme_icon("project_age_categories")."
".i18n("Age Categories")."
".theme_icon("images")."
".i18n("Images (Fair Logo)")."
"; echo " "; - echo " "; + echo " "; + echo " "; echo " "; echo " "; echo " "; diff --git a/config/systemvariables.php b/config/systemvariables.php new file mode 100644 index 00000000..9717086e --- /dev/null +++ b/config/systemvariables.php @@ -0,0 +1,83 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Configuration' => 'config/index.php') + ,"configuration_variables" + ); + + + $q=mysql_query("SELECT DISTINCT(category) AS cat FROM config WHERE section='system' ORDER BY cat"); + echo "\n
".theme_icon("configuration_variables")."
".i18n("Configuration Variables")."
".theme_icon("configuration_variables")."
".i18n("System Configuration Variables")."
".theme_icon("configuration_variables")."
".i18n("Conference Configuration Variables")."
".theme_icon("important_dates")."
".i18n("Important Dates")."
".theme_icon("project_age_categories")."
".i18n("Project Age Categories")."
".theme_icon("project_divisions")."
".i18n("Project Divisions")."
"; + + echo "
"; + echo ""; + $trclass = 'odd'; + while($r=mysql_fetch_object($q)) { + $trclass = ($trclass == 'odd') ? 'even' : 'odd'; + echo ""; + echo ""; + echo "\n"; + } + echo "
"; + if($r->cat==$category) + echo "".i18n($r->cat).""; + else + echo "cat)."\">".i18n($r->cat).""; + echo "
"; + + echo "
"; + + if($category) { + if($category=="Special") { + echo error(i18n("Warning, modifying values on this configuration variables page could cause your SFIAB to stop working. Only change anything on this page if you really know what you are doing")); + } + + echo "

".i18n($category)."

"; + config_editor($category, 0, "var", $_SERVER['PHP_SELF']); +} +else { + echo i18n("Please choose a configuration category"); +} + + echo "
"; + + send_footer(); +?> diff --git a/config/variables.php b/config/variables.php index e521ce55..8f1eb6f9 100644 --- a/config/variables.php +++ b/config/variables.php @@ -27,9 +27,9 @@ require_once("../config_editor.inc.php"); user_auth_required('committee', 'config'); - $q=mysql_query("SELECT * FROM config WHERE year='-1'"); + $q=mysql_query("SELECT * FROM config WHERE conferences_id='-1' AND conferencetypes LIKE '%{$conference['type']}%'"); while($r=mysql_fetch_object($q)) { - mysql_query("INSERT INTO config (var,val,category,type,type_values,ord,description,year) VALUES ( + mysql_query("INSERT INTO config (var,val,category,type,type_values,ord,description,conferences_id,section,conferencetypes) VALUES ( '".mysql_escape_string($r->var)."', '".mysql_escape_string($r->val)."', '".mysql_escape_string($r->category)."', @@ -37,17 +37,9 @@ '".mysql_escape_string($r->type_values)."', '".mysql_escape_string($r->ord)."', '".mysql_escape_string($r->description)."', - '".$config['FAIRYEAR']."')"); - } - - //for the Special category - if($_POST['action']=="save") { - if($_POST['specialconfig']) { - foreach($_POST['specialconfig'] as $key=>$val) { - mysql_query("UPDATE config SET val='".mysql_escape_string(stripslashes($val))."' WHERE year='0' AND var='$key'"); - } - } - message_push(happy(i18n("Configuration successfully saved"))); + '".mysql_escape_string($conference['id'])."', + '".mysql_escape_string($r->section)."', + '".mysql_escape_string($r->conferencetypes)."')"); } //get the category, and if nothing is chosen, default to Global @@ -55,20 +47,20 @@ else if($_POST['category']) $category=$_POST['category']; else $category="Global"; - $action = config_editor_handle_actions($category, $config['FAIRYEAR'], "var"); + $action = config_editor_handle_actions($category, $conference['id'], "var"); if($action == 'update') { header("Location: variables.php?category=$category"); exit; } - send_header("Configuration Variables", + send_header("Conference Configuration Variables", array('Committee Main' => 'committee_main.php', - 'SFIAB Configuration' => 'config/index.php') + 'Configuration' => 'config/index.php') ,"configuration_variables" ); - $q=mysql_query("SELECT DISTINCT(category) AS cat FROM config ORDER BY cat"); + $q=mysql_query("SELECT DISTINCT(category) AS cat FROM config WHERE conferences_id='{$conference['id']}' ORDER BY cat"); echo "\n"; echo ""); - print(""); + print(""); print("
"; @@ -90,34 +82,8 @@ echo ""; if($category) { - if($category=="Special") { - echo "

".i18n("Special Configuration Settings")."

"; - echo "
"; - echo "\n"; - echo "\n"; - echo ""; - $q=mysql_query("SELECT * FROM config WHERE year=0 ORDER BY var"); - echo ""; - while($r=mysql_fetch_object($q)) { - if($r->var=="FAIRYEAR" || $r->var=="DBVERSION" || $r->var=="FISCALYEAR") { - echo ""; - } - else { - echo ""; - } - } - echo "
"; - echo i18n("Warning, modifying values on this configuration variables page could cause your SFIAB to stop working. Only change anything on this page if you really know what you are doing"); - echo "
$r->var - ".i18n($r->description)."$r->val
$r->var - ".i18n($r->description)."var]\" value=\"$r->val\" />
"; - echo "\n"; - echo "
"; - } - else { -// echo "

".i18n("Configuration settings for fair year %1",array($config['FAIRYEAR']),array("fair year"))."

"; - echo "

".i18n($category)." ({$config['FAIRYEAR']})

"; - - config_editor($category, $config['FAIRYEAR'], "var", $_SERVER['PHP_SELF']); - } + echo "

".i18n($category)." ({$conference['name']})

"; + config_editor($category, $conference['id'], "var", $_SERVER['PHP_SELF']); } else { echo i18n("Please choose a configuration category"); diff --git a/config_editor.inc.php b/config_editor.inc.php index b10e7eef..60c7a10d 100644 --- a/config_editor.inc.php +++ b/config_editor.inc.php @@ -23,9 +23,9 @@ ?> var]['ord'] = $r->ord; $var[$r->var]['type'] = $r->type; $var[$r->var]['type_values'] = $r->type_values; + $var[$r->var]['conferences_id'] = $r->conferences_id; + $var[$r->var]['section'] = $r->section; + $var[$r->var]['conferencetypes'] = $r->conferencetypes; } return $var; } @@ -62,67 +65,78 @@ function config_editor_parse_from_http_headers($array_name) return $ans; } -/* Ensure the fairyear has all variables that are in -1. This is called: +/* Ensure the conferenceid has all variables that are in -1. This is called: * - From the database update script (which could add new variables to - * the -1 year, and we want them automatically copied to the current year + * the -1 conference, and we want them automatically copied to the current conference + +FIXME: this comment is wrong, but im leaving it here for now so we dont forget +FIXME: we need to update the rollover! * - From the rollover script to copy all last year variables to * the new year - * - After an install to copy all the variables to the current year + + * - After an install to copy all the variables to the current conference */ -function config_update_variables($fairyear=NULL, $lastfairyear=NULL) +function config_update_variables($conference_id=NULL, $last_conference_id=NULL) { global $config; + global $conference; - /* if fairyear isn't specified... */ - if($fairyear == NULL) $fairyear = $config['FAIRYEAR']; - if($lastfairyear == NULL) $lastfairyear = $fairyear - 1; + /* if conference isn't specified... */ + if($conference_id == NULL && $last_conference_id==NULL) { + //FIXME: what the heck do we do? + } + else { + // if($lastfairyear == NULL) $lastfairyear = $fairyear - 1; - /* The master list of variables is the year=-1, grab - * ALL config variables that exist for -1 but - * do NOT exist for $fairyear */ - $q = "SELECT config.var FROM `config` - LEFT JOIN `config` AS C2 ON(config.var=C2.var - AND C2.year='$fairyear') - WHERE config.year=-1 AND C2.year IS NULL"; - $r = mysql_query($q); - while($i = mysql_fetch_assoc($r)) { - $var = $i['var']; - /* See if this var exists for last year or - * the -1 year, prefer last year's value */ - $q = "SELECT * FROM `config` - WHERE config.var='$var' - AND (config.year='$lastfairyear' - OR config.year='-1') - ORDER BY config.year DESC"; - $r2 = mysql_query($q); - if(mysql_num_rows($r2) < 1) { - /* Uhoh, this shouldn't happen */ - echo "ERROR, Variable '$var' doesn't exist"; - exit; + /* The master list of variables is the year=-1, grab + * ALL config variables that exist for -1 but + * do NOT exist for $fairyear */ + $q = "SELECT config.var FROM `config` + LEFT JOIN `config` AS C2 ON(config.var=C2.var + AND C2.conferences_id='$conference_id') + WHERE config.conferences_id=-1 AND C2.conferences_id IS NULL"; + $r = mysql_query($q); + while($i = mysql_fetch_assoc($r)) { + $var = $i['var']; + /* See if this var exists for last year or + * the -1 year, prefer last year's value */ + $q = "SELECT * FROM `config` + WHERE config.var='$var' + AND (config.conferences_id='$last_conference_id' + OR config.conferences_id='-1') + ORDER BY config.conferences_id DESC"; + $r2 = mysql_query($q); + if(mysql_num_rows($r2) < 1) { + /* Uhoh, this shouldn't happen */ + echo "ERROR, Variable '$var' doesn't exist"; + exit; + } + $v = mysql_fetch_object($r2); + + mysql_query("INSERT INTO config (var,val,category,type,type_values,ord,description,conferences_id,section,conferencetypes) VALUES ( + '".mysql_escape_string($v->var)."', + '".mysql_escape_string($v->val)."', + '".mysql_escape_string($v->category)."', + '".mysql_escape_string($v->type)."', + '".mysql_escape_string($v->type_values)."', + '".mysql_escape_string($v->ord)."', + '".mysql_escape_string($v->description)."', + '".mysql_escape_string($conference_id)."', + '".mysql_escape_string($v->section)."', + '".mysql_escape_string($v->conferencetypes)."')"); } - $v = mysql_fetch_object($r2); - - mysql_query("INSERT INTO config (var,val,category,type,type_values,ord,description,year) VALUES ( - '".mysql_escape_string($v->var)."', - '".mysql_escape_string($v->val)."', - '".mysql_escape_string($v->category)."', - '".mysql_escape_string($v->type)."', - '".mysql_escape_string($v->type_values)."', - '".mysql_escape_string($v->ord)."', - '".mysql_escape_string($v->description)."', - '$fairyear')"); } } $config_editor_actions_done = false; $config_editor_updated = false; -function config_editor_handle_actions($category, $year, $array_name) +function config_editor_handle_actions($category, $conference_id, $array_name) { global $config; global $config_editor_actions_done; - $config_vars = config_editor_load($category, $year); + $config_vars = config_editor_load($category, $conference_id); $config_editor_actions_done = true; $updated = false; @@ -155,7 +169,7 @@ function config_editor_handle_actions($category, $year, $array_name) $v = mysql_escape_string(stripslashes($k)); mysql_query("UPDATE config SET val=\"$val\" WHERE var=\"$v\" - AND `year`='$year'"); + AND `conferences_id`='$conference_id'"); print mysql_error(); // echo "Saving {$v} = $val
"; $config_editor_updated = true; @@ -169,25 +183,25 @@ function config_editor_handle_actions($category, $year, $array_name) } /* 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 conference, the array_name to use for * POSTing and GETting the questions (so you can put more than one * edtior on a single page), and give it $_SERVER['PHP_SELF'], because * php_self inside this function is this file. * FUTURE WORK: it would be nice to hide the order, and just implement * a bunch of up/down arrows, and dynamically compute the order for * all elements */ -function config_editor($category, $year, $array_name, $self) +function config_editor($category, $conference_id, $array_name, $self) { global $config; global $config_editor_actions_done, $config_editor_updated; if($config_editor_actions_done == false) { - config_editor_handle_actions($category, $year, $array_name); + config_editor_handle_actions($category, $conference_id, $array_name); } /* Load questions, then handle up and down, because with up and down we * have to modify 2 questions to maintain the order */ - $var = config_editor_load($category, $year); + $var = config_editor_load($category, $conference_id); echo "
"; @@ -212,7 +226,13 @@ function config_editor($category, $year, $array_name, $self) $line++; print("
".i18n($var[$k]['desc']).""); + if($var[$k]['desc']) { + echo i18n($var[$k]['desc']); + } else { + echo $k; + } + print(""); $val = htmlspecialchars($var[$k]['val']); diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 6c412452..598ed30e 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -189 +190 diff --git a/db/db.update.190.php b/db/db.update.190.php new file mode 100644 index 00000000..869598f7 --- /dev/null +++ b/db/db.update.190.php @@ -0,0 +1,32 @@ +0"); + while($r=mysql_fetch_object($q)) { + echo " Updating config for year={$r->year} to conferences_id={$r->id}\n"; + mysql_query("UPDATE config SET conferences_id='$r->id' WHERE year='$r->year'"); + } +} + +function db_update_190_post() +{ + global $config; + $q=mysql_query("SELECT DISTINCT var FROM config WHERE section='system'"); + while($r=mysql_fetch_object($q)) { + echo " Upgrading system variable $r->var ... "; + $q2=mysql_query("SELECT * FROM config WHERE var='$r->var' ORDER BY year DESC LIMIT 1"); + $r2=mysql_fetch_object($q2); + if($r2->year!=0) { + echo " copying from year {$r2->year} ... "; + mysql_query("UPDATE config SET conferences_id=0, year=0 WHERE var='$r->var' AND year='$r2->year'"); + } + else + echo " no year based record to udpate "; + + mysql_query("DELETE FROM config WHERE var='$r->var' AND (conferences_id>0 OR year>0)"); + echo " deleted ".mysql_affected_rows()." old year-based records\n"; + } +} + +?> diff --git a/db/db.update.190.sql b/db/db.update.190.sql new file mode 100644 index 00000000..551ba4c2 --- /dev/null +++ b/db/db.update.190.sql @@ -0,0 +1,104 @@ +ALTER TABLE `config` ADD `section` ENUM( 'system', 'conference' ) NOT NULL; +ALTER TABLE `config` ADD `conferencetypes` SET( 'sciencefair', 'scienceolympics' ) NULL DEFAULT NULL; +UPDATE config SET `section`='system' WHERE `category`='Committee Members' AND var='committee_personal_fields'; +UPDATE config SET `section`='system' WHERE `category`='Committee Members' AND var='committee_personal_required'; +UPDATE config SET `section`='system' WHERE `category`='Feeder Fairs' AND var='fairs_name'; +UPDATE config SET `section`='system' WHERE `category`='Fundraising' AND var='charity_number'; +UPDATE config SET `section`='system' WHERE `category`='Fundraising' AND var='fiscal_yearend'; +UPDATE config SET `section`='system' WHERE `category`='Fundraising' AND var='registered_charity'; +UPDATE config SET `section`='system' WHERE `category`='Global' AND var='committee_publiclayout'; +UPDATE config SET `section`='system' WHERE `category`='Global' AND var='default_language'; +UPDATE config SET `section`='system' WHERE `category`='Global' AND var='fairmanageremail'; +UPDATE config SET `section`='system' WHERE `category`='Global' AND var='fairname'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Global' AND var='filterdivisionbycategory'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Global' AND var='project_num_format'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Global' AND var='project_sort_format'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Global' AND var='winners_show_prize_amounts'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='judges_availability_enable'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='judges_password_expiry_days'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Registration' AND var='judges_specialaward_enable'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Registration' AND var='judges_specialaward_max'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Registration' AND var='judges_specialaward_min'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Registration' AND var='judges_specialaward_only_enable'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='judge_personal_fields'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='judge_personal_required'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='judge_registration_singlepassword'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='judge_registration_type'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='maxjudgeage'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Judge Registration' AND var='minjudgeage'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='effort'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='max_judges_per_team'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='max_projects_per_team'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='min_judges_per_team'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='projects_per_special_award_judge'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='project_status'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='scheduler_enable_sa_scheduling'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Judge Scheduler' AND var='times_judged'; +UPDATE config SET `section`='system' WHERE `category`='Localization' AND var='country'; +UPDATE config SET `section`='system' WHERE `category`='Localization' AND var='dateformat'; +UPDATE config SET `section`='system' WHERE `category`='Localization' AND var='postalzip'; +UPDATE config SET `section`='system' WHERE `category`='Localization' AND var='provincestate'; +UPDATE config SET `section`='system' WHERE `category`='Localization' AND var='timeformat'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='maxage'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='maxgrade'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='maxmentorsperproject'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='maxspecialawardsperproject'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='maxstudentsperproject'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='minage'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='mingrade'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='minmentorsperproject'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='minstudentsperproject'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_mentor'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_project_electricity'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_project_summary_wordmax'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_project_summary_wordmin'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_project_table'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_project_title_charmax'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_regfee_items_enable'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_registration_singlepassword'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_registration_type'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_short_title_charmax'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='participant_short_title_enable'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_student_foodreq'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_student_personal'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_student_pronunciation'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_student_tshirt'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Participant Registration' AND var='participant_student_tshirt_cost'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='regfee'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='regfee_per'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='regfee_show_info'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='specialawardnomination'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='specialawardnomination_aftersignatures'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Participant Registration' AND var='usedivisionselector'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Reports' AND var='reports_show_criteria'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Reports' AND var='reports_show_unawarded_awards'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Reports' AND var='reports_show_unawarded_prizes'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Science Fairs' AND var='fairs_allow_login'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair' WHERE `category`='Science Fairs' AND var='fairs_enable'; +UPDATE config SET `section`='system' WHERE `category`='Special' AND var='DBVERSION'; +UPDATE config SET `section`='system' WHERE `category`='Special' AND var='emailqueue_lock'; +UPDATE config SET `section`='system' WHERE `category`='Special' AND var='FAIRYEAR'; +UPDATE config SET `section`='system' WHERE `category`='Special' AND var='FISCALYEAR'; +UPDATE config SET `section`='system' WHERE `category`='Special' AND var='judge_scheduler_activity'; +UPDATE config SET `section`='system' WHERE `category`='Special' AND var='judge_scheduler_percent'; +UPDATE config SET `section`='system' WHERE `category`='Special' AND var='SFIABDIRECTORY'; +UPDATE config SET `section`='system' WHERE `category`='Sponsors' AND var='sponsor_personal_fields'; +UPDATE config SET `section`='system' WHERE `category`='Sponsors' AND var='sponsor_personal_required'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Tour Assigner' AND var='tours_assigner_activity'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Tour Assigner' AND var='tours_assigner_effort'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Tour Assigner' AND var='tours_assigner_percent'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Tours' AND var='tours_choices_max'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Tours' AND var='tours_choices_min'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Tours' AND var='tours_enable'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Volunteer Registration' AND var='volunteer_enable'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Volunteer Registration' AND var='volunteer_password_expiry_days'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Volunteer Registration' AND var='volunteer_personal_fields'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Volunteer Registration' AND var='volunteer_personal_required'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Volunteer Registration' AND var='volunteer_registration_singlepassword'; +UPDATE config SET `section`='conference', conferencetypes='sciencefair,scienceolympics' WHERE `category`='Volunteer Registration' AND var='volunteer_registration_type'; +UPDATE config SET `section`='system', category='Global' WHERE var='theme'; +UPDATE config SET `section`='system', category='Global' WHERE var='theme_icons'; +UPDATE config SET conferences_id=-1 WHERE year=-1; +UPDATE config SET conferences_id=0 WHERE year=0; +ALTER TABLE `config` ADD UNIQUE ( `var` , `conferences_id`); +ALTER TABLE `config` DROP INDEX var; diff --git a/db/db_update.php b/db/db_update.php index 15954411..35c6b014 100644 --- a/db/db_update.php +++ b/db/db_update.php @@ -8,68 +8,69 @@ if(!function_exists("system")) { //so we have the db connection info require("../data/config.inc.php"); echo "
\n";
-if(file_exists("db.code.version.txt"))
-{
+if(file_exists("db.code.version.txt")) {
 	$dbcodeversion_file=file("db.code.version.txt");
 	$dbcodeversion=trim($dbcodeversion_file[0]);
 }
-else
-{
+else {
 	echo "Couldnt load current db.code.version.txt\n";
 	exit;
 }
 
-
 mysql_connect($DBHOST,$DBUSER,$DBPASS);
 mysql_select_db($DBNAME);
 @mysql_query("SET NAMES utf8");
 $q=mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'");
 $r=mysql_fetch_object($q);
 $dbdbversion=$r->val;
-if(!$dbdbversion)
-{
+if(!$dbdbversion) {
 	echo "Couldnt get current db version.  Is SFIAB properly installed?\n";
 	exit;
 }
 
-/* Get the fair year */
-$q=mysql_query("SELECT val FROM config WHERE var='FAIRYEAR' AND year='0'");
-$r=mysql_fetch_object($q);
-$config = array('FAIRYEAR' => $r->val);
+if($dbdbversion>=190) {
+	//we can only load in the 'system', because when running from here we have no clue what
+	//conference the script is interested in
+	//also, FAIRYEAR doesnt exist anymore
 
-/* Load config just in case there's a PHP script that wants it */
-$q=mysql_query("SELECT * FROM config WHERE year='{$config['FAIRYEAR']}'");
-while($r=mysql_fetch_object($q)) $config[$r->var]=$r->val;
+	/* Load config just in case there's a PHP script that wants it */
+	$q=mysql_query("SELECT * FROM config WHERE section='system' AND conferences_id=0");
+	while($r=mysql_fetch_object($q)) $config[$r->var]=$r->val;
+}
+else {
+	/* Get the fair year */
+	$q=mysql_query("SELECT val FROM config WHERE var='FAIRYEAR' AND year='0'");
+	$r=mysql_fetch_object($q);
+	$config = array('FAIRYEAR' => $r->val);
+
+	/* Load config just in case there's a PHP script that wants it */
+	$q=mysql_query("SELECT * FROM config WHERE year='{$config['FAIRYEAR']}'");
+	while($r=mysql_fetch_object($q)) $config[$r->var]=$r->val;
+}
 
 
 require_once("../config_editor.inc.php"); // For config_update_variables()
 
-if($dbcodeversion && $dbdbversion)
-{
+if($dbcodeversion && $dbdbversion) {
 	//lets see if they match
-	if($dbcodeversion == $dbdbversion)
-	{
+	if($dbcodeversion == $dbdbversion) {
 		echo "DB and CODE are all up-to-date.  Version: $dbdbversion\n";
 		exit;
 	}
-	else if($dbcodeversion<$dbdbversion)
-	{
+	else if($dbcodeversion<$dbdbversion) {
 		echo "ERROR: dbcodeversion$dbdbversion)
-	{
+	else if($dbcodeversion>$dbdbversion) {
 		echo "DB update requirements detected\n";
 		echo "Current DB Version: $dbdbversion\n";
 		echo "Current CODE Version: $dbcodeversion\n";
 
 		echo "Updating database from $dbdbversion to $dbcodeversion\n";
 
-		for($ver=$dbdbversion+1;$ver<=$dbcodeversion;$ver++)
-		{
-			if(file_exists("db.update.$ver.php"))
-			{
+		for($ver=$dbdbversion+1;$ver<=$dbcodeversion;$ver++) {
+			if(file_exists("db.update.$ver.php")) {
 				include("db.update.$ver.php");
 			}
 			if(is_callable("db_update_{$ver}_pre")) {
@@ -77,15 +78,13 @@ if($dbcodeversion && $dbdbversion)
 				call_user_func("db_update_{$ver}_pre");
 				echo "db.update.$ver.php::db_update_{$ver}_pre() done.\n";
 			}
-			if(file_exists("db.update.$ver.sql"))
-			{
+			if(file_exists("db.update.$ver.sql")) {
 				echo "db.update.$ver.sql detected - running...\n";
 				readfile("db.update.$ver.sql");
 				echo "\n";
 				system("mysql --default-character-set=utf8 -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME