<?
/* 
   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");
 require_once("../user.inc.php");
 user_auth_required('committee', 'admin');
 include "judges.inc.php";

 send_header("Judge List",
 		array('Committee Main' => 'committee_main.php',
			'Administration' => 'admin/index.php',
			'Judges' => 'admin/judges.php')
				);
?>
<script language="javascript" type="text/javascript">

function openjudgeinfo(id)
{
	if(id)
		currentid=id;
	else
		currentid=document.forms.judges["judgelist[]"].options[document.forms.judges["judgelist[]"].selectedIndex].value;

	window.open("judges_info.php?id="+currentid,"JudgeInfo","location=no,menubar=no,directories=no,toolbar=no,width=770,height=500,scrollbars=yes"); 
	return false;

}
</script>

<?

	if($_GET['action']=="remove" && $_GET['remove'])
	{
		//we need to remove them from:
		// judges_teams
		// judges_years
		mysql_query("DELETE FROM judges_teams_link WHERE judges_id='".$_GET['remove']."' AND year=".$config['FAIRYEAR']."'");
		mysql_query("DELETE FROM judges_years WHERE judges_id='".$_GET['remove']."' AND year='".$config['FAIRYEAR']."'");
		echo happy(i18n("Successfully removed judge from this year's fair"));
	}

	echo "<h3>".i18n("Active Judges list for %1",array($config['FAIRYEAR']))."</h3>";
	echo "<table class=\"viewtable\">";
		$querystr="SELECT 
				judges.id, 
				judges.firstname, 
				judges.lastname,
				judges.email,
				judges.complete,
				judges_years.year
			FROM 
				judges
				JOIN judges_years ON judges.id=judges_years.judges_id
			WHERE 
				judges_years.year='".$config['FAIRYEAR']."'
				AND judges.deleted='no'
			ORDER BY 
				lastname,
				firstname";
	$q=mysql_query($querystr);
	$num=mysql_num_rows($q);
	echo i18n("Listing %1 judges total.  See the bottom for breakdown of judges by complete status",array($num),array("the number of judges"));

	echo mysql_error();
	echo "<tr>";
	echo " <th>".i18n("Judge Name")."</th>";
	echo " <th>".i18n("Email Address")."</th>";
	echo " <th>".i18n("Complete")."</th>";
	echo " <th>".i18n("Actions")."</th>";
	echo "</tr>";
	$completeyes=0;
	$completeno=0;
	while($r=mysql_fetch_object($q))
	{
		echo "<tr><td>";
		echo "<a href=\"\" onclick=\"return openjudgeinfo($r->id)\">$r->firstname $r->lastname</a>";
		echo "</td>";
		echo "<td>$r->email</td>";

		if($r->complete=="yes" && $r->year)
		{
			echo "<td class=\"happy\" align=\"center\">".i18n("yes")."</td>";
			$completeyes++;
		}
		else 
		{
			echo "<td class=\"error\" align=\"center\">".i18n("no")."</td>";
			$cl="error";
			$completeno++;
		}
		echo "<td align=\"center\">";
		echo "<a onclick=\"return confirmClick('Are you sure you want to deactivate this judge from this years fair?')\" href=\"judges_judges.php?action=remove&remove=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
		echo "</td>";
		echo "</tr>";
	}

	echo "</table>";
	echo i18n("Note: Deleting judges from this list only deactivates the judge for this year's fair.  To completely delete a judge, use the 'Manage Judges' page");
	echo "<br />";
	echo "<br />";
	echo i18n("There are %1 total active judges.",array($num),array("the number of judges"));
	echo "<br />";
	echo i18n("There are %1 complete judges.",array($completeyes),array("the number of judges"));
	echo "<br />";
	echo i18n("There are %1 incomplete judges.",array($completeno),array("the number of judges"));
	echo "<br />";
	echo "<br />";
	echo "<br />";

	send_footer();
?>