science-ation/admin/schedule.php
james 80fc39bf7f Implement start hour and end hour for schedule view
Implement event duration height calculations
2010-06-11 15:55:16 +00:00

183 lines
5.0 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($_POST['date']) {
$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;\">&nbsp;</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)\">";
/*
if($h==8&&$m==0&&$id==3) {
$height=4;
$pxheight=$height*25;
echo "<div class=\"scheduleevent\" style=\"height: {$pxheight}px;\">";
echo "</div>";
}
*/
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 * FROM schedule WHERE conferences_id='{$conference['id']}' AND date='{$date}'");
while($r=mysql_fetch_object($q)) {
echo "<div class=\"scheduleevent\" id=\"event_{$r->id}\">";
print_r($r);
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 {
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();
});
function changeDate() {
$("#schedulediv").load("schedule.php",{date:$("#date").val(),starthour:$("#starthour").val(),endhour:$("#endhour").val()},function() {
placeEvents();
});
}
function clickTableCell(t) {
var p=$("#"+t.id).offset();
// alert('You clicked in empty cell : '+t.id+' at top:'+position.top+' left:'+position.left);
$("#scheduleeventeditor").css(p);
// $("#scheduleeventeditor").width(150);
// $("#scheduleeventeditor").height(100);
$("#scheduleeventeditor").show();
}
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);
}
);
}
</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,"onchange=\"changeDate()\"");
echo i18n("End hour")." ";
emit_hour_selector("endhour",17,"onchange=\"changeDate()\"");
?>
</form>
<hr />
<div id="schedulediv">
</div>
<div id="scheduleeventeditor">
</div>
<?
send_footer();
}
?>