properly detect where the config.inc.php is even when we're in a known SFIAB subdirectory.

This commit is contained in:
james 2005-05-26 19:20:24 +00:00
parent 9604c35f4b
commit 3841d7c86c
2 changed files with 74 additions and 55 deletions

View File

@ -25,8 +25,18 @@
$sfiabversion=@file("version.txt");
$config['version']=$sfiabversion[0];
//figure out the directory to prepend to directoroy names, depending on if we are in a subdirectory or not
if(substr(getcwd(),-6)=="/admin")
$prependdir="../";
else if(substr(getcwd(),-7)=="/config")
$prependdir="../";
else if(substr(getcwd(),-3)=="/db")
$prependdir="../";
else
$prependdir="";
//make sure the data subdirectory is writable, if its not, then we're screwed, so make sure it is!
if(!is_writable("data"))
if(!is_writable($prependdir."data"))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
@ -39,6 +49,62 @@ if(!is_writable("data"))
exit;
}
if(file_exists($prependdir."data/config.inc.php"))
{
require_once($prependdir."data/config.inc.php");
}
else
{
echo "<html><head><title>SFIAB</title></head><body>";
echo "<h1>Science Fair In A Box - Installation</h1>";
echo "It looks like this is a new installation of SFIAB, and the database has not yet been configured. Please choose from the following options: <br />";
echo "<br />";
echo "<a href=\"install.php\">Proceed with Fresh SFIAB Installation</a>";
echo "<br />";
echo "</body></html>";
exit;
}
if(!mysql_connect($DBHOST,$DBUSER,$DBPASS))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "Cannot connect to database!";
echo "</body></html>";
exit;
}
if(!mysql_select_db($DBNAME))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "Cannot select database!";
echo "</body></html>";
exit;
}
//find out the fair year and any other 'year=0' configuration parameters (things that dont change as the years go on)
$q=mysql_query("SELECT * FROM config WHERE year='0'");
while($r=mysql_fetch_object($q))
{
$config[$r->var]=$r->val;
}
//now pull the rest of the configuration
$q=mysql_query("SELECT * FROM config WHERE year='".$config['FAIRYEAR']."'");
while($r=mysql_fetch_object($q))
{
$config[$r->var]=$r->val;
}
//now pull the dates
$q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."'");
while($r=mysql_fetch_object($q))
{
$config['dates'][$r->name]=$r->date;
}
@ -65,66 +131,14 @@ if($dbcodeversion[0]!=$dbdbversion[0])
echo "</body></html>";
exit;
}
if(file_exists("data/config.inc.php"))
{
require_once("data/config.inc.php");
}
else
{
echo "<html><head><title>SFIAB</title></head><body>";
echo "<h1>Science Fair In A Box - Installation</h1>";
echo "It looks like this is a new installation of SFIAB, and the database has not yet been configured. Please choose from the following options: <br />";
echo "<br />";
echo "<a href=\"install.php\">Proceed with Fresh SFIAB Installation</a>";
echo "<br />";
echo "</body></html>";
exit;
}
require_once("committee_auth.php");
if(!mysql_connect($DBHOST,$DBUSER,$DBPASS))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "Cannot connect to database!";
echo "</body></html>";
exit;
}
if(!mysql_select_db($DBNAME))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "Cannot select database!";
echo "</body></html>";
exit;
}
session_start();
//find out the fair year and any other 'year=0' configuration parameters (things that dont change as the years go on)
$q=mysql_query("SELECT * FROM config WHERE year='0'");
while($r=mysql_fetch_object($q))
{
$config[$r->var]=$r->val;
}
//now pull the rest of the configuration
$q=mysql_query("SELECT * FROM config WHERE year='".$config['FAIRYEAR']."'");
while($r=mysql_fetch_object($q))
{
$config[$r->var]=$r->val;
}
//now pull the dates
$q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."'");
while($r=mysql_fetch_object($q))
{
$config['dates'][$r->name]=$r->date;
}
//detect the browser first, so we know what icons to use - we store this in the config array as well
//even though its not configurable by the fair
if(stristr($_SERVER['HTTP_USER_AGENT'],"MSIE"))

View File

@ -52,8 +52,10 @@ if($_POST['dbhost'] && $_POST['dbname'] && $_POST['dbuser'] && $_POST['dbpass'])
echo "<div class=\"happy\">Database connection successful!</div>";
echo "<br />";
echo "Storing database connection information... ";
//create the config.inc.php
if($fp=fopen("data/config.inc.php","w"))
{
fputs($fp,"<?\n");
fputs($fp,"\$DBHOST=\"".$_POST['dbhost']."\";\n");
fputs($fp,"\$DBUSER=\"".$_POST['dbuser']."\";\n");
@ -62,6 +64,9 @@ if($_POST['dbhost'] && $_POST['dbname'] && $_POST['dbuser'] && $_POST['dbpass'])
fputs($fp,"?>\n");
fclose($fp);
echo "<b>Done!</b>";
//only if this file was created will we go ahead with the rest
//creating all the tables and such..
}
else
{