science-ation/register_judges.inc.php
james 12c514d8c5 refactor some of the authenticaiton code into the .inc.php
add a password changer

check for expired passwords and force changing if expired
2005-02-16 20:04:12 +00:00

110 lines
3.4 KiB
PHP

<?
/*
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.
*/
?>
<?
function personalStatus()
{
global $config;
$required_fields=array("firstname","lastname","address","city","postalcode","phonehome","email");
$q=mysql_query("SELECT * FROM judges WHERE id='".$_SESSION['judges_id']."'");
while($r=mysql_fetch_object($q))
{
foreach ($required_fields AS $req)
{
if(!$r->$req)
{
return "incomplete";
}
}
}
//and they also have to select at least one language to judge in
$q=mysql_query("SELECT COUNT(judges_id) AS num FROM judges_languages WHERE judges_id='".$_SESSION['judges_id']."'");
$r=mysql_fetch_object($q);
if($r->num==0)
return "incomplete";
//if it made it through without returning incomplete, then we must be complete
return "complete";
}
function expertiseStatus()
{
global $config;
//easiest check here is to check the number of divisions, then check the number of entries
//that they have in the judges_expertise table. If they are the same, then we're good to go
//if they are different, they forgot to fill one out (because it only gets inserted if a value)
//is choosen, and they are always ALL removed before each update
$q=mysql_query("SELECT COUNT(id) AS num FROM projectdivisions WHERE year='".$config['FAIRYEAR']."'");
$r=mysql_fetch_object($q);
$numdivisions=$r->num;
$q=mysql_query("SELECT COUNT(id) AS num FROM judges_expertise WHERE projectdivisions_id IS NOT NULL AND judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'");
$r=mysql_fetch_object($q);
$numjudgesexpertise=$r->num;
if($numdivisions == $numjudgesexpertise)
return "complete";
else
return "incomplete";
}
//authenticate based on email address and registration number from the SESSION
if(! ($_SESSION['email'] && $_SESSION['judges_id']) )
{
header("Location: register_judges.php");
exit;
}
$q=mysql_query("SELECT * FROM judges WHERE email='".$_SESSION['email']."' AND id='".$_SESSION['judges_id']."' AND deleted='no'");
echo mysql_error();
if(mysql_num_rows($q)==0)
{
header("Location: register_judges.php?action=logout");
exit;
}
$judgeinfo=mysql_fetch_object($q);
//only check for password expiry if we are NOT on the change password page, otherwise we create endless redirect loops
if(!strstr($_SERVER['PHP_SELF'],"register_judges_password.php"))
{
//check for expired password
$q=mysql_query("SELECT id FROM judges WHERE email='".$_SESSION['email']."' AND id='".$_SESSION['judges_id']."' AND deleted='no' AND passwordexpiry<=NOW()");
if(mysql_num_rows($q))
{
$_SESSION['judges_password_expired']=true;
header("Location: register_judges_password.php");
}
}
?>