Copyright (C) 2005 James Grant 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. */ ?> << ".i18n("Back to Administration")."\n"; echo "<< ".i18n("Back to Judges")."\n"; if($_GET['edit']) $edit=$_GET['edit']; if($_POST['edit']) $edit=$_POST['edit']; if($_GET['action']) $action=$_GET['action']; if($_POST['action']) $action=$_POST['action']; if($action=="delete" && $_GET['delete']) { //ALSO DELETE: team members, timeslots, projects, awards mysql_query("DELETE FROM judges_teams_link WHERE judges_teams_id='".$_GET['delete']."' AND year='".$config['FAIRYEAR']."'"); mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='".$_GET['delete']."' AND year='".$config['FAIRYEAR']."'"); mysql_query("DELETE FROM judges_teams_timeslots_projects_link WHERE judges_teams_id='".$_GET['delete']."' AND year='".$config['FAIRYEAR']."'"); mysql_query("DELETE FROM judges_teams_awards_link WHERE judges_teams_id='".$_GET['delete']."' AND year='".$config['FAIRYEAR']."'"); mysql_query("DELETE FROM judges_teams WHERE id='".$_GET['delete']."' AND year='".$config['FAIRYEAR']."'"); echo happy(i18n("Judge team successfully removed, and all of its corresponding members, timeslots, projects and awards unlinked from team")); } if(($action=="save" || $action=="assign") && $edit) { //if we're updating or assigning, it doesnt matter, lets do the same thing (save record, add award //but when we're done, if we're "assign" then go back to edit that team //if we're save, then go back to the team list $err=false; $q=mysql_query("UPDATE judges_teams SET num='".$_POST['team_num']."', name='".mysql_escape_string(stripslashes($_POST['team_name']))."' WHERE id='$edit'"); if(mysql_error()) { $err=true; echo error(mysql_error()); } if($_POST['award']) { //we can only have 1 special award assigned to any given team so we'll be able to properly //manage the projects that we assign to the team. If there was more than one special award //the judges wouldnt know which projects to judge for which award. This doesnt apply for divisions //because the category/division is obvious based on project numbesr. A divisional judge team could easily //be assigned to do all of Comp Sci - Junior, Intermediate and Senior without any problems. $q=mysql_query("SELECT award_types.type FROM award_awards, award_types WHERE award_awards.award_types_id=award_types.id AND award_awards.id='".$_POST['award']."'"); $aw=mysql_fetch_object($q); $addaward=true; if($aw->type=="Special") { $q=mysql_query("SELECT COUNT(*) AS num FROM judges_teams_awards_link, award_awards, award_types WHERE judges_teams_awards_link.judges_teams_id='$edit' AND judges_teams_awards_link.award_awards_id=award_awards.id AND award_awards.award_types_id=award_types.id AND award_types.type='Special' "); $r=mysql_fetch_object($q); echo "special awards: $r->num"; if($r->num) { $addaward=false; echo error(i18n("Sorry, only one Special Award can be assigned to a judging team")); } else { $addaward=true; } } if($addaward) { //link up the award mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) VALUES ('".$_POST['award']."','$edit','".$config['FAIRYEAR']."')"); echo happy(i18n("Award assigned to team")); } } if($action=="assign") $action="edit"; else if($action=="save") { if($err) $action="edit"; else { echo happy(i18n("Team successfully saved")); unset($action); unset($edit); } } } if($action=="unassign") { mysql_query("DELETE FROM judges_teams_awards_link WHERE judges_teams_id='$edit' AND award_awards_id='".$_GET['unassign']."' AND year='".$config['FAIRYEAR']."'"); echo happy(i18n("Award unassigned from judge team")); //keep editing the same team $action="edit"; } if($action=="createall") { //first make sure we're really empty (dont want people hitting refresh and adding all the teams twice $q=mysql_query("SELECT COUNT(*) AS c FROM judges_teams WHERE year='".$config['FAIRYEAR']."'"); $r=mysql_fetch_object($q); if($r->c) { echo error(i18n("Cannot 'Create All' teams when any teams currently exist. Try deleting all existing teams first.")); } else { //grab all the awards $q=mysql_query("SELECT award_awards.*, award_types.type AS award_type, award_types.order AS award_types_order FROM award_awards,award_types WHERE award_awards.award_types_id=award_types.id AND award_awards.year='".$config['FAIRYEAR']."' ORDER BY award_types_order, name"); $num=1; while($r=mysql_fetch_object($q)) { $name=mysql_escape_string("($r->award_type) $r->name"); mysql_query("INSERT INTO judges_teams(num,name,year) VALUES ('$num','$name','".$config['FAIRYEAR']."')"); $team_id=mysql_insert_id(); //now link the new team to the award mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) VALUES ('$r->id','$team_id','".$config['FAIRYEAR']."')"); echo happy(i18n("Created team #%1: %2",array($num,$name))); $num++; } } } if($action=="add" && $_GET['num']) { mysql_query("INSERT INTO judges_teams(num,year) VALUES ('".$_GET['num']."','".$config['FAIRYEAR']."')"); echo mysql_error(); $edit=mysql_insert_id(); $action="edit"; } if($action=="edit" && $edit) { echo "<< ".i18n("Back to Judging Teams")."\n"; echo "
"; echo "
"; $team=getJudgingTeam($edit); if(!$_SESSION['viewstate']['judges_teams_awards_show']) $_SESSION['viewstate']['judges_teams_awards_show']='unassigned'; //now update the judges_teams_awards_show viewstate if($_GET['judges_teams_awards_show']) $_SESSION['viewstate']['judges_teams_awards_show']=$_GET['judges_teams_awards_show']; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
".i18n("Team Number").":
".i18n("Team Name").":
".i18n("Awards").":"; foreach($team['awards'] AS $award) { echo ""; echo " (".$award['award_type'].") ".$award['name']."
"; } echo ""; if($_SESSION['viewstate']['judges_teams_awards_show']=='all') { echo ""; echo ""; } else { echo ""; echo ""; } echo ""; if($_SESSION['viewstate']['judges_teams_awards_show']=='all') { $querystr="SELECT award_awards.id, award_awards.name, award_types.type AS award_type, award_types.order AS award_type_order FROM award_awards, award_types WHERE award_awards.year='".$config['FAIRYEAR']."' AND award_types.id=award_awards.award_types_id ORDER BY award_type_order, name "; } else { $querystr="SELECT award_awards.id, award_awards.name, award_types.type AS award_type, award_types.order AS award_type_order FROM award_awards, award_types LEFT JOIN judges_teams_awards_link ON award_awards.id = judges_teams_awards_link.award_awards_id WHERE award_awards.year='".$config['FAIRYEAR']."' AND judges_teams_awards_link.award_awards_id IS NULL AND award_types.id=award_awards.award_types_id ORDER BY award_type_order, name"; } echo ""; echo "
".i18n("show unassigned")."".i18n("show all")."".i18n("show unassigned")."".i18n("show all")."
"; $q=mysql_query($querystr); echo mysql_error(); echo ""; echo ""; echo "
"; echo "
"; echo ""; echo "
"; } else { echo "
"; echo "
"; $teams=getJudgingTeams(); if(!count($teams)) { echo "".i18n("Automatically create one new team for every award")."
"; echo "".i18n("Manually add individual team")."
"; } else { //grab an array of all the current team numbers foreach($teams AS $team) $teamnumbers[$team['num']]=1; //start at 1, and find the next available team number $newteamnum=1; while($teamnumbers[$newteamnum]==1) { $newteamnum++; } echo "Add individual team
"; echo "\n"; echo ""; echo ""; echo ""; echo ""; echo ""; foreach($teams AS $team) { echo ""; echo ""; echo " \n"; echo "\n"; } echo "
NumTeam NameAward(s)Actions
#".$team['num'].""; echo $team['name']; echo ""; if(count($team['awards'])) { foreach($team['awards'] AS $award) { echo $award['name']."
"; } } else { echo error(i18n("No award assigned to team"),"inline"); } echo "
"; echo ""; echo " "; echo ""; echo "
"; echo "
"; } } send_footer(); ?>