diff --git a/admin/judges_schedulerconfig.php b/admin/judges_schedulerconfig.php
index 1640c0e..c37171a 100644
--- a/admin/judges_schedulerconfig.php
+++ b/admin/judges_schedulerconfig.php
@@ -36,14 +36,6 @@ ogram; see the file COPYING. If not, write to
'Judges' => 'admin/judges.php')
);
- config_editor_require_vars("Judge Scheduler", $config['FAIRYEAR'],
- array( "max_projects_per_team", "times_judged",
- "min_judges_per_team", "max_judges_per_team",
- "effort", "project_status") );
- config_editor_require_vars("Judge Scheduler", 0,
- array( "judge_scheduler_percent",
- "judge_scheduler_activity" ) );
-
config_editor("Judge Scheduler", $config['FAIRYEAR'], "var", $_SERVER['PHP_SELF']);
echo "
";
diff --git a/config/rollover.php b/config/rollover.php
index 85f23a7..e734657 100644
--- a/config/rollover.php
+++ b/config/rollover.php
@@ -24,6 +24,7 @@
require("../common.inc.php");
require_once("../user.inc.php");
+ require_once("../config_editor.inc.php");
user_auth_required('committee', 'config');
send_header("Year Rollover",
array('Committee Main' => 'committee_main.php',
@@ -67,18 +68,7 @@
//first, lets do all of the configuration variables
echo i18n("Rolling configuration variables")."
";
- $q=mysql_query("SELECT * FROM config WHERE year='$currentfairyear'");
- echo mysql_error();
- while($r=mysql_fetch_object($q))
- mysql_query("INSERT INTO config (var,val,category,ord,description,type,type_values,year) VALUES (
- '".mysql_escape_string($r->var)."',
- '".mysql_escape_string($r->val)."',
- '".mysql_escape_string($r->category)."',
- '".mysql_escape_string($r->ord)."',
- '".mysql_escape_string($r->description)."',
- '".mysql_escape_string($r->type)."',
- '".mysql_escape_string($r->type_values)."',
- '".mysql_escape_string($newfairyear)."')");
+ config_update_variables($newfairyear, $currentfairyear);
//now the dates
echo i18n("Rolling dates")."
";
diff --git a/config_editor.inc.php b/config_editor.inc.php
index 8d34de5..0ab52ed 100644
--- a/config_editor.inc.php
+++ b/config_editor.inc.php
@@ -53,31 +53,58 @@ function config_editor_parse_from_http_headers($array_name)
return $ans;
}
-function config_editor_require_vars($category, $year, $varlist)
+/* Ensure the fairyear 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
+ * - 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
+ */
+function config_update_variables($fairyear=NULL, $lastfairyear=NULL)
{
global $config;
- foreach($varlist as $v) {
- if(isset($config[$v])) continue;
- /* FInd var with year = -1 */
- $q = mysql_query("SELECT * FROM config WHERE ".
- "var='$v' AND year='-1'");
- if(mysql_num_rows($q) != 1) {
- /* Insert a dummy */
- mysql_query("INSERT INTO `config` (`var`, `val`,
- `description`, `category`, `type`, `type_values`,
- `year`, `ord`) VALUES ('$v', '', '',
- '$category', 'text', '', $year, 99999)");
- } else {
- $r = mysql_fetch_object($q);
- mysql_query("INSERT INTO `config` (`var`, `val`,
- `description`, `category`, `type`, `type_values`,
- `year`, `ord`) VALUES ('$v', '{$r->val}',
- '{$r->description}', '{$r->category}', '{$r->type}',
- '{$r->type_values}', '$year', {$r->ord})");
+ /* if fairyear isn't specified... */
+ if($fairyear == NULL) $fairyear = $config['FAIRYEAR'];
+ 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";
+ $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,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')");
}
}
+
/* 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
diff --git a/db/db_update.php b/db/db_update.php
index 4ba3fa9..01809f6 100644
--- a/db/db_update.php
+++ b/db/db_update.php
@@ -31,6 +31,13 @@ if(!$dbdbversion)
exit;
}
+/* Get the fair year */
+$q=mysql_query("SELECT val FROM config WHERE var='FAIRYEAR' AND year='0'");
+$r=mysql_fetch_object($q);
+$fairyear=$r->val;
+
+require_once("../config_editor.inc.php"); // For config_update_variables()
+
if($dbcodeversion && $dbdbversion)
{
//lets see if they match
@@ -81,8 +88,15 @@ if($dbcodeversion && $dbdbversion)
echo "db.update.$ver.php::db_update_{$ver}_post() done.\n";
}
}
+ if($db_update_skip_variables != true) {
+ echo "\nUpdating Configuration Variables...\n";
+ config_update_variables($fairyear);
+ }
+
echo "\nAll done - updating new DB version to $dbcodeversion\n";
mysql_query("UPDATE config SET val='$dbcodeversion' WHERE var='DBVERSION' AND year='0'");
+
+
}
}
diff --git a/install2.php b/install2.php
index 5ec64b4..6b47be5 100644
--- a/install2.php
+++ b/install2.php
@@ -127,6 +127,9 @@ mysql_select_db($DBNAME);
echo "Attempting to update database using standard update script to update from $x to $dbcodeversion
";
echo "
Please scroll to the bottom of this page for the link to the next step of the installation process.
";
chdir ("db");
+ /* Update the database, but don't update the config variables yet, because
+ * We haven't set the FAIRYEAR */
+ $db_update_skip_variables = true;
include "db_update.php";
chdir ("../");
diff --git a/install3.php b/install3.php
index 2d918e2..f8868b5 100644
--- a/install3.php
+++ b/install3.php
@@ -39,6 +39,8 @@ if(!file_exists("data/config.inc.php"))
}
require_once("data/config.inc.php");
+require_once("config_editor.inc.php");
+require_once("user.inc.php");
mysql_connect($DBHOST,$DBUSER,$DBPASS);
mysql_select_db($DBNAME);
@@ -108,22 +110,21 @@ if($_POST['action']=="save")
echo "Creating configuration settings...";
mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('FAIRYEAR','".$_POST['fairyear']."','Special','0','0')");
mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('SFIABDIRECTORY','".$_POST['sfiabdirectory']."','Special','','0')");
+
+ $year = intval($_POST['fairyear']);
//copy over the config defautls
- $q=mysql_query("SELECT * FROM config WHERE year='-1'");
- while($r=mysql_fetch_object($q))
- {
- //add the actual fair name, and just insert the defaults of everything else
- if($r->var=="fairname")
- mysql_query("INSERT INTO config (var,val,description,category,ord,year,type,type_values) VALUES ('$r->var','".mysql_escape_string(stripslashes($_POST['fairname']))."','".mysql_escape_string($r->description)."','".mysql_escape_string($r->category)."','$r->ord','".$_POST['fairyear']."','".mysql_escape_string($r->type)."','".mysql_escape_string($r->type_values)."')");
- //add the fair manager as well
- else if($r->var=="fairmanager")
- mysql_query("INSERT INTO config (var,val,description,category,ord,year,type,type_values) VALUES ('$r->var','".mysql_escape_string(stripslashes($_POST['email']))."','".mysql_escape_string($r->description)."','".mysql_escape_string($r->category)."','$r->ord','".$_POST['fairyear']."','".mysql_escape_string($r->type)."','".mysql_escape_string($r->type_values)."')");
- else
- mysql_query("INSERT INTO config (var,val,description,category,ord,year,type,type_values) VALUES ('$r->var','$r->val','".mysql_escape_string($r->description)."','".mysql_escape_string($r->category)."','$r->ord','".$_POST['fairyear']."','".mysql_escape_string($r->type)."','".mysql_escape_string($r->type_values)."')");
- }
+ config_update_variables($year);
+
+ // Update some variables
+ mysql_query("UPDATE config SET
+ val='".mysql_escape_string(stripslashes($_POST['fairname']))."'
+ WHERE var='fairname' AND year='$year'");
+
+ mysql_query("UPDATE config SET
+ val='".mysql_escape_string(stripslashes($_POST['email']))."'
+ WHERE var='fairmanageremail' AND year='$year'");
- //copy over the dates defautls
$q=mysql_query("SELECT * FROM dates WHERE year='-1'");
while($r=mysql_fetch_object($q))
{
@@ -139,8 +140,18 @@ if($_POST['action']=="save")
echo "Done!
";
echo "Creating superuser account...";
- mysql_query("INSERT INTO committees_members (name,email,emailprivate,password,access_admin,access_config,access_super) VALUES ('Superuser Account','".$_POST['email']."','".$_POST['email']."','".$_POST['pass1']."','Y','Y','Y')");
- echo mysql_error();
+
+
+ $u = user_create('committee');
+ $u['firstname'] = '';
+ $u['lastname'] = 'Superuser Account';
+ $u['emailprivate'] = mysql_escape_string(stripslashes($_POST['email']));
+ $u['username'] = mysql_escape_string(stripslashes($_POST['email']));
+ $u['password'] = mysql_escape_string(stripslashes($_POST['pass1']));
+ $u['access_admin'] = 'yes';
+ $u['access_config'] = 'yes';
+ $u['access_super'] = 'yes';
+ user_save($u);
echo "Done!
";
echo "Installation is now complete! You can now proceed to the following location:
";
diff --git a/user.inc.php b/user.inc.php
index fdc206e..1bdf38c 100644
--- a/user.inc.php
+++ b/user.inc.php
@@ -23,8 +23,6 @@
*/
?>
-require_once('common.inc.php');
-
$user_types = array('student','judge','committee','volunteer','region');
$user_what = array('student'=>'Participant', 'judge' => 'Judge',