Massive overhaul of the configuration variables

- split into system variables and conference variables
- rely on conference_id instead of year
This commit is contained in:
james 2010-06-22 21:32:03 +00:00
parent b3448b7c7c
commit b7f3274543
8 changed files with 337 additions and 134 deletions

View File

@ -34,7 +34,8 @@
if($conference['type']=='scienceolympics') {
echo "<table class=\"adminconfigtable\">";
echo " <tr>";
echo " <td><a href=\"variables.php\">".theme_icon("configuration_variables")."<br />".i18n("Configuration Variables")."</a></td>";
echo " <td><a href=\"systemvariables.php\">".theme_icon("configuration_variables")."<br />".i18n("System Configuration Variables")."</a></td>";
echo " <td><a href=\"variables.php\">".theme_icon("configuration_variables")."<br />".i18n("Conference Configuration Variables")."</a></td>";
echo " <td><a href=\"dates.php\">".theme_icon("important_dates")."<br />".i18n("Important Dates")."</a></td>";
//echo " <td><a href=\"categories.php\">".theme_icon("project_age_categories")."<br />".i18n("Age Categories")."</a></td>";
echo " <td><a href=\"images.php\">".theme_icon("images")."<br />".i18n("Images (Fair Logo)")."</a></td>";
@ -45,7 +46,8 @@
else {
echo "<table class=\"adminconfigtable\">";
echo " <tr>";
echo " <td><a href=\"variables.php\">".theme_icon("configuration_variables")."<br />".i18n("Configuration Variables")."</a></td>";
echo " <td><a href=\"systemvariables.php\">".theme_icon("configuration_variables")."<br />".i18n("System Configuration Variables")."</a></td>";
echo " <td><a href=\"variables.php\">".theme_icon("configuration_variables")."<br />".i18n("Conference Configuration Variables")."</a></td>";
echo " <td><a href=\"dates.php\">".theme_icon("important_dates")."<br />".i18n("Important Dates")."</a></td>";
echo " <td><a href=\"categories.php\">".theme_icon("project_age_categories")."<br />".i18n("Project Age Categories")."</a></td>";
echo " <td><a href=\"divisions.php\">".theme_icon("project_divisions")."<br />".i18n("Project Divisions")."</a></td>";

View File

@ -0,0 +1,83 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
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.
*/
?>
<?
require("../common.inc.php");
require_once("../user.inc.php");
require_once("../config_editor.inc.php");
user_auth_required('committee', 'config');
//get the category, and if nothing is chosen, default to Global
if($_GET['category']) $category=$_GET['category'];
else if($_POST['category']) $category=$_POST['category'];
else $category="Global";
$action = config_editor_handle_actions($category, 0, "var");
if($action == 'update') {
header("Location: systemvariables.php?category=$category");
exit;
}
send_header("Configuration - System Variables",
array('Committee Main' => '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<table valign=\"top\" cellspacing=0 cellpadding=5 border=0>";
echo "<tr><td width=\"120\" style=\"border-right: 1px solid black;\">";
echo "<table cellspacing=0 cellpadding=3 border=0>";
$trclass = 'odd';
while($r=mysql_fetch_object($q)) {
$trclass = ($trclass == 'odd') ? 'even' : 'odd';
echo "<tr class=\"$trclass\">";
echo "<td align=\"right\">";
if($r->cat==$category)
echo "<b>".i18n($r->cat)."</b>";
else
echo "<a href=\"".$_SERVER['PHP_SELF']."?category=".urlencode($r->cat)."\">".i18n($r->cat)."</a>";
echo "</td>";
echo "</tr>\n";
}
echo "</table>";
echo "</td><td>";
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 "<h3>".i18n($category)."</h3>";
config_editor($category, 0, "var", $_SERVER['PHP_SELF']);
}
else {
echo i18n("Please choose a configuration category");
}
echo "</td></tr></table>";
send_footer();
?>

View File

@ -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<table valign=\"top\" cellspacing=0 cellpadding=5 border=0>";
echo "<tr><td width=\"120\" style=\"border-right: 1px solid black;\">";
@ -90,34 +82,8 @@
echo "</td><td>";
if($category) {
if($category=="Special") {
echo "<h3>".i18n("Special Configuration Settings")."</h3>";
echo "<form method=\"post\" action=\"variables.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"save\">\n";
echo "<input type=\"hidden\" name=\"category\" value=\"Special\">\n";
echo "<table cellpadding=\"3\">";
$q=mysql_query("SELECT * FROM config WHERE year=0 ORDER BY var");
echo "<tr><td colspan=\"2\">";
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 "</td></tr>";
while($r=mysql_fetch_object($q)) {
if($r->var=="FAIRYEAR" || $r->var=="DBVERSION" || $r->var=="FISCALYEAR") {
echo "<tr><td><b>$r->var</b> - ".i18n($r->description)."</td><td>$r->val</td></tr>";
}
else {
echo "<tr><td><b>$r->var</b> - ".i18n($r->description)."</td><td><input type=\"text\" name=\"specialconfig[$r->var]\" value=\"$r->val\" /></td></tr>";
}
}
echo "</table>";
echo "<input type=\"submit\" value=\"".i18n("Save Configuration")."\" />\n";
echo "</form>";
}
else {
// echo "<h3>".i18n("Configuration settings for fair year %1",array($config['FAIRYEAR']),array("fair year"))."</h3>";
echo "<h3>".i18n($category)." ({$config['FAIRYEAR']})</h3>";
config_editor($category, $config['FAIRYEAR'], "var", $_SERVER['PHP_SELF']);
}
echo "<h3>".i18n($category)." ({$conference['name']})</h3>";
config_editor($category, $conference['id'], "var", $_SERVER['PHP_SELF']);
}
else {
echo i18n("Please choose a configuration category");

View File

@ -23,9 +23,9 @@
?>
<?
function config_editor_load($category, $year)
function config_editor_load($category, $conference_id)
{
$query = "SELECT * FROM config WHERE year='$year' AND category='$category' ORDER BY ord";
$query = "SELECT * FROM config WHERE conferences_id='$conference_id' AND category='$category' ORDER BY ord";
$q = mysql_query($query);
print(mysql_error());
@ -37,6 +37,9 @@ function config_editor_load($category, $year)
$var[$r->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<br>";
$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 "<form method=\"post\" action=\"$self\">";
@ -212,7 +226,13 @@ function config_editor($category, $year, $array_name, $self)
$line++;
print("<tr class=\"$trclass\">");
print("<td>".i18n($var[$k]['desc'])."</td>");
print("<td>");
if($var[$k]['desc']) {
echo i18n($var[$k]['desc']);
} else {
echo $k;
}
print("</td>");
print("<td>");
$val = htmlspecialchars($var[$k]['val']);

View File

@ -1 +1 @@
189
190

32
db/db.update.190.php Normal file
View File

@ -0,0 +1,32 @@
<?
function db_update_190_pre()
{
//before we do this, make sure we set the configuration variables based on the conferences.
$q=mysql_query("SELECT * FROM conferences WHERE type='sciencefair' AND year>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";
}
}
?>

104
db/db.update.190.sql Normal file
View File

@ -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;

View File

@ -8,68 +8,69 @@ if(!function_exists("system")) {
//so we have the db connection info
require("../data/config.inc.php");
echo "<pre>\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 ($dbcodeversion<$dbdbversion). This should not happen!";
exit;
}
else if($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 <db.update.$ver.sql");
}
else
{
else {
echo "Version $ver SQL update file not found - skipping over\n";
}
if(is_callable("db_update_{$ver}_post")) {
@ -96,17 +95,14 @@ if($dbcodeversion && $dbdbversion)
}
if($db_update_skip_variables != true) {
echo "\nUpdating Configuration Variables...\n";
config_update_variables($config['FAIRYEAR']);
config_update_variables();
}
echo "\nAll done - updating new DB version to $dbcodeversion\n";
mysql_query("UPDATE config SET val='$dbcodeversion' WHERE var='DBVERSION' AND year='0'");
mysql_query("UPDATE config SET val='$dbcodeversion' WHERE var='DBVERSION' AND conferences_id='0'");
}
}
else
{
else {
echo "ERROR: dbcodeversion and dbdbversion are not defined\n";
}