Revert Dennis's invalid line endings commit

This commit is contained in:
james 2011-02-16 17:00:55 +00:00
parent 19304cf75a
commit d58e8f4a1e
4 changed files with 1908 additions and 2002 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,144 +1,117 @@
<? <?
// dspanogle 2011-02-04 This is not required since we have removed the system("mysql".. calls to allow Windows servers installs if(!function_exists("system")) {
/* echo "DB Update requires php's system() function to be available\n";
if(!function_exists("system")) { exit;
echo "DB Update requires php's system() function to be available\n"; }
exit;
} //include the config.inc.php
*/ //so we have the db connection info
//include the config.inc.php require("../data/config.inc.php");
//so we have the db connection info echo "<pre>\n";
require("../data/config.inc.php"); if(file_exists("db.code.version.txt"))
echo "<pre>\n"; {
if(file_exists("db.code.version.txt")) $dbcodeversion_file=file("db.code.version.txt");
{ $dbcodeversion=trim($dbcodeversion_file[0]);
$dbcodeversion_file=file("db.code.version.txt"); }
$dbcodeversion=trim($dbcodeversion_file[0]); else
} {
else echo "Couldnt load current db.code.version.txt\n";
{ exit;
echo "Couldnt load current db.code.version.txt\n"; }
exit;
} //same fix here for mysql 5.1 not truncating the 16 char usernames
$DBUSER=substr($DBUSER,0,16);
//same fix here for mysql 5.1 not truncating the 16 char usernames
$DBUSER=substr($DBUSER,0,16); mysql_connect($DBHOST,$DBUSER,$DBPASS);
mysql_select_db($DBNAME);
mysql_connect($DBHOST,$DBUSER,$DBPASS); @mysql_query("SET NAMES latin1");
mysql_select_db($DBNAME); $q=mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'");
@mysql_query("SET NAMES latin1"); $r=mysql_fetch_object($q);
$q=mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'"); $dbdbversion=$r->val;
$r=mysql_fetch_object($q); if(!$dbdbversion)
$dbdbversion=$r->val; {
if(!$dbdbversion) echo "Couldnt get current db version. Is SFIAB properly installed?\n";
{ exit;
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'");
/* Get the fair year */ $r=mysql_fetch_object($q);
$q=mysql_query("SELECT val FROM config WHERE var='FAIRYEAR' AND year='0'"); $config = array('FAIRYEAR' => $r->val);
$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']}'");
/* Load config just in case there's a PHP script that wants it */ while($r=mysql_fetch_object($q)) $config[$r->var]=$r->val;
$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()
require_once("../config_editor.inc.php"); // For config_update_variables() if($dbcodeversion && $dbdbversion)
{
if($dbcodeversion && $dbdbversion) //lets see if they match
{ if($dbcodeversion == $dbdbversion)
//lets see if they match {
if($dbcodeversion == $dbdbversion) echo "DB and CODE are all up-to-date. Version: $dbdbversion\n";
{ exit;
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;
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 "DB update requirements detected\n"; echo "Current CODE Version: $dbcodeversion\n";
echo "Current DB Version: $dbdbversion\n";
echo "Current CODE Version: $dbcodeversion\n"; echo "Updating database from $dbdbversion to $dbcodeversion\n";
echo "Updating database from $dbdbversion to $dbcodeversion\n"; for($ver=$dbdbversion+1;$ver<=$dbcodeversion;$ver++)
{
for($ver=$dbdbversion+1;$ver<=$dbcodeversion;$ver++) if(file_exists("db.update.$ver.php"))
{ {
if(file_exists("db.update.$ver.php")) include("db.update.$ver.php");
{ }
include("db.update.$ver.php"); if(is_callable("db_update_{$ver}_pre")) {
} echo "db.update.$ver.php::db_update_{$ver}_pre() exists - running...\n";
if(is_callable("db_update_{$ver}_pre")) { call_user_func("db_update_{$ver}_pre");
echo "db.update.$ver.php::db_update_{$ver}_pre() exists - running...\n"; echo "db.update.$ver.php::db_update_{$ver}_pre() done.\n";
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 "db.update.$ver.sql detected - running...\n"; echo "\n";
readfile("db.update.$ver.sql"); system("mysql --default-character-set=latin1 -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME <db.update.$ver.sql");
echo "\n"; }
// dspanogle 2011-02-04 Use each section of the sql file instead of using system("sql" ... else
// For windows ISP servers that do not provide "sql: executable - replace system call. {
// system("mysql --default-character-set=latin1 -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME <db.update.$ver.sql"); echo "Version $ver SQL update file not found - skipping over\n";
$filename = 'db.update.'.$ver.'.sql'; }
// Temporary variable, used to store current query if(is_callable("db_update_{$ver}_post")) {
$templine = ''; echo "db.update.$ver.php::db_update_{$ver}_post() exists - running...\n";
// Read in entire file call_user_func("db_update_{$ver}_post");
$lines = file($filename); echo "db.update.$ver.php::db_update_{$ver}_post() done.\n";
// Loop through each line }
foreach ($lines as $line) }
{ if($db_update_skip_variables != true) {
// Skip it if it's a comment echo "\nUpdating Configuration Variables...\n";
if (substr($line, 0, 2) == '--' || $line == '') config_update_variables($config['FAIRYEAR']);
continue; }
// Add this line to the current segment
$templine .= $line; echo "\nAll done - updating new DB version to $dbcodeversion\n";
// If it has a semicolon at the end, it's the end of the query mysql_query("UPDATE config SET val='$dbcodeversion' WHERE var='DBVERSION' AND year='0'");
if (substr(trim($line), -1, 1) == ';')
{ }
// Perform the query
mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />'); }
// Reset temp variable to empty else
$templine = ''; {
} echo "ERROR: dbcodeversion and dbdbversion are not defined\n";
} }
echo "<br />";
} echo "</pre>\n";
else
{ ?>
echo "Version $ver SQL update file not found - skipping over\n";
}
if(is_callable("db_update_{$ver}_post")) {
echo "db.update.$ver.php::db_update_{$ver}_post() exists - running...\n";
call_user_func("db_update_{$ver}_post");
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($config['FAIRYEAR']);
}
echo "\nAll done - updating new DB version to $dbcodeversion\n";
mysql_query("UPDATE config SET val='$dbcodeversion' WHERE var='DBVERSION' AND year='0'");
}
}
else
{
echo "ERROR: dbcodeversion and dbdbversion are not defined\n";
}
echo "</pre>\n";
?>

View File

@ -1,199 +1,150 @@
<? <?
/* /*
This file is part of the 'Science Fair In A Box' project This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org> Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org> Copyright (C) 2005 James Grant <james@lightbox.org>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2. License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. Boston, MA 02111-1307, USA.
*/ */
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n"; echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title>SFIAB Installation</title> <head><title>SFIAB Installation</title>
<link rel="stylesheet" href="sfiab.css" type="text/css" /> <link rel="stylesheet" href="sfiab.css" type="text/css" />
</head> </head>
<body> <body>
<h1>SFIAB Installation - Step 2</h1> <h1>SFIAB Installation - Step 2</h1>
<? <?
// dspanogle 2011-02-04 This is not required since we have removed the system("mysql".. calls to allow Windows servers installs
/* if(!function_exists("system")) {
if(!function_exists("system")) { echo "<div class=\"error\">Installation requires php's system() function to be available</div>\n";
echo "<div class=\"error\">Installation requires php's system() function to be available</div>\n"; echo "</body></html>";
echo "</body></html>"; exit;
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 "<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 "<a href=\"install.php\">Go back to installation step 1</a><br />"; echo "</body></html>";
echo "</body></html>"; exit;
exit; }
}
require_once("data/config.inc.php");
require_once("data/config.inc.php"); $DBUSER=substr($DBUSER,0,16);
$DBUSER=substr($DBUSER,0,16); mysql_connect($DBHOST,$DBUSER,$DBPASS);
mysql_connect($DBHOST,$DBUSER,$DBPASS); mysql_select_db($DBNAME);
mysql_select_db($DBNAME);
echo "Getting database version requirements for code... ";
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_file=file("db/db.code.version.txt"); $dbcodeversion=trim($dbcodeversion_file[0]);
$dbcodeversion=trim($dbcodeversion_file[0]); }
} else
else {
{ echo "<b>ERROR: Couldnt load current db/db.code.version.txt</b><br />";
echo "<b>ERROR: Couldnt load current db/db.code.version.txt</b><br />"; exit;
exit; }
} echo "<b>version $dbcodeversion</b><br />";
echo "<b>version $dbcodeversion</b><br />";
echo "Checking for existing SFIAB database... ";
echo "Checking for existing SFIAB database... ";
$q=@mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'");
$q=@mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'"); $r=@mysql_fetch_object($q);
$r=@mysql_fetch_object($q); $dbdbversion=$r->val;
$dbdbversion=$r->val;
if($dbdbversion)
if($dbdbversion) {
{ echo "<b>ERROR: found version $dbdbversion</b><br />";
echo "<b>ERROR: found version $dbdbversion</b><br />";
//lets see if they match
//lets see if they match if($dbcodeversion == $dbdbversion)
if($dbcodeversion == $dbdbversion) echo "Your SFIAB database is already setup with the required version\n";
echo "Your SFIAB database is already setup with the required version\n"; else if($dbcodeversion<$dbdbversion)
else if($dbcodeversion<$dbdbversion) echo "ERROR: dbcodeversion<dbdbversion ($dbcodeversion<$dbdbversion). This should not happen!";
echo "ERROR: dbcodeversion<dbdbversion ($dbcodeversion<$dbdbversion). This should not happen!"; else if($dbcodeversion>$dbdbversion)
else if($dbcodeversion>$dbdbversion) echo "Your SFIAB database needs to be updated. You should run the update script instead of this installer!\n";
echo "Your SFIAB database needs to be updated. You should run the update script instead of this installer!\n"; exit;
exit; }
} else
else {
{ echo "<b>Not found (good!)</b><br />";
echo "<b>Not found (good!)</b><br />"; }
}
echo "Checking for database installer for version $dbcodeversion... ";
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 "<b>db/db.full.$dbcodeversion.sql found</b><br />";
echo "Setting up database tables... ";
echo "Setting up database tables... ";
// dspanogle 2011-02-04 Use each section of the sql file instead of using system("sql" ... system("mysql --default-character-set=latin1 -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME <db/db.full.$dbcodeversion.sql");
// For windows ISP servers that do not provide "sql: executable - replace system call.
// system("mysql --default-character-set=latin1 -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME <db/db.full.$dbcodeversion.sql"); echo "<b>Done! installed database version $dbcodeversion</b><br />\n";
$filename = 'db/db.full.'.$dbcodeversion.'.sql';
// Temporary variable, used to store current query //now update the db version in the database
$templine = ''; mysql_query("UPDATE config SET val='$dbcodeversion' WHERE var='DBVERSION' AND year='0'");
// Read in entire file
$lines = file($filename); echo "<br />";
// Loop through each line echo "<b>Done!</b><br />";
foreach ($lines as $line) echo "<a href=\"install3.php\">Proceed to installation step 3</a><br />";
{ }
// Skip it if it's a comment else
if (substr($line, 0, 2) == '--' || $line == '') {
continue; echo "<b>WARNING: Couldnt find db/db.full.$dbcodeversion.sql</b><br />";
echo "Trying to find an older version... <br />";
// Add this line to the current segment
$templine .= $line; for($x=$dbcodeversion;$x>0;$x--)
// If it has a semicolon at the end, it's the end of the query {
if (substr(trim($line), -1, 1) == ';') if(file_exists("db/db.full.$x.sql"))
{ {
// Perform the query echo "<b>db/db.full.$x.sql found</b><br />";
mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />'); echo "Setting up database tables... ";
// Reset temp variable to empty
$templine = ''; system("mysql --default-character-set=latin1 -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME <db/db.full.$x.sql");
}
} echo "<b>Done! installed database version $x</b><br />\n";
echo "<br />";
echo "<b>Done! installed database version $dbcodeversion</b><br />\n"; //now update the db version in the database
mysql_query("UPDATE config SET val='$x' WHERE var='DBVERSION' AND year='0'");
//now update the db version in the database
mysql_query("UPDATE config SET val='$dbcodeversion' WHERE var='DBVERSION' AND year='0'"); 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>";
echo "<br />"; chdir ("db");
echo "<b>Done!</b><br />"; /* Update the database, but don't update the config variables yet, because
echo "<a href=\"install3.php\">Proceed to installation step 3</a><br />"; * We haven't set the FAIRYEAR */
} $db_update_skip_variables = true;
else include "db_update.php";
{ chdir ("../");
echo "<b>WARNING: Couldnt find db/db.full.$dbcodeversion.sql</b><br />";
echo "Trying to find an older version... <br />"; echo "<br />";
echo "<b>Done!</b><br />";
for($x=$dbcodeversion;$x>0;$x--) echo "<a href=\"install3.php\">Proceed to installation step 3</a><br />";
{ break;
if(file_exists("db/db.full.$x.sql")) }
{ }
echo "<b>db/db.full.$x.sql found</b><br />"; }
echo "Setting up database tables... ";
// dspanogle 2011-02-04 Use each section of the sql file instead of using system("sql" ... //only if this file was created will we go ahead with the rest
// For windows ISP servers that do not provide "sql: executable - replace system call. //creating all the tables and such..
// system("mysql --default-character-set=latin1 -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME <db/db.full.$x.sql");
$filename = 'db/db.full.'.$x.'.sql'; ?>
// Temporary variable, used to store current query
$templine = ''; </body></html>
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
// Perform the query
mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
// Reset temp variable to empty
$templine = '';
}
}
echo "<br />";
echo "<b>Done! installed database version $x</b><br />\n";
//now update the db version in the database
mysql_query("UPDATE config SET val='$x' WHERE var='DBVERSION' AND year='0'");
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 ("../");
echo "<br />";
echo "<b>Done!</b><br />";
echo "<a href=\"install3.php\">Proceed to installation step 3</a><br />";
break;
}
}
}
//only if this file was created will we go ahead with the rest
//creating all the tables and such..
?>
</body></html>

View File

@ -1,212 +1,211 @@
<? <?
/* /*
This file is part of the 'Science Fair In A Box' project This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org> Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org> Copyright (C) 2005 James Grant <james@lightbox.org>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2. License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. Boston, MA 02111-1307, USA.
*/ */
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n"; echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title>SFIAB Installation</title> <head><title>SFIAB Installation</title>
<link rel="stylesheet" href="sfiab.css" type="text/css" /> <link rel="stylesheet" href="sfiab.css" type="text/css" />
</head> </head>
<body> <body>
<h1>SFIAB Installation - Step 3</h1> <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 "<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 "<a href=\"install.php\">Go back to installation step 1</a><br />";
echo "</body></html>"; echo "</body></html>";
exit; exit;
} }
require_once("data/config.inc.php"); require_once("data/config.inc.php");
require_once("config_editor.inc.php"); require_once("config_editor.inc.php");
require_once("user.inc.php"); require_once("user.inc.php");
require_once("committee.inc.php"); require_once("committee.inc.php");
$DBUSER=substr($DBUSER,0,16); $DBUSER=substr($DBUSER,0,16);
mysql_connect($DBHOST,$DBUSER,$DBPASS); mysql_connect($DBHOST,$DBUSER,$DBPASS);
mysql_select_db($DBNAME); 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'"); $q=@mysql_query("SELECT val FROM config WHERE var='DBVERSION' AND year='0'");
$r=@mysql_fetch_object($q); $r=@mysql_fetch_object($q);
$dbdbversion=$r->val; $dbdbversion=$r->val;
if(!$dbdbversion) if(!$dbdbversion)
{ {
echo "<div class=\"error\">SFIAB Installation Step 2 is not yet complete.</div>"; 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 "<a href=\"install2.php\">Go back to installation step 2</a><br />";
echo "</body></html>"; echo "</body></html>";
exit; exit;
} }
//a fresh install should ONLY have DBVERSION defined in the config table. If there are others (FAIRYEAR, SFIABDIRECTORY) then this is NOT fresh //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 ( 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) //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; //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 "<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>"; echo "</body></html>";
exit; exit;
} }
//1 is okay (DBVERSION). More than 1 is bad (already isntalled) //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; //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 "<div class=\"error\">ERROR: Detected existing table data, SFIAB Installation Step 3 requires a clean SFIAB database installation.</div>";
echo "</body></html>"; echo "</body></html>";
exit; exit;
} }
echo "<b>Found!</b><br />"; echo "<b>Found!</b><br />";
if($_POST['action']=="save") if($_POST['action']=="save")
{ {
$err=false; $err=false;
if(!$_POST['fairyear']) if(!$_POST['fairyear'])
{ {
echo "Fair Year is required"; echo "Fair Year is required";
$err=true; $err=true;
} }
if(!$_POST['email']) if(!$_POST['email'])
{ {
echo "Superuser email address is required"; echo "Superuser email address is required";
$err=true; $err=true;
} }
if(!( $_POST['pass1'] && $_POST['pass2'])) if(!( $_POST['pass1'] && $_POST['pass2']))
{ {
echo "Superuser password and password confirmation are required"; echo "Superuser password and password confirmation are required";
$err=true; $err=true;
} }
if($_POST['pass1'] != $_POST['pass2']) if($_POST['pass1'] != $_POST['pass2'])
{ {
echo "Password and Password confirmation do not match"; echo "Password and Password confirmation do not match";
$err=true; $err=true;
} }
if(!$err) if(!$err)
{ {
echo "Creating configuration settings..."; 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 ('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 ('FISCALYEAR','".$_POST['fiscalyear']."','Special','0','0')");
mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('SFIABDIRECTORY','".$_POST['sfiabdirectory']."','Special','','0')"); mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('SFIABDIRECTORY','".$_POST['sfiabdirectory']."','Special','','0')");
$year = intval($_POST['fairyear']); $year = intval($_POST['fairyear']);
//copy over the config defautls //copy over the config defautls
config_update_variables($year); config_update_variables($year);
// Update some variables // Update some variables
mysql_query("UPDATE config SET mysql_query("UPDATE config SET
val='".mysql_escape_string(stripslashes($_POST['fairname']))."' val='".mysql_escape_string(stripslashes($_POST['fairname']))."'
WHERE var='fairname' AND year='$year'"); WHERE var='fairname' AND year='$year'");
mysql_query("UPDATE config SET mysql_query("UPDATE config SET
val='".mysql_escape_string(stripslashes($_POST['email']))."' val='".mysql_escape_string(stripslashes($_POST['email']))."'
WHERE var='fairmanageremail' AND year='$year'"); WHERE var='fairmanageremail' AND year='$year'");
$q=mysql_query("SELECT * FROM dates WHERE year='-1'"); $q=mysql_query("SELECT * FROM dates WHERE year='-1'");
while($r=mysql_fetch_object($q)) while($r=mysql_fetch_object($q))
{ {
mysql_query("INSERT INTO dates (date,name,description,year) VALUES ('$r->date','$r->name','$r->description','".$_POST['fairyear']."')"); mysql_query("INSERT INTO dates (date,name,description,year) VALUES ('$r->date','$r->name','$r->description','".$_POST['fairyear']."')");
} }
//copy over the award_types defautls //copy over the award_types defautls
$q=mysql_query("SELECT * FROM award_types WHERE year='-1'"); $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']."')"); 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 "<b>Done!</b><br />";
echo "Creating superuser account..."; echo "Creating superuser account...";
$u = user_create('committee',$_POST['email']); $u = user_create('committee',$_POST['email']);
if($_POST['firstname'] && $_POST['lastname']) { if($_POST['firstname'] && $_POST['lastname']) {
$u['firstname']=mysql_escape_string(stripslashes($_POST['firstname'])); $u['firstname']=mysql_escape_string(stripslashes($_POST['firstname']));
$u['lastname']=mysql_escape_string(stripslashes($_POST['lastname'])); $u['lastname']=mysql_escape_string(stripslashes($_POST['lastname']));
} }
else { else {
$u['firstname'] = 'Superuser'; $u['firstname'] = 'Superuser';
$u['lastname'] = 'Account'; $u['lastname'] = 'Account';
} }
$u['emailprivate'] = mysql_escape_string(stripslashes($_POST['email'])); $u['emailprivate'] = mysql_escape_string(stripslashes($_POST['email']));
$u['email'] = mysql_escape_string(stripslashes($_POST['email'])); $u['email'] = mysql_escape_string(stripslashes($_POST['email']));
$u['username'] = mysql_escape_string(stripslashes($_POST['email'])); $u['username'] = mysql_escape_string(stripslashes($_POST['email']));
$u['password'] = mysql_escape_string(stripslashes($_POST['pass1'])); $u['password'] = mysql_escape_string(stripslashes($_POST['pass1']));
$u['access_admin'] = 'yes'; $u['access_admin'] = 'yes';
$u['access_config'] = 'yes'; $u['access_config'] = 'yes';
$u['access_super'] = 'yes'; $u['access_super'] = 'yes';
user_save($u); user_save($u);
echo "<b>Done!</b><br />"; echo "<b>Done!</b><br />";
echo "Installation is now complete! You can now proceed to the following location: <br />"; echo "Installation is now complete! You can now proceed to the following location: <br />";
echo "&nbsp; &nbsp; <a href=\"".$_POST['sfiabdirectory']."\">Your SFIAB main page</a><br />"; echo "&nbsp; &nbsp; <a href=\"".$_POST['sfiabdirectory']."\">Your SFIAB main page</a><br />";
echo "</body></html>"; echo "</body></html>";
exit; exit;
} }
} }
echo "<br />"; echo "<br />";
echo "Please enter the following options <br />"; echo "Please enter the following options <br />";
echo "<br />"; echo "<br />";
$month=date("m"); $month=date("m");
if($month>4) $fairyearsuggest=date("Y")+1; if($month>4) $fairyearsuggest=date("Y")+1;
else $fairyearsuggest=date("Y"); else $fairyearsuggest=date("Y");
if($month>6) $fiscalyearsuggest=date("Y")+1; if($month>6) $fiscalyearsuggest=date("Y")+1;
else $fiscalyearsuggest=date("Y"); else $fiscalyearsuggest=date("Y");
// DES dspanogle 2011-02-05 $_SERVER['REQUEST_URI'] is not available on many Windows servers
//$directorysuggest = substr($_SERVER['REQUEST_URI'],0,-13); $directorysuggest=substr($_SERVER['REQUEST_URI'],0,-13);
$directorysuggest = substr(getenv("SCRIPT_NAME"),0,-13); echo "<h3>Options</h3>";
echo "<h3>Options</h3>"; echo "<form method=\"post\" action=\"install3.php\">";
echo "<form method=\"post\" action=\"install3.php\">"; echo "<input type=\"hidden\" name=\"action\" value=\"save\" />";
echo "<input type=\"hidden\" name=\"action\" value=\"save\" />";
echo "<table>";
echo "<table>"; echo "<tr><td>Fair Name</td><td><input size=\"25\" type=\"text\" name=\"fairname\" value=\"\"></td><td>The name of the fair you are installing SFIAB to run</td></tr>";
echo "<tr><td>Fair Name</td><td><input size=\"25\" type=\"text\" name=\"fairname\" value=\"\"></td><td>The name of the fair you are installing SFIAB to run</td></tr>"; echo "<tr><td>Fair Year</td><td><input size=\"8\" type=\"text\" name=\"fairyear\" value=\"$fairyearsuggest\"></td><td>The year of the fair you are installing SFIAB to run</td></tr>";
echo "<tr><td>Fair Year</td><td><input size=\"8\" type=\"text\" name=\"fairyear\" value=\"$fairyearsuggest\"></td><td>The year of the fair you are installing SFIAB to run</td></tr>"; echo "<tr><td>Fiscal Year</td><td><input size=\"8\" type=\"text\" name=\"fiscalyear\" value=\"$fiscalyearsuggest\"></td><td>The current fiscal year (for fundraising/accounting purposes)</td></tr>";
echo "<tr><td>Fiscal Year</td><td><input size=\"8\" type=\"text\" name=\"fiscalyear\" value=\"$fiscalyearsuggest\"></td><td>The current fiscal year (for fundraising/accounting purposes)</td></tr>"; echo "<tr><td>Directory</td><td><input size=\"25\" type=\"text\" name=\"sfiabdirectory\" value=\"$directorysuggest\"></td><td>The directory of this SFIAB installation as seen by the web browser</td></tr>";
echo "<tr><td>Directory</td><td><input size=\"25\" type=\"text\" name=\"sfiabdirectory\" value=\"$directorysuggest\"></td><td>The directory of this SFIAB installation as seen by the web browser</td></tr>";
echo "</table>";
echo "</table>"; echo "<br />";
echo "<br />"; echo "<h3>Superuser Account</h3>";
echo "<h3>Superuser Account</h3>"; echo "Please choose your superuser account which is required to login to SFIAB and configure the system, as well as to add other users. <br />";
echo "Please choose your superuser account which is required to login to SFIAB and configure the system, as well as to add other users. <br />"; echo "<table>";
echo "<table>"; echo "<tr><td>Superuser Email Address</td><td><input size=\"40\" type=\"text\" name=\"email\"></td></tr>";
echo "<tr><td>Superuser Email Address</td><td><input size=\"40\" type=\"text\" name=\"email\"></td></tr>"; echo "<tr><td>Superuser Password</td><td><input size=\"15\" type=\"password\" name=\"pass1\"></td></tr>";
echo "<tr><td>Superuser Password</td><td><input size=\"15\" type=\"password\" name=\"pass1\"></td></tr>"; echo "<tr><td>Superuser Password (Confirm)</td><td><input size=\"15\" type=\"password\" name=\"pass2\"></td></tr>";
echo "<tr><td>Superuser Password (Confirm)</td><td><input size=\"15\" type=\"password\" name=\"pass2\"></td></tr>"; echo "</table>";
echo "</table>"; echo "<br />";
echo "<br />"; echo "<input type=\"submit\" value=\"Complete Installation\">";
echo "<input type=\"submit\" value=\"Complete Installation\">"; echo "</form>";
echo "</form>";
?>
?>
</body></html>
</body></html>