From 3841d7c86c7524d7808d8de96303af0ae2ec26a4 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 26 May 2005 19:20:24 +0000 Subject: [PATCH] properly detect where the config.inc.php is even when we're in a known SFIAB subdirectory. --- common.inc.php | 124 +++++++++++++++++++++++++++---------------------- install.php | 5 ++ 2 files changed, 74 insertions(+), 55 deletions(-) diff --git a/common.inc.php b/common.inc.php index c64775b..6488314 100644 --- a/common.inc.php +++ b/common.inc.php @@ -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 "SFIAB ERROR"; echo "

Science Fair In A Box - ERROR

"; @@ -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 "SFIAB"; + echo "

Science Fair In A Box - Installation

"; + 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:
"; + echo "
"; + echo "Proceed with Fresh SFIAB Installation"; + echo "
"; + echo ""; + exit; +} + +if(!mysql_connect($DBHOST,$DBUSER,$DBPASS)) +{ + echo "SFIAB ERROR"; + echo "

Science Fair In A Box - ERROR

"; + echo "Cannot connect to database!"; + echo ""; + exit; +} + +if(!mysql_select_db($DBNAME)) +{ + echo "SFIAB ERROR"; + echo "

Science Fair In A Box - ERROR

"; + echo "Cannot select database!"; + echo ""; + 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 ""; exit; } -if(file_exists("data/config.inc.php")) -{ - require_once("data/config.inc.php"); -} -else -{ - echo "SFIAB"; - echo "

Science Fair In A Box - Installation

"; - 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:
"; - echo "
"; - echo "Proceed with Fresh SFIAB Installation"; - echo "
"; - echo ""; - exit; -} + require_once("committee_auth.php"); -if(!mysql_connect($DBHOST,$DBUSER,$DBPASS)) -{ - echo "SFIAB ERROR"; - echo "

Science Fair In A Box - ERROR

"; - echo "Cannot connect to database!"; - echo ""; - exit; -} - -if(!mysql_select_db($DBNAME)) -{ - echo "SFIAB ERROR"; - echo "

Science Fair In A Box - ERROR

"; - echo "Cannot select database!"; - echo ""; - 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")) diff --git a/install.php b/install.php index baf968d..d5efc15 100644 --- a/install.php +++ b/install.php @@ -52,8 +52,10 @@ if($_POST['dbhost'] && $_POST['dbname'] && $_POST['dbuser'] && $_POST['dbpass']) echo "
Database connection successful!
"; echo "
"; echo "Storing database connection information... "; + //create the config.inc.php if($fp=fopen("data/config.inc.php","w")) { + fputs($fp,"\n"); fclose($fp); echo "Done!"; + + //only if this file was created will we go ahead with the rest + //creating all the tables and such.. } else {