forked from science-ation/science-ation
285 lines
8.3 KiB
PHP
285 lines
8.3 KiB
PHP
<?
|
|
/*
|
|
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');
|
|
|
|
$ROWHEIGHT=20;
|
|
$BORDERSIZE=2;
|
|
|
|
if($_GET['action']=="loadschedule") {
|
|
$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;
|
|
|
|
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>";
|
|
$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;
|
|
}
|
|
|
|
echo "<table class=\"schedule\">\n";
|
|
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";
|
|
|
|
$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
|
|
$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();
|
|
while($r=mysql_fetch_object($q)) {
|
|
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);
|
|
|
|
echo "</div>";
|
|
$js.="eventdivs[$r->id]={hour:$r->hour,minute:$r->minute,location:$r->locations_id,duration:$r->duration};\n";
|
|
$x++;
|
|
}
|
|
echo "<script type=\"text/javascript\">\n";
|
|
echo $js;
|
|
echo "</script>";
|
|
}
|
|
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") {
|
|
//FIXME: dont let it delete an event that is already in use!
|
|
//FIXME: and if we do, delete everything that its been linked to!
|
|
$id=intval($_POST['id']);
|
|
mysql_query("DELETE FROM schedule WHERE conferences_id='{$conference['id']}' AND id='{$id}'");
|
|
exit;
|
|
}
|
|
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();
|
|
|
|
/* 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");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
function changeDate() {
|
|
$("#schedulediv").load("schedule.php?action=loadschedule",{date:$("#date").val(),starthour:$("#starthour").val(),endhour:$("#endhour").val()},function() {
|
|
placeEvents();
|
|
});
|
|
}
|
|
|
|
function clickTableCell(t) {
|
|
var p=$("#"+t.id).offset();
|
|
editEvent(null,t.id);
|
|
|
|
|
|
}
|
|
|
|
function placeEvents() {
|
|
$('.scheduleevent').each(function(idx,item) {
|
|
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; ?>;
|
|
|
|
var p=$("#"+tablecellid).offset();
|
|
$("#"+item.id).css(p);
|
|
$("#"+item.id).show();
|
|
$("#"+item.id).height(eheight);
|
|
}
|
|
);
|
|
}
|
|
|
|
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;
|
|
}
|
|
</script>
|
|
|
|
<?
|
|
if(!$editdate) {
|
|
list($editdate,$bla)=explode(" ",$config['dates']['fairdate']);
|
|
}
|
|
?>
|
|
<form method="post">
|
|
<? echo i18n("Schedule date"); ?>
|
|
<input id="date" class="date" type="text" name="date" value="<?=$editdate?>" size="15" onchange="changeDate()">
|
|
<? echo i18n("Start hour")." ";
|
|
emit_hour_selector("starthour",7,"id=\"starthour\" onchange=\"changeDate()\"");
|
|
echo i18n("End hour")." ";
|
|
emit_hour_selector("endhour",17,"id=\"endhour\" onchange=\"changeDate()\"");
|
|
?>
|
|
</form>
|
|
<hr />
|
|
<div id="schedulediv">
|
|
</div>
|
|
<div id="event_editor_dialog">
|
|
<? include "schedule_edit_dialog.php"; ?>
|
|
</div>
|
|
<?
|
|
|
|
send_footer();
|
|
|
|
}
|
|
?>
|