- Fixup the timeslot assignment editor to deal (primitively) with rounds

This commit is contained in:
dave 2009-02-06 07:05:29 +00:00
parent c8705bc70d
commit cac041186a

View File

@ -22,22 +22,64 @@
*/
?>
<?
require("../common.inc.php");
require_once("../user.inc.php");
require_once('../common.inc.php');
require_once('../user.inc.php');
user_auth_required('committee', 'admin');
require("judges.inc.php");
require_once('judges.inc.php');
send_header("Judging Teams Timeslots",
$round_str = array('timeslot' => 'Judging Timeslot',
'divisional1' => 'Divisional Round 1',
'divisional2' => 'Divisional Round 2',
'grand' => 'Grand Awards',
'special' => 'Special Awards' );
if(array_key_exists('action',$_GET))
$action = $_GET['action'];
if(array_key_exists('action',$_POST))
$action = $_POST['action'];
if($action == 'delete' && array_key_exists('delete', $_GET)) {
$id = intval($_GET['delete']);
mysql_query("DELETE FROM judges_teams_timeslots_link WHERE id='$id'");
message_push(happy(i18n("Judging team timeslot successfully removed")));
}
if($action == 'empty' && array_key_exists('empty',$_GET)) {
$id = intval($_GET['empty']);
mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='$id'");
message_push(happy(i18n("Judging team timeslots successfully removed")));
}
if($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.
if(count($_POST['teams']) && count($_POST['timeslots'])) {
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']}')");
}
}
message_push(happy(i18n("%1 Timeslots assigned to %2 teams",array(count($_POST['timeslots']),count($_POST['teams'])))));
} else {
message_push(error(i18n("You must select both team(s) and timeslot(s) to assign")));
}
}
send_header("Judging Teams Timeslots",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Judges' => 'admin/judges.php')
);
?>
<script language="javascript" type="text/javascript">
function checkall(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
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;
@ -48,8 +90,7 @@ function checkall(what)
}
function checknone(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
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;
@ -60,8 +101,7 @@ function checknone(what)
function checkinvert(what)
{
for(i=0;i<document.forms.teamstimeslots.elements.length;i++)
{
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;
@ -71,44 +111,10 @@ function checkinvert(what)
}
</script>
<?
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.
if(count($_POST['teams']) && count($_POST['timeslots']))
{
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']))));
}
else
echo error(i18n("You must select both team(s) and timeslot(s) to assign"));
}
echo "<form name=\"teamstimeslots\" method=\"post\" action=\"judges_teams_timeslots.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"assign\">";
@ -134,15 +140,23 @@ function checkinvert(what)
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))
{
$q=mysql_query("SELECT * FROM judges_timeslots
WHERE year='{$config['FAIRYEAR']}'
AND round_id='0' 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";
$span = $show_date ? 4 : 3;
echo "<td colspan=\"$span\">{$r->name} (".$round_str[$r->type].")</td>";
$qq = mysql_query("SELECT * FROM judges_timeslots
WHERE round_id='{$r->id}' ORDER BY date,starttime");
while($rr = mysql_fetch_object($qq)) {
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"timeslots[]\" value=\"{$rr->id}\" /></td>";
if($show_date) echo "<td>{$r->date}</td>";
echo "<td align=\"center\">".substr($rr->starttime,0,-3)."</td>";
echo "<td align=\"center\">".substr($rr->endtime,0,-3)."</td>";
echo "</tr>\n";
}
}
echo "</table>";