- add judge special awards selection

- fixup the judge_complete detection
- rename judges_id to users_id in the 117 db update, so it's done after the 116
  update converts everything
This commit is contained in:
dave 2008-10-18 03:30:58 +00:00
parent 4b247de611
commit 81c211c913
7 changed files with 179 additions and 66 deletions

View File

@ -10,4 +10,10 @@ ALTER TABLE `question_answers` CHANGE `registrations_id` `users_id` INT( 10 ) UN
-- The answer has been linked to a users_id that is unique per-year, so we don't need to duplicate the year storage
ALTER TABLE `question_answers` DROP `year`;
-- Use users_id instead of judges_id now, the judges_id was converted to the proper users_id in the 116 update
ALTER TABLE `judges_specialaward_sel` CHANGE `judges_id` `users_id` INT( 11 ) NOT NULL DEFAULT '0';
ALTER TABLE `judges_teams_link` CHANGE `judges_id` `users_id` INT( 11 ) NOT NULL DEFAULT '0' ;
-- The users_id is linked with the year, don't need to store it here too
ALTER TABLE `judges_specialaward_sel` DROP `year`;

View File

@ -31,26 +31,13 @@ $preferencechoices=array(
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)
function judge_status_expertise(&$u)
{
global $config;
if($u['load_full'] == false) {
echo "ERROR: judge_status_expertise() called without a full user.";
exit;
}
/* If the judging special awards are active, and the judge has
* selected "I am a special awards judge", then disable
@ -74,9 +61,13 @@ function judge_status_expertise($u)
return 'complete';
}
function judge_status_other($u)
function judge_status_other(&$u)
{
global $config;
if($u['load_full'] == false) {
echo "ERROR: judge_status_other() called without a full user.";
exit;
}
/* They must select a language to judge in */
if(count($u['languages']) < 1) return 'incomplete';
@ -86,64 +77,61 @@ function judge_status_other($u)
function specialawardStatus()
function judge_status_special_awards(&$u)
{
global $config;
if($u['load_full'] == false) {
echo "ERROR: judge_status_special_awards() called without a full user.";
exit;
}
/* 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);
* - judge has selected between min and max preferences
*/
$qq = mysql_query("SELECT COUNT(id) AS num FROM judges_specialaward_sel
WHERE judges_id='{$_SESSION['judges_id']}'
AND year={$config['FAIRYEAR']}");
WHERE users_id='{$u['id']}'");
$rr = mysql_fetch_object($qq);
$awards_selected = $rr->num;
// echo "$awards_selected awards selected, ({$config['judges_specialaward_min']} - {$config['judges_specialaward_max']})";
switch($r->typepref) {
case "speconly": /* Judge for special award */
if($u['special_award_only'] == 'yes') {
/* 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;
if($awards_selected >= 1) return 'complete';
return 'incomplete';
}
case "pref": /* Special award preferences specified */
default:
if( ($awards_selected >= $config['judges_specialaward_min'])
&&($awards_selected <= $config['judges_specialaward_max']) ){
return "complete";
}
break;
if( ($awards_selected >= $config['judges_specialaward_min'])
&&($awards_selected <= $config['judges_specialaward_max']) ){
return 'complete';
}
return "incomplete";
return 'incomplete';
}
//ji = judgeinfo record from database (select * from judges where id='whatever')
function updateJudgeCompleteStatus($ji)
function judge_status_update(&$u)
{
if( personalStatus()=="complete" &&
expertiseStatus()=="complete"
)
$complete="yes";
else
$complete="no";
if($u['load_full'] == false) {
echo "ERROR: judge_status_update() called without a full user.";
exit;
}
if( user_personal_info_status($u) == 'complete'
&& judge_status_expertise($u) == 'complete'
&& judge_status_other($u) == 'complete'
&& judge_status_special_awards($u) == 'complete')
$u['judge_complete'] = 'yes';
else
$u['judge_complete'] = 'no';
user_save($u);
return ($u['judge_complete'] == 'yes') ? 'complete' : 'incomplete';
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);
?>

View File

@ -67,7 +67,7 @@
$u = user_load($_SESSION['users_id'], true);
}
// updateJudgeCompleteStatus($judgeinfo);
judge_status_update($u);
//output the current status
$newstatus=judge_status_expertise($u);

View File

@ -67,14 +67,14 @@
if($config['judges_specialaward_enable'] == 'yes' || $u['special_award_only'] == 'yes') {
user_page_summary_item("Special Award Preferences",
"register_judges_specialawards.php", "specialawardStatus", array($u));
"judge_special_awards.php", "judge_status_special_awards", array($u));
}
// user_page_summary_item("Areas of Expertise",
// "register_judges_expertise.php", "expertiseStatus", array($u));
$overallstatus = user_page_summary_end(true);
user_update_complete($u, $overallstatus);
judge_status_update($u);
echo '<br /><br />';
if($overallstatus!="complete")

View File

@ -55,7 +55,7 @@
$u = user_load($_SESSION['users_id'], true);
}
// updateJudgeCompleteStatus($judgeinfo);
judge_status_update($u);
//output the current status
$newstatus=judge_status_other($u);

117
judge_special_awards.php Normal file
View File

@ -0,0 +1,117 @@
<?
/*
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.
*/
?>
<?
require_once('common.inc.php');
require_once('user.inc.php');
require_once('judge.inc.php');
$u = user_load($_SESSION['users_id'], true);
//send the header
send_header('Special Awards',
array('Judge Registration' => 'judge_main.php')
);
if($_POST['action']=="save") {
//first delete all their old associations for this year..
mysql_query("DELETE FROM judges_specialaward_sel WHERE users_id='{$u['id']}'");
if(array_key_exists('spaward', $_POST)) {
foreach($_POST['spaward'] AS $aid) {
mysql_query("INSERT INTO judges_specialaward_sel (users_id, award_awards_id)
VALUES ('{$u['id']}','$aid')");
}
}
echo notice(i18n("Special Award preferences successfully saved"));
}
judge_status_update($u);
//output the current status
$newstatus=judge_status_special_awards($u);
if($newstatus!='complete')
echo error(i18n("Special Award Preferences Incomplete"));
else
echo happy(i18n("Special Award Preferences Complete"));
echo "<form name=\"specialawardform\" method=\"post\" action=\"judge_special_awards.php\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save\">\n";
if($u['special_award_only'] == 'yes') {
echo i18n("Please select the special award you are supposed to judge.");
} else {
echo i18n("Please select any special awards you would prefer to judge.");
echo "&nbsp;&nbsp;";
echo i18n("We assign judges to divisional awards first. So please note that by selecting awards here it does not guarantee that you will be judging special awards. This selects your special award judging preferences IF you are not assigned to a divisional judging team.");
}
echo "<br />";
echo "<br />";
$q=mysql_query("SELECT * FROM judges_specialaward_sel WHERE users_id='{$u['id']}'");
$spawards = array();
while($r=mysql_fetch_object($q)) $spawards[] = $r->award_awards_id;
echo "<table>\n";
//query all of the awards
$q=mysql_query("SELECT award_awards.id,
award_awards.name,
award_awards.criteria,
award_sponsors.organization
FROM
award_awards,
award_types,
award_sponsors
WHERE
award_types.id=award_awards.award_types_id
AND award_sponsors.id=award_awards.award_sponsors_id
AND (award_types.type='Special' OR award_types.type='Other')
AND award_awards.year='{$config['FAIRYEAR']}'
AND award_types.year='{$config['FAIRYEAR']}'
ORDER BY
name");
echo mysql_error();
while($r=mysql_fetch_object($q))
{
echo "<tr><td rowspan=\"2\">";
$ch = (in_array($r->id,$spawards)) ? "checked=\"checked\"" : "";
echo "<input onclick=\"checkboxclicked(this)\" $ch type=\"checkbox\" name=\"spaward[]\" value=\"{$r->id}\" />";
echo "</td><td>";
echo "<b>{$r->name}</b> ({$r->organization})";
echo "</td></tr>";
echo "<tr><td>";
echo "{$r->criteria}";
echo "<br /><br />";
echo "</td></tr>";
}
echo "</table>";
echo "<input type=\"submit\" value=\"".i18n("Save Special Award Preferences")."\" />\n";
echo "</form>";
send_footer();
?>

View File

@ -89,6 +89,7 @@ function user_load_judge($u)
$r = mysql_fetch_object($q);
$ret = array();
$ret['judge_active'] = $r->judge_active;
$ret['judge_complete'] = $r->judge_complete;
$ret['years_school'] = intval($r->years_school);
$ret['years_regional'] = intval($r->years_regional);
$ret['years_national'] = intval($r->years_national);
@ -304,12 +305,13 @@ function user_save_type_list($u, $db, $fields)
if($set != "") {
$query = "UPDATE $db SET $set WHERE users_id='{$u['id']}'";
mysql_query($query);
echo mysql_error();
}
}
function user_save_volunteer($u)
{
$fields = array('volunteer_active');
$fields = array('volunteer_active','volunteer_complete');
user_save_type_list($u, 'users_volunteer', $fields);
}
@ -322,7 +324,7 @@ function user_save_committee($u)
function user_save_judge($u)
{
$fields = array('judge_active','years_school','years_regional','years_national',
$fields = array('judge_active','judge_complete','years_school','years_regional','years_national',
'willing_chair','special_award_only',
'cat_prefs','div_prefs','divsub_prefs',
'expertise_other','languages', 'highest_psd');
@ -331,7 +333,7 @@ function user_save_judge($u)
function user_save_student($u)
{
// $fields = array('student_active',);
// $fields = array('student_active','student_complete');
// user_save_type_list($u, 'users_student', $fields);
}
@ -399,8 +401,8 @@ function user_delete_judge($u)
{
global $config;
$id = $u['id'];
mysql_query("DELETE FROM judges_teams_link WHERE judges_id='$id' AND year='{$config['FAIRYEAR']}'");
mysql_query("DELETE FROM judges_years WHERE judges_id='$id' AND year='{$config['FAIRYEAR']}'");
mysql_query("DELETE FROM judges_teams_link WHERE users_id='$id'");
mysql_query("DELETE FROM judges_specialawards_sel WHERE users_id='$id'");
}
function user_delete_fair($u)