2005-03-09 23:20:44 +00:00
< ?
/*
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 ( " ../common.inc.php " );
auth_required ( 'admin' );
send_header ( " Administration - Judging Teams " );
?>
< script language = " javascript " type = " text/javascript " >
function addbuttonclicked ( team )
{
document . forms . judges . action . value = " add " ;
document . forms . judges . team_num . value = team ;
document . forms . judges . submit ();
}
2005-03-29 20:28:35 +00:00
function delbuttonclicked ( team_id , team_num , team_name , judge )
2005-03-09 23:20:44 +00:00
{
document . forms . judges . action . value = " del " ;
document . forms . judges . team_id . value = team_id ;
document . forms . judges . team_num . value = team_num ;
2005-03-29 20:28:35 +00:00
document . forms . judges . team_name . value = team_name ;
2005-03-09 23:20:44 +00:00
document . forms . judges . judges_id . value = judge ;
document . forms . judges . submit ();
}
2005-03-29 19:38:58 +00:00
function saveteamnamesbuttonclicked ()
{
document . forms . judges . action . value = " saveteamnames " ;
document . forms . judges . submit ();
}
2005-03-30 18:02:45 +00:00
function openjudgeinfo ( id )
{
if ( id )
currentid = id ;
else
currentid = document . forms . judges [ " judgelist[] " ] . options [ document . forms . judges [ " judgelist[] " ] . selectedIndex ] . value ;
2005-03-30 18:21:48 +00:00
window . open ( " judges_info.php?id= " + currentid , " JudgeInfo " , " location=no,menubar=no,directories=no,toolbar=no,width=770,height=500 " );
2005-03-30 18:02:45 +00:00
return false ;
}
function switchjudgeinfo ()
{
if ( document . forms . judges [ " judgelist[] " ] . selectedIndex != - 1 )
{
currentname = document . forms . judges [ " judgelist[] " ] . options [ document . forms . judges [ " judgelist[] " ] . selectedIndex ] . text ;
currentid = document . forms . judges [ " judgelist[] " ] . options [ document . forms . judges [ " judgelist[] " ] . selectedIndex ] . value ;
document . forms . judges . judgeinfobutton . disabled = false ;
2005-03-30 18:13:58 +00:00
document . forms . judges . judgeinfobutton . value = currentname ;
2005-03-30 18:02:45 +00:00
}
else
{
document . forms . judges . judgeinfobutton . disabled = true ;
document . forms . judges . judgeinfobutton . value = " <? echo i18n( " Judge Info " )?> " ;
}
}
2005-03-09 23:20:44 +00:00
</ script >
< ?
echo " <a href= \" index.php \" ><< " . i18n ( " Back to Administration " ) . " </a> \n " ;
echo " <a href= \" judges.php \" ><< " . i18n ( " Back to Judges " ) . " </a> \n " ;
if ( $_POST [ 'action' ] == " add " && $_POST [ 'team_num' ] && count ( $_POST [ 'judgelist' ]) > 0 )
{
//first check if this team exists.
2005-03-29 20:28:35 +00:00
$q = mysql_query ( " SELECT id,name FROM judges_teams WHERE num=' " . $_POST [ 'team_num' ] . " ' AND year=' " . $config [ 'FAIRYEAR' ] . " ' " );
2005-03-09 23:20:44 +00:00
if ( mysql_num_rows ( $q ))
{
$r = mysql_fetch_object ( $q );
$team_id = $r -> id ;
2005-03-29 20:28:35 +00:00
$team_name = $r -> name ;
2005-03-09 23:20:44 +00:00
}
else
{
2005-03-29 20:28:35 +00:00
echo notice ( i18n ( " Creating new team #%1 with name '%2' " , array ( $_POST [ 'team_num' ], $_POST [ 'new_team_name' ])));
mysql_query ( " INSERT INTO judges_teams (num,name,year) VALUES (' " . $_POST [ 'team_num' ] . " ',' " . $_POST [ 'new_team_name' ] . " ',' " . $config [ 'FAIRYEAR' ] . " ') " );
2005-03-09 23:20:44 +00:00
$team_id = mysql_insert_id ();
2005-03-29 20:28:35 +00:00
$team_name = $_POST [ 'new_team_name' ];
2005-03-09 23:20:44 +00:00
}
$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 " );
2005-03-29 20:28:35 +00:00
echo happy ( i18n ( " %1 %2 added to team #%3 (%4) " , array ( $added , $j , $_POST [ 'team_num' ], $team_name )));
2005-03-09 23:20:44 +00:00
}
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' ] . " ' " );
2005-03-29 20:28:35 +00:00
echo happy ( i18n ( " Removed judge from team #%1 (%2) " , array ( $_POST [ 'team_num' ], $_POST [ 'team_name' ])));
2005-03-09 23:20:44 +00:00
$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' ] . " ' " );
2005-03-29 20:28:35 +00:00
echo notice ( i18n ( " Removed empty team #%1 (%2) " , array ( $_POST [ 'team_num' ], $_POST [ 'team_name' ])));
2005-03-09 23:20:44 +00:00
}
2005-03-29 19:38:58 +00:00
}
if ( $_POST [ 'action' ] == " saveteamnames " )
{
2005-03-29 20:28:35 +00:00
if ( count ( $_POST [ 'team_names' ]))
2005-03-29 19:38:58 +00:00
{
2005-03-29 20:28:35 +00:00
foreach ( $_POST [ 'team_names' ] AS $team_id => $team_name )
2005-03-29 19:38:58 +00:00
{
mysql_query ( " UPDATE judges_teams SET name=' " . mysql_escape_string ( stripslashes ( $team_name )) . " ' WHERE id=' $team_id ' " );
}
echo happy ( i18n ( " Team names successfully saved " ));
}
2005-03-09 23:20:44 +00:00
}
echo " <form name= \" judges \" method= \" post \" action= \" judges_teams.php \" > " ;
echo " <input type= \" hidden \" name= \" action \" > " ;
echo " <input type= \" hidden \" name= \" team_id \" > " ;
echo " <input type= \" hidden \" name= \" team_num \" > " ;
2005-03-29 20:28:35 +00:00
echo " <input type= \" hidden \" name= \" team_name \" > " ;
2005-03-09 23:20:44 +00:00
echo " <input type= \" hidden \" name= \" judges_id \" > " ;
echo " <table> " ;
echo " <tr> " ;
2005-03-30 18:02:45 +00:00
echo " <th> " . i18n ( " Judges List " );
echo " <br /> " ;
echo " <input disabled= \" true \" name= \" judgeinfobutton \" id= \" judgeinfobutton \" onclick= \" openjudgeinfo() \" type= \" button \" value= \" " . i18n ( " Judge Info " ) . " \" > " ;
echo " </th> " ;
echo " <th> " . i18n ( " Judge Teams " ) . " </th> " ;
2005-03-09 23:20:44 +00:00
echo " </tr> " ;
echo " <tr><td valign= \" top \" > " ;
/*
//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
2005-03-10 19:43:49 +00:00
judges_teams_link . judges_id IS NULL AND
judges . complete = 'yes'
2005-03-09 23:20:44 +00:00
ORDER BY
lastname ,
firstname " ;
$q = mysql_query ( $querystr );
echo mysql_error ();
2005-03-30 18:02:45 +00:00
echo " <select name= \" judgelist[] \" onchange= \" switchjudgeinfo() \" multiple= \" multiple \" style= \" width: 250px; height: 600px; \" > " ;
2005-03-09 23:20:44 +00:00
while ( $r = mysql_fetch_object ( $q ))
{
2005-03-09 23:29:00 +00:00
if ( $r -> firstname && $r -> lastname )
echo " <option value= \" $r->id\ " > $r -> firstname $r -> lastname </ option > \n " ;
2005-03-09 23:20:44 +00:00
}
echo " </select> " ;
echo " </td> " ;
echo " <td valign= \" top \" > " ;
$q = mysql_query ( " SELECT judges_teams.id,
judges_teams . num ,
2005-03-29 19:38:58 +00:00
judges_teams . name ,
2005-03-09 23:20:44 +00:00
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
2005-03-29 19:53:48 +00:00
name ,
2005-03-09 23:20:44 +00:00
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 ;
2005-03-29 19:38:58 +00:00
$teams [ $r -> id ][ 'name' ] = $r -> name ;
2005-03-09 23:20:44 +00:00
$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));
2005-03-09 23:25:15 +00:00
if ( $lastteamnum ==- 1 ) $newteamid = 1 ;
else $newteamid = $lastteamnum + 1 ;
echo " <table> " ;
echo " <tr><td valign=top> " ;
echo " <input onclick= \" addbuttonclicked(' $newteamid ') \" type= \" button \" value= \" Add >> \" > " ;
echo " </td><td> " ;
echo " <table> " ;
2005-03-29 20:28:35 +00:00
echo " <tr><th align= \" left \" >New # $newteamid : <input type= \" text \" name= \" new_team_name \" value= \" Team # $newteamid\ " /></ th ></ tr > " ;
2005-03-09 23:25:15 +00:00
echo " </table> " ;
echo " </td></tr></table> " ;
2005-03-09 23:20:44 +00:00
foreach ( $teams AS $team )
{
2005-03-09 23:26:50 +00:00
echo " <hr> " ;
2005-03-09 23:20:44 +00:00
echo " <table> " ;
echo " <tr><td valign=top> " ;
echo " <input onclick= \" addbuttonclicked(' " . $team [ 'num' ] . " ') \" type= \" button \" value= \" Add >> \" > " ;
echo " </td><td> " ;
2005-03-29 20:28:35 +00:00
echo " <table> \n " ;
2005-03-29 19:38:58 +00:00
echo " <tr><th colspan= \" 2 \" align= \" left \" ># " . $team [ 'num' ] . " : " ;
2005-03-29 20:28:35 +00:00
echo " <input type= \" text \" name= \" team_names[ " . $team [ 'id' ] . " ] \" value= \" " . $team [ 'name' ] . " \" size= \" 10 \" > " ;
echo " </th></tr> \n " ;
2005-03-09 23:20:44 +00:00
foreach ( $team [ 'members' ] AS $member )
{
echo " <tr><td> " ;
2005-03-29 20:28:35 +00:00
echo " <input onclick= \" delbuttonclicked(' " . $team [ 'id' ] . " ',' " . $team [ 'num' ] . " ',' " . htmlspecialchars ( $team [ 'name' ]) . " ',' " . $member [ 'id' ] . " ') \" type= \" button \" value= \" << \" > " ;
2005-03-09 23:20:44 +00:00
echo " </td><td> " ;
2005-03-30 18:02:45 +00:00
echo " <a href= \" \" onclick= \" return openjudgeinfo( " . $member [ 'id' ] . " ); \" > " ;
2005-03-09 23:20:44 +00:00
echo $member [ 'firstname' ] . " " . $member [ 'lastname' ];
2005-03-30 18:02:45 +00:00
echo " </a> " ;
2005-03-09 23:20:44 +00:00
echo " </td></tr> " ;
}
echo " </table> " ;
echo " </td></tr></table> " ;
}
2005-03-29 19:38:58 +00:00
echo " <br /> " ;
echo " <input type= \" button \" onclick= \" saveteamnamesbuttonclicked() \" type= \" button \" value= \" Save Team Names \" /> " ;
2005-03-09 23:20:44 +00:00
echo " </td></tr> " ;
echo " </table> " ;
echo " </form> " ;
send_footer ();
?>