2004-11-10 13:52:01 +00:00
< ?
2005-01-24 18:00:03 +00:00
/*
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 >
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 .
*/
?>
< ?
2010-02-03 16:20:23 +00:00
//if we dont set the charset any page that doesnt call send_header() (where it used to be set) would defualt to the server's encoding,
//which in many cases (like ysf-fsj.ca/sfiab) is UTF-8. This was causing a lot of the newly AJAX'd editors to fail on french characters,
//becuase they were being encoded improperly. Ideally, all the databases will be switched to UTF-8, but thats not a near-term possibility,
//so this is kind of a band-aid solution until we can make everything UTF8. Hope it doesnt break anything anywhere else!
2010-06-04 20:23:59 +00:00
header ( " Content-Type: text/html; charset=UTF-8 " );
2010-02-03 16:20:23 +00:00
2006-09-04 16:13:07 +00:00
//set error reporting to not show notices, for some reason some people's installation dont set this by default
//so we will set it in the code instead just to make sure
error_reporting ( E_ALL ^ E_NOTICE );
2006-01-12 16:27:47 +00:00
define ( 'REQUIREDFIELD' , '<span class="requiredfield">*</span>' );
2005-05-26 19:20:24 +00:00
//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 = " ../ " ;
2010-06-03 19:21:27 +00:00
else if ( substr ( getcwd (), - 6 ) == " /super " )
$prependdir = " ../ " ;
2005-05-26 19:20:24 +00:00
else if ( substr ( getcwd (), - 7 ) == " /config " )
$prependdir = " ../ " ;
else if ( substr ( getcwd (), - 3 ) == " /db " )
$prependdir = " ../ " ;
2006-01-03 02:03:30 +00:00
else if ( substr ( getcwd (), - 8 ) == " /scripts " )
$prependdir = " ../ " ;
2005-05-26 19:20:24 +00:00
else
$prependdir = " " ;
2005-11-21 21:11:34 +00:00
$sfiabversion =@ file ( $prependdir . " version.txt " );
2006-02-14 21:50:41 +00:00
$config [ 'version' ] = trim ( $sfiabversion [ 0 ]);
2005-11-21 21:11:34 +00:00
2005-05-25 21:58:03 +00:00
//make sure the data subdirectory is writable, if its not, then we're screwed, so make sure it is!
2005-05-26 19:20:24 +00:00
if ( ! is_writable ( $prependdir . " data " ))
2005-05-25 21:58:03 +00:00
{
echo " <html><head><title>SFIAB ERROR</title></head><body> " ;
echo " <h1>Science Fair In A Box - ERROR</h1> " ;
echo " data/ subdirectory is not writable by the web server " ;
echo " <br> " ;
echo " <h2>Details</h2> " ;
echo " The data/ subdirectory is used to store files uploaded through the SFIAB software. The web server must have write access to this directory in order to function properly. Please contact your system administrator (if you are the system administrator, chown/chmod the data directory appropriately). " ;
echo " <br> " ;
echo " </body></html> " ;
exit ;
}
2005-05-26 19:20:24 +00:00
if ( file_exists ( $prependdir . " data/config.inc.php " ))
2005-05-25 21:58:03 +00:00
{
2005-05-26 19:20:24 +00:00
require_once ( $prependdir . " data/config.inc.php " );
2005-05-25 21:58:03 +00:00
}
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 ;
}
2005-03-10 17:28:15 +00:00
2005-05-25 21:58:03 +00:00
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 ;
}
2005-06-07 21:03:55 +00:00
2010-06-09 15:14:41 +00:00
//this will silently fail on mysql 4.x, but is needed on mysql5.x to ensure we're only using utf8 encodings
@ mysql_query ( " SET NAMES utf8 " );
2004-11-30 19:06:35 +00:00
//find out the fair year and any other 'year=0' configuration parameters (things that dont change as the years go on)
2010-06-23 16:06:01 +00:00
$q =@ mysql_query ( " SELECT * FROM config WHERE conferences_id=0 OR year=0 " );
2005-06-07 21:07:52 +00:00
//we might get an error if installation step 2 is not done (ie, the config table doesnt even exist)
if ( mysql_error ())
{
echo " <html><head><title>SFIAB ERROR</title></head><body> " ;
echo " <h1>Science Fair In A Box - ERROR</h1> " ;
echo " SFIAB installation is not complete. Please go to <A href= \" install2.php \" >Installer Step 2</a> to complete the installation process " ;
echo " <br> " ;
echo " </body></html> " ;
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 )
2004-11-30 19:06:35 +00:00
{
2005-06-07 01:23:15 +00:00
echo " <html><head><title>SFIAB ERROR</title></head><body> " ;
echo " <h1>Science Fair In A Box - ERROR</h1> " ;
echo " SFIAB installation is not complete. Please go to <A href= \" install3.php \" >Installer Step 3</a> to complete the installation process " ;
echo " <br> " ;
echo " </body></html> " ;
exit ;
}
else
{
2010-06-17 21:14:00 +00:00
while ( $r = mysql_fetch_object ( $q )) {
2005-06-07 01:23:15 +00:00
$config [ $r -> var ] = $r -> val ;
}
2004-11-30 19:06:35 +00:00
}
2004-11-30 18:34:25 +00:00
2005-06-07 21:03:55 +00:00
$dbdbversion = $config [ 'DBVERSION' ];
$dbcodeversion =@ file ( $prependdir . " db/db.code.version.txt " );
2005-06-07 21:10:39 +00:00
$dbcodeversion = trim ( $dbcodeversion [ 0 ]);
2005-06-07 21:03:55 +00:00
if ( ! $dbdbversion )
{
echo " <html><head><title>SFIAB ERROR</title></head><body> " ;
echo " <h1>Science Fair In A Box - ERROR</h1> " ;
echo " SFIAB installation is not complete. Please go to <A href= \" install2.php \" >Installer Step 2</a> to complete the installation process " ;
echo " <br> " ;
echo " </body></html> " ;
exit ;
}
2005-06-07 21:10:39 +00:00
if ( $dbcodeversion != $dbdbversion )
2005-06-07 21:03:55 +00:00
{
echo " <html><head><title>SFIAB ERROR</title></head><body> " ;
echo " <h1>Science Fair In A Box - ERROR</h1> " ;
echo " SFIAB database and code are mismatched " ;
echo " <br> " ;
echo " Please run the db_update.php script in order to update " ;
echo " <br> " ;
echo " your database to the same version as the code " ;
echo " <br> " ;
echo " <br> " ;
echo " <br> " ;
echo " <h2>Details</h2> " ;
2005-06-07 21:10:39 +00:00
echo " Current SFIAB codebase requires DB version: " . $dbcodeversion ;
2005-06-07 21:03:55 +00:00
echo " <br> " ;
echo " Current SFIAB database is detected as version: " . $dbdbversion ;
echo " <br> " ;
echo " </body></html> " ;
exit ;
}
2010-04-18 22:40:07 +00:00
/* Check that magic_quotes is OFF */
if ( get_magic_quotes_gpc ()) {
?>
< html >< head >< title > SFIAB ERROR </ title ></ head >< body >
< h1 > Science Fair In A Box - ERROR </ h1 >
< p > Your PHP configuration has magic_quotes ENABLED . They should be
disabled , and are disabled in the . htaccess file , so your server is
ignoring the . htaccess file or overriding it .
< p > Magic quotes is DEPRECATED as of PHP 5.3 . 0 , REMOVE as of 6.0 , but ON
by default for any PHP & lt ; 5.3 . 0.
< p > It ' s a pain in the butt because PHP runs urldecode () on all inputs
from GET and POST , but if it sees the string has quotes , then it escapes
existing quotes before passing it to us . This is a problem for json_decode
where we do not want this behaviour , and thus need to pass through stripslashes ()
first , but only if magicquotes is ON . If it ' s off , stripslashes will
break json_decode .
< p > Add < pre > php_flag magic_quotes_gpc off </ pre > to the . htacces , or add
< pre > php_flag magic_quotes_gpc = off </ pre > to php . ini
< br ></ body ></ html >
< ?
exit ;
}
2005-06-07 21:03:55 +00:00
2010-06-10 19:40:20 +00:00
if ( $config [ 'SFIABDIRECTORY' ] == '' ) {
session_name ( " SFIABSESSID " );
session_set_cookie_params ( 0 , '/' );
} else {
session_name ( " SFIABSESSID " . ereg_replace ( " [^A-Za-z] " , " _ " , $config [ 'SFIABDIRECTORY' ]));
session_set_cookie_params ( 0 , $config [ 'SFIABDIRECTORY' ]);
}
session_start ();
2010-06-10 17:58:27 +00:00
2010-07-13 05:20:35 +00:00
if ( ! $_SESSION [ 'conferences_id' ]) {
2010-06-17 21:14:00 +00:00
$q = mysql_query ( " SELECT * FROM conferences WHERE status='running' ORDER BY name LIMIT 1 " );
if ( $r = mysql_fetch_object ( $q )) {
2010-07-13 05:20:35 +00:00
$_SESSION [ 'conferences_id' ] = $r -> id ;
2010-06-17 21:14:00 +00:00
}
else {
echo " No conferences defined! " ;
}
}
2010-06-10 17:58:27 +00:00
//move the conference stuff before the configuration loading, so we can load the right configuration for the conference :)
if ( isset ( $_GET [ 'switchconference' ])) {
//make sure its good
$cid = intval ( $_GET [ 'switchconference' ]);
// echo "cid=$cid";
2010-06-17 21:14:00 +00:00
$q = mysql_query ( " SELECT * FROM conferences WHERE id=' $cid ' AND status='running' " );
if ( $r = mysql_fetch_object ( $q )) {
2010-07-13 05:20:35 +00:00
$_SESSION [ 'conferences_id' ] = $cid ;
2010-06-10 17:58:27 +00:00
}
}
2010-07-13 05:20:35 +00:00
if ( intval ( $_SESSION [ 'conferences_id' ]) > 0 ) {
$q = mysql_query ( " SELECT * FROM conferences WHERE id=' { $_SESSION [ 'conferences_id' ] } ' " );
2010-06-10 17:58:27 +00:00
$conference = mysql_fetch_assoc ( $q );
2010-06-17 21:14:00 +00:00
/*
******* THIS IS TEMPORARY .. probably remove it in a year or so ********
if the conference year is set , this is temporary for migratory purposes , so set the FAIRYEAR = confierence year - this will
gracefully handle the science fair parts that still rely on FAIRYEAR
if conference year is NOT set , then make sure config [ 'FAIRYEAR' ] is NOT set , so we can weed out any code that relies on
FAIRYEAR from the conference system
*/
if ( $conference [ 'year' ])
$config [ 'FAIRYEAR' ] = $conference [ 'year' ];
else
$config [ 'FAIRYEAR' ] = NULL ;
2010-06-10 17:58:27 +00:00
}
2004-11-30 18:34:25 +00:00
//now pull the rest of the configuration
2010-06-23 16:06:01 +00:00
$q = mysql_query ( " SELECT * FROM config WHERE conferences_id=' " . $conference [ 'id' ] . " ' " );
2010-06-17 21:14:00 +00:00
while ( $r = mysql_fetch_object ( $q )) {
2004-11-30 18:34:25 +00:00
$config [ $r -> var ] = $r -> val ;
}
2005-03-29 19:21:14 +00:00
//now pull the dates
2010-06-10 17:58:27 +00:00
if ( $conference [ 'id' ])
$q = mysql_query ( " SELECT * FROM dates WHERE conferences_id=' " . $conference [ 'id' ] . " ' " );
else
2010-06-23 16:06:01 +00:00
$config [ 'dates' ] = array ();
2010-06-10 17:58:27 +00:00
while ( $r = mysql_fetch_object ( $q )) {
2005-03-29 19:21:14 +00:00
$config [ 'dates' ][ $r -> name ] = $r -> date ;
}
2010-07-13 03:30:11 +00:00
//load roles
$roles = array ();
$q = mysql_query ( " SELECT * FROM roles " );
while (( $r = mysql_fetch_assoc ( $q ))) {
$roles [ $r [ 'type' ]] = $r ;
}
2008-07-24 16:20:16 +00:00
//and now pull the theme
2009-11-06 22:10:06 +00:00
require_once ( " theme/ { $config [ 'theme' ] } /theme.php " );
require_once ( " theme/ { $config [ 'theme_icons' ] } /icons.php " );
2008-07-24 16:20:16 +00:00
2004-12-20 16:36:25 +00:00
//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 " ))
$config [ 'icon_extension' ] = " gif " ;
else
$config [ 'icon_extension' ] = " png " ;
2004-11-30 18:34:25 +00:00
//now get the languages, and make sure we have at least one active language
$q = mysql_query ( " SELECT * FROM languages WHERE active='Y' ORDER BY langname " );
2010-06-03 19:21:27 +00:00
if ( mysql_num_rows ( $q ) == 0 ) {
2004-11-30 18:34:25 +00:00
echo " No active languages defined, defaulting to English " ;
$config [ 'languages' ][ 'en' ] = " English " ;
}
2010-06-03 19:21:27 +00:00
else {
while ( $r = mysql_fetch_object ( $q )) {
2004-11-30 18:34:25 +00:00
$config [ 'languages' ][ $r -> lang ] = $r -> langname ;
}
}
2004-11-30 18:52:31 +00:00
//now if no language has been set yet, lets set it to the default language
2010-06-03 19:21:27 +00:00
if ( ! $_SESSION [ 'lang' ]) {
2004-11-30 18:52:31 +00:00
//first try the default language, if that doesnt work, use "en"
if ( $config [ 'default_language' ])
$_SESSION [ 'lang' ] = $config [ 'default_language' ];
else
$_SESSION [ 'lang' ] = " en " ;
}
2007-12-20 22:39:21 +00:00
//only allow debug to get set if we're using a development version (odd numbered ending)
if ( substr ( $config [ 'version' ], - 1 ) % 2 != 0 )
if ( $_GET [ 'debug' ]) $_SESSION [ 'debug' ] = $_GET [ 'debug' ];
2004-11-30 18:34:25 +00:00
//if the user has switched languages, go ahead and switch the session variable
2010-06-03 19:21:27 +00:00
if ( $_GET [ 'switchlanguage' ]) {
2004-11-30 18:34:25 +00:00
//first, make sure its a valid language:
2010-06-03 19:21:27 +00:00
if ( $config [ 'languages' ][ $_GET [ 'switchlanguage' ]]) {
2004-11-30 18:34:25 +00:00
$_SESSION [ 'lang' ] = $_GET [ 'switchlanguage' ];
}
2010-06-03 19:21:27 +00:00
else {
2004-11-30 18:34:25 +00:00
//invalid language, dont do anything
}
}
2007-04-03 20:12:43 +00:00
function i18n ( $str , $args = array (), $argsdesc = array (), $forcelang = " " )
2004-11-30 17:46:39 +00:00
{
if ( ! $str )
return " " ;
2007-04-03 20:12:43 +00:00
if ( $forcelang )
{
$savelang = $_SESSION [ 'lang' ];
$_SESSION [ 'lang' ] = $forcelang ;
}
2004-11-30 17:46:39 +00:00
if ( $_SESSION [ 'lang' ])
{
if ( $_SESSION [ 'lang' ] == " en " )
2004-11-30 22:59:27 +00:00
{
for ( $x = 1 ; $x <= count ( $args ); $x ++ )
{
$str = str_replace ( " % $x " , $args [ $x - 1 ], $str );
}
2007-04-03 20:12:43 +00:00
if ( $forcelang ) $_SESSION [ 'lang' ] = $savelang ;
2004-11-30 17:46:39 +00:00
return $str ;
2004-11-30 22:59:27 +00:00
}
2004-11-30 17:46:39 +00:00
else
{
2004-11-30 18:34:25 +00:00
$q = mysql_query ( " SELECT * FROM translations WHERE lang=' " . $_SESSION [ 'lang' ] . " ' AND strmd5=' " . md5 ( $str ) . " ' " );
2004-11-30 17:46:39 +00:00
if ( $r =@ mysql_fetch_object ( $q ))
{
if ( $r -> val )
2004-11-30 22:59:27 +00:00
{
$ret = $r -> val ;
for ( $x = 1 ; $x <= count ( $args ); $x ++ )
{
$ret = str_replace ( " % $x " , $args [ $x - 1 ], $ret );
}
2007-04-03 20:12:43 +00:00
if ( $forcelang ) $_SESSION [ 'lang' ] = $savelang ;
2004-11-30 22:59:27 +00:00
return $ret ;
}
2004-11-30 17:46:39 +00:00
else
{
2004-11-30 22:59:27 +00:00
for ( $x = 1 ; $x <= count ( $args ); $x ++ )
{
$str = str_replace ( " % $x " , $args [ $x - 1 ], $str );
}
2007-04-03 20:12:43 +00:00
if ( $forcelang ) $_SESSION [ 'lang' ] = $savelang ;
2006-01-19 17:15:07 +00:00
return " { { " . $str . " }} " ;
2004-11-30 17:46:39 +00:00
}
}
else
{
2006-01-19 17:15:07 +00:00
if ( count ( $argsdesc ))
{
$argsdescstring = " " ;
$n = 1 ;
foreach ( $argsdesc AS $ad )
{
$argsdescstring .= " % $n = $ad , " ;
$n ++ ;
}
$argsdescstring = substr ( $argsdescstring , 0 , - 2 );
$argsdescstring = " ' " . mysql_escape_string ( $argsdescstring ) . " ' " ;
}
else
$argsdescstring = " null " ;
mysql_query ( " INSERT INTO translations (lang,strmd5,str,argsdesc) VALUES (' " . $_SESSION [ 'lang' ] . " ',' " . md5 ( $str ) . " ',' " . mysql_escape_string ( $str ) . " ', $argsdescstring ) " );
2004-11-30 22:59:27 +00:00
for ( $x = 1 ; $x <= count ( $args ); $x ++ )
{
$str = str_replace ( " % $x " , $args [ $x - 1 ], $str );
}
2007-04-03 20:12:43 +00:00
if ( $forcelang ) $_SESSION [ 'lang' ] = $savelang ;
2006-01-19 17:15:07 +00:00
return " { { " . $str . " }} " ;
2004-11-30 17:46:39 +00:00
}
}
}
else
{
//no language set, assume english
2007-04-03 20:12:43 +00:00
if ( $forcelang ) $_SESSION [ 'lang' ] = $savelang ;
2004-11-30 17:46:39 +00:00
return $str ;
}
}
2005-05-06 16:13:37 +00:00
function error ( $str , $type = " normal " )
2004-11-30 22:59:27 +00:00
{
2005-05-06 16:13:37 +00:00
if ( $type == " normal " )
return " <div class= \" error \" > $str </div><br /> " ;
else if ( $type == " inline " )
return " <span class= \" error \" > $str </span><br /> " ;
2004-11-30 22:59:27 +00:00
}
2005-05-06 16:13:37 +00:00
function notice ( $str , $type = " normal " )
2004-11-30 22:59:27 +00:00
{
2005-05-06 16:13:37 +00:00
if ( $type == " normal " )
return " <div class= \" notice \" > $str </div><br /> " ;
else if ( $type == " inline " )
return " <span class= \" notice \" > $str </span><br /> " ;
2004-11-30 22:59:27 +00:00
}
2004-11-10 13:52:01 +00:00
2005-05-06 16:13:37 +00:00
function happy ( $str , $type = " normal " )
2004-12-08 20:34:02 +00:00
{
2005-05-06 16:13:37 +00:00
if ( $type == " normal " )
return " <div class= \" happy \" > $str </div><br /> " ;
else if ( $type == " inline " )
return " <span class= \" happy \" > $str </span><br /> " ;
2004-12-08 20:34:02 +00:00
}
2009-09-09 00:26:12 +00:00
function display_messages ()
{
/* Dump any messages in the queue */
if ( is_array ( $_SESSION [ 'messages' ])) {
foreach ( $_SESSION [ 'messages' ] as $m ) echo $m ;
}
$_SESSION [ 'messages' ] = array ();
}
2004-11-30 22:59:27 +00:00
$HEADER_SENT = false ;
2008-11-02 02:35:46 +00:00
function send_header ( $title = " " , $nav = null , $icon = null , $titletranslated = false )
2004-11-10 13:52:01 +00:00
{
2004-11-30 22:59:27 +00:00
global $HEADER_SENT ;
2004-11-30 18:34:25 +00:00
global $config ;
2010-07-13 21:23:39 +00:00
global $roles ;
2007-10-23 21:54:22 +00:00
global $prependdir ;
2010-06-09 20:24:52 +00:00
global $conference ;
2004-11-30 22:59:27 +00:00
//do this so we can use send_header() a little more loosly and not worry about it being sent more than once.
if ( $HEADER_SENT ) return ;
else $HEADER_SENT = true ;
2004-11-30 18:34:25 +00:00
2004-11-10 13:52:01 +00:00
?>
2010-07-12 19:40:06 +00:00
<! doctype html >
< html >
2008-11-02 02:35:46 +00:00
< head >< title >< ? if ( $title && ! $titletranslated ) echo i18n ( $title ); else if ( $title ) echo $title ; else echo i18n ( $config [ 'fairname' ]); ?> </title>
2009-11-06 08:24:31 +00:00
< link rel = " stylesheet " href = " <?= $config['SFIABDIRECTORY'] ?>/theme/<?= $config['theme'] ?>/jquery-ui-1.7.2.custom.css " type = " text/css " media = " all " />
2008-07-24 16:20:16 +00:00
< link rel = " stylesheet " href = " <?= $config['SFIABDIRECTORY'] ?>/theme/<?= $config['theme'] ?>/sfiab.css " type = " text/css " media = " all " />
< link rel = " stylesheet " href = " <?= $config['SFIABDIRECTORY'] ?>/tableeditor.css " type = " text/css " media = " all " />
2004-11-10 15:31:30 +00:00
</ head >
< body >
2009-10-28 18:51:02 +00:00
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/jquery/1.3.2/jquery.min.js " ></ script >
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/jqueryui/1.7.2/jquery-ui.min.js " ></ script >
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/sfiab.js " ></ script >
2010-03-30 21:59:04 +00:00
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/tablesorter/jquery.tablesorter.min.js " ></ script >
2010-07-15 09:18:08 +00:00
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/validate/jquery.validate.pack.js " ></ script >
2010-03-30 21:59:04 +00:00
< script type = " text/javascript " >
$ ( document ) . ready ( function (){
$ ( '.tableview' ) . tablesorter ();
2010-07-12 20:29:20 +00:00
if ( $ ( " #importantdatesbox " ) . length )
$ ( " #importantdatesbox " ) . load ( " important_dates.php?display=box " );
2010-03-30 21:59:04 +00:00
});
2010-07-13 21:23:39 +00:00
function taskNav ( id , pid , level ) {
switch ( level ) {
case 0 : //clicked on a top-level nav, so populate the secondary menu
$ ( " #secondarymenu " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/nav.php?level=1&id= " + id );
$ ( " #secondarymenu " ) . show ();
$ ( " #tertiarymenu " ) . hide ();
$ ( " .primarynav-selected " ) . removeClass ( " primarynav-selected " );
$ ( " #primary_nav_ " + id ) . addClass ( " primarynav-selected " );
break ;
case 1 : //clicked on a secondary nav, so populate the left-menu
$ ( " .secondarynav-selected " ) . removeClass ( " secondarynav-selected " );
$ ( " #secondary_nav_ " + id ) . addClass ( " secondarynav-selected " );
$ ( " #tertiarymenu_accordion " ) . accordion ( " destroy " );
$ ( " #tertiarymenu_accordion " ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/nav.php?level=2&id= " + id , null , function () {
$ ( " #tertiarymenu_accordion " ) . accordion ({ clearStyle : true }); //"option", "collapsible", true);
});
$ ( " #tertiarymenu " ) . show ();
break ;
}
return false ;
}
2010-03-30 21:59:04 +00:00
</ script >
2006-09-19 22:40:46 +00:00
< ?
2009-09-11 05:33:41 +00:00
//if we're under /admin or /config we also want the translation editor
2006-09-19 22:40:46 +00:00
if ( substr ( getcwd (), - 6 ) == " /admin " || substr ( getcwd (), - 7 ) == " /config " )
2009-09-11 05:33:41 +00:00
require_once ( " ../translationseditor.inc.php " );
2006-09-19 22:40:46 +00:00
?>
2009-09-18 03:29:13 +00:00
< div id = " notice_area " class = " notice_area " ></ div >
2010-07-09 19:04:25 +00:00
< div id = " topnav " >
< ?
2010-07-09 19:24:04 +00:00
echo " <form name= \" languageselect \" method= \" get \" action= \" " . $_SERVER [ 'PHP_SELF' ] . " \" > " ;
echo " <a href= \" { $config [ " SFIABDIRECTORY " ] } /contact.php \" > " . i18n ( " Contact Us " ) . " </a> | \n " ;
2010-07-09 19:04:25 +00:00
if ( count ( $config [ 'languages' ]) > 1 ) {
echo i18n ( " Language " ) . " : " ;
echo " <select name= \" switchlanguage \" onchange= \" document.forms.languageselect.submit() \" > \n " ;
foreach ( $config [ 'languages' ] AS $key => $val ) {
if ( $_SESSION [ 'lang' ] == $key ) $selected = " selected= \" selected \" " ; else $selected = " " ;
echo " <option $selected value= \" $key\ " > $val </ option > " ;
}
echo " </select> " ;
}
2010-07-09 19:24:04 +00:00
echo " </form> " ;
2010-07-09 19:04:25 +00:00
?>
</ div >
2004-11-30 17:46:39 +00:00
< div id = " header " >
2010-07-09 19:04:25 +00:00
< div id = " header_logo " >
2004-11-30 17:46:39 +00:00
< ?
2010-07-09 19:24:04 +00:00
echo " <a href= \" { $config [ 'SFIABDIRECTORY' ] } /index.php \" > " ;
2010-07-09 19:04:25 +00:00
if ( file_exists ( $prependdir . " data/ { $conference [ 'id' ] } -logo-100.gif " )) {
2010-07-09 19:24:04 +00:00
echo " <img style= \" border: 0px; \" height= \" 70 \" src= \" " . $config [ 'SFIABDIRECTORY' ] . " /data/ { $conference [ 'id' ] } -logo-100.gif \" > " ;
2010-07-09 19:04:25 +00:00
} else if ( file_exists ( $prependdir . " data/logo-100.gif " )) {
2010-07-09 19:24:04 +00:00
echo " <img style= \" border: 0px; \" height= \" 70 \" src= \" " . $config [ 'SFIABDIRECTORY' ] . " /data/logo-100.gif \" > " ;
} else {
echo i18n ( " Home Page " );
2010-07-09 19:04:25 +00:00
}
2010-07-09 19:24:04 +00:00
echo " </a> " ;
2010-07-09 19:04:25 +00:00
?>
</ div >
< div id = " header_title " >
< ?
2007-11-12 20:43:47 +00:00
2010-07-13 05:20:35 +00:00
if ( ! $_SESSION [ 'conferences_id' ]) {
2010-06-03 19:21:27 +00:00
echo " <h1> " . i18n ( $config [ 'fairname' ]) . " </h1> " ;
} else {
global $conference ;
echo " <h1> " . i18n ( $conference [ 'name' ]) . " </h1> " ;
}
2010-07-09 19:04:25 +00:00
?>
</ div >
< div id = " header_conferences " >
< ?
$q = mysql_query ( " SELECT * FROM conferences WHERE status='running' ORDER BY name " );
if ( mysql_num_rows ( $q )) {
echo " <ul class= \" conferencenav \" > " ;
while ( $r = mysql_fetch_object ( $q )) {
2010-07-13 05:20:35 +00:00
if ( $_SESSION [ 'conferences_id' ] == $r -> id )
2010-07-09 19:04:25 +00:00
$cl = " class= \" selected \" " ;
else
$cl = " " ;
echo " <li $cl ><a $cl href= \" " . $_SERVER [ 'PHP_SELF' ] . " ?switchconference= $r->id\ " > $r -> name </ a ></ li > \n " ;
}
echo " </ul> \n " ;
}
?>
</ div >
< div id = " header_login " >
< ?
2010-07-13 21:23:39 +00:00
if ( isset ( $_SESSION [ 'roles' ]) && $_SESSION [ 'username' ]) {
echo i18n ( " Logged in as %1 " , array ( $_SESSION [ 'username' ])) . " <br /> " ;
echo " <a href= \" { $config [ 'SFIABDIRECTORY' ] } /user_login.php?action=logout \" > " . i18n ( " Logout " ) . " </a> " ;
2007-11-13 21:00:58 +00:00
2007-11-12 20:43:47 +00:00
} else if ( isset ( $_SESSION [ 'email' ])) {
/* Backwards compatible login settings */
2009-09-09 00:26:12 +00:00
if ( isset ( $_SESSION [ 'registration_id' ])) {
2007-11-12 20:43:47 +00:00
echo i18n ( 'Participant' );
echo " { $_SESSION [ 'email' ] } : " ;
2007-11-13 14:47:01 +00:00
echo " <a href= \" { $config [ 'SFIABDIRECTORY' ] } /register_participants.php?action=logout \" >[ " . i18n ( " Logout " ) . " ]</a> " ;
2007-11-12 20:43:47 +00:00
} else {
echo " " ;
}
} else {
2010-07-09 19:04:25 +00:00
?>
2010-07-13 03:30:11 +00:00
< form method = " post " action = " user_login.php " >
2010-07-09 19:04:25 +00:00
< input type = " hidden " name = " action " value = " login " />
2010-07-09 20:25:31 +00:00
< table cellspacing = 1 cellpadding = 1 >< tr >< td >
2010-07-13 04:33:42 +00:00
< ? = i18n ( " Username " ) ?> :</td><td><input type="text" size="14" name="username" />
2010-07-09 19:04:25 +00:00
</ td ></ tr >< tr >< td >
2010-07-13 03:54:34 +00:00
< ? = i18n ( " Password " ) ?> :</td><td><input type="password" size="14" name="password" />
2010-07-09 19:04:25 +00:00
</ td ></ tr >
2010-07-09 19:24:04 +00:00
< tr >< td align = " center " colspan = " 2 " >
< a href = " register.php " >< ? = i18n ( " Register " ) ?> </a>
& nbsp ; & nbsp ; & nbsp ;
2010-07-09 19:04:25 +00:00
< input type = " submit " value =< ? = i18n ( " Login " ) ?> />
</ td ></ tr >
</ table >
</ form >
< ?
2007-11-12 20:43:47 +00:00
}
2004-11-30 17:46:39 +00:00
?>
2010-07-09 19:04:25 +00:00
</ div >
2004-11-30 17:46:39 +00:00
</ div >
2010-07-09 20:25:31 +00:00
< div id = " primarymenu " >
2007-03-08 21:33:22 +00:00
< ?
2009-10-01 17:05:11 +00:00
if ( is_array ( $nav )) {
$navkeys = array_keys ( $nav );
switch ( $navkeys [ 2 ]) {
case " Fundraising " :
2010-07-13 21:23:39 +00:00
echo " <ul class= \" primarynav \" > \n " ;
2009-10-01 17:05:11 +00:00
echo " <li><h4 style= \" text-align: center; \" > " . i18n ( " Fundraising " ) . " </h4></li> \n " ;
2009-10-01 17:08:56 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /admin/fundraising.php \" > " . i18n ( " Fundraising Dashboard " ) . '</a></li>' ;
2009-10-02 19:21:43 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /admin/fundraising_setup.php \" > " . i18n ( " Fundraising Setup " ) . '</a></li>' ;
2009-10-14 19:53:09 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /admin/fundraising_campaigns.php \" > " . i18n ( " Manage Appeals " ) . '</a></li>' ;
2009-10-02 16:46:13 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /admin/donors.php \" > " . i18n ( " Manage Donors/Sponsors " ) . '</a></li>' ;
2009-10-16 15:43:26 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /admin/fundraising_reports.php \" > " . i18n ( " Fundraising Reports " ) . '</a></li>' ;
2009-10-01 17:05:11 +00:00
echo " </ul><br /> \n " ;
break ;
default :
//no special menu
break ;
}
}
?>
2010-07-13 21:23:39 +00:00
< ul class = " primarynav " >
2007-11-16 07:54:33 +00:00
< ?
2010-07-11 14:46:44 +00:00
if ( $config [ 'website' ]) {
if ( $config [ 'website_name' ]) {
echo " <li><a href= \" { $config [ 'website' ] } \" > { $config [ 'website_name' ] } </a></li> " ;
} else {
echo " <li><a href= \" { $config [ 'website' ] } \" > " . i18n ( " Fair Home " ) . '</a></li>' ;
}
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /index.php \" > " . i18n ( " Registration Home " ) . '</a></li>' ;
} else {
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /index.php \" > " . i18n ( " Home " ) . '</a></li>' ;
}
2010-07-12 20:29:20 +00:00
//if the date is greater than the date/time that the confirmed participants gets posted,
//then we will show the registration confirmation page as a link in the menu,
$registrationconfirmationlink = " " ;
//only display it if a date is set to begin with.
if ( $config [ 'dates' ][ 'postparticipants' ] && $config [ 'dates' ][ 'postparticipants' ] != " 0000-00-00 00:00:00 " ) {
$q = mysql_query ( " SELECT (NOW()>' " . $config [ 'dates' ][ 'regclose' ] . " ') AS test " );
$r = mysql_fetch_object ( $q );
if ( $r -> test == 1 ) {
$registrationconfirmationlink = " <li><a href= \" " . $config [ 'SFIABDIRECTORY' ] . " /confirmed_participants.php \" > " . i18n ( " Confirmed Participants " ) . " </a></li> " ;
}
}
2007-11-16 07:54:33 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /important_dates.php \" > " . i18n ( " Important Dates " ) . '</a></li>' ;
echo $registrationconfirmationlink ;
2009-09-09 00:26:12 +00:00
/*
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /register_participants.php \" > " . i18n ( " Participant Registration " ) . '</a></li>' ;
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /user_login.php?type=judge \" > " . i18n ( " Judges Registration " ) . '</a></li>' ;
2007-11-16 07:54:33 +00:00
if ( $config [ 'volunteer_enable' ] == 'yes' ) {
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /user_login.php?type=volunteer \" > " . i18n ( " Volunteer Registration " ) . '</a></li>' ;
}
2009-09-09 00:26:12 +00:00
*/
2007-11-16 07:54:33 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /committees.php \" > " . i18n ( " Committee " ) . '</a></li>' ;
2010-07-13 20:18:50 +00:00
if ( $config [ 'show_winners' ] == " yes " ) {
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /winners.php \" > " . i18n ( " Winners " ) . '</a></li>' ;
}
2010-07-12 20:29:20 +00:00
2010-07-13 21:23:39 +00:00
if ( is_array ( $_SESSION [ 'roles' ])) {
foreach ( $_SESSION [ 'roles' ] AS $roletype ) {
$roleid = $roles [ $roletype ][ 'id' ];
$q = mysql_query ( " SELECT * FROM rolestasks WHERE roles_id=' $roleid ' AND pid=0 ORDER BY task " );
if ( mysql_num_rows ( $q ) == 1 ) {
$setPrimaryNav = true ;
}
$cl = " " ;
while ( $r = mysql_fetch_object ( $q )) {
if ( $setPrimarynav ) {
$_SESSION [ 'nav' ][ 'primary' ] = $r -> id ;
$cl = " class= \" selected \" " ;
}
echo " <li id= \" primary_nav_ { $r -> id } \" $cl ><a href= \" # \" onclick= \" return taskNav( $r->id , $r->pid , $r->level ) \" > " . i18n ( $r -> task ) . " </a></li> \n " ;
}
}
}
2007-11-16 07:54:33 +00:00
?>
2005-02-16 22:50:43 +00:00
< ?
2010-07-13 03:30:11 +00:00
if ( array_key_exists ( 'users_id' , $_SESSION )) {
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /user_main.php \" > " . i18n ( " Main Page " ) . '</a></li>' ;
2009-09-09 00:26:12 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /user_personal.php \" > " . i18n ( " My Profile " ) . '</a></li>' ;
2010-07-13 03:30:11 +00:00
if ( in_array ( 'committee' , $_SESSION [ 'roles' ])) {
// echo "<li><a href=\"{$config['SFIABDIRECTORY']}/committee_main.php\">".i18n("Committee Home").'</a></li>';
}
if ( in_array ( 'admin' , $_SESSION [ 'roles' ])) {
2010-07-13 21:23:39 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /admin/ \" > " . i18n ( " Administration " ) . ' (old) </a></li>' ;
2007-12-12 04:15:17 +00:00
}
2010-07-13 03:30:11 +00:00
if ( in_array ( 'config' , $_SESSION [ 'roles' ])) {
2010-07-13 21:23:39 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /config/ \" > " . i18n ( " Configuration " ) . ' (old) </a></li>' ;
2007-12-12 04:15:17 +00:00
}
2010-07-13 03:30:11 +00:00
if ( $_SESSION [ 'superuser' ] == 'yes' ) {
2010-06-23 21:18:06 +00:00
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /super/ \" > " . i18n ( " System Setup " ) . '</a></li>' ;
2010-07-13 03:30:11 +00:00
}
if ( in_array ( 'volunteer' , $_SESSION [ 'roles' ])) {
// echo "<li><a href=\"{$config['SFIABDIRECTORY']}/volunteer_main.php\">".i18n("Volunteer Home").'</a></li>';
}
if ( in_array ( 'sponsor' , $_SESSION [ 'roles' ])) {
// echo "<li><a href=\"{$config['SFIABDIRECTORY']}/sponsor_main.php\">".i18n("Sponsor Home").'</a></li>';
}
/* FIXME : setting the schoolid should move to the user_login routine , so we can just test for
* the presence of the school / teacher / principal role here */
if ( $_SESSION [ 'schoolid' ] && $_SESSION [ 'schoolaccesscode' ]) {
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /schoolaccess.php \" > " . i18n ( " School Home " ) . '</a></li>' ;
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /schoolaccess.php?action=logout \" > " . i18n ( " Logout " ) . '</a></li>' ;
}
if ( in_array ( 'student' , $_SESSION [ 'roles' ])) {
echo " <li><a href= \" { $config [ 'SFIABDIRECTORY' ] } /register_participants_main.php \" > " . i18n ( " Participant Home " ) . '</a></li>' ;
}
2005-05-13 18:23:31 +00:00
}
2010-07-13 03:30:11 +00:00
?>
</ ul >
2004-11-30 17:46:39 +00:00
</ div >
2010-07-13 21:23:39 +00:00
< div id = " secondarymenu " >
</ div >
< div id = " tertiarymenu " >
< div id = " tertiarymenu_accordion " >
</ div >
</ div >
2010-07-09 20:25:31 +00:00
< ?
2010-07-13 21:23:39 +00:00
if ( $_SESSION [ 'nav' ][ 'primary' ]) {
echo " <script type= \" text/javascript \" > " ;
echo " $ (document).ready(function() { \n " ;
echo " taskNav( { $_SESSION [ 'nav' ][ 'primary' ] } ,0,0); " ;
echo " }); " ;
echo " </script> \n " ;
2010-07-12 20:29:20 +00:00
}
2010-07-13 21:23:39 +00:00
if ( $_SESSION [ 'nav' ][ 'secondary' ]) {
echo " <script type= \" text/javascript \" > " ;
echo " $ (document).ready(function() { \n " ;
echo " taskNav( { $_SESSION [ 'nav' ][ 'secondary' ] } , { $_SESSION [ 'nav' ][ 'primary' ] } ,1); " ;
echo " }); " ;
echo " </script> \n " ;
}
2010-07-09 20:25:31 +00:00
?>
2010-07-13 21:23:39 +00:00
2007-11-16 06:47:53 +00:00
< ?
2010-07-09 20:35:05 +00:00
/*
2007-11-16 06:47:53 +00:00
if ( is_array ( $nav )) {
2007-11-23 20:56:59 +00:00
echo " <div id= \" mainwhere \" > " . i18n ( 'You are here:' ) . ' ' ;
2007-11-16 06:47:53 +00:00
foreach ( $nav as $t => $l ) {
2008-02-04 23:40:26 +00:00
echo " <a href= \" { $config [ 'SFIABDIRECTORY' ] } / $l\ " > " .i18n( $t ).'</a> » ';
2007-11-16 06:47:53 +00:00
}
2009-09-09 00:26:12 +00:00
if ( ! $titletranslated )
echo i18n ( $title );
else
echo $title ;
2007-11-16 06:47:53 +00:00
echo '</div>' ;
}
2010-07-09 20:35:05 +00:00
*/
2007-11-16 06:47:53 +00:00
?>
2004-11-30 17:46:39 +00:00
< div id = " main " >
2004-11-10 13:52:01 +00:00
< ?
2006-10-23 18:38:05 +00:00
2010-07-13 03:30:11 +00:00
if ( is_array ( $_SESSION [ 'roles' ])) {
$has_config = array_key_exists ( 'config' , $_SESSION [ 'roles' ]);
$has_admin = array_key_exists ( 'admin' , $_SESSION [ 'roles' ]);
if ( $has_config || $has_admin )
committee_warnings ();
if ( $has_config )
config_warnings ();
if ( $has_admin )
admin_warnings ();
}
2006-10-23 18:38:05 +00:00
2010-07-12 19:40:06 +00:00
if ( substr ( getcwd (), - 6 ) != " /admin " && substr ( getcwd (), - 7 ) != " /config " && substr ( getcwd (), - 6 ) != " /super " ) {
?>
< div id = " importantdatesbox " >
</ div >
< ?
}
2008-08-22 20:35:08 +00:00
2008-09-24 21:56:11 +00:00
if ( $icon && theme_icon ( $icon )) {
2010-07-12 19:40:06 +00:00
echo " <div style= \" float: left; margin-right: 5px; \" > " ;
echo theme_icon ( $icon );
echo " </div> " ;
2008-08-22 20:35:08 +00:00
}
2006-10-18 17:32:14 +00:00
//if we're under /admin or /config then we want to show the ? help icon
2010-07-09 20:35:05 +00:00
if ( substr ( getcwd (), - 6 ) == " /admin " || substr ( getcwd (), - 7 ) == " /config " || substr ( getcwd (), - 6 ) == " /super " ) {
2009-01-27 21:52:11 +00:00
if ( $_SERVER [ 'REDIRECT_SCRIPT_URL' ])
$fname = substr ( $_SERVER [ 'REDIRECT_SCRIPT_URL' ], strlen ( $config [ 'SFIABDIRECTORY' ]) + 1 );
else
$fname = substr ( $_SERVER [ 'PHP_SELF' ], strlen ( $config [ 'SFIABDIRECTORY' ]) + 1 );
2010-07-12 19:40:06 +00:00
echo " <div style= \" float: right; \" <a target= \" _sfiabhelp \" href= \" http://www.sfiab.ca/wiki/index.php/Help_ $fname\ " >< img border = \ " 0 \" src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/32/help. " . $config [ 'icon_extension' ] . " \" ></a></div> " ;
2006-10-18 17:32:14 +00:00
}
2010-07-09 20:35:05 +00:00
2010-07-12 19:40:06 +00:00
if ( $title && ! $titletranslated )
echo " <h2> " . i18n ( $title ) . " </h2> " ;
else if ( $title )
echo " <h2> " . $title . " </h2> " ;
2009-09-09 00:26:12 +00:00
2010-07-09 20:35:05 +00:00
display_messages ();
2010-07-13 03:30:11 +00:00
2004-11-10 13:52:01 +00:00
}
2009-09-09 00:26:12 +00:00
/* END OF send_header */
2004-11-10 13:52:01 +00:00
function send_footer ()
{
2005-05-25 19:08:50 +00:00
global $config ;
2004-11-10 13:52:01 +00:00
?>
2004-11-30 17:46:39 +00:00
</ div >
< div id = " footer " >
2005-12-14 21:00:02 +00:00
< ?
//we only show the debug session variables if we have an ODD numbered version.
2006-09-03 21:45:54 +00:00
if ( substr ( $config [ 'version' ], - 1 ) % 2 != 0 )
2006-02-14 21:50:41 +00:00
{
2007-12-20 22:39:21 +00:00
$revision = exec ( " svn info |grep Revision " );
$extra = " (Development $revision ) " ;
if ( $_SESSION [ 'debug' ] == " true " )
$extra .= " DEBUG: " . print_r ( $_SESSION , true );
2006-02-14 21:50:41 +00:00
}
2007-12-20 22:39:21 +00:00
echo " <a target= \" blank \" href= \" http://www.sfiab.ca \" >SFIAB Version " . $config [ 'version' ] . " { $extra } </a> " ;
2005-12-14 21:00:02 +00:00
?>
2004-11-30 17:46:39 +00:00
</ div >
2010-02-23 19:58:06 +00:00
< div id = " debug " style = " display:<?=( $_SESSION['debug'] =='true')?'block':'none'?>; font-family:monospace; white-space:pre; " > Debug ...</ div >
2009-10-15 07:11:43 +00:00
< iframe id = " content " src = " " style = " visibility:hidden; width:0px; height:0px " ></ iframe >
2004-11-30 17:46:39 +00:00
2004-11-10 15:31:30 +00:00
</ body >
</ html >
2004-11-10 13:52:01 +00:00
< ?
}
2005-03-30 18:02:45 +00:00
function send_popup_header ( $title = " " )
{
global $HEADER_SENT ;
global $config ;
//do this so we can use send_header() a little more loosly and not worry about it being sent more than once.
if ( $HEADER_SENT ) return ;
else $HEADER_SENT = true ;
2010-06-04 20:23:59 +00:00
echo " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " ;
2005-03-30 18:02:45 +00:00
?>
<! 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 >< ? = i18n ( $title ) ?> </title>
2009-11-06 22:10:06 +00:00
< link rel = " stylesheet " href = " <?= $config['SFIABDIRECTORY'] ?>/theme/<?= $config['theme'] ?>/jquery-ui-1.7.2.custom.css " type = " text/css " media = " all " />
2009-09-09 00:26:12 +00:00
< link rel = " stylesheet " href = " <?= $config['SFIABDIRECTORY'] ?>/theme/<?= $config['theme'] ?>/sfiab.css " type = " text/css " media = " all " />
2006-10-11 00:28:58 +00:00
< link media = all href = " <?= $config['SFIABDIRECTORY'] ?>/tableeditor.css " type = text / css rel = stylesheet >
2005-03-30 18:02:45 +00:00
</ head >
2005-03-30 18:19:31 +00:00
< body onload = " window.focus() " >
2009-10-28 18:52:38 +00:00
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/jquery/1.3.2/jquery.min.js " ></ script >
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/jqueryui/1.7.2/jquery-ui.min.js " ></ script >
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/sfiab.js " ></ script >
2010-07-15 09:18:08 +00:00
< script type = " text/javascript " src = " <?= $config['SFIABDIRECTORY'] ?>/js/validate/jquery.validate.pack.js " ></ script >
2009-09-23 16:42:24 +00:00
< div id = " notice_area " class = " notice_area " ></ div >
2005-03-30 18:02:45 +00:00
< ?
2005-03-30 18:19:31 +00:00
if ( $title )
echo " <h2> " . i18n ( $title ) . " </h2> " ;
2009-09-09 00:26:12 +00:00
2005-03-30 18:02:45 +00:00
}
function send_popup_footer ()
{
?>
2005-03-30 18:21:48 +00:00
< br />
< br />
2005-03-30 18:19:31 +00:00
< div id = " footer " >
2006-03-28 21:41:51 +00:00
< ?
global $config ;
$lastdigit = $config [ 'version' ][ strlen ( $config [ 'version' ]) - 1 ];
if ( $lastdigit % 2 != 0 )
{
echo " DEBUG: " ;
print_r ( $_SESSION );
}
echo " SFIAB Version " . $config [ 'version' ];
?>
2005-03-30 18:19:31 +00:00
</ div >
2009-09-23 16:42:24 +00:00
< div id = " debug " style = " display:<?=( $_SESSION['debug'] =='true')?'block':'none'?> " > Debug ...</ div >
2009-10-15 07:11:43 +00:00
< iframe id = " content " src = " " style = " visibility:hidden; width:0px; height:0px " ></ iframe >
2005-03-30 18:19:31 +00:00
2005-03-30 18:02:45 +00:00
</ body >
</ html >
< ?
}
2004-11-10 13:52:01 +00:00
2004-12-03 04:28:18 +00:00
function emit_month_selector ( $name , $selected = " " )
{
echo " <select name= \" $name\ " > \n " ;
$months = array ( " " , " Jan " , " Feb " , " Mar " , " Apr " , " May " , " Jun " , " Jul " , " Aug " , " Sep " , " Oct " , " Nov " , " Dec " );
echo " <option value= \" \" > " . i18n ( " Month " ) . " </option> \n " ;
for ( $x = 1 ; $x <= 12 ; $x ++ )
{
if ( $x == $selected )
$s = " selected= \" selected \" " ;
else
$s = " " ;
echo " <option $s value= \" $x\ " > " . $months[$x] . " </ option > \n " ;
}
echo " </select> \n " ;
}
function emit_day_selector ( $name , $selected = " " )
{
echo " <select name= \" $name\ " > \n " ;
echo " <option value= \" \" > " . i18n ( " Day " ) . " </option> \n " ;
for ( $x = 1 ; $x <= 31 ; $x ++ )
echo " <option value= \" " . ( $x < 10 ? " 0 " : " " ) . " $x\ " " .( $selected == $x ? " selected = \ " selected \" " : " " ) . " > $x </option> \n " ;
echo " </select> \n " ;
}
function emit_year_selector ( $name , $selected = " " , $min = 0 , $max = 0 )
{
$curyear = date ( " Y " );
echo " <select name= \" $name\ " > \n " ;
echo " <option value= \" \" > " . i18n ( " Year " ) . " </option> \n " ;
if ( $min && $max )
{
for ( $x = $min ; $x <= $max ; $x ++ )
echo " <option value= \" $x\ " " .( $selected == $x ? " selected = \ " selected \" " : " " ) . " > $x </option> \n " ;
}
else
{
//if we arent given a min and max, lets show current year + 5
for ( $x = $curyear ; $x < $curyear + 5 ; $x ++ )
echo " <option value= \" $x\ " " .( $selected == $x ? " selected = \ " selected \" " : " " ) . " > $x </option> \n " ;
}
echo " </select> \n " ;
}
2005-04-15 20:33:13 +00:00
function emit_date_selector ( $name , $selected = " " )
{
if ( $selected )
{
list ( $year , $month , $day ) = split ( " - " , $selected );
}
echo " <table cellpadding=0> " ;
echo " <tr><td> " ;
emit_year_selector ( $name . " _year " , $year );
echo " </td><td> " ;
emit_month_selector ( $name . " _month " , $month );
echo " </td><td> " ;
emit_day_selector ( $name . " _day " , $day );
echo " </td></tr> " ;
echo " </table> " ;
}
2010-06-11 20:04:51 +00:00
function emit_hour_selector ( $name , $selected = " " , $extra = " " )
2005-04-15 20:33:13 +00:00
{
if ( $selected != " " ) $selected = ( int ) $selected ;
2010-06-11 20:04:51 +00:00
echo " <select name= \" $name\ " $extra > \n " ;
2005-04-15 20:33:13 +00:00
echo " <option value= \" \" >HH</option> \n " ;
for ( $x = 0 ; $x <= 23 ; $x ++ )
{
if ( $x === $selected )
$sel = " selected " ;
else
$sel = " " ;
echo " <option value= \" $x\ " $sel > " .sprintf( " % 02 d " , $x ). " </ option > \n " ;
}
echo " </select> \n " ;
}
2010-06-11 20:04:51 +00:00
function emit_minute_selector ( $name , $selected = " " , $extra = " " , $interval = 5 )
2005-04-15 20:33:13 +00:00
{
2010-06-11 20:04:51 +00:00
$mins = array ();
for ( $x = 0 ; $x < 60 ; $x += $interval ) {
$mins [] = $x ;
}
// $mins=array("00","05","10","15","20","25","30","35","40","45","50","55");
2010-06-14 19:25:49 +00:00
echo " <select name= \" $name\ " $extra > \n " ;
2005-04-15 20:33:13 +00:00
echo " <option value= \" \" >MM</option> \n " ;
for ( $x = 0 ; $x < count ( $mins ); $x ++ )
2010-06-11 20:04:51 +00:00
echo " <option value= \" " . $mins [ $x ] . " \" " . ( $selected == $mins [ $x ] ? " selected " : " " ) . " > " . sprintf ( " %02d " , $mins [ $x ]) . " </option> \n " ;
2005-04-15 20:33:13 +00:00
echo " </select> \n " ;
}
function emit_time_selector ( $name , $selected = " " )
{
if ( $selected )
{
list ( $hour , $minute , $second ) = split ( " : " , $selected );
}
echo " <table cellpadding=0> " ;
echo " <tr><td> " ;
emit_hour_selector ( $name . " _hour " , $hour );
echo " </td><td> " ;
emit_minute_selector ( $name . " _minute " , $minute );
echo " </td></tr> " ;
echo " </table> " ;
}
2005-02-21 23:07:10 +00:00
function emit_province_selector ( $name , $selected = " " , $extra = " " )
2005-01-05 16:23:11 +00:00
{
2008-07-16 17:23:53 +00:00
global $config ;
2008-08-28 21:41:31 +00:00
$q = mysql_query ( " SELECT * FROM provinces WHERE countries_code=' " . mysql_escape_string ( $config [ 'country' ]) . " ' ORDER BY province " );
2005-01-05 16:23:11 +00:00
if ( mysql_num_rows ( $q ) == 1 )
{
$r = mysql_fetch_object ( $q );
echo " <input type= \" hidden \" name= \" $name\ " value = \ " $r -code \" > " ;
echo i18n ( $r -> province );
}
else
{
2005-02-21 23:07:10 +00:00
echo " <select name= \" $name\ " $extra > \n " ;
2008-07-16 17:23:53 +00:00
echo " <option value= \" \" > " . i18n ( " Select a { $config [ 'provincestate' ] } " ) . " </option> \n " ;
2005-01-05 16:23:11 +00:00
while ( $r = mysql_fetch_object ( $q ))
{
if ( $r -> code == $selected ) $sel = " selected= \" selected \" " ; else $sel = " " ;
2005-05-13 18:23:31 +00:00
echo " <option $sel value= \" $r->code\ " > " .i18n( $r->province );
echo " </option> \n " ;
2005-01-05 16:23:11 +00:00
}
echo " </select> \n " ;
}
}
2004-12-03 04:28:18 +00:00
2004-12-19 23:16:46 +00:00
function outputStatus ( $status )
{
$ret = " " ;
switch ( $status )
{
case 'incomplete' :
$ret .= " <div class= \" incomplete \" > " ;
$ret .= i18n ( " Incomplete " );
$ret .= " </div> " ;
break ;
case 'complete' :
$ret .= " <div class= \" complete \" > " ;
$ret .= i18n ( " Complete " );
$ret .= " </div> " ;
break ;
case 'empty' :
$ret .= " <div class= \" incomplete \" > " ;
$ret .= i18n ( " Empty " );
$ret .= " </div> " ;
break ;
default :
$ret .= i18n ( " Unknown " );
break ;
}
return $ret ;
}
Add an email address verification function so we dont need to keep duplicating the regex everywhere
Add a function to get the email recipients for a given registration id, for now, it just gets the students, but downt eh road it should check if teachers, parents, emergency contacts, mentors, etc should receive fair updates as well.
Implement the code/replacement tags for the two new emails, one for 'forms received, with payment' and the other for 'forms received, without payment'
2007-10-30 22:35:00 +00:00
//returns true if its a valid email address, false if its not
function isEmailAddress ( $str ) {
2010-03-02 00:07:16 +00:00
if ( eregi ( '^[+a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$' , $str ))
Add an email address verification function so we dont need to keep duplicating the regex everywhere
Add a function to get the email recipients for a given registration id, for now, it just gets the students, but downt eh road it should check if teachers, parents, emergency contacts, mentors, etc should receive fair updates as well.
Implement the code/replacement tags for the two new emails, one for 'forms received, with payment' and the other for 'forms received, without payment'
2007-10-30 22:35:00 +00:00
return true ;
else
return false ;
}
2004-12-03 04:28:18 +00:00
2009-12-01 22:02:03 +00:00
function communication_get_user_replacements ( & $u ) {
2009-10-16 06:16:48 +00:00
global $config ;
$rep = array ( 'FAIRNAME' => $config [ 'fairname' ],
'NAME' => $u [ 'name' ],
'EMAIL' => $u [ 'email' ],
'PASSWORD' => $u [ 'password' ],
'SALUTATION' => $u [ 'salutation' ],
'FIRSTNAME' => $u [ 'firstname' ],
'LASTNAME' => $u [ 'lastname' ],
2009-12-01 22:02:03 +00:00
'ORGANIZATION' => $u [ 'sponsor' ][ 'organization' ],
);
return $rep ;
}
function communication_replace_vars ( $text , & $u , $otherrep = array ()) {
global $config ;
if ( $u ) {
2009-12-02 22:17:20 +00:00
$userrep = communication_get_user_replacements ( $u );
2009-12-01 22:02:03 +00:00
}
else {
$userrep = array ();
}
$rep = array_merge ( $userrep , $otherrep );
2009-10-16 06:16:48 +00:00
foreach ( $rep AS $k => $v ) {
$text = ereg_replace ( " \ [ $k\ ] " , $v , $text );
}
return $text ;
}
2005-02-11 18:25:59 +00:00
function email_send ( $val , $to , $sub_subject = array (), $sub_body = array ())
{
2007-10-29 20:21:40 +00:00
global $config ;
2010-01-27 20:24:16 +00:00
/* Standard substitutions that are constant no matter who
* the $to is */
$urlproto = $_SERVER [ 'SERVER_PORT' ] == 443 ? " https:// " : " http:// " ;
$urlmain = " $urlproto { $_SERVER [ 'HTTP_HOST' ] } { $config [ 'SFIABDIRECTORY' ] } " ;
$urllogin = " $urlmain /login.php " ;
$stdsub = array ( " FAIRNAME " => i18n ( $config [ 'fairname' ]),
" URLMAIN " => $urlmain ,
" URLLOGIN " => $urllogin ,
);
/* Add standard subs to existing sub arrays */
$sub_subject = array_merge ( $sub_subject , $stdsub );
$sub_body = array_merge ( $sub_body , $stdsub );
2006-02-14 21:50:41 +00:00
//if our "to" doesnt look like a valid email, then forget about sending it.
Add an email address verification function so we dont need to keep duplicating the regex everywhere
Add a function to get the email recipients for a given registration id, for now, it just gets the students, but downt eh road it should check if teachers, parents, emergency contacts, mentors, etc should receive fair updates as well.
Implement the code/replacement tags for the two new emails, one for 'forms received, with payment' and the other for 'forms received, without payment'
2007-10-30 22:35:00 +00:00
if ( ! isEmailAddress ( $to ))
return false ;
2006-02-14 21:50:41 +00:00
2005-02-11 18:25:59 +00:00
$q = mysql_query ( " SELECT * FROM emails WHERE val=' $val ' " );
2009-12-02 22:17:20 +00:00
if ( $r = mysql_fetch_object ( $q )) {
2005-02-11 18:25:59 +00:00
$subject = i18n ( $r -> subject );
$body = i18n ( $r -> body );
2009-10-16 06:16:48 +00:00
/* Eventually we should just do this with communication_replace_vars() */
2009-12-02 22:17:20 +00:00
if ( count ( $sub_subject )) {
foreach ( $sub_subject AS $sub_k => $sub_v ) {
2006-01-20 19:26:13 +00:00
$subject = ereg_replace ( " \ [ $sub_k\ ] " , " $sub_v " , $subject );
2005-02-11 18:25:59 +00:00
}
}
2009-12-02 22:17:20 +00:00
if ( count ( $sub_body )) {
foreach ( $sub_body AS $sub_k => $sub_v ) {
2006-01-20 19:26:13 +00:00
$body = ereg_replace ( " \ [ $sub_k\ ] " , " $sub_v " , $body );
2005-02-11 18:25:59 +00:00
}
}
2007-10-29 20:21:40 +00:00
if ( $r -> from )
$fr = $r -> from ;
else if ( $config [ 'fairmanageremail' ])
$fr = $config [ 'fairmanageremail' ];
else
$fr = " " ;
2005-02-11 18:25:59 +00:00
2007-10-29 20:21:40 +00:00
//only send the email if we have a from
if ( $fr ) {
2009-12-02 22:17:20 +00:00
//send using RMail
email_send_new ( $to , $fr , $subject , $body );
2007-10-29 20:21:40 +00:00
}
else
echo error ( i18n ( " CRITICAL ERROR: email '%1' does not have a 'From' and the Fair Manager Email is not configured " , array ( $val ), array ( " email key name " )));
2005-02-11 18:25:59 +00:00
}
2009-12-02 22:17:20 +00:00
else {
2007-10-29 20:21:40 +00:00
echo error ( i18n ( " CRITICAL ERROR: email '%1' not found " , array ( $val ), array ( " email key name " )));
2005-02-11 18:25:59 +00:00
}
}
2009-12-02 22:17:20 +00:00
require_once ( " Rmail/Rmail.php " );
2010-02-16 00:15:21 +00:00
require_once ( " Rmail/RFC822.php " );
2009-12-02 22:17:20 +00:00
//this sends out an all-ready-to-go email, it does no substitution or changes or database lookups or anything
function email_send_new ( $to , $from , $subject , $body , $bodyhtml = " " ) {
$mail = new RMail ();
2010-06-09 15:14:41 +00:00
$mail -> setHeadCharset ( " UTF-8 " );
$mail -> setTextCharset ( " UTF-8 " );
$mail -> setHTMLCharset ( " UTF-8 " );
2009-12-02 22:17:20 +00:00
$mail -> setFrom ( $from );
$mail -> setSubject ( $subject );
$mail -> setText ( $body );
2010-02-16 00:15:21 +00:00
$r = new Mail_RFC822 ( $from );
$structure = $r -> parseAddressList ( $from );
$s = $structure [ 0 ];
$ret = sprintf ( " %s@%s " , $s -> mailbox , $s -> host );
$mail -> setReturnPath ( $ret );
$mail -> setHeader ( " Bounce-To " , $ret );
2009-12-02 22:17:20 +00:00
//only add the html if we have it
if ( $bodyhtml ) {
$mail -> setHTML ( $bodyhtml );
}
if ( is_array ( $to )) {
return $mail -> send ( $to );
} else {
return $mail -> send ( array ( $to ));
}
}
Add an email address verification function so we dont need to keep duplicating the regex everywhere
Add a function to get the email recipients for a given registration id, for now, it just gets the students, but downt eh road it should check if teachers, parents, emergency contacts, mentors, etc should receive fair updates as well.
Implement the code/replacement tags for the two new emails, one for 'forms received, with payment' and the other for 'forms received, without payment'
2007-10-30 22:35:00 +00:00
/*
returns an array of arrays
[ 0 ] = array ( to , firstname , lastname , email )
[ 1 ] = array ( to , firstname , lastname , email )
... etc
*/
function getEmailRecipientsForRegistration ( $reg_id )
{
global $config ;
//okay first grab the registration record, to see if we should email the kids, the teacher, and/or the parents
$q = mysql_query ( " SELECT * FROM registrations WHERE id=' $reg_id ' AND year=' { $config [ 'FAIRYEAR' ] } ' " );
$registration = mysql_fetch_object ( $q );
2007-11-15 21:18:06 +00:00
if ( $registration -> emailcontact && isEmailAddress ( $registration -> emailcontact )) {
2007-11-15 21:17:20 +00:00
$ret [] = array ( " to " => $registration -> emailcontact ,
" firstname " => " " ,
" lastname " => " " ,
" email " => $registration -> emailcontact ,
);
}
Add an email address verification function so we dont need to keep duplicating the regex everywhere
Add a function to get the email recipients for a given registration id, for now, it just gets the students, but downt eh road it should check if teachers, parents, emergency contacts, mentors, etc should receive fair updates as well.
Implement the code/replacement tags for the two new emails, one for 'forms received, with payment' and the other for 'forms received, without payment'
2007-10-30 22:35:00 +00:00
$sq = mysql_query ( " SELECT * FROM students WHERE registrations_id=' $reg_id ' AND year=' { $config [ 'FAIRYEAR' ] } ' " );
$ret = array ();
while ( $sr = mysql_fetch_object ( $sq )) {
if ( $sr -> email && isEmailAddress ( $sr -> email )) {
if ( $sr -> firstname && $sr -> lastname )
$to = $sr -> firstname . " " . $sr -> lastname . " < " . $sr -> email . " > " ;
else if ( $sr -> firstname )
$to = $sr -> firstname . " < " . $sr -> email . " > " ;
else if ( $sr -> lastname )
$to = $sr -> lastname . " < " . $sr -> email . " > " ;
2007-11-15 21:17:20 +00:00
else
$to = $sr -> email ;
Add an email address verification function so we dont need to keep duplicating the regex everywhere
Add a function to get the email recipients for a given registration id, for now, it just gets the students, but downt eh road it should check if teachers, parents, emergency contacts, mentors, etc should receive fair updates as well.
Implement the code/replacement tags for the two new emails, one for 'forms received, with payment' and the other for 'forms received, without payment'
2007-10-30 22:35:00 +00:00
$ret [] = array ( " to " => $to ,
" firstname " => $sr -> firstname ,
" lastname " => $sr -> lastname ,
" email " => $sr -> email ,
);
}
}
return $ret ;
}
2005-11-21 19:36:48 +00:00
function output_page_text ( $textname )
{
2005-11-21 20:33:18 +00:00
global $config ;
2008-08-18 21:08:23 +00:00
$q = mysql_query ( " SELECT * FROM pagetext WHERE textname=' $textname ' AND year=' " . $config [ 'FAIRYEAR' ] . " ' AND lang=' " . $_SESSION [ 'lang' ] . " ' " );
2005-11-21 20:33:18 +00:00
if ( mysql_num_rows ( $q ))
$r = mysql_fetch_object ( $q );
else
{
//not defined, lets grab the default text
2008-08-18 21:08:23 +00:00
$q = mysql_query ( " SELECT * FROM pagetext WHERE textname=' $textname ' AND year='-1' AND lang=' " . $config [ 'default_language' ] . " ' " );
2005-11-21 20:33:18 +00:00
$r = mysql_fetch_object ( $q );
}
2006-01-18 21:28:00 +00:00
//if it looks like we have HTML content, dont do a nl2br, if there's no html, then do the nl2br
if ( strlen ( $r -> text ) == strlen ( strip_tags ( $r -> text )))
2008-08-18 21:08:23 +00:00
echo nl2br ( $r -> text );
2006-01-18 21:28:00 +00:00
else
2008-08-18 21:08:23 +00:00
echo $r -> text ;
2005-11-21 19:36:48 +00:00
}
2005-11-25 21:15:29 +00:00
2008-08-19 21:13:29 +00:00
function output_page_cms ( $filename )
{
global $config ;
$q = mysql_query ( " SELECT * FROM cms WHERE filename=' " . mysql_escape_string ( $filename ) . " ' AND lang=' " . $_SESSION [ 'lang' ] . " ' ORDER BY dt DESC LIMIT 1 " );
if ( mysql_num_rows ( $q ))
{
$r = mysql_fetch_object ( $q );
2008-11-02 02:35:46 +00:00
send_header ( $r -> title , null , null , true );
2008-08-19 21:13:29 +00:00
if ( file_exists ( " data/logo-200.gif " ) && $r -> showlogo == 1 )
2008-08-28 22:14:17 +00:00
echo " <img align= \" right \" src= \" " . $config [ 'SFIABDIRECTORY' ] . " /data/logo-200.gif \" border= \" 0 \" > " ;
2008-08-19 21:13:29 +00:00
//if it looks like we have HTML content, dont do a nl2br, if there's no html, then do the nl2br
if ( strlen ( $r -> text ) == strlen ( strip_tags ( $r -> text )))
echo nl2br ( $r -> text );
else
echo $r -> text ;
}
else {
2008-11-02 02:35:46 +00:00
send_header ( " Error: File not found " );
2008-08-19 21:13:29 +00:00
echo error ( i18n ( " The file you have requested (%1), does not exist on the server. " , array ( $filename )));
return ;
//not defined, lets grab the default text
}
send_footer ();
}
2006-12-06 19:24:09 +00:00
function generatePassword ( $pwlen = 8 )
2005-11-25 21:15:29 +00:00
{
//these are good characters that are not easily confused with other characters :)
$available = " ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789 " ;
2007-12-13 18:09:22 +00:00
$len = strlen ( $available ) - 1 ;
2005-11-25 21:15:29 +00:00
$key = " " ;
2006-12-06 19:24:09 +00:00
for ( $x = 0 ; $x < $pwlen ; $x ++ )
2007-12-13 18:09:22 +00:00
$key .= $available { rand ( 0 , $len )};
2005-11-25 21:15:29 +00:00
return $key ;
}
2006-10-23 18:38:05 +00:00
//config specific warning
function config_warnings ()
{
}
//admin specific warnings
function admin_warnings ()
{
}
//warnings to show to both config and/or admin people
function committee_warnings ()
{
global $config ;
//it is vital that each year the system be rolled over before we start it again
//we should do this, say, 4 months after the FAIRDATE, so its soon enough that they should see
//the message as soon as they login to start preparing for hte new year, but not too late to do it
//properly :)
$q = mysql_query ( " SELECT DATE_ADD(' " . $config [ 'dates' ][ 'fairdate' ] . " ', INTERVAL 4 MONTH) < NOW() AS rollovercheck " );
$r = mysql_fetch_object ( $q );
2010-03-30 17:45:37 +00:00
if ( $r -> rollovercheck ) {
2006-10-23 18:38:05 +00:00
echo error ( i18n ( " It has been more than 4 months since your fair. In order to prepare the system for the next year's fair, you should go to the SFIAB Configuration page, and click on 'Rollover Fair Year'. Do not start updating the system with new information until the year has been properly rolled over. " ));
}
2010-03-30 17:45:37 +00:00
2010-04-02 05:19:33 +00:00
$warn = false ;
$q = mysql_query ( " SELECT * FROM award_prizes WHERE `external_identifier` IS NOT NULL
AND external_identifier = prize " );
if ( mysql_num_rows ( $q ) > 0 ) {
/* The bug was that the external_identifier was set to the prize name .. so only display the warning
* if we find that case for a non - sfiab external fair */
while (( $p = mysql_fetch_assoc ( $q ) )) {
$qq = mysql_query ( " SELECT * FROM award_awards
LEFT JOIN fairs ON fairs . id = award_awards . award_source_fairs_id
WHERE award_awards . id = '{$p[' award_awards_id ']}'
AND year = '{$config[' FAIRYEAR ']}'
AND award_awards . award_source_fairs_id IS NOT NULL
AND fairs . type = 'ysc' " );
echo mysql_error ();
if ( mysql_num_rows ( $qq ) > 0 ) {
$warn = true ;
break ;
}
}
}
if ( $warn ) {
//let everyone know about the need to re-download awards before being able to upload
echo notice ( i18n ( " March 30, 2010 - There was a minor issue with uploading award results that has now been corrected, however, you will need to re-download your awards from all external sources, before you will be able to upload the award winners back to those external sources. Re-downloading the awards will not affect the awards in any visible way, it will just allow the winners to be uploaded properly. Click on Fair Administration -> Awards Management -> Download awards from external sources -> and click 'check' for each award source " ));
}
2010-03-30 17:45:37 +00:00
2006-10-23 18:38:05 +00:00
}
2006-10-19 21:39:30 +00:00
$CWSFDivisions = array (
2010-03-30 15:06:08 +00:00
1 => " Automotive " ,
2 => " Biotechnology & Pharmaceutical Sciences " ,
3 => " Computing & Information Technology " ,
4 => " Earth & Environmental Sciences " ,
5 => " Engineering " ,
6 => " Environmental Innovation " ,
7 => " Health Sciences " ,
8 => " Life Sciences " ,
9 => " Physical & Mathematical Sciences "
2006-10-19 21:39:30 +00:00
);
2009-11-06 22:10:06 +00:00
function theme_icon ( $icon , $width = 0 ) {
global $theme_icons , $config ;
$w = ( $width == 0 ) ? '' : " width= \" $width\ " " ;
if ( $theme_icons [ 'icons' ][ $icon ])
return " <img src= \" { $config [ 'SFIABDIRECTORY' ] } /theme/ { $config [ 'theme_icons' ] } / { $theme_icons [ 'icons' ][ $icon ] } \" border= \" 0 \" $w alt= \" " . htmlspecialchars ( $icon ) . " \" > " ;
return " " ;
2008-07-24 16:20:16 +00:00
}
2008-08-28 22:02:06 +00:00
2008-08-28 22:11:10 +00:00
//$d can be a unix timestamp integer, OR a text string, eg 2008-01-22
2008-08-28 22:02:06 +00:00
function format_date ( $d ) {
global $config ;
2008-08-28 22:11:10 +00:00
if ( is_numeric ( $d ))
return date ( $config [ 'dateformat' ], $d );
else
return date ( $config [ 'dateformat' ], strtotime ( $d ));
2008-08-28 22:02:06 +00:00
}
2008-08-28 22:11:10 +00:00
//$t can be a unix timestamp integer, or a text string, eg 10:23:48
2008-08-28 22:02:06 +00:00
function format_time ( $t ) {
global $config ;
2008-08-28 22:11:10 +00:00
if ( is_numeric ( $t ))
return date ( $config [ 'timeformat' ], $t );
else
return date ( $config [ 'timeformat' ], strtotime ( $t ));
2008-08-28 22:02:06 +00:00
}
2008-08-28 22:11:10 +00:00
//$dt can be a unix timestamp integer, or a text string, eg 2008-01-22 10:23:48
2008-08-28 22:02:06 +00:00
function format_datetime ( $dt ) {
2008-08-28 22:11:10 +00:00
if ( is_numeric ( $dt )) {
return format_date ( $dt ) . " " . i18n ( " at " ) . " " . format_time ( $dt );
}
else {
list ( $d , $t ) = split ( " " , $dt );
return format_date ( $d ) . " " . i18n ( " at " ) . " " . format_time ( $t );
}
2008-08-28 22:02:06 +00:00
}
2009-09-09 00:26:12 +00:00
2009-10-02 19:21:43 +00:00
function format_money ( $n , $decimals = true )
2009-09-09 00:26:12 +00:00
{
if ( $n < 0 ){
$neg = true ;
$n = $n *- 1 ;
}
//get the part before the decimal
$before = floor ( $n );
$out = " " ;
//space it out in blocks of three
for ( $x = strlen ( $before ); $x > 3 ; $x -= 3 ) {
$out = substr ( $before , $x - 3 , 3 ) . " " . $out ;
}
if ( $x > 0 )
$out = substr ( $before , 0 , $x ) . " " . $out ;
//trim any leading/trailing space that was added
$out = trim ( $out );
if ( $neg ) $negdisp = " - " ; else $negdisp = " " ;
2009-10-02 19:21:43 +00:00
if ( $decimals ) {
//get everything after the decimal place, and %02f it.
$after = substr ( strstr ( sprintf ( " %.02f " , $n ), " . " ), 1 );
2009-09-09 00:26:12 +00:00
2009-10-02 19:21:43 +00:00
//finally display it with the right language localization
if ( $_SESSION [ 'lang' ] == " fr " )
return sprintf ( " %s%s,%s \$ " , $negdisp , $out , $after );
else
return sprintf ( " %s \$ %s.%s " , $negdisp , $out , $after );
}
else {
if ( $_SESSION [ 'lang' ] == " fr " )
return sprintf ( " %s%s \$ " , $negdisp , $out );
else
return sprintf ( " %s \$ %s " , $negdisp , $out );
}
2009-09-09 00:26:12 +00:00
}
function message_push ( $m )
{
if ( ! is_array ( $_SESSION [ 'messages' ])) $_SESSION [ 'messages' ] = array ();
$_SESSION [ 'messages' ][] = $m ;
}
2009-09-25 22:43:12 +00:00
function notice_ ( $str , $i18n_array = array (), $timeout =- 1 , $type = 'notice' )
2009-09-13 08:33:54 +00:00
{
2009-09-18 03:29:13 +00:00
if ( $timeout == - 1 ) $timeout = 5000 ;
2009-09-13 08:33:54 +00:00
echo " <script type= \" text/javascript \" >
2009-09-18 03:29:13 +00:00
notice_create ( '$type' , \ " " . i18n ( $str , $i18n_array ) . " \" , $timeout );
2009-09-13 08:33:54 +00:00
</ script > " ;
}
2009-09-18 03:29:13 +00:00
2009-09-25 22:43:12 +00:00
function happy_ ( $str , $i18n_array = array (), $timeout =- 1 )
2009-09-18 03:29:13 +00:00
{
2009-09-25 22:43:50 +00:00
notice_ ( $str , $i18n_array , $timeout , 'happy' );
2009-09-18 03:29:13 +00:00
}
2009-09-25 22:43:12 +00:00
function error_ ( $str , $i18n_array = array (), $timeout =- 1 )
2009-09-18 03:29:13 +00:00
{
2009-09-25 22:43:50 +00:00
notice_ ( $str , $i18n_array , $timeout , 'error' );
2009-09-18 03:29:13 +00:00
}
2010-02-23 19:58:06 +00:00
function debug_ ( $str )
{
if ( $_SESSION [ 'debug' ] != true ) return ;
$s = str_replace ( " \n " , " " , nl2br ( htmlspecialchars ( $str ))) . '<br />' ;
echo " <script type= \" text/javascript \" >
$ ( document ) . ready ( function () {
$ ( \ " #debug \" ).append( \" $s\ " );
});
</ script > " ;
}
2009-10-06 21:00:12 +00:00
//this function returns a HTML colour code ranging between red and green, with yellow in the middle based on the percent passed into it
2010-02-23 19:58:06 +00:00
function colour_to_percent ( $percent )
{
//0 is red
//50 is yellow
//100 is green
2009-10-06 21:00:12 +00:00
2010-02-23 19:58:06 +00:00
if ( $percent <= 50 ) $red = 255 ;
else $red = ( 100 - $percent ) * 2 / 100 * 255 ;;
2009-10-06 21:00:12 +00:00
2010-02-23 19:58:06 +00:00
if ( $percent > 50 ) $green = 255 ;
else $green = ( $percent ) * 2 / 100 * 255 ;;
2009-10-06 21:00:12 +00:00
// echo "red=$red";
// echo "green=$green";
2010-02-23 19:58:06 +00:00
$str = " # " . sprintf ( " %02s " , dechex ( $red )) . sprintf ( " %02s " , dechex ( $green )) . " 00 " ;
return $str ;
2009-10-06 21:00:12 +00:00
}
2009-12-01 22:02:03 +00:00
function format_duration ( $seconds , $granularity = 2 )
{
$units = array (
'1 year|:count years' => 31536000 ,
'1 week|:count weeks' => 604800 ,
'1 day|:count days' => 86400 ,
'1 hour|:count hours' => 3600 ,
'1 min|:count min' => 60 ,
'1 sec|:count sec' => 1 );
$output = '' ;
// $output.=time()." - ".$timestamp." = ".$seconds;
foreach ( $units as $key => $value ) {
$key = explode ( '|' , $key );
if ( $seconds >= $value ) {
$count = floor ( $seconds / $value );
$output .= ( $output ? ' ' : '' );
$output .= ( $count == 1 ) ? $key [ 0 ] : str_replace ( ':count' , $count , $key [ 1 ]);
$seconds %= $value ;
$granularity -- ;
}
if ( $granularity == 0 ) {
break ;
}
}
return $output ? $output : '0 sec' ;
}
2009-12-02 23:11:25 +00:00
function getTextFromHtml ( $html ) {
//first, replace an </p> with </p><br />
$text = str_replace ( " </p> " , " </p><br /> " , $html );
2010-03-30 04:39:56 +00:00
//next, replace a </div> with </div><br />
$text = str_replace ( " </div> " , " </div><br /> " , $html );
2009-12-02 23:11:25 +00:00
//now replace any <br /> with newlines
$text = eregi_replace ( '<br[[:space:]]*/?[[:space:]]*>' , chr ( 13 ) . chr ( 10 ), $text );
//and strip the rest of the tags
$text = strip_tags ( $text );
2009-12-03 21:13:31 +00:00
//a few common html entities
//replace & with & first, so multiply-encoded entities will decode (like "&#160;")
$text = str_replace ( " & " , " & " , $text );
2009-12-02 23:11:25 +00:00
$text = str_replace ( " " , " " , $text );
2009-12-03 21:13:31 +00:00
$text = str_replace ( "   " , " " , $text );
$text = str_replace ( " < " , " < " , $text );
$text = str_replace ( " > " , " > " , $text );
2010-03-30 04:03:23 +00:00
//text version should always wrap at 75 chars, some mail severs wont accept
2010-03-30 04:01:38 +00:00
//mail with very long lines
2010-03-30 04:03:23 +00:00
$text = wordwrap ( $text , 75 , " \n " , true );
2010-03-30 04:01:38 +00:00
2009-12-02 23:11:25 +00:00
return $text ;
}
2010-01-14 18:34:33 +00:00
function getUserForSponsor ( $sponsor_id ) {
// loop through each contact and draw a form with their data in it.
$q = mysql_query ( " SELECT *,MAX(year) FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id
WHERE
sponsors_id = '" . $sponsor_id . "'
AND types LIKE '%sponsor%'
GROUP BY uid
HAVING deleted = 'no'
ORDER BY users_sponsor . primary DESC , lastname , firstname
LIMIT 1
" );
$r = mysql_fetch_object ( $q );
return user_load_by_uid ( $r -> uid );
}
2010-02-22 20:26:23 +00:00
function projectdivisions_load ( $year = false )
{
global $config ;
if ( $year == false ) $year = $config [ 'FAIRYEAR' ];
$divs = array ();
$q = mysql_query ( " SELECT * FROM projectdivisions WHERE year=' $year ' " );
while (( $d = mysql_fetch_assoc ( $q ))) $divs [ $d [ 'id' ]] = $d ;
return $divs ;
}
function projectcategories_load ( $year = false )
{
global $config ;
if ( $year == false ) $year = $config [ 'FAIRYEAR' ];
$cats = array ();
$q = mysql_query ( " SELECT * FROM projectcategories WHERE year=' $year ' " );
while (( $c = mysql_fetch_assoc ( $q ))) $cats [ $c [ 'id' ]] = $d ;
return $cats ;
}
2009-09-18 03:29:13 +00:00
2004-11-10 13:52:01 +00:00
?>