- Cleanup how variables are handled/rolled/etc. Convert the require_vars

function in the config editor to one that checks where ALL variables marked
  with year=-1 exist for FAIRYEAR.  If it doesn't, it creates them.  This
  function gets called in three places:
 	- On installation
	- On rollover
	- Whenever the database is updated
 We should, now, be able to just insert new variables with year=-1, and they
 will be automatically updated for the current year with the default value.
 (no more going into the variable editor to make sure the copy is done).

- Fix the superuser account creation in the install script
This commit is contained in:
dave 2007-11-25 19:53:15 +00:00
parent 33471e80ee
commit f6cc5d7326
7 changed files with 91 additions and 56 deletions

View File

@ -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 "<hr />";

View File

@ -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")."<br />";
$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")."<br />";

View File

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

View File

@ -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'");
}
}

View File

@ -127,6 +127,9 @@ mysql_select_db($DBNAME);
echo "<b>Attempting to update database using standard update script to update from $x to $dbcodeversion<br />";
echo "<br />Please scroll to the bottom of this page for the link to the next step of the installation process.<br /></b>";
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 ("../");

View File

@ -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);
@ -109,21 +111,20 @@ if($_POST['action']=="save")
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')");
//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)."')");
}
$year = intval($_POST['fairyear']);
//copy over the config defautls
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 "<b>Done!</b><br />";
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 "<b>Done!</b><br />";
echo "Installation is now complete! You can now proceed to the following location: <br />";

View File

@ -23,8 +23,6 @@
*/
?>
<?
require_once('common.inc.php');
$user_types = array('student','judge','committee','volunteer','region');
$user_what = array('student'=>'Participant', 'judge' => 'Judge',