Updates and cleanups to the installer

This commit is contained in:
james 2010-07-05 19:37:24 +00:00
parent 16c5e8ecc9
commit 548ebf24db
3 changed files with 52 additions and 70 deletions

View File

@ -20,8 +20,15 @@ function db_update_188_post()
//now update a couple config options for now, until we cna do soemthing better, without theme and theme_icons
//being fairyear independent, they wont get set at all so the page wont even load
mysql_query("UPDATE config SET year=0, category='Special' WHERE year='{$config['FAIRYEAR']}' AND var='theme'");
if(!mysql_affected_rows()) {
mysql_query("UPDATE config SET year=0, category='Special' WHERE year='-1' AND var='theme'");
}
mysql_query("UPDATE config SET year=0, category='Special' WHERE year='{$config['FAIRYEAR']}' AND var='theme_icons'");
if(!mysql_affected_rows()) {
mysql_query("UPDATE config SET year=0, category='Special' WHERE year='-1' AND var='theme_icons'");
}
mysql_query("DELETE FROM config WHERE year!=0 AND var='theme'");
mysql_query("DELETE FROM config WHERE year!=0 AND var='theme_icons'");

View File

@ -37,8 +37,7 @@ if(!function_exists("system")) {
exit;
}
if(!file_exists("data/config.inc.php"))
{
if(!file_exists("data/config.inc.php")) {
echo "<div class=\"error\">SFIAB Installation Step 1 is not yet complete.</div>";
echo "<a href=\"install.php\">Go back to installation step 1</a><br />";
echo "</body></html>";
@ -51,13 +50,11 @@ mysql_select_db($DBNAME);
echo "Getting database version requirements for code... ";
if(file_exists("db/db.code.version.txt"))
{
if(file_exists("db/db.code.version.txt")) {
$dbcodeversion_file=file("db/db.code.version.txt");
$dbcodeversion=trim($dbcodeversion_file[0]);
}
else
{
else {
echo "<b>ERROR: Couldnt load current db/db.code.version.txt</b><br />";
exit;
}
@ -69,8 +66,7 @@ mysql_select_db($DBNAME);
$r=@mysql_fetch_object($q);
$dbdbversion=$r->val;
if($dbdbversion)
{
if($dbdbversion) {
echo "<b>ERROR: found version $dbdbversion</b><br />";
//lets see if they match
@ -82,14 +78,12 @@ mysql_select_db($DBNAME);
echo "Your SFIAB database needs to be updated. You should run the update script instead of this installer!\n";
exit;
}
else
{
else {
echo "<b>Not found (good!)</b><br />";
}
echo "Checking for database installer for version $dbcodeversion... ";
if(file_exists("db/db.full.$dbcodeversion.sql"))
{
if(file_exists("db/db.full.$dbcodeversion.sql")) {
echo "<b>db/db.full.$dbcodeversion.sql found</b><br />";
echo "Setting up database tables... ";
@ -105,15 +99,12 @@ mysql_select_db($DBNAME);
echo "<b>Done!</b><br />";
echo "<a href=\"install3.php\">Proceed to installation step 3</a><br />";
}
else
{
echo "<b>WARNING: Couldnt find db/db.full.$dbcodeversion.sql</b><br />";
else {
echo "<b>Couldnt find db/db.full.$dbcodeversion.sql</b><br />";
echo "Trying to find an older version... <br />";
for($x=$dbcodeversion;$x>0;$x--)
{
if(file_exists("db/db.full.$x.sql"))
{
for($x=$dbcodeversion;$x>0;$x--) {
if(file_exists("db/db.full.$x.sql")) {
echo "<b>db/db.full.$x.sql found</b><br />";
echo "Setting up database tables... ";
@ -140,10 +131,8 @@ mysql_select_db($DBNAME);
}
}
}
//only if this file was created will we go ahead with the rest
//creating all the tables and such..
?>
</body></html>

View File

@ -30,8 +30,7 @@ echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
<body>
<h1>SFIAB Installation - Step 3</h1>
<?
if(!file_exists("data/config.inc.php"))
{
if(!file_exists("data/config.inc.php")) {
echo "<div class=\"error\">SFIAB Installation Step 1 is not yet complete.</div>";
echo "<a href=\"install.php\">Go back to installation step 1</a><br />";
echo "</body></html>";
@ -45,25 +44,23 @@ require_once("committee.inc.php");
mysql_connect($DBHOST,$DBUSER,$DBPASS);
mysql_select_db($DBNAME);
echo "Checking for SFIAB database... ";
echo "Checking for SFIAB database... ";
$q=@mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'");
$r=@mysql_fetch_object($q);
$dbdbversion=$r->val;
$q=@mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'");
$r=@mysql_fetch_object($q);
$dbdbversion=$r->val;
if(!$dbdbversion)
{
echo "<div class=\"error\">SFIAB Installation Step 2 is not yet complete.</div>";
echo "<a href=\"install2.php\">Go back to installation step 2</a><br />";
echo "</body></html>";
exit;
}
if(!$dbdbversion) {
echo "<div class=\"error\">SFIAB Installation Step 2 is not yet complete.</div>";
echo "<a href=\"install2.php\">Go back to installation step 2</a><br />";
echo "</body></html>";
exit;
}
//a fresh install should ONLY have DBVERSION defined in the config table. If there are others (FAIRYEAR, SFIABDIRECTORY) then this is NOT fresh
$q=mysql_query("SELECT * FROM config WHERE year='0' AND ( var='DBVERSION' OR var='FAIRYEAR' OR var='SFIABDIRECTORY') ");
$q=mysql_query("SELECT * FROM config WHERE year='0' AND conferences_id='0' AND ( var='DBVERSION' OR var='FAIRYEAR' OR var='SFIABDIRECTORY') ");
//we might get an error if the config table does not exist (ie, installer step 2 failed)
if(mysql_error())
{
if(mysql_error()) {
//we say all tables, but really only we check for config where year=0;
echo "<div class=\"error\">ERROR: No SFIAB tables detected, It seems like step 2 failed. Please go <a href=\"install2.php\">Back to Installation Step 2</a> and try again.</div>";
echo "</body></html>";
@ -71,8 +68,7 @@ if(mysql_error())
}
//1 is okay (DBVERSION). More than 1 is bad (already isntalled)
if(mysql_num_rows($q)>1)
{
if(mysql_num_rows($q)>1) {
//we say all tables, but really only we check for config where year=0;
echo "<div class=\"error\">ERROR: Detected existing table data, SFIAB Installation Step 3 requires a clean SFIAB database installation.</div>";
echo "</body></html>";
@ -80,35 +76,29 @@ if(mysql_num_rows($q)>1)
}
echo "<b>Found!</b><br />";
if($_POST['action']=="save")
{
if($_POST['action']=="save") {
$err=false;
if(!$_POST['fairyear'])
{
if(!$_POST['fairyear']) {
echo "Fair Year is required";
$err=true;
}
if(!$_POST['email'])
{
if(!$_POST['email']) {
echo "Superuser email address is required";
$err=true;
}
if(!( $_POST['pass1'] && $_POST['pass2']))
{
if(!( $_POST['pass1'] && $_POST['pass2'])) {
echo "Superuser password and password confirmation are required";
$err=true;
}
if($_POST['pass1'] != $_POST['pass2'])
{
if($_POST['pass1'] != $_POST['pass2']) {
echo "Password and Password confirmation do not match";
$err=true;
}
if(!$err)
{
echo "Creating configuration settings...";
if(!$err) {
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 ('FISCALYEAR','".$_POST['fiscalyear']."','Special','0','0')");
mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('SFIABDIRECTORY','".$_POST['sfiabdirectory']."','Special','','0')");
@ -120,42 +110,38 @@ if($_POST['action']=="save")
// Update some variables
mysql_query("UPDATE config SET
val='".mysql_escape_string(stripslashes($_POST['fairname']))."'
val='".mysql_escape_string($_POST['fairname'])."'
WHERE var='fairname' AND year='$year'");
mysql_query("UPDATE config SET
val='".mysql_escape_string(stripslashes($_POST['email']))."'
val='".mysql_escape_string($_POST['email'])."'
WHERE var='fairmanageremail' AND year='$year'");
$q=mysql_query("SELECT * FROM dates WHERE year='-1'");
while($r=mysql_fetch_object($q))
{
mysql_query("INSERT INTO dates (date,name,description,year) VALUES ('$r->date','$r->name','$r->description','".$_POST['fairyear']."')");
}
//copy over the award_types defautls
$q=mysql_query("SELECT * FROM award_types WHERE year='-1'");
while($r=mysql_fetch_object($q))
{
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO award_types (id,type,`order`,year) VALUES ('$r->id','$r->type','$r->order','".$_POST['fairyear']."')");
}
echo "<b>Done!</b><br />";
echo "Creating superuser account...";
echo "Creating a science fair conference... ";
mysql_query("INSERT INTO conferences (`name`,`type`,`status`) VALUES ('".mysql_real_escape_string($_POST['fairname'])."','sciencefair','running')");
echo "<b>Done!</b><br />";
echo "Creating superuser account... ";
$u = user_create('committee',$_POST['email']);
if($_POST['firstname'] && $_POST['lastname']) {
$u['firstname']=mysql_escape_string(stripslashes($_POST['firstname']));
$u['lastname']=mysql_escape_string(stripslashes($_POST['lastname']));
$u['firstname']=mysql_escape_string($_POST['firstname']);
$u['lastname']=mysql_escape_string($_POST['lastname']);
}
else {
$u['firstname'] = 'Superuser';
$u['lastname'] = 'Account';
}
$u['emailprivate'] = mysql_escape_string(stripslashes($_POST['email']));
$u['email'] = mysql_escape_string(stripslashes($_POST['email']));
$u['username'] = mysql_escape_string(stripslashes($_POST['email']));
$u['password'] = mysql_escape_string(stripslashes($_POST['pass1']));
$u['emailprivate'] = mysql_escape_string($_POST['email']);
$u['email'] = mysql_escape_string($_POST['email']);
$u['username'] = mysql_escape_string($_POST['email']);
$u['password'] = mysql_escape_string($_POST['pass1']);
$u['access_admin'] = 'yes';
$u['access_config'] = 'yes';
$u['access_super'] = 'yes';