<?
/* 
   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');
 include "judges.inc.php";

 send_header("Administration - Judges");
?>
<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>

<?
	echo "<a href=\"index.php\">&lt;&lt; ".i18n("Back to Administration")."</a>\n";
	echo "<a href=\"judges.php\">&lt;&lt; ".i18n("Back to Judges")."</a>\n";

	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.complete,
				judges_years.year
				
			FROM 
				judges
				LEFT JOIN judges_years ON judges.id=judges_years.judges_id
			WHERE 
				(judges_years.year='".$config['FAIRYEAR']."'
				OR
				judges_years.year IS NULL) 
			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("Active")."</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>";
		if($r->year)
		{
			echo "<td class=\"happy\" align=\"center\">".i18n("yes")."</td>";
			$active++;
		}
		else
		{
			echo "<td class=\"error\" align=\"center\">".i18n("no")."</td>";
			$inactive++;
		}

		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 remove 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 "<br />";
	echo i18n("There are %1 total judges, %2 of which are active for this year, %3 are inactive.",array($num,$active,$inactive),array("the number of judges","number of active judges","number of inactive 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();
?>