2005-05-06 16:13:37 +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 " );
2007-11-21 17:02:09 +00:00
require_once ( " ../user.inc.php " );
2007-11-18 23:50:23 +00:00
user_auth_required ( 'committee' , 'admin' );
2005-05-06 16:13:37 +00:00
include " judges.inc.php " ;
2007-11-18 23:50:23 +00:00
send_header ( " Judging Team Members " ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ,
'Judges' => 'admin/judges.php' )
);
2005-05-06 16:13:37 +00:00
?>
< 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 ();
}
function openjudgeinfo ( id )
{
if ( id )
currentid = id ;
else
currentid = document . forms . judges [ " judgelist[] " ] . options [ document . forms . judges [ " judgelist[] " ] . selectedIndex ] . value ;
2006-01-26 17:52:06 +00:00
window . open ( " judges_info.php?id= " + currentid , " JudgeInfo " , " location=no,menubar=no,directories=no,toolbar=no,width=770,height=500,scrollbars=yes " );
2005-05-06 16:13:37 +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 ;
document . forms . judges . judgeinfobutton . value = currentname ;
}
else
{
document . forms . judges . judgeinfobutton . disabled = true ;
document . forms . judges . judgeinfobutton . value = " <? echo i18n( " Judge Info " )?> " ;
}
}
</ script >
< ?
if ( $_POST [ 'action' ] == " add " && $_POST [ 'team_num' ] && count ( $_POST [ 'judgelist' ]) > 0 )
{
//first check if this team exists.
$q = mysql_query ( " SELECT id,name 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 ;
$team_name = $r -> name ;
//if the team is empty, we'll add the first person as the captain
$team = getJudgingTeam ( $team_id );
if ( count ( $team [ 'members' ]))
$captain = 'no' ;
else
$captain = 'yes' ;
}
$added = 0 ;
foreach ( $_POST [ 'judgelist' ] AS $selectedjudge )
{
//before we insert them, we need to make sure they dont already belong to this team. We can not have the same judge assigned to the same team multiple times.
$q = mysql_query ( " SELECT * FROM judges_teams_link WHERE judges_id=' $selectedjudge ' AND judges_teams_id=' $team_id ' " );
if ( mysql_num_rows ( $q ))
{
echo notice ( i18n ( " Judge (%1) already belongs to judging team: %2 " , array ( $selectedjudge , $team_name )));
}
else
{
//lets make the first one we add a captain, the rest, non-captains :)
mysql_query ( " INSERT INTO judges_teams_link (judges_id,judges_teams_id,captain,year) VALUES (' $selectedjudge ',' $team_id ',' $captain ',' " . $config [ 'FAIRYEAR' ] . " ') " );
$added ++ ;
}
//if this is alreayd no, then who cares, but if its the first one that is going into the new team, then
//captain will be yes, and we only want the first one assigned to a new team to be the captain
//sno now we can set this back to no
$captain = 'no' ;
}
if ( $added == 1 ) $j = i18n ( " judge " );
else $j = i18n ( " judges " );
echo happy ( i18n ( " %1 %2 added to team #%3 (%4) " , array ( $added , $j , $_POST [ 'team_num' ], $team_name )));
}
2005-05-06 16:34:13 +00:00
if ( $_GET [ 'action' ] == " del " && $_GET [ 'team_num' ] && $_GET [ 'team_id' ] && $_GET [ 'judges_id' ])
2005-05-06 16:13:37 +00:00
{
2005-05-06 16:34:13 +00:00
mysql_query ( " DELETE FROM judges_teams_link WHERE judges_id=' " . $_GET [ 'judges_id' ] . " ' AND judges_teams_id=' " . $_GET [ 'team_id' ] . " ' AND year=' " . $config [ 'FAIRYEAR' ] . " ' " );
echo happy ( i18n ( " Removed judge from team #%1 (%2) " , array ( $_GET [ 'team_num' ], $_GET [ 'team_name' ])));
2005-05-06 16:13:37 +00:00
//if there is still members left in the team, make sure we have a captain still
2005-05-06 16:34:13 +00:00
$q = mysql_query ( " SELECT * FROM judges_teams_link WHERE judges_teams_id=' " . $_GET [ 'team_id' ] . " ' AND year=' " . $config [ 'FAIRYEAR' ] . " ' " );
2005-05-06 16:13:37 +00:00
if ( mysql_num_rows ( $q ))
{
//make sure the team still has a captain!
//FIXME: this might best come from the "i am willing to be a team captain" question under the judges profile
$gotcaptain = false ;
$first = true ;
while ( $r = mysql_fetch_object ( $q ))
{
if ( $first )
{
$firstjudge = $r -> judges_id ;
$first = false ;
}
if ( $r -> captain == " yes " )
{
$gotcaptain = true ;
break ;
}
}
if ( ! $gotcaptain )
{
//make the first judge the captain
2005-05-06 16:34:13 +00:00
mysql_query ( " UPDATE judges_teams_link SET captain='yes' WHERE judges_teams_id=' " . $_GET [ 'team_id' ] . " ' AND judges_id=' $firstjudge ' AND year=' " . $config [ 'FAIRYEAR' ] . " ' " );
2005-05-06 16:13:37 +00:00
echo notice ( i18n ( " Team captain was removed. A new team captain has been automatically assigned " ));
}
}
}
2005-05-06 16:34:13 +00:00
if ( $_GET [ 'action' ] == " empty " && $_GET [ 'team_num' ] && $_GET [ 'team_id' ])
{
mysql_query ( " DELETE FROM judges_teams_link WHERE judges_teams_id=' " . $_GET [ 'team_id' ] . " ' AND year=' " . $config [ 'FAIRYEAR' ] . " ' " );
echo happy ( i18n ( " Emptied all judges from team #%1 (%2) " , array ( $_GET [ 'team_num' ], $_GET [ 'team_name' ])));
}
2005-05-06 16:13:37 +00:00
if ( $_POST [ 'action' ] == " saveteamnames " )
{
if ( count ( $_POST [ 'team_names' ]))
{
foreach ( $_POST [ 'team_names' ] AS $team_id => $team_name )
{
mysql_query ( " UPDATE judges_teams SET name=' " . mysql_escape_string ( stripslashes ( $team_name )) . " ' WHERE id=' $team_id ' " );
}
echo happy ( i18n ( " Team names successfully saved " ));
}
}
if ( $_GET [ 'action' ] == " addcaptain " )
{
//teams can have as many captains as they want, so just add it.
mysql_query ( " UPDATE judges_teams_link SET captain='yes' WHERE judges_teams_id=' " . $_GET [ 'team_id' ] . " ' AND judges_id=' " . $_GET [ 'judge_id' ] . " ' " );
echo happy ( i18n ( " Team captain assigned " ));
}
if ( $_GET [ 'action' ] == " removecaptain " )
{
//teams must always have at least one captain, so if we only have one, and we are trying to remove it, dont let them!
$q = mysql_query ( " SELECT * FROM judges_teams_link WHERE captain='yes' AND judges_teams_id=' " . $_GET [ 'team_id' ] . " ' " );
if ( mysql_num_rows ( $q ) < 2 )
{
echo error ( i18n ( " A judge team must always have at least one captain " ));
}
else
{
mysql_query ( " UPDATE judges_teams_link SET captain='no' WHERE judges_teams_id=' " . $_GET [ 'team_id' ] . " ' AND judges_id=' " . $_GET [ 'judge_id' ] . " ' " );
echo happy ( i18n ( " Team captain removed " ));
}
}
if ( ! $_SESSION [ 'viewstate' ][ 'judges_teams_list_show' ])
$_SESSION [ 'viewstate' ][ 'judges_teams_list_show' ] = 'unassigned' ;
//now update the judges_teams_list_show viewstate
if ( $_GET [ 'judges_teams_list_show' ])
$_SESSION [ 'viewstate' ][ 'judges_teams_list_show' ] = $_GET [ 'judges_teams_list_show' ];
echo " <form name= \" judges \" method= \" post \" action= \" judges_teams_members.php \" > " ;
echo " <input type= \" hidden \" name= \" action \" > " ;
echo " <input type= \" hidden \" name= \" team_id \" > " ;
echo " <input type= \" hidden \" name= \" team_num \" > " ;
echo " <input type= \" hidden \" name= \" team_name \" > " ;
echo " <input type= \" hidden \" name= \" judges_id \" > " ;
echo " <table> " ;
echo " <tr> " ;
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> " ;
echo " </tr> " ;
echo " <tr><td valign= \" top \" > " ;
echo " <table width= \" 100% \" ><tr> " ;
if ( $_SESSION [ 'viewstate' ][ 'judges_teams_list_show' ] == 'all' )
{
echo " <td align=left><a href= \" judges_teams_members.php?judges_teams_list_show=unassigned \" > " . i18n ( " show unassigned " ) . " </a></td> " ;
echo " <td align=right><b> " . i18n ( " show all " ) . " </b></td> " ;
}
else
{
echo " <td align=left><b> " . i18n ( " show unassigned " ) . " </b></td> " ;
echo " <td align=right><a href= \" judges_teams_members.php?judges_teams_list_show=all \" > " . i18n ( " show all " ) . " </a></td> " ;
}
echo " </tr></table> " ;
/*
//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 " ;
*/
2008-03-27 07:46:52 +00:00
$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 . complete = 'yes'
ORDER BY
lastname ,
firstname " ;
$q = mysql_query ( $querystr );
$judgelist = array ();
while ( $r = mysql_fetch_object ( $q )) {
$judgelist [ $r -> id ] = $r ;
}
if ( $_SESSION [ 'viewstate' ][ 'judges_teams_list_show' ] == 'unassigned' )
2005-05-06 16:13:37 +00:00
{
$querystr = " SELECT
judges . id ,
judges . firstname ,
judges . lastname
FROM
judges ,
2008-03-27 07:46:52 +00:00
judges_teams_link ,
2005-05-06 16:13:37 +00:00
judges_years
WHERE
2008-03-27 07:46:52 +00:00
judges_years . year = '".$config[' FAIRYEAR ']."'
AND judges_teams_link . year = '".$config[' FAIRYEAR ']."'
AND judges . id = judges_years . judges_id
AND judges . id = judges_teams_link . judges_id
AND judges . complete = 'yes'
2005-05-06 16:13:37 +00:00
ORDER BY
lastname ,
firstname " ;
2008-03-27 07:46:52 +00:00
$q = mysql_query ( $querystr );
while ( $r = mysql_fetch_object ( $q )) {
//remove anyone we find here from the list of all judges
unset ( $judgelist [ $r -> id ]);
}
2005-05-06 16:13:37 +00:00
}
2008-03-27 07:46:52 +00:00
echo " <center> " ;
echo i18n ( " Listing %1 judges " , array ( count ( $judgelist )));
echo " <br /> " ;
echo " </center> " ;
2005-05-06 16:13:37 +00:00
echo mysql_error ();
echo " <select name= \" judgelist[] \" onchange= \" switchjudgeinfo() \" multiple= \" multiple \" style= \" width: 250px; height: 600px; \" > " ;
2008-03-27 07:46:52 +00:00
foreach ( $judgelist AS $r ) {
2005-05-06 16:13:37 +00:00
if ( $r -> firstname && $r -> lastname )
echo " <option value= \" $r->id\ " > $r -> firstname $r -> lastname </ option > \n " ;
}
echo " </select> " ;
echo " </td> " ;
echo " <td valign= \" top \" > " ;
$teams = getJudgingTeams ();
foreach ( $teams AS $team )
{
echo " <hr> " ;
2006-01-03 01:50:23 +00:00
echo " <table width= \" 100% \" > " ;
echo " <tr><td valign=top width= \" 80 \" > " ;
2005-05-06 16:13:37 +00:00
echo " <input onclick= \" addbuttonclicked(' " . $team [ 'num' ] . " ') \" type= \" button \" value= \" Add >> \" > " ;
echo " </td><td> " ;
2006-01-03 01:50:23 +00:00
echo " <table width= \" 100% \" > \n " ;
2005-05-06 16:13:37 +00:00
echo " <tr><th colspan= \" 2 \" align= \" left \" ># " . $team [ 'num' ] . " : " ;
echo $team [ 'name' ];
echo " </th></tr> \n " ;
2005-05-06 16:34:13 +00:00
if ( count ( $team [ 'members' ]))
2005-05-06 16:13:37 +00:00
{
2005-05-06 16:34:13 +00:00
foreach ( $team [ 'members' ] AS $member )
2005-05-06 16:13:37 +00:00
{
2005-05-06 16:34:13 +00:00
echo " <tr><td> " ;
2006-03-30 17:46:37 +00:00
echo " <a onclick= \" return confirmClick('Are you sure you want to remove this judge from this team?') \" href= \" judges_teams_members.php?action=del&team_id= " . $team [ 'id' ] . " &team_num= " . $team [ 'num' ] . " &judges_id= " . $member [ 'id' ] . " &team_name= " . rawurlencode ( $team [ 'name' ]) . " \" ><img border=0 src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. " . $config [ 'icon_extension' ] . " \" ></a> " ;
2005-05-06 16:34:13 +00:00
echo " </td><td width= \" 100% \" > " ;
if ( $member [ 'captain' ] == " yes " )
{
echo " <a title= \" Captain - Click to remove captain status \" href= \" judges_teams_members.php?action=removecaptain&team_id= " . $team [ 'id' ] . " &judge_id= " . $member [ 'id' ] . " \" > " ;
echo " <img border=0 src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/16/bookmark. " . $config [ 'icon_extension' ] . " \" > " ;
echo " </a> " ;
2005-05-06 16:13:37 +00:00
2005-05-06 16:34:13 +00:00
}
else
{
echo " <a title= \" Non-Captain - Click to make a team captain \" href= \" judges_teams_members.php?action=addcaptain&team_id= " . $team [ 'id' ] . " &judge_id= " . $member [ 'id' ] . " \" > " ;
echo " <img border=0 src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/16/bookmark_disabled. " . $config [ 'icon_extension' ] . " \" > " ;
echo " </a> " ;
2005-05-06 16:13:37 +00:00
2005-05-06 16:34:13 +00:00
}
echo " <a href= \" \" onclick= \" return openjudgeinfo( " . $member [ 'id' ] . " ); \" > " ;
echo $member [ 'firstname' ] . " " . $member [ 'lastname' ];
2008-04-03 20:34:42 +00:00
echo " </a> ( " . $member [ 'languages' ] . " ) " ;
2005-05-06 16:34:13 +00:00
echo " </td></tr> " ;
2005-05-06 16:13:37 +00:00
}
2005-05-06 16:34:13 +00:00
echo " <tr><td colspan= \" 2 \" > " ;
2006-03-30 17:46:37 +00:00
echo " <a onclick= \" return confirmClick('Are you sure you want to empty all judges from this team?') \" href= \" judges_teams_members.php?action=empty&team_id= " . $team [ 'id' ] . " &team_num= " . $team [ 'num' ] . " &team_name= " . rawurlencode ( $team [ 'name' ]) . " \" > " ;
2005-05-06 16:34:13 +00:00
echo " " . i18n ( " Empty All Members " ) . " " ;
echo " <img border=0 src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. " . $config [ 'icon_extension' ] . " \" > " ;
2005-05-06 16:13:37 +00:00
echo " </a> " ;
echo " </td></tr> " ;
}
2005-05-06 16:34:13 +00:00
else
{
echo " <tr><td colspan= \" 2 \" > " ;
echo error ( i18n ( " Team has no members " ), " inline " );
echo " </td></tr> " ;
}
2005-05-06 16:13:37 +00:00
echo " </table> " ;
echo " </td></tr></table> " ;
}
echo " <br /> " ;
echo " </td></tr> " ;
echo " </table> " ;
echo " </form> " ;
send_footer ();
?>