forked from science-ation/science-ation
185 lines
6.4 KiB
PHP
185 lines
6.4 KiB
PHP
<?php
|
|
/*
|
|
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>
|
|
|
|
New functionality:
|
|
Copyright (C) 2011 At Work Software <dennis@spanogle.net>
|
|
Copyright (C) 2011 Dennis Spanogle <dennis@spanogle.net>
|
|
|
|
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.
|
|
*/
|
|
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">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
|
<head><title>SFIAB plug-in Installation (Evaluations)</title>
|
|
<link rel="stylesheet" href="sfiab.css" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<h1>SFIAB Evaluations Plug-in - Installation</h1>
|
|
<?php
|
|
include_once "sfiab_common.inc.php"; // get config from SFIAB etc.
|
|
echo "Getting 'Evaluations' database version requirements for code... <br /> ";
|
|
if(file_exists("db/eval.code.version.txt"))
|
|
{
|
|
$evaldbcodeversion_file=file("db/eval.code.version.txt");
|
|
$evaldbcodeversion=trim($evaldbcodeversion_file[0]);
|
|
}
|
|
else
|
|
{
|
|
echo "<b>ERROR: Couldnt load plugins/evaluations/db/eval.code.version.txt</b><br />";
|
|
exit;
|
|
}
|
|
echo "<b>'Evaluations version $evaldbcodeversion</b><br />";
|
|
echo "Checking for existing 'Evaluations' database... ";
|
|
$q=@mysql_query("SELECT db_version FROM eval_config");
|
|
$r=@mysql_fetch_object($q);
|
|
$evaldbdbversion=$r->db_version;
|
|
if($evaldbdbversion)
|
|
{
|
|
echo "<b>Found version $evaldbdbversion</b><br />";
|
|
//lets see if they match
|
|
if($evaldbcodeversion == $evaldbdbversion)
|
|
echo "Your 'Evaluations' plug-in database is already setup with the required version\n";
|
|
else if($evaldbcodeversion<$evaldbdbversion)
|
|
echo "ERROR: evaldbcodeversion<evaldbdbversion ($dbcodeversion<$dbdbversion). This should not happen!";
|
|
else if($evaldbcodeversion>$evaldbdbversion)
|
|
echo "Your 'Evaluations' plug-in database needs to be updated. You should run the update script instead of this installer!\n";
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
echo "<b>Installing 'Evaluations' plug-in database!</b><br />";
|
|
}
|
|
$error_count = 0;
|
|
echo "Checking for database installer for 'Evaluations' version $evaldbcodeversion... ";
|
|
if(file_exists("db/db.eval.full.$evaldbcodeversion.sql"))
|
|
{
|
|
echo "<b>db/db.eval.full.$evaldbcodeversion.sql found</b><br />";
|
|
echo "Setting up database tables... ";
|
|
$exit_code = 0;
|
|
$filename = 'db/db.eval.full.'.$evaldbcodeversion.'.sql';
|
|
// Temporary variable, used to store current query
|
|
$templine = '';
|
|
// 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
|
|
if(!mysql_query($templine)){
|
|
echo('<br/>Error performing query!<br/>'.$templine.'<br/> mysqlerror: '.mysql_error().'<br /><br />');
|
|
$exit_code = -1; // do we bail out here or keep going? keep going for now, get all errors
|
|
}
|
|
// Reset temp variable to empty
|
|
$templine = '';
|
|
}
|
|
}
|
|
echo "<br/><br />";
|
|
if($exit_code != 0) {
|
|
/* mysql failed!, what now? */
|
|
$error_count += 1;
|
|
echo "<br /><b>mysql failed to execute query(s) without error!<b><br />";
|
|
}
|
|
echo "<b>Done! installed valuations' database version $dbcodeversion</b><br />\n";
|
|
echo "<br />";
|
|
echo "<b>Done!</b><br />";
|
|
// Dennis allert if errors!
|
|
if ($error_count > 0){
|
|
echo "<b>THERE WERE ERRORS! The database was not created correctly!</b><br />";
|
|
}
|
|
else{
|
|
echo "<b>DATABASE CREATED SUCCESSFULLY!</b><br />";
|
|
}
|
|
echo "<a href=\"eval_setup.php\">Proceed to Evaluations setup</a><br />";
|
|
}
|
|
else
|
|
{
|
|
echo "<br /><b>Notice: Could not find db/db.eval.full.$evaldbcodeversion.sql</b><br />";
|
|
echo "Trying to find an older version... <br />";
|
|
for($x=$evaldbcodeversion;$x>0;$x--)
|
|
{
|
|
if(file_exists("db/db.eval.full.$x.sql"))
|
|
{
|
|
echo "<b>Found db/db.eval.full.$x.sql!</b><br />";
|
|
echo "Setting up 'Evaluations' database tables... ";
|
|
$exit_code = 0;
|
|
$filename = 'db/db.eval.full.'.$x.'.sql';
|
|
// Temporary variable, used to store current query
|
|
$templine = '';
|
|
// 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
|
|
if(!mysql_query($templine)){
|
|
echo('<br/>Error performing query!<br/>'.$templine.'<br/> mysqlerror: '.mysql_error().'<br /><br />');
|
|
$exit_code = -1; // do we bail out here or keep going? keep going for now, get all errors
|
|
}
|
|
// Reset temp variable to empty
|
|
$templine = '';
|
|
}
|
|
}
|
|
echo "<br/><br />";
|
|
if($exit_code != 0) {
|
|
/* mysql failed!, what now? */
|
|
$error_count += 1;
|
|
}
|
|
echo "<b>Installed 'Evaluations' database version $x</b><br />\n";
|
|
echo "<b>Attempting to update 'Evaluations' from $x to $evaldbcodeversion<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");
|
|
include "db_eval_update.php";
|
|
chdir ("../");
|
|
echo "<br />";
|
|
echo "<b>Done!</b><br />";
|
|
// Dennis allert if errors! 2011-02-18
|
|
if ($error_count > 0){
|
|
echo "<b>THERE WERE ERRORS! The 'Evaluations' database was not created correctly!</b><br />";
|
|
}
|
|
else{
|
|
echo "<b>DATABASE CREATED SUCCESSFULLY!</b><br />";
|
|
}
|
|
echo "<a href=\"eval_setup.php\">Proceed to Evaluations setup</a><br />";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
</body>
|