Add judges team timeslots assignments (finished)

Add judges team projects assignments (in progress)
This commit is contained in:
james 2005-04-19 18:36:03 +00:00
parent 229f2670f1
commit 57ec92392a
3 changed files with 588 additions and 0 deletions

View File

@ -1,6 +1,8 @@
<?
function getJudgingTeams()
{
global $config;
$q=mysql_query("SELECT judges_teams.id,
judges_teams.num,
judges_teams.name,
@ -48,4 +50,57 @@ function getJudgingTeams()
return $teams;
}
function getJudgingTeam($teamid)
{
global $config;
$q=mysql_query("SELECT judges_teams.id,
judges_teams.num,
judges_teams.name,
judges.id AS judges_id,
judges.firstname,
judges.lastname,
judges_teams_link.captain
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 AND
judges_teams.id='$teamid'
ORDER BY
name,
num,
captain DESC,
lastname,
firstname");
$team=array();
$first=true;
while($r=mysql_fetch_object($q))
{
//this only gets done the first time
if($first)
{
$team['id']=$r->id;
$team['num']=$r->num;
$team['name']=$r->name;
$first=false;
}
$team['members'][]=array(
"id"=>$r->judges_id,
"firstname"=>$r->firstname,
"lastname"=>$r->lastname,
"captain"=>$r->captain
);
}
return $team;
}
?>

View File

@ -0,0 +1,308 @@
<?
/*
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');
require("judges.inc.php");
send_header("Judging Teams Projects");
?>
<script language="javascript" type="text/javascript">
function checkall(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
if(document.forms.teamstimeslots.elements[i].name==what+"[]")
document.forms.teamstimeslots.elements[i].checked=true;
}
return false;
}
function checknone(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
if(document.forms.teamstimeslots.elements[i].name==what+"[]")
document.forms.teamstimeslots.elements[i].checked=false;
}
return false;
}
function checkinvert(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
if(document.forms.teamstimeslots.elements[i].name==what+"[]")
document.forms.teamstimeslots.elements[i].checked=!document.forms.teamstimeslots.elements[i].checked;
}
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";
echo "<br />";
echo "<br />";
if($_GET['action']=="delete" && $_GET['delete'])
{
mysql_query("DELETE FROM judges_teams_timeslots_link WHERE id='".$_GET['delete']."'");
echo happy(i18n("Judging team timeslot successfully removed"));
}
if($_GET['action']=="empty" && $_GET['empty'])
{
mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='".$_GET['empty']."'");
echo happy(i18n("Judging team timeslots successfully removed"));
}
if($_POST['action']=="assign")
{
//the db handles the uniqueness (to ensure the same timeslot isnt assigned to the same team more than once)
//so all we'll do here is just mass insert without regards for whats already there.
foreach($_POST['teams'] AS $tm)
{
foreach($_POST['timeslots'] AS $ts)
{
mysql_query("INSERT INTO judges_teams_timeslots_link (judges_teams_id,judges_timeslots_id,year) VALUES ('$tm','$ts','".$config['FAIRYEAR']."')");
}
}
echo happy(i18n("%1 Timeslots assigned to %2 teams",array(count($_POST['timeslots']),count($_POST['teams']))));
}
if($_GET['action']=="edit" && $_GET['edit'])
{
echo "<form name=\"teamstimeslots\" method=\"post\" action=\"judges_teams_timeslots.php\">";
$team=getJudgingTeam($_GET['edit']);
echo "<b>".$team['name']." (#".$team['num'].")</b><br />";
$memberlist="&nbsp;&nbsp;";
foreach($team['members'] AS $member)
{
if($member['captain']=="yes")
$memberlist.="<i>";
$memberlist.=$member['firstname']." ".$member['lastname'];
if($member['captain']=="yes")
$memberlist.="</i>";
$memberlist.=", ";
}
$memberlist=substr($memberlist,0,-2);
echo $memberlist;
echo "<br />";
$q=mysql_query("SELECT
projects.id,
projects.projectnumber,
projects.title,
registrations.status
FROM
projects,
registrations
WHERE
projectnumber is not null AND
registrations.status='complete' AND
projects.registrations_id=registrations.id AND
projects.year='".$config['FAIRYEAR']."'
ORDER BY
projectnumber
");
echo mysql_error();
$numprojects=mysql_num_rows($q);
echo "<br />";
echo "<select name=\"project_id\">";
echo "<option value=\"\">Choose Project to Assign to Timeslot</option>\n";
while($r=mysql_fetch_object($q))
{
echo "<option value=\"$r->id\">$r->projectnumber - $r->title</option>\n";
}
echo "</select>";
echo "$numprojects projects listed";
//get the timeslots that this team has.
$q=mysql_query("SELECT
judges_timeslots.id,
judges_timeslots.date,
judges_timeslots.starttime,
judges_timeslots.endtime
FROM
judges_timeslots,
judges_teams,
judges_teams_timeslots_link
WHERE
judges_teams.id='".$team['id']."' AND
judges_teams.id=judges_teams_timeslots_link.judges_teams_id AND
judges_timeslots.id=judges_teams_timeslots_link.judges_timeslots_id
ORDER BY
date,starttime
");
$numslots=mysql_num_rows($q);
echo "<br />";
echo "<br />";
echo "<table class=\"summarytable\">";
echo "<tr>";
echo "<th>Timeslot</th>";
echo "<th>Project</th>";
echo "</tr>";
while($r=mysql_fetch_object($q))
{
echo "<tr><td>";
if($show_date)
echo "$r->date ";
echo substr($r->starttime,0,-3);
echo " - ";
echo substr($r->endtime,0,-3);
echo "</td><td>";
$projq=mysql_query("SELECT
projects.projectnumber,
projects.id,
projects.title
FROM
projects,
judges_teams_timeslots_projects_link
WHERE
judges_teams_timeslots_projects_link.judges_timeslots_id='$r->id' AND
judges_teams_timeslots_projects_link.judges_teams_id='".$team['id']."' AND
judges_teams_timeslots_projects_link.projects_id=projects.id AND
judges_teams_timeslots_projects_link.year='".$config['FAIRYEAR']."'
ORDER BY
projectnumber
");
echo mysql_Error();
while($proj=mysql_fetch_object($projq))
{
echo "$proj->projectnumber - $proj->title <br />";
}
echo "</td></tr>";
}
echo "</table>";
echo "</form>";
}
else
{
echo "<input type=\"hidden\" name=\"action\" value=\"assign\">";
echo "<table class=\"summarytable\">";
echo "<tr>";
echo "<th>".i18n("Team")."</th>";
echo "<th>".i18n("Timeslots and Projects")."</th>";
echo "</tr>";
$teams=getJudgingTeams();
foreach($teams AS $team)
{
echo "<tr>";
echo "<td>";
echo "<b>".$team['name']." (#".$team['num'].")</b><br />";
$memberlist="";
foreach($team['members'] AS $member)
{
echo "&nbsp;&nbsp;";
if($member['captain']=="yes")
echo "<i>";
echo $member['firstname']." ".$member['lastname']."<br />";
if($member['captain']=="yes")
echo "</i>";
}
echo "</td>";
echo "<td>";
//get the timeslots that this team has.
$q=mysql_query("SELECT
judges_teams_timeslots_link.id,
judges_timeslots.date,
judges_timeslots.starttime,
judges_timeslots.endtime
FROM
judges_timeslots,
judges_teams,
judges_teams_timeslots_link
WHERE
judges_teams.id='".$team['id']."' AND
judges_teams.id=judges_teams_timeslots_link.judges_teams_id AND
judges_timeslots.id=judges_teams_timeslots_link.judges_timeslots_id
ORDER BY
date,starttime
");
$numslots=mysql_num_rows($q);
echo "<a href=\"judges_teams_projects.php?action=edit&edit=".$team['id']."\">Edit team project assignments</a>";
echo "<table class=summarytable style=\"margin-left: 0px\">";
while($r=mysql_fetch_object($q))
{
echo "<tr><td>";
if($show_date)
echo "$r->date ";
echo substr($r->starttime,0,-3);
echo " - ";
echo substr($r->endtime,0,-3);
echo "</td><td>";
//FIXME: list the projects :)
echo "</td></tr>";
}
echo "</table>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
send_footer();
?>

View File

@ -0,0 +1,225 @@
<?
/*
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');
require("judges.inc.php");
send_header("Judging Teams Timeslots");
?>
<script language="javascript" type="text/javascript">
function checkall(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
if(document.forms.teamstimeslots.elements[i].name==what+"[]")
document.forms.teamstimeslots.elements[i].checked=true;
}
return false;
}
function checknone(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
if(document.forms.teamstimeslots.elements[i].name==what+"[]")
document.forms.teamstimeslots.elements[i].checked=false;
}
return false;
}
function checkinvert(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
if(document.forms.teamstimeslots.elements[i].name==what+"[]")
document.forms.teamstimeslots.elements[i].checked=!document.forms.teamstimeslots.elements[i].checked;
}
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";
echo "<br />";
echo "<br />";
if($_GET['action']=="delete" && $_GET['delete'])
{
mysql_query("DELETE FROM judges_teams_timeslots_link WHERE id='".$_GET['delete']."'");
echo happy(i18n("Judging team timeslot successfully removed"));
}
if($_GET['action']=="empty" && $_GET['empty'])
{
mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='".$_GET['empty']."'");
echo happy(i18n("Judging team timeslots successfully removed"));
}
if($_POST['action']=="assign")
{
//the db handles the uniqueness (to ensure the same timeslot isnt assigned to the same team more than once)
//so all we'll do here is just mass insert without regards for whats already there.
foreach($_POST['teams'] AS $tm)
{
foreach($_POST['timeslots'] AS $ts)
{
mysql_query("INSERT INTO judges_teams_timeslots_link (judges_teams_id,judges_timeslots_id,year) VALUES ('$tm','$ts','".$config['FAIRYEAR']."')");
}
}
echo happy(i18n("%1 Timeslots assigned to %2 teams",array(count($_POST['timeslots']),count($_POST['teams']))));
}
echo "<form name=\"teamstimeslots\" method=\"post\" action=\"judges_teams_timeslots.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"assign\">";
echo "Choose timeslots to assign: <br />";
echo "<a href=\"\" onclick=\"return checkall('timeslots')\">select all</a>";
echo "&nbsp;|&nbsp";
echo "<a href=\"\" onclick=\"return checknone('timeslots')\">select none</a>";
echo "&nbsp;|&nbsp";
echo "<a href=\"\" onclick=\"return checkinvert('timeslots')\">invert selection</a>";
$q=mysql_query("SELECT DISTINCT(date) AS d FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q)>1)
$show_date=true;
else
$show_date=false;
echo "<table class=\"summarytable\">";
echo "<tr>";
echo "<th>&nbsp;</th>";
if($show_date) echo "<th>".i18n("Date")."</th>";
echo "<th>".i18n("Start Time")."</th>";
echo "<th>".i18n("End Time")."</th>";
echo "</tr>\n";
$q=mysql_query("SELECT * FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' ORDER BY date,starttime");
while($r=mysql_fetch_object($q))
{
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"timeslots[]\" value=\"$r->id\" /></td>";
if($show_date) echo "<td>$r->date</td>";
echo "<td align=\"center\">".substr($r->starttime,0,-3)."</td>";
echo "<td align=\"center\">".substr($r->endtime,0,-3)."</td>";
echo "</tr>\n";
}
echo "</table>";
echo "<br />";
echo "<br />";
echo "Choose teams to assign the above selected timeslots to:";
echo "<br />";
echo "<a href=\"\" onclick=\"return checkall('teams')\">select all</a>";
echo "&nbsp;|&nbsp";
echo "<a href=\"\" onclick=\"return checknone('teams')\">select none</a>";
echo "&nbsp;|&nbsp";
echo "<a href=\"\" onclick=\"return checkinvert('teams')\">invert selection</a>";
echo "<table class=\"summarytable\">";
echo "<tr>";
echo "<th>&nbsp;</th>";
echo "<th>".i18n("Team")."</th>";
echo "<th>".i18n("Timeslots")."</th>";
echo "</tr>";
$teams=getJudgingTeams();
foreach($teams AS $team)
{
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"teams[]\" value=\"".$team['id']."\" /></td>";
echo "<td>";
echo "<b>".$team['name']." (#".$team['num'].")</b><br />";
$memberlist="";
foreach($team['members'] AS $member)
{
echo "&nbsp;&nbsp;";
if($member['captain']=="yes")
echo "<i>";
echo $member['firstname']." ".$member['lastname']."<br />";
if($member['captain']=="yes")
echo "</i>";
}
echo "</td>";
echo "<td>";
//get the timeslots that this team has.
$q=mysql_query("SELECT
judges_teams_timeslots_link.id,
judges_timeslots.date,
judges_timeslots.starttime,
judges_timeslots.endtime
FROM
judges_timeslots,
judges_teams,
judges_teams_timeslots_link
WHERE
judges_teams.id='".$team['id']."' AND
judges_teams.id=judges_teams_timeslots_link.judges_teams_id AND
judges_timeslots.id=judges_teams_timeslots_link.judges_timeslots_id
ORDER BY
date,starttime
");
$numslots=mysql_num_rows($q);
while($r=mysql_fetch_object($q))
{
if($show_date)
echo "$r->date ";
echo substr($r->starttime,0,-3);
echo " - ";
echo substr($r->endtime,0,-3);
echo "&nbsp;&nbsp;<a onclick=\"return confirmClick('Are you sure you want to remove this timeslot from the team?')\" href=\"judges_teams_timeslots.php?action=delete&delete=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
echo "<br />";
}
if($numslots)
echo "&nbsp; <a onclick=\"return confirmClick('Are you sure you want to remove all timeslots from the team?')\" href=\"judges_teams_timeslots.php?action=empty&empty=".$team['id']."\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"> remove all</a>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<br />";
echo "<br />";
echo "<input type=\"submit\" value=\"".i18n("Assign selected timeslots to selected teams")."\">";
echo "</form>";
send_footer();
?>