science-ation/judge.inc.php

153 lines
4.0 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.
*/
?>
<?
$preferencechoices=array(
-2=>"Very Low",
-1=>"Low",
0=>"Indifferent",
1=>"Medium",
2=>"High"
);
function personalStatus()
{
global $config;
//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 judge_status_expertise($u)
{
global $config;
/* If the judging special awards are active, and the judge has
* selected "I am a special awards judge", then disable
* expertise checking */
if($config['judges_specialaward_only_enable'] == 'yes') {
if($u['special_award_only'] == 'yes')
return 'complete';
}
/* Check to see if they have ranked all project age categories, and all divisions */
$q=mysql_query("SELECT COUNT(id) AS num FROM projectcategories WHERE year='".$config['FAIRYEAR']."'");
$r=mysql_fetch_object($q);
$numcats=$r->num;
if($numcats != count($u['catprefs'])) {
return "incomplete";
}
$q=mysql_query("SELECT COUNT(id) AS num FROM projectdivisions WHERE year='".$config['FAIRYEAR']."'");
$r=mysql_fetch_object($q);
$numdivisions=$r->num;
if($numdivisions != count($u['divprefs'])) {
return "incomplete";
}
return "complete";
}
function judge_status_other($u)
{
global $config;
return 'complete';
}
function specialawardStatus()
{
global $config;
/* Complete if:
* - judge has selected (none) "no special award preferences"
* - judge has selected (pref) "i would like to specify awards", and has
* selected between min and max preferences
* - judge has selected "i am a special awards judge, and has
* selected an award */
$q = mysql_query("SELECT typepref FROM judges WHERE
id='{$_SESSION['judges_id']}'");
if(mysql_num_rows($q) != 1) return "incomplete";
$r = mysql_fetch_object($q);
$qq = mysql_query("SELECT COUNT(id) AS num FROM judges_specialaward_sel
WHERE judges_id='{$_SESSION['judges_id']}'
AND year={$config['FAIRYEAR']}");
$rr = mysql_fetch_object($qq);
$awards_selected = $rr->num;
switch($r->typepref) {
case "speconly": /* Judge for special award */
/* They may judge more than one award, so don't limit them
* to one */
if($awards_selected >= 1) return "complete";
break;
case "pref": /* Special award preferences specified */
default:
if( ($awards_selected >= $config['judges_specialaward_min'])
&&($awards_selected <= $config['judges_specialaward_max']) ){
return "complete";
}
break;
}
return "incomplete";
}
//ji = judgeinfo record from database (select * from judges where id='whatever')
function updateJudgeCompleteStatus($ji)
{
if( personalStatus()=="complete" &&
expertiseStatus()=="complete"
)
$complete="yes";
else
$complete="no";
if($complete!=$ji->complete)
{
mysql_query("UPDATE judges SET complete='$complete' WHERE id='".$ji->id."'");
}
}
//finally, if everything else is good, update their 'overall status' if it needs to be
//updateJudgeCompleteStatus($judgeinfo);
?>