2005-04-15 20:33:13 +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' );
send_header ( " Judging Timeslots " ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ,
'Judges' => 'admin/judges.php' )
);
2005-04-15 20:33:13 +00:00
echo " <br /> " ;
if ( $_POST [ 'action' ] == " add " || $_POST [ 'action' ] == " edit " )
{
$err = 0 ;
if ( $_POST [ 'date_year' ] && $_POST [ 'date_month' ] && $_POST [ 'date_day' ])
{
$date = $_POST [ 'date_year' ] . " - " . $_POST [ 'date_month' ] . " - " . $_POST [ 'date_day' ];
}
else
{
$err = 1 ;
echo error ( i18n ( " Date is required " ));
}
if ( $_POST [ 'starttime_hour' ] && $_POST [ 'starttime_minute' ])
{
$starttime = $_POST [ 'starttime_hour' ] . " : " . $_POST [ 'starttime_minute' ] . " :00 " ;
}
else
{
$err = 1 ;
echo error ( i18n ( " Start Time is required " ));
}
if ( $_POST [ 'endtime_hour' ] && $_POST [ 'endtime_minute' ])
{
$endtime = $_POST [ 'endtime_hour' ] . " : " . $_POST [ 'endtime_minute' ] . " :00 " ;
}
else
{
$err = 1 ;
echo error ( i18n ( " End Time is required " ));
}
2006-01-26 21:42:04 +00:00
$allowdivisional = $_POST [ 'allowdivisional' ];
if ( ! $allowdivisional ) $allowdivisional = " no " ;
2005-04-15 20:33:13 +00:00
if ( ! $err )
{
if ( $_POST [ 'action' ] == " add " )
{
mysql_query ( " INSERT INTO judges_timeslots (date,starttime,endtime,year) VALUES (' $date ',' $starttime ',' $endtime ',' " . $config [ 'FAIRYEAR' ] . " ') " );
echo happy ( i18n ( " New timeslot successfully added " ));
}
if ( $_POST [ 'action' ] == " edit " )
{
2006-01-26 21:42:04 +00:00
mysql_query ( " UPDATE judges_timeslots SET `date`=' $date ', starttime=' $starttime ', endtime=' $endtime ', allowdivisional=' $allowdivisional ' WHERE id=' " . $_POST [ 'edit' ] . " ' " );
2005-04-15 20:33:13 +00:00
echo mysql_error ();
echo happy ( i18n ( " Timeslot successfully saved " ));
}
}
}
2006-01-26 21:42:04 +00:00
else if ( $_POST [ 'action' ] == " addmultiple " )
{
if ( $_POST [ 'addnum' ] && $_POST [ 'date_day' ] && $_POST [ 'date_month' ] && $_POST [ 'date_year' ] && $_POST [ 'starttime_hour' ] && $_POST [ 'starttime_minute' ] && $_POST [ 'duration' ] && $_POST [ 'break' ])
{
$date = $_POST [ 'date_year' ] . " - " . $_POST [ 'date_month' ] . " - " . $_POST [ 'date_day' ];
$hr = $_POST [ 'starttime_hour' ];
$min = $_POST [ 'starttime_minute' ];
$dur = $_POST [ 'duration' ];
$brk = $_POST [ 'break' ];
$tt = $dur + $brk ;
if ( $_POST [ 'allowdivisional' ] == " yes " ) $ad = " yes " ; else $ad = " no " ;
for ( $x = 0 ; $x < $_POST [ 'addnum' ]; $x ++ )
{
$q = mysql_query ( " SELECT DATE_ADD(' $date $hr : $min :00', INTERVAL $dur MINUTE) AS endtime,
DATE_ADD ( '$date $hr:$min:00' , INTERVAL $tt MINUTE ) AS startnext
" );
echo mysql_error ();
$r = mysql_fetch_object ( $q );
list ( $ed , $et ) = split ( " " , $r -> endtime );
list ( $nd , $nt ) = split ( " " , $r -> startnext );
mysql_query ( " INSERT INTO judges_timeslots (date,starttime,endtime,allowdivisional,year) VALUES (
'$date' ,
'$hr:$min:00' ,
'$et' ,
'$ad' ,
'".$config[' FAIRYEAR ']."' ) " );
echo mysql_Error ();
$date = $nd ;
list ( $s_h , $s_m , $s_s ) = split ( " : " , $nt );
list ( $e_h , $e_m , $e_s ) = split ( " : " , $et );
echo happy ( i18n ( " Adding timeslot: %1 " , array ( $date . " " . $hr . " : " . $min . " - " . $e_h . " : " . $e_m )));
$hr = $s_h ;
$min = $s_m ;
}
}
else
echo error ( i18n ( " All fields are required to add multiple timeslots " ));
}
2005-04-15 20:33:13 +00:00
//FIXME: only delete if the timeslot is not in use!!!
if ( $_GET [ 'action' ] == " delete " && $_GET [ 'delete' ])
{
mysql_query ( " DELETE FROM judges_timeslots WHERE id=' " . $_GET [ 'delete' ] . " ' " );
echo happy ( i18n ( " Timeslot successfully removed " ));
}
2006-01-26 21:42:04 +00:00
if ( $_GET [ 'action' ] == " addmultiple " )
{
echo " <h3>Add Multiple New Judging Timeslots</h3> " ;
echo " <a href= \" judges_timeslots.php \" ><< " . i18n ( " Back to Judging Timeslots " ) . " </a> \n " ;
$q = mysql_query ( " SELECT * FROM judges_timeslots WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' ORDER BY date DESC LIMIT 1 " );
if ( mysql_num_rows ( $q ))
{
$r = mysql_fetch_object ( $q );
$date = $r -> date ;
}
else
{
$date = $config [ 'dates' ][ 'fairdate' ];
}
echo " <form method= \" post \" action= \" judges_timeslots.php \" > " ;
echo " <input type= \" hidden \" name= \" action \" value= \" addmultiple \" > \n " ;
echo " <table border=0> " ;
echo " <tr><td> " ;
echo i18n ( " Add " );
echo " </td><td width= \" 50 \" > " ;
echo " <input type= \" text \" name= \" addnum \" size= \" 4 \" > " ;
echo " </td><td> " ;
echo i18n ( " new timeslots " );
echo " </td></tr><tr><td> " ;
echo i18n ( " On date " );
echo " </td><td colspan= \" 2 \" > " ;
emit_date_selector ( " date " , $date );
echo " </td></tr><tr><td> " ;
echo i18n ( " Starting timeslots at " );
echo " </td><td colspan= \" 2 \" > " ;
emit_time_selector ( " starttime " );
echo " </td></tr> " ;
echo " <tr><td> " ;
echo i18n ( " With a duration of " );
echo " </td><td> " ;
echo " <input type= \" text \" name= \" duration \" size= \" 4 \" > " ;
echo " </td><td> " ;
echo i18n ( " minutes " );
echo " </td></tr> " ;
echo " <tr><td> " ;
echo i18n ( " And a break of " );
echo " </td><td> " ;
echo " <input type= \" text \" name= \" break \" size= \" 4 \" > " ;
echo " </td><td> " ;
echo i18n ( " minutes " );
echo " </td></tr> " ;
echo " <tr><td align= \" center \" > " ;
if ( $allowdivisional == " yes " ) $ch = " checked= \" checked \" " ; else $ch = " " ;
echo " <input $ch type= \" checkbox \" name= \" allowdivisional \" value= \" yes \" > " ;
echo " </td><td colspan= \" 2 \" > " ;
echo i18n ( " Allow this timeslot to be used by the automatic judges scheduler for divisional awards " );
echo " </td></tr> " ;
echo " <tr><td colspan= \" 3 \" > " ;
echo " <input type= \" submit \" value= \" " . i18n ( " Add these timeslots " ) . " \" > " ;
echo " </td></tr> " ;
echo " </table> " ;
echo " </form> " ;
$showlist = false ;
}
else if ( $_GET [ 'action' ] == " add " || $_GET [ 'action' ] == " edit " )
2005-04-15 20:33:13 +00:00
{
echo " <form method= \" post \" action= \" judges_timeslots.php \" > " ;
echo " <input type= \" hidden \" name= \" action \" value= \" " . $_GET [ 'action' ] . " \" > \n " ;
if ( $_GET [ 'action' ] == " add " )
{
echo " <h3>Add New Judging Timeslot</h3> " ;
$buttontext = i18n ( " Add Timeslot " );
2006-01-26 21:42:04 +00:00
//get a default date, either the date from a different timeslot, or the date of the fair, whichever.
2005-04-15 20:33:13 +00:00
$q = mysql_query ( " SELECT * FROM judges_timeslots WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' ORDER BY date DESC LIMIT 1 " );
if ( mysql_num_rows ( $q ))
{
$r = mysql_fetch_object ( $q );
$date = $r -> date ;
}
else
{
$date = $config [ 'dates' ][ 'fairdate' ];
}
2006-01-26 21:42:04 +00:00
$starttime = " " ;
$endtime = " " ;
$allowdivisional = " yes " ;
2005-04-15 20:33:13 +00:00
}
else if ( $_GET [ 'action' ] == " edit " )
{
echo " <input type= \" hidden \" name= \" edit \" value= \" " . $_GET [ 'edit' ] . " \" > \n " ;
echo " <h3>Edit Judging Timeslot</h3> " ;
$buttontext = i18n ( " Save Timeslot " );
$q = mysql_query ( " SELECT * FROM judges_timeslots WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' AND id=' " . $_GET [ 'edit' ] . " ' " );
$r = mysql_fetch_object ( $q );
$date = $r -> date ;
$starttime = $r -> starttime ;
$endtime = $r -> endtime ;
2006-01-26 21:42:04 +00:00
$allowdivisional = $r -> allowdivisional ;
2005-04-15 20:33:13 +00:00
}
echo " <table> " ;
2006-01-26 21:42:04 +00:00
echo " <tr><td> " . i18n ( " Date " ) . " :</td><td> " ;
2005-04-15 20:33:13 +00:00
emit_date_selector ( " date " , $date );
echo " </td></tr> " ;
2006-01-26 21:42:04 +00:00
echo " <tr><td> " . i18n ( " Start Time " ) . " :</td><td> " ;
2005-04-15 20:33:13 +00:00
emit_time_selector ( " starttime " , $starttime );
echo " </td></tr> " ;
2006-01-26 21:42:04 +00:00
echo " <tr><td> " . i18n ( " End Time " ) . " :</td><td> " ;
2005-04-15 20:33:13 +00:00
emit_time_selector ( " endtime " , $endtime );
echo " </td></tr> " ;
2006-01-26 21:42:04 +00:00
echo " <tr><td align= \" center \" > " ;
if ( $allowdivisional == " yes " ) $ch = " checked= \" checked \" " ; else $ch = " " ;
echo " <input $ch type= \" checkbox \" name= \" allowdivisional \" value= \" yes \" > " ;
echo " </td><td> " ;
echo i18n ( " Allow this timeslot to be used by the automatic judges scheduler for divisional awards " );
echo " </td></tr> " ;
2005-04-15 20:33:13 +00:00
echo " </table> " ;
echo " <input type= \" submit \" value= \" $buttontext\ " /> " ;
echo " </form> " ;
}
else
{
echo " <A href= \" judges_timeslots.php?action=add \" > " . i18n ( " Add new judging timeslot " ) . " </a><br /> " ;
2006-01-26 21:42:04 +00:00
echo " <A href= \" judges_timeslots.php?action=addmultiple \" > " . i18n ( " Add multiple new judging timeslots " ) . " </a><br /> " ;
2005-04-15 20:33:13 +00:00
echo " <table class= \" summarytable \" > " ;
echo " <tr> " ;
echo " <th> " . i18n ( " Date " ) . " </th> " ;
echo " <th> " . i18n ( " Start Time " ) . " </th> " ;
echo " <th> " . i18n ( " End Time " ) . " </th> " ;
2006-01-26 21:42:04 +00:00
echo " <th> " . i18n ( " Div OK? " ) . " </th> " ;
2005-04-15 20:33:13 +00:00
echo " <th> " . i18n ( " Actions " ) . " </th> " ;
echo " </tr> " ;
$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>$r->id</td>";
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> " ;
2006-01-26 21:42:04 +00:00
echo " <td align= \" center \" > $r->allowdivisional </td> " ;
2005-04-15 20:33:13 +00:00
echo " <td align= \" center \" > " ;
echo " <a href= \" judges_timeslots.php?action=edit&edit= $r->id\ " >< img border = \ " 0 \" src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/16/edit. " . $config [ 'icon_extension' ] . " \" ></a> " ;
echo " " ;
echo " <a onclick= \" return confirmClick('Are you sure you want to remove this timeslot?') \" href= \" judges_timeslots.php?action=delete&delete= $r->id\ " >< img border = \ " 0 \" src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. " . $config [ 'icon_extension' ] . " \" ></a> " ;
echo " </td> \n " ;
echo " </tr> " ;
}
echo " </table> " ;
}
send_footer ();
?>