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
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 " );
require_once ( " ../user.inc.php " );
user_auth_required ( 'committee' , 'admin' );
2010-06-11 15:55:16 +00:00
$ROWHEIGHT = 20 ;
$BORDERSIZE = 2 ;
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
if ( $starthour < 0 || $starthour > 24 ) $starthour = 7 ;
if ( $endhour < $starthour )
$endhour = $starthour + 10 ;
if ( $endhour < 0 || $endhour > 24 ) $endhour = 17 ;
//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-11 19:36:50 +00:00
$q = mysql_query ( " SELECT schedule.*, events.name FROM schedule JOIN events ON schedule.events_id=events.id WHERE schedule.conferences_id=' { $conference [ 'id' ] } ' AND date=' { $date } ' " );
echo mysql_error ();
2010-06-10 20:35:02 +00:00
while ( $r = mysql_fetch_object ( $q )) {
2010-06-11 19:36:50 +00:00
echo " <div class= \" scheduleevent \" id= \" event_ { $r -> id } \" onclick= \" editEvent( $r->id ) \" > " ;
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 \" > " ;
echo $r -> name ;
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-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' ]);
$q = mysql_query ( " SELECT * FROM schedule WHERE id=' $id ' AND conferences_id=' { $conference [ 'id' ] } ' " );
if ( $r = mysql_fetch_array ( $q )) {
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 ();
}
mysql_query ( " UPDATE schedule SET
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 = '".mysql_real_escape_string($_POST[' event_id '])."' ,
locations_id = '".mysql_real_escape_string($_POST[' location_id '])."'
WHERE id = '$id' AND conferences_id = '{$conference[' id ']}' " );
echo mysql_error ();
exit ;
}
else if ( $_GET [ 'action' ] == " deleteevent " ) {
2010-06-11 20:08:27 +00:00
//FIXME: dont let it delete an event that is already in use!
//FIXME: and if we do, delete everything that its been linked to!
2010-06-11 19:36:50 +00:00
$id = intval ( $_POST [ 'id' ]);
mysql_query ( " DELETE FROM schedule WHERE conferences_id=' { $conference [ 'id' ] } ' AND id=' { $id } ' " );
exit ;
}
2010-06-10 19:40:50 +00:00
else {
send_header ( " Schedule Management " ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ),
" 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 ;
var eheight = (( eventobj . duration / 15 ) *< ? = $ROWHEIGHT ?> )-<? echo $BORDERSIZE*2; ?>;
2010-06-11 20:39:29 +00:00
var ewidth = $ ( " # " + tablecellid ) . width () -< ? echo $BORDERSIZE ; ?> ;
2010-06-10 19:40:50 +00:00
2010-06-10 20:35:02 +00:00
var p = $ ( " # " + tablecellid ) . offset ();
$ ( " # " + item . id ) . css ( p );
$ ( " # " + item . id ) . show ();
2010-06-11 15:55:16 +00:00
$ ( " # " + item . id ) . height ( eheight );
2010-06-11 20:39:29 +00:00
$ ( " # " + item . id ) . width ( ewidth );
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 ) {
$ ( " #edit_schedule_id " ) . val ( json . id );
$ ( " #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 );
$ ( " #edit_event " ) . val ( json . events_id );
});
}
else {
$ ( " #event_editor_dialog " ) . dialog ( 'option' , 'title' , 'Create Event' );
var a = cell . split ( " _ " );
$ ( " #edit_schedule_id " ) . val ( 0 );
$ ( " #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 ( " " );
}
$ ( " #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);
$ . post ( " schedule.php?action=saveevent " , o , function () {
changeDate ();
});
}
function deleteEvent ( event , id ) {
event . stopPropagation ();
if ( confirmClick ( 'Are you sure you want to delete this event from the schedule?' )) {
$ . post ( 'schedule.php?action=deleteevent' ,{ id : id }, function () {
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-11 20:04:51 +00:00
emit_hour_selector ( " starthour " , 7 , " id= \" starthour \" onchange= \" changeDate() \" " );
2010-06-11 15:55:16 +00:00
echo i18n ( " End hour " ) . " " ;
2010-06-11 20:04:51 +00:00
emit_hour_selector ( " endhour " , 17 , " 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 ();
}
?>