From e5d9460d73d3c27b31f4b4764f663861f9a18eaa Mon Sep 17 00:00:00 2001 From: james Date: Tue, 15 Jun 2010 21:43:21 +0000 Subject: [PATCH] Add schedule view for school access, allow schools to register teams for events --- db/db.code.version.txt | 2 +- db/db.update.184.sql | 7 + schoolaccess.php | 1 + schoolschedule.php | 252 ++++++++++++++++++++++++++++++++ schoolschedule_event_dialog.php | 47 ++++++ schoolschedule_event_tab.php | 202 +++++++++++++++++++++++++ theme/default/sfiab.css | 6 +- 7 files changed, 513 insertions(+), 4 deletions(-) create mode 100644 db/db.update.184.sql create mode 100644 schoolschedule.php create mode 100644 schoolschedule_event_dialog.php create mode 100644 schoolschedule_event_tab.php diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 90afb3e9..dc37bbdb 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -183 +184 diff --git a/db/db.update.184.sql b/db/db.update.184.sql new file mode 100644 index 00000000..c3d1aedc --- /dev/null +++ b/db/db.update.184.sql @@ -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; diff --git a/schoolaccess.php b/schoolaccess.php index ba6cf48b..7f082681 100644 --- a/schoolaccess.php +++ b/schoolaccess.php @@ -59,6 +59,7 @@ function draw_dashboard(){ }else if($conference['type'] == 'scienceolympics'){ echo '
  • ' . i18n("Manage Students") . "
  • \n"; echo '
  • ' . i18n("Manage Teams") . "
  • \n"; + echo '
  • ' . i18n("Register Teams for Events") . "
  • \n"; } echo '
  • ' . i18n("School Feedback / Questions") . "
  • "; echo "\n"; diff --git a/schoolschedule.php b/schoolschedule.php new file mode 100644 index 00000000..283f30f8 --- /dev/null +++ b/schoolschedule.php @@ -0,0 +1,252 @@ + + Copyright (C) 2005 James Grant + + 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. +*/ +?> +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 "

    ".i18n("Schedule for %1",array(format_date($date)))."

    "; + $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 "\n"; + echo ""; + echo ""; + foreach($locations AS $id=>$name) { + echo " \n"; + } + for($h=$starthour;$h<$endhour;$h++) { + for($m=0;$m<60;$m+=$increment) { + echo ""; + echo " "; + foreach($locations AS $id=>$name) { + echo ""; + } + echo ""; + } + } + echo "
     $name
    "; + if($m==0) { + echo format_time("$h:$m"); + } + echo ""; + echo "
    \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 "
    eventtype}\" id=\"event_{$r->id}\" onclick=\"viewEvent($r->id)\">"; + echo ""; + echo $r->title; + echo ""; + echo "
    "; + $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 "
    "; + echo i18n("Capacity").": "; + //FIXME: get # actually registered + $regteams=0; + + $maxteams=$r->somaxteams; + echo i18n("%1 of %2",array($regteams,$maxteams)); + + } + + echo "
    "; + $js.="eventdivs[$r->id]={hour:$r->hour,minute:$r->minute,location:$r->locations_id,duration:$r->duration};\n"; + $x++; + } + echo ""; + } + 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 "
    "; + ?> + + + date; + } + if(count($dates)) + $editdate=$dates[0]; + else + list($editdate,$bla)=explode(" ",$config['dates']['fairdate']); + + echo "
    \n"; + echo i18n("Schedule date").": "; + echo ""; + echo "
    \n"; + ?> +
    +
    +
    +
    + +
    + diff --git a/schoolschedule_event_dialog.php b/schoolschedule_event_dialog.php new file mode 100644 index 00000000..a7469596 --- /dev/null +++ b/schoolschedule_event_dialog.php @@ -0,0 +1,47 @@ + + +
    +
      +
    • +
    • +
    +
    +
    +
    +
    +
    + diff --git a/schoolschedule_event_tab.php b/schoolschedule_event_tab.php new file mode 100644 index 00000000..9a316b46 --- /dev/null +++ b/schoolschedule_event_tab.php @@ -0,0 +1,202 @@ + + Copyright (C) 2005 James Grant + + 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. +*/ +?> +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 "

    $r->title $name

    "; + + switch($_GET['tab']) { + case "summary": + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
    ".i18n("Time")."".i18n("Duration")."".i18n("Location")."
    ".format_time(strtotime($r->hour.":".$r->minute))."$r->duration minutes$r->location
    \n"; + echo "
    "; + echo "

    ".i18n("Summary")."

    \n"; + echo nl2br(trim($r->summary)); + echo "
    \n"; + echo "
    \n"; + + if($r->website) { + echo "website\">".i18n("Click here for the full event description")."
    \n"; + } + + break; + case "register": + $regteams=getNumRegistrations($r->id); + echo i18n("Current capacity: %1 of %2 Teams",array($regteams,$r->somaxteams)); + echo "
    "; + echo "
    "; + echo i18n("Your school's teams").":
    "; + echo ""; + echo ""; + echo " "; + echo " "; + echo " "; + echo ""; + + //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 ""; + echo ""; + echo ""; + echo "\n"; + } + echo "
    ".i18n("Team Name")."".i18n("Current Status")."".i18n("Action")."
    $team->name$statusmsgid,$r->id,'$action')\">
    \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"; +} + +?> diff --git a/theme/default/sfiab.css b/theme/default/sfiab.css index 2c9fc153..468825f5 100644 --- a/theme/default/sfiab.css +++ b/theme/default/sfiab.css @@ -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;