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($_POST['action']=="add" && $_POST['team_num'] && count($_POST['judgelist'])>0) { //first check if this team exists. $q=mysql_query("SELECT id FROM judges_teams WHERE num='".$_POST['team_num']."' AND year='".$config['FAIRYEAR']."'"); if(mysql_num_rows($q)) { $r=mysql_fetch_object($q); $team_id=$r->id; } else { echo notice(i18n("Creating new team #%1",array($_POST['team_num']))); mysql_query("INSERT INTO judges_teams (num,year) VALUES ('".$_POST['team_num']."','".$config['FAIRYEAR']."')"); $team_id=mysql_insert_id(); } $added=0; foreach($_POST['judgelist'] AS $selectedjudge) { mysql_query("INSERT INTO judges_teams_link (judges_id,judges_teams_id,year) VALUES ('$selectedjudge','$team_id','".$config['FAIRYEAR']."')"); $added++; } if($added==1) $j=i18n("judge"); else $j=i18n("judges"); echo happy(i18n("%1 %2 added to team #%3",array($added,$j,$_POST['team_num']))); } if($_POST['action']=="del" && $_POST['team_num'] && $_POST['team_id'] && $_POST['judges_id']) { mysql_query("DELETE FROM judges_teams_link WHERE judges_id='".$_POST['judges_id']."' AND judges_teams_id='".$_POST['team_id']."' AND year='".$config['FAIRYEAR']."'"); echo happy(i18n("Removed judge from team #%1",array($_POST['team_num']))); $q=mysql_query("SELECT * FROM judges_teams_link WHERE judges_teams_id='".$_POST['team_id']."' AND year='".$config['FAIRYEAR']."'"); if(mysql_num_rows($q)==0) { mysql_query("DELETE FROM judges_teams WHERE year='".$config['FAIRYEAR']."' AND id='".$_POST['team_id']."'"); echo notice(i18n("Removed empty team #%1",array($_POST['team_num']))); } } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
".i18n("Judges List")."Judge Teams
"; /* //mysql 4.0 does not support subqueries - it is supported as of mysql 4.1 //this means we cant use NOT IN (SELECT..) so, we will have to workaround this //at least for now. $querystr="SELECT judges.id, judges.firstname, judges.lastname FROM judges, judges_years WHERE judges_years.year='".$config['FAIRYEAR']."' AND judges.id=judges_years.judges_id AND judges.id NOT IN (SELECT judges_id AS id FROM judges_teams_link WHERE judges_teams_link.year='".$config['FAIRYEAR']."') ORDER BY lastname, firstname"; */ $querystr="SELECT judges.id, judges.firstname, judges.lastname, judges_teams_link.judges_id FROM judges LEFT JOIN judges_teams_link ON judges.id = judges_teams_link.judges_id, judges_years WHERE judges_years.year='".$config['FAIRYEAR']."' AND judges.id=judges_years.judges_id AND judges_teams_link.judges_id IS NULL ORDER BY lastname, firstname"; $q=mysql_query($querystr); echo mysql_error(); echo ""; echo ""; $q=mysql_query("SELECT judges_teams.id, judges_teams.num, judges.id AS judges_id, judges.firstname, judges.lastname FROM judges, judges_teams, judges_teams_link WHERE judges_teams.year='".$config['FAIRYEAR']."' AND judges_teams_link.judges_id=judges.id AND judges_teams_link.judges_teams_id=judges_teams.id ORDER BY num, lastname, firstname"); $lastteamid=-1; $lastteamnum=-1; echo mysql_error(); $teams=array(); while($r=mysql_fetch_object($q)) { if($r->id!=$lastteamid) { $teams[$r->id]['id']=$r->id; $teams[$r->id]['num']=$r->num; $lastteamid=$r->id; $lastteamnum=$r->num; } $teams[$lastteamid]['members'][]=array("id"=>$r->judges_id,"firstname"=>$r->firstname,"lastname"=>$r->lastname); } //echo nl2br(print_r($teams,true)); if($lastteamnum==-1) $newteamid=1; else $newteamid=$lastteamnum+1; echo ""; echo "
"; echo ""; echo ""; echo ""; echo ""; echo "
New Team #$newteamid
"; echo "
"; foreach($teams AS $team) { echo "
"; echo ""; echo "
"; echo ""; echo ""; echo ""; echo ""; foreach($team['members'] AS $member) { echo ""; } echo "
Team #".$team['num']."
"; echo ""; echo ""; echo $member['firstname']." ".$member['lastname']; echo "
"; echo "
"; } echo "
"; echo "
"; send_footer(); ?>