science-ation/plugins/evaluations/sfiab_common.inc.php

116 lines
3.5 KiB
PHP

<?php
/*
This file is a plug-in to 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>
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.
*/
?>
<?php
if(substr(getcwd(),-6)=="/db" || substr(getcwd(),-3)=="\\db")
$prependdir="../";
//else if(substr(getcwd(),-6)=="/super" || substr(getcwd(),-6)=="\\super")
// $prependdir="../";
//else if(substr(getcwd(),-7)=="/config" || substr(getcwd(),-7)=="\\config")
// $prependdir="../";
//else if(substr(getcwd(),-3)=="/db" || substr(getcwd(),-3)=="\\db")
// $prependdir="../";
//else if(substr(getcwd(),-8)=="/scripts" || substr(getcwd(),-8)=="\\scripts")
// $prependdir="../";
else
$prependdir="";
//Plug-in: should rely on SFIAB to open the database. uses the same DBHOST,DBUSER,DBPASS
// Just to make sure.. and for debug we will need the DBHOST, DBUSER,DBPASS
if (!$DBUSER)
{
//echo "Checking SFIAB config <br />";
if(file_exists($prependdir."../../data/config.inc.php"))
{
require_once($prependdir."../../data/config.inc.php");
}
else
{
echo "SFIAB is not setup. Do that prior to starting plug-ins<br />";
exit;
}
$DBUSER=substr($DBUSER,0,16);
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'");
//we might get an error if installation step 2 is not done (ie, the config table doesnt even exist)
if(mysql_error())
{
echo "SFIAB installation is not complete. Plug-ins require a complete installation!";
echo "<br>";
exit;
}
//if we have 0 (<1) then install2 is not done, which would get caught above,
//if we have 1 (<2) then insatll3 is not done (no entries for FAIRYEAR and SFIABDIRECTORY)
if(mysql_num_rows($q)<2)
{
echo "SFIAB installation is not complete. Plug-ins require a complete installation!";
echo "<br>";
exit;
}
else
{
if (!config)
{
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 probably not required in plug-ins keep for now
$q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."'");
while($r=mysql_fetch_object($q))
{
$config['dates'][$r->name]=$r->date;
}
?>