science-ation/common.inc.php
james c17447ed70 registration summary table
summarytable css class
2004-12-02 19:03:53 +00:00

217 lines
4.6 KiB
PHP

<?
require("config.inc.php");
mysql_connect($DBHOST,$DBUSER,$DBPASS);
mysql_select_db($DBNAME);
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 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");
if(mysql_num_rows($q)==0)
{
echo "No active languages defined, defaulting to English";
$config['languages']['en']="English";
}
else
{
while($r=mysql_fetch_object($q))
{
$config['languages'][$r->lang]=$r->langname;
}
}
//now if no language has been set yet, lets set it to the default language
if(!$_SESSION['lang'])
{
//first try the default language, if that doesnt work, use "en"
if($config['default_language'])
$_SESSION['lang']=$config['default_language'];
else
$_SESSION['lang']="en";
}
//if the user has switched languages, go ahead and switch the session variable
if($_GET['switchlanguage'])
{
//first, make sure its a valid language:
if($config['languages'][$_GET['switchlanguage']])
{
$_SESSION['lang']=$_GET['switchlanguage'];
}
else
{
//invalid language, dont do anything
}
}
function i18n($str,$args=array())
{
if(!$str)
return "";
if($_SESSION['lang'])
{
if($_SESSION['lang']=="en")
{
for($x=1;$x<=count($args);$x++)
{
$str=str_replace("%$x",$args[$x-1],$str);
}
return $str;
}
else
{
$q=mysql_query("SELECT * FROM translations WHERE lang='".$_SESSION['lang']."' AND strmd5='".md5($str)."'");
if($r=@mysql_fetch_object($q))
{
if($r->val)
{
$ret=$r->val;
for($x=1;$x<=count($args);$x++)
{
$ret=str_replace("%$x",$args[$x-1],$ret);
}
return $ret;
}
else
{
for($x=1;$x<=count($args);$x++)
{
$str=str_replace("%$x",$args[$x-1],$str);
}
return "<font color=red>$str</font>";
}
}
else
{
mysql_query("INSERT INTO translations (lang,strmd5,str) VALUES ('".$_SESSION['lang']."','".md5($str)."','".mysql_escape_string($str)."')");
for($x=1;$x<=count($args);$x++)
{
$str=str_replace("%$x",$args[$x-1],$str);
}
return "<font color=red>($str)</font>";
}
}
}
else
{
//no language set, assume english
return $str;
}
}
function error($str)
{
return $str."<br />";
}
function notice($str)
{
return $str."<br />";
}
$HEADER_SENT=false;
function send_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;
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><?=i18n($title)?></title>
<link rel="stylesheet" href="<?=$config['SFIABDIRECTORY']?>/sfiab.css" type="text/css" />
</head>
<body>
<div id="header">
<?
echo "<h1>".i18n($config['fairname'])."</h1>";
?>
<hr />
</div>
<div id="left">
<ul class="mainnav">
<li><a href="<?=$config['SFIABDIRECTORY']?>/register_participants.php"><?=i18n("Participant Registration")?></a></li>
<li><a href="<?=$config['SFIABDIRECTORY']?>/register_judges.php"><?=i18n("Judges Registration")?></a></li>
</ul>
<br />
<ul class="mainnav">
<li><a href="<?=$config['SFIABDIRECTORY']?>/admin/"><?=i18n("Fair Administration")?></a></li>
<li><a href="<?=$config['SFIABDIRECTORY']?>/config/"><?=i18n("SFIAB Configuration")?></a></li>
</ul>
<div class="aligncenter">
<?
if(count($config['languages'])>1)
{
echo "<br />";
echo "<form name=\"languageselect\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">";
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>";
echo "</form>";
}
?>
<a href="http://www.sfiab.ca/"><?=i18n("Return to SFIAB Development Page")?></a>
</div>
</div>
<div id="main">
<?
if($title)
echo "<h2>".i18n($title)."</h2>";
}
function send_footer()
{
?>
</div>
<div id="footer">
<? print_r($_SESSION); ?>
</div>
</body>
</html>
<?
}
?>