Add schedule view for school access, allow schools to register teams for events

This commit is contained in:
james 2010-06-15 21:43:21 +00:00
parent 41efbd89b0
commit e5d9460d73
7 changed files with 513 additions and 4 deletions

View File

@ -1 +1 @@
183
184

7
db/db.update.184.sql Normal file
View File

@ -0,0 +1,7 @@
CREATE TABLE `schedule_registrations` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`schedule_id` INT NOT NULL ,
`so_teams_id` INT NOT NULL ,
`dt` DATETIME NOT NULL ,
`conferences_id` INT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;

View File

@ -59,6 +59,7 @@ function draw_dashboard(){
}else if($conference['type'] == 'scienceolympics'){
echo '<li><a href="schoolstudents.php">' . i18n("Manage Students") . "</a></li>\n";
echo '<li><a href="schoolteams.php">' . i18n("Manage Teams") . "</a></li>\n";
echo '<li><a href="schoolschedule.php">' . i18n("Register Teams for Events") . "</a></li>\n";
}
echo '<li><a href="schoolfeedback.php">' . i18n("School Feedback / Questions") . "</a></li>";
echo "</ul>\n";

252
schoolschedule.php Normal file
View File

@ -0,0 +1,252 @@
<?
/*
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");
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']){
// we're logged in, make sure the school is good
$q=mysql_query("SELECT * FROM schools WHERE id='".$_SESSION['schoolid']."' AND accesscode='".$_SESSION['schoolaccesscode']."'");
echo mysql_error();
$school=mysql_fetch_object($q);
if($school) {
$ROWHEIGHT=20;
$BORDERSIZE=2;
if($_GET['action']=="loadschedule") {
$date=$_POST['date'];
//cant change this
$q=mysql_query("SELECT MIN(hour) AS minhour, MAX(hour) AS maxhour, CEIL(MAX(hour)+duration/60) AS maxfinish FROM schedule WHERE conferences_id='{$conference['id']}' AND date='{$date}'");
$parameters=mysql_fetch_object($q);
$starthour=$parameters->minhour;
$endhour=$parameters->maxfinish;
//do some sanity checks
if($starthour<0 || $starthour>24) $starthour=8;
if($endhour<$starthour)
$endhour=$starthour+10;
if($endhour<0 || $endhour>24) $endhour=15;
//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."));
exit;
}
echo "<table class=\"schedule\" id=\"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}\">";
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, events.eventtype 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 scheduleevent_{$r->eventtype}\" id=\"event_{$r->id}\" onclick=\"viewEvent($r->id)\">";
echo "<span class=\"scheduleevent_title\">";
echo $r->title;
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);
if($r->eventtype=="scienceolympic") {
echo "<br />";
echo i18n("Capacity").": ";
//FIXME: get # actually registered
$regteams=0;
$maxteams=$r->somaxteams;
echo i18n("%1 of %2",array($regteams,$maxteams));
}
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") {
}
else if($_GET['action']=="saveevent") {
}
else {
send_header("Event Registration",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Events & Scheduling' => 'admin/eventsscheduling.php'),
"events_scheduling" );
echo "<br />";
?>
<script type="text/javascript">
$(document).ready(function() {
$(".date").datepicker({ dateFormat: 'yy-mm-dd' });
changeDate();
/* Setup the editor dialog */
$("#event_dialog").dialog({
bgiframe: true, autoOpen: false,
modal: true, resizable: false,
draggable: false,
buttons: {
"<?=i18n('Close')?>": function() {
$(this).dialog("close");
}
}
});
$(window).resize(function() {
placeEvents();
}
);
});
function changeDate() {
$("#schedulediv").load("schoolschedule.php?action=loadschedule",{date:$("#date").val()},function() {
placeEvents();
});
}
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;
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();
}
}
);
}
var scheduleId;
function viewEvent(id) {
scheduleId=id;
if(id) {
var eventobj=eventdivs[id];
$("#event_dialog").dialog('option','title','Event Information');
$("#event_dialog").dialog('option','width',600);
$("#event_dialog").dialog('option','height',400);
$("#event_dialog").dialog('open');
$("#event_tabs").tabs('select',0);
update_tab_summary();
}
}
function saveEvent() {
var o=$("#edit_event_form").serializeArray();
//alert(o);
$("#debug").load("schoolschedule.php?action=saveevent",o,function() {
changeDate();
});
}
</script>
<?
$q=mysql_query("SELECT DISTINCT(date) AS date FROM schedule WHERE conferences_id='{$conference['id']}' ORDER BY date");
$dates=array();
while($r=mysql_fetch_object($q)) {
$dates[]=$r->date;
}
if(count($dates))
$editdate=$dates[0];
else
list($editdate,$bla)=explode(" ",$config['dates']['fairdate']);
echo "<form method=\"post\">\n";
echo i18n("Schedule date").": ";
echo "<select id=\"date\" name=\"date\" onchange=\"changeDate()\">";
foreach($dates AS $d) {
echo "<option value=\"$d\">".format_date($d)."</option>\n";
}
echo "</select>";
echo "</form>\n";
?>
<hr />
<div id="schedulediv">
</div>
<div id="event_dialog">
<? include "schoolschedule_event_dialog.php"; ?>
</div>
<?
send_footer();
}
}
}
?>

View File

@ -0,0 +1,47 @@
<script type="text/javascript">
$(document).ready(function() {
$("#event_tabs").tabs({
show: function(event, ui) {
switch(ui.panel.id) {
case 'event_tab_summary':
update_tab_summary();
break;
case 'event_tab_register':
update_tab_register();
break;
}
},
selected: 0
});
});
function update_tab_summary() {
$("#event_tab_summary").load("schoolschedule_event_tab.php?action=load&tab=summary&id="+scheduleId,null,function() { });
}
function update_tab_register() {
if(scheduleId) {
$("#event_tab_register").load("schoolschedule_event_tab.php?action=load&tab=register&id="+scheduleId);
}
}
function registerSchedule(teamid,scheduleid,action) {
$("#debug").load("schoolschedule_event_tab.php?action=register",{teamid:teamid, scheduleid:scheduleid, regaction:action}, function() {
update_tab_register();
});
return false;
}
</script>
<div id="event_tabs">
<ul>
<li><a href="#event_tab_summary"><span><?=i18n('Event Summary')?></span></a></li>
<li><a href="#event_tab_register"><span><?=i18n('Register')?></span></a></li>
</ul>
<div id="event_tab_summary">
</div>
<div id="event_tab_register">
</div>
</div>

View File

@ -0,0 +1,202 @@
<?
/*
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");
function getTeamEventStatus($teamid,$scheduleid) {
global $conference;
$q=mysql_query("SELECT * FROM schedule_registrations WHERE so_teams_id='$teamid' AND schedule_id='$scheduleid' AND conferences_id='{$conference['id']}'");
//we use registered/notregistered insetad of true/false becuase we might haevf other statuses down the line, like "waitinglist"
if(mysql_num_rows($q)) {
return "registered";
}
else
return "notregistered";
}
function getNumRegistrations($scheduleid) {
global $conference;
$q=mysql_query("SELECT COUNT(*) AS num FROM schedule_registrations WHERE schedule_id='$scheduleid' AND conferences_id='{$conference['id']}'");
$r=mysql_fetch_object($q);
return $r->num;
}
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']){
// we're logged in, make sure the school is good
$q=mysql_query("SELECT * FROM schools WHERE id='".$_SESSION['schoolid']."' AND accesscode='".$_SESSION['schoolaccesscode']."'");
echo mysql_error();
$school=mysql_fetch_object($q);
if($school) {
switch($_GET['action']) {
case "load":
$id=intval($_GET['id']);
$q=mysql_query("SELECT schedule.*,
events.eventtype,
events.website,
events.summary,
events.name,
locations.name AS location
FROM schedule
JOIN events ON schedule.events_id=events.id
JOIN locations ON schedule.locations_id=locations.id
WHERE schedule.conferences_id='{$conference['id']}'
AND schedule.id='{$id}'");
echo mysql_error();
$r=mysql_fetch_object($q);
if($r->title!=$r->name) {
$name="($r->name)";
}
echo "<h3>$r->title $name</h3>";
switch($_GET['tab']) {
case "summary":
echo "<table width=\"95%\" class=\"tableview\">";
echo "<tr>";
echo "<th>".i18n("Time")."</th>\n";
echo "<th>".i18n("Duration")."</th>\n";
echo "<th>".i18n("Location")."</th>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td>".format_time(strtotime($r->hour.":".$r->minute))."</td>\n";
echo "<td>$r->duration minutes</td>\n";
echo "<td>$r->location</td>\n";
echo "</tr></table>\n";
echo "<br />";
echo "<h4>".i18n("Summary")."</h4>\n";
echo nl2br(trim($r->summary));
echo "<br />\n";
echo "<br />\n";
if($r->website) {
echo "<a target=\"_blank\" href=\"$r->website\">".i18n("Click here for the full event description")."</a> <br />\n";
}
break;
case "register":
$regteams=getNumRegistrations($r->id);
echo i18n("Current capacity: %1 of %2 Teams",array($regteams,$r->somaxteams));
echo "<br />";
echo "<br />";
echo i18n("Your school's teams").": <br />";
echo "<table class=\"summarytable\" style=\"width: 90%;\">";
echo "<tr>";
echo " <th>".i18n("Team Name")."</th>";
echo " <th>".i18n("Current Status")."</th>";
echo " <th>".i18n("Action")."</th>";
echo "</tr>";
//FIXME: replace when jacob fixes the so_teams table
//$query="SELECT * FROM so_teams WHERE schools_id='{$school->id}' AND conferences_id='{$conference['id']}'";
$query="SELECT * FROM so_teams WHERE schools_id='{$school->id}'";
$tq=mysql_query($query);
echo mysql_error();
while($team=mysql_fetch_object($tq)) {
$status=getTeamEventStatus($team->id,$r->id);
if($status=="registered") {
$cl="class=\"happy\"";
$statusmsg=i18n("Registered");
$buttonmsg=i18n("Un-Register");
$action="unregister";
} else {
$cl="class=\"error\"";
$statusmsg=i18n("Not Registered");
$buttonmsg=i18n("Register");
$action="register";
}
echo "<tr><td>$team->name</td>";
echo "<td $cl>$statusmsg</td>";
echo "<td style=\"text-align: center;\"><input type=\"button\" value=\"$buttonmsg\" onclick=\"return registerSchedule($team->id,$r->id,'$action')\"></td>";
echo "</tr>\n";
}
echo "</table>\n";
break;
}
break;
case "register":
$teamid=intval($_POST['teamid']);
$scheduleid=intval($_POST['scheduleid']);
$conferenceid=$conference['id'];
$q=mysql_query("SELECT schedule.*,
events.eventtype,
events.website,
events.summary,
events.name,
locations.name AS location
FROM schedule
JOIN events ON schedule.events_id=events.id
JOIN locations ON schedule.locations_id=locations.id
WHERE schedule.conferences_id='{$conference['id']}'
AND schedule.id='{$scheduleid}'");
$schedule=mysql_fetch_object($q);
echo mysql_error();
switch($_POST['regaction']) {
case "register":
$q=mysql_query("SELECT * FROM schedule_registrations WHERE so_teams_id=$teamid AND schedule_id=$scheduleid AND conferences_id=$conferenceid");
if(mysql_num_rows($q)) {
error_("This team is already registered for this scheduled event");
}
else {
$regteams=getNumRegistrations($scheduleid);
if($regteams<$schedule->somaxteams) {
mysql_query("INSERT INTO schedule_registrations (schedule_id, so_teams_id, conferences_id, dt) VALUES ('$scheduleid','$teamid','$conferenceid',NOW())");
happy_("Successfully registered the team for this scheduled event");
}
else {
error_("This event has reached its capacity and can no longer be registered for");
}
}
break;
case "unregister":
$q=mysql_query("SELECT * FROM schedule_registrations WHERE so_teams_id=$teamid AND schedule_id=$scheduleid AND conferences_id=$conferenceid");
if(mysql_num_rows($q)) {
mysql_query("DELETE FROM schedule_registrations WHERE so_teams_id='$teamid' AND schedule_id='$scheduleid' AND conferences_id='$conferenceid'");
happy_("Successfully unregistered the team from this scheduled event");
}
else {
error_("This team is not registered for this scheduled event, and thus, cannot be unregistered");
}
break;
}
break;
}
}
else {
echo "Invalid school";
}
}
else {
echo "Invalid school id or access code";
}
?>

View File

@ -154,7 +154,7 @@ a:hover {
.summarytable {
border-collapse: collapse;
border-spacing: 0px;
border: 2px solid black;
border: 1px solid black;
margin: 0px;
padding: 0px;
margin-left: 30px;
@ -163,7 +163,7 @@ a:hover {
}
.summarytable th {
border: 2px solid black;
border: 1px solid black;
background-color: #5C6F90;
padding: 5px;
margin: 0px;
@ -179,7 +179,7 @@ a:hover {
}
.summarytable td {
border: 2px solid black;
border: 1px solid black;
margin: 0px;
padding: 2px;