2010-06-10 19:40:50 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
2010-06-16 16:15:17 +00:00
Copyright ( C ) 2010 Youth Science Ontario < info @ scitechontario . org >
Copyright ( C ) 2010 James Grant < james @ lightbox . org >
2010-06-10 19:40:50 +00:00
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 " );
2010-06-16 16:15:17 +00:00
require_once ( " ../schedule.inc.php " );
2010-06-11 15:55:16 +00:00
2010-06-16 16:15:17 +00:00
user_auth_required ( 'committee' , 'admin' );
2010-06-11 15:55:16 +00:00
2010-06-11 19:36:50 +00:00
if ( $_GET [ 'action' ] == " loadschedule " ) {
2010-06-11 15:55:16 +00:00
$date = $_POST [ 'date' ];
$starthour = $_POST [ 'starthour' ];
$endhour = $_POST [ 'endhour' ];
//do some sanity checks
2010-06-14 16:58:33 +00:00
if ( $starthour < 0 || $starthour > 24 ) $starthour = 8 ;
2010-06-11 15:55:16 +00:00
if ( $endhour < $starthour )
$endhour = $starthour + 10 ;
2010-06-14 16:58:33 +00:00
if ( $endhour < 0 || $endhour > 24 ) $endhour = 15 ;
2010-06-11 15:55:16 +00:00
//minute increment
$increment = 15 ;
2010-06-10 20:35:02 +00:00
if ( ! eregi ( " [0-9] { 4}-[0-9] { 2}-[0-9] { 2} " , $date )) {
echo " Invalid date " ;
exit ;
}
echo " <h3> " . i18n ( " Schedule for %1 " , array ( format_date ( $date ))) . " </h3> " ;
2010-06-10 19:40:50 +00:00
$q = mysql_query ( " SELECT * FROM locations WHERE conferences_id=' { $conference [ 'id' ] } ' ORDER BY name " );
while ( $r = mysql_fetch_object ( $q )) {
$locations [ $r -> id ] = $r -> name ;
}
if ( ! count ( $locations )) {
echo error ( i18n ( " There are no locations defined. Please set up your locations first " ));
echo " <a href= \" locations.php \" > " . i18n ( " Location Editor " ) . " </a> \n " ;
exit ;
}
2010-06-11 20:39:29 +00:00
echo " <table class= \" schedule \" id= \" schedule \" > \n " ;
2010-06-10 19:40:50 +00:00
echo " <tr> " ;
echo " <th style= \" width: 50px; \" > </th> " ;
foreach ( $locations AS $id => $name ) {
echo " <th> $name </th> \n " ;
}
for ( $h = $starthour ; $h < $endhour ; $h ++ ) {
for ( $m = 0 ; $m < 60 ; $m += $increment ) {
echo " <tr> " ;
echo " <td class= \" scheduletime \" > " ;
if ( $m == 0 ) {
echo format_time ( " $h : $m " );
}
echo " </td> " ;
foreach ( $locations AS $id => $name ) {
echo " <td id= \" { $h } _ { $m } _ { $id } \" onclick= \" clickTableCell(this) \" > " ;
echo " </td> " ;
}
echo " </tr> " ;
}
}
echo " </table> \n " ;
2010-06-10 20:35:02 +00:00
$js = " var eventdivs=new Array(); \n " ;
//now make all our DIV's for the events that are scheduled in the database
$x = 0 ;
//they will be moved by javascript after the fact
2010-06-14 19:25:49 +00:00
$q = mysql_query ( " SELECT schedule.*, events.name, events.eventtype FROM schedule JOIN events ON schedule.events_id=events.id WHERE schedule.conferences_id=' { $conference [ 'id' ] } ' AND date=' { $date } ' " );
2010-06-11 19:36:50 +00:00
echo mysql_error ();
2010-06-10 20:35:02 +00:00
while ( $r = mysql_fetch_object ( $q )) {
2010-06-14 19:25:49 +00:00
echo " <div class= \" scheduleevent scheduleevent_ { $r -> eventtype } \" id= \" event_ { $r -> id } \" onclick= \" editEvent( $r->id ) \" > " ;
2010-06-11 19:36:50 +00:00
echo " <div style= \" width: 99%; text-align: right; \" ><a href= \" # \" onclick= \" return deleteEvent(event, $r->id ) \" ><img style= \" border: 0px; \" src= \" " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. { $config [ 'icon_extension' ] } \" ></a></div> \n " ;
echo " <span class= \" scheduleevent_title \" > " ;
2010-06-14 20:37:31 +00:00
echo $r -> title ;
2010-06-11 19:36:50 +00:00
echo " </span> " ;
echo " <br /> " ;
$starttime = strtotime ( $r -> hour . " : " . $r -> minute );
$endtime = $starttime + $r -> duration * 60 ;
echo format_time ( $starttime );
echo " to " ;
echo format_time ( $endtime );
2010-06-14 20:37:31 +00:00
if ( $r -> eventtype == " scienceolympic " ) {
echo " <br /> " ;
echo i18n ( " Teams " ) . " : " ;
2010-06-16 16:15:17 +00:00
$regteams = getNumRegistrations ( $r -> id );
2010-06-14 20:37:31 +00:00
$maxteams = $r -> somaxteams ;
echo i18n ( " %1 of %2 " , array ( $regteams , $maxteams ));
}
2010-06-10 20:35:02 +00:00
echo " </div> " ;
2010-06-11 15:55:16 +00:00
$js .= " eventdivs[ $r->id ]= { hour: $r->hour ,minute: $r->minute ,location: $r->locations_id ,duration: $r->duration }; \n " ;
2010-06-10 20:35:02 +00:00
$x ++ ;
}
echo " <script type= \" text/javascript \" > \n " ;
echo $js ;
echo " </script> " ;
2010-06-10 19:40:50 +00:00
}
2010-06-11 19:36:50 +00:00
else if ( $_GET [ 'action' ] == " loadevent " ) {
$id = intval ( $_GET [ 'id' ]);
2010-06-14 19:25:49 +00:00
$q = mysql_query ( " SELECT schedule.*, events.name, events.eventtype FROM schedule, events WHERE schedule.id=' $id ' AND schedule.conferences_id=' { $conference [ 'id' ] } ' AND schedule.events_id=events.id " );
echo mysql_error ();
2010-06-11 19:36:50 +00:00
if ( $r = mysql_fetch_array ( $q )) {
2010-06-14 19:25:49 +00:00
$r [ 'idtype' ] = $r [ 'events_id' ] . " : " . $r [ 'eventtype' ];
2010-06-11 19:36:50 +00:00
echo json_encode ( $r );
}
else
echo json_encode ( array ( " id " => 0 ));
exit ;
}
else if ( $_GET [ 'action' ] == " saveevent " ) {
$id = intval ( $_POST [ 'id' ]);
if ( ! $id ) {
mysql_query ( " INSERT INTO schedule (conferences_id) VALUES (' { $conference [ 'id' ] } ') " );
$id = mysql_insert_id ();
}
2010-06-14 19:25:49 +00:00
list ( $event_id , $event_type ) = explode ( " : " , $_POST [ 'event_id' ]);
if ( $event_id > 0 ) {
mysql_query ( " UPDATE schedule SET
2010-06-14 20:37:31 +00:00
title = '".mysql_real_escape_string($_POST[' title '])."' ,
2010-06-14 19:25:49 +00:00
date = '".mysql_real_escape_string($_POST[' date '])."' ,
hour = '".mysql_real_escape_string($_POST[' hour '])."' ,
minute = '".mysql_real_escape_string($_POST[' minute '])."' ,
duration = '".mysql_real_escape_string($_POST[' duration '])."' ,
events_id = '$event_id' ,
2010-06-14 20:37:31 +00:00
locations_id = '".mysql_real_escape_string($_POST[' location_id '])."' ,
somaxteams = '".mysql_real_escape_string($_POST[' somaxteams '])."'
2010-06-14 19:25:49 +00:00
WHERE id = '$id' AND conferences_id = '{$conference[' id ']}' " );
echo mysql_error ();
happy_ ( " Event successfully saved " );
} else {
error_ ( " Error saving event - You must select an event " );
}
2010-06-11 19:36:50 +00:00
exit ;
}
else if ( $_GET [ 'action' ] == " deleteevent " ) {
$id = intval ( $_POST [ 'id' ]);
2010-06-16 17:09:42 +00:00
$q = mysql_query ( " SELECT * FROM schedule_registrations WHERE schedule_id=' { $id } ' AND conferences_id=' { $conference [ 'id' ] } ' " );
if ( mysql_num_rows ( $q )) {
error_ ( " Cannot remove an event that has teams registered for it. Remove the teams first " );
}
else {
mysql_query ( " DELETE FROM schedule WHERE conferences_id=' { $conference [ 'id' ] } ' AND id=' { $id } ' " );
happy_ ( " Event successfully removed from the schedule " );
}
2010-06-11 19:36:50 +00:00
exit ;
}
2010-06-10 19:40:50 +00:00
else {
send_header ( " Schedule Management " ,
array ( 'Committee Main' => 'committee_main.php' ,
2010-06-15 15:44:25 +00:00
'Administration' => 'admin/index.php' ,
'Events & Scheduling' => 'admin/eventsscheduling.php' ),
2010-06-10 19:40:50 +00:00
" events_scheduling " );
echo " <br /> " ;
?>
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
$ ( " .date " ) . datepicker ({ dateFormat : 'yy-mm-dd' });
changeDate ();
2010-06-11 19:36:50 +00:00
/* Setup the editor dialog */
$ ( " #event_editor_dialog " ) . dialog ({
bgiframe : true , autoOpen : false ,
modal : true , resizable : false ,
draggable : false ,
buttons : {
" <?=i18n('Cancel')?> " : function () {
$ ( this ) . dialog ( " close " );
},
" <?=i18n('Save')?> " : function () {
saveEvent ();
$ ( this ) . dialog ( " close " );
}
}
});
2010-06-11 20:39:29 +00:00
$ ( window ) . resize ( function () {
placeEvents ();
}
);
2010-06-10 19:40:50 +00:00
});
function changeDate () {
2010-06-11 19:36:50 +00:00
$ ( " #schedulediv " ) . load ( " schedule.php?action=loadschedule " ,{ date : $ ( " #date " ) . val (), starthour : $ ( " #starthour " ) . val (), endhour : $ ( " #endhour " ) . val ()}, function () {
2010-06-10 20:35:02 +00:00
placeEvents ();
});
2010-06-10 19:40:50 +00:00
}
function clickTableCell ( t ) {
var p = $ ( " # " + t . id ) . offset ();
2010-06-11 19:36:50 +00:00
editEvent ( null , t . id );
2010-06-10 19:40:50 +00:00
2010-06-10 20:35:02 +00:00
}
function placeEvents () {
$ ( '.scheduleevent' ) . each ( function ( idx , item ) {
2010-06-11 15:55:16 +00:00
var eventid = item . id . substr ( 6 );
var eventobj = eventdivs [ eventid ];
var tablecellid = eventobj . hour + '_' + eventobj . minute + '_' + eventobj . location ;
2010-06-14 16:20:25 +00:00
if ( $ ( " # " + tablecellid ) . length ) {
var eheight = (( eventobj . duration / 15 ) *< ? = $ROWHEIGHT ?> )-<? echo $BORDERSIZE*2; ?>;
var ewidth = $ ( " # " + tablecellid ) . width () -< ? echo $BORDERSIZE ; ?> ;
var p = $ ( " # " + tablecellid ) . offset ();
$ ( " # " + item . id ) . css ( p );
$ ( " # " + item . id ) . show ();
$ ( " # " + item . id ) . height ( eheight );
$ ( " # " + item . id ) . width ( ewidth );
}
else {
$ ( " # " + item . id ) . hide ();
}
2010-06-10 20:35:02 +00:00
}
);
2010-06-10 19:40:50 +00:00
}
2010-06-11 19:36:50 +00:00
function editEvent ( id , cell ) {
if ( id ) {
var eventobj = eventdivs [ id ];
$ ( " #event_editor_dialog " ) . dialog ( 'option' , 'title' , 'Edit Event' );
$ . getJSON ( " schedule.php?action=loadevent&id= " + id , function ( json ) {
2010-06-14 19:25:49 +00:00
//general tab
2010-06-11 19:36:50 +00:00
$ ( " #edit_schedule_id " ) . val ( json . id );
2010-06-14 20:37:31 +00:00
$ ( " #edit_title " ) . val ( json . title );
2010-06-11 19:36:50 +00:00
$ ( " #edit_date " ) . val ( json . date );
$ ( " #edit_hour " ) . val ( json . hour );
$ ( " #edit_minute " ) . val ( json . minute );
$ ( " #edit_duration " ) . val ( json . duration );
$ ( " #edit_location " ) . val ( json . locations_id );
2010-06-14 19:25:49 +00:00
$ ( " #edit_event " ) . val ( json . idtype );
//science olympics tab
$ ( " #edit_somaxteams " ) . val ( json . somaxteams );
$ ( " #schedule_tabs " ) . tabs ( 'select' , 0 );
event_change ();
2010-06-11 19:36:50 +00:00
});
}
else {
$ ( " #event_editor_dialog " ) . dialog ( 'option' , 'title' , 'Create Event' );
var a = cell . split ( " _ " );
$ ( " #edit_schedule_id " ) . val ( 0 );
2010-06-14 20:37:31 +00:00
$ ( " #edit_title " ) . val ( " " );
2010-06-11 19:36:50 +00:00
$ ( " #edit_date " ) . val ( $ ( " #date " ) . val ());
$ ( " #edit_hour " ) . val ( a [ 0 ]);
$ ( " #edit_minute " ) . val ( a [ 1 ]);
$ ( " #edit_duration " ) . val ( 60 );
$ ( " #edit_location " ) . val ( a [ 2 ]);
$ ( " #edit_event " ) . val ( " " );
2010-06-14 20:37:31 +00:00
//science olympics tab
$ ( " #edit_somaxteams " ) . val ( " " );
$ ( " #schedule_tabs " ) . tabs ( 'select' , 0 );
event_change ();
2010-06-11 19:36:50 +00:00
}
$ ( " #event_editor_dialog " ) . dialog ( 'option' , 'width' , 600 );
$ ( " #event_editor_dialog " ) . dialog ( 'option' , 'height' , 400 );
$ ( " #event_editor_dialog " ) . dialog ( 'open' );
}
function saveEvent () {
var o = $ ( " #edit_event_form " ) . serializeArray ();
//alert(o);
2010-06-14 19:25:49 +00:00
$ ( " #debug " ) . load ( " schedule.php?action=saveevent " , o , function () {
2010-06-11 19:36:50 +00:00
changeDate ();
});
}
function deleteEvent ( event , id ) {
event . stopPropagation ();
2010-06-16 17:09:42 +00:00
if ( confirmClick ( 'Are you sure you want to remove this event from the schedule?' )) {
2010-06-14 19:25:49 +00:00
$ ( " #debug " ) . load ( 'schedule.php?action=deleteevent' ,{ id : id }, function () {
2010-06-11 19:36:50 +00:00
changeDate ();
});
}
return false ;
}
2010-06-10 19:40:50 +00:00
</ script >
< ?
if ( ! $editdate ) {
list ( $editdate , $bla ) = explode ( " " , $config [ 'dates' ][ 'fairdate' ]);
}
?>
< form method = " post " >
2010-06-11 15:55:16 +00:00
< ? echo i18n ( " Schedule date " ); ?>
2010-06-10 19:40:50 +00:00
< input id = " date " class = " date " type = " text " name = " date " value = " <?= $editdate ?> " size = " 15 " onchange = " changeDate() " >
2010-06-11 15:55:16 +00:00
< ? echo i18n ( " Start hour " ) . " " ;
2010-06-14 16:58:58 +00:00
emit_hour_selector ( " starthour " , 8 , " id= \" starthour \" onchange= \" changeDate() \" " );
2010-06-11 15:55:16 +00:00
echo i18n ( " End hour " ) . " " ;
2010-06-14 16:58:58 +00:00
emit_hour_selector ( " endhour " , 15 , " id= \" endhour \" onchange= \" changeDate() \" " );
2010-06-11 15:55:16 +00:00
?>
2010-06-10 19:40:50 +00:00
</ form >
< hr />
< div id = " schedulediv " >
</ div >
2010-06-11 19:36:50 +00:00
< div id = " event_editor_dialog " >
< ? include " schedule_edit_dialog.php " ; ?>
2010-06-10 19:40:50 +00:00
</ div >
< ?
send_footer ();
}
?>