From 0a02525d14f8b22b8420639c32396a1bb20ec115 Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 28 Sep 2010 20:09:31 +0000 Subject: [PATCH] Added some API functionality used in schoolschedule.php --- api.php | 56 +++++++ schedule.inc.php | 40 +++++ schoolschedule.php | 360 +++++++++++++++++++++++---------------------- testapi.php | 7 + 4 files changed, 290 insertions(+), 173 deletions(-) diff --git a/api.php b/api.php index 3a64a83..7e425a4 100644 --- a/api.php +++ b/api.php @@ -25,6 +25,7 @@ include "common.inc.php"; require_once("account.inc.php"); require_once("user.inc.php"); +require_once("schedule.inc.php"); if($_SERVER['HTTPS']!="on") { $ret['status']="error"; @@ -37,6 +38,61 @@ $request=explode("/",$_GET['request']); $ret=array(); switch($request[0]) { + case 'locations': + switch($request[1]){ + case 'list': + /* APIDOC: locations/list + description(lists locations at the current conference) + return(list array) + */ + $locationData = getLocationList($_SESSION['conferences_id']); + if(is_array($locationData)){ + $ret['status'] = 'ok'; + $ret['list'] = $locationData; + }else{ + $ret['status'] = 'error'; + $ret['error'] = $locationData; + } + break; + default: + $ret['status'] = 'error'; + $ret['error']="Invalid API command ({$request[1]})"; + } + break; + case "schedule": + $u = user_load($_SESSION['users_id']); + $school_id = null; + if($u['schools_id']) { + $school_id=$u['schools_id']; + }else{ + $ret['status'] = 'error'; + $ret['error']="Not connected to a school"; + break; + } + + switch($request[1]){ + case 'list': + /* APIDOC: events/list + description(gets a list of all events at the current conference, and team information if applicable) + return(list array) + */ + $eventData = getEventList($_SESSION['conferences_id'], $school_id); + if(is_array($eventData)){ + $ret['status'] = 'ok'; + $ret['list'] = $eventData; + }else{ + $ret['status'] = 'error'; + $ret['error'] = $eventData; + } + break; + + default: + $ret['status'] = 'error'; + $ret['error']="Invalid API command ({$request[1]})"; + + } + + break; case "conferences": /* APIDOC: conferences/switch description(switches the active conference) diff --git a/schedule.inc.php b/schedule.inc.php index 75b259a..8fef911 100644 --- a/schedule.inc.php +++ b/schedule.inc.php @@ -44,5 +44,45 @@ function getNumRegistrations($scheduleid) { return $r->num; } +function getEventList($conferencesId, $school_id){ + global $conference; + $events = array(); + $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']}'"); + $err = mysql_error(); + if($err != "") return($err); + while($event = mysql_fetch_assoc($q)) { + + if($event['eventtype'] == "scienceolympic") { + $regteams = getNumRegistrations($event['id']); + $maxteams = $event['somaxteams']; + + $regq = mysql_query("SELECT so_teams.name, schedule_registrations.id + FROM schedule_registrations + JOIN so_teams ON so_teams_id=so_teams.id + WHERE schedule_registrations.conferences_id='{$conferencesId}' + AND so_teams.schools_id=$school_id + AND schedule_registrations.schedule_id='{$event['id']}'"); + $err = mysql_error(); + if($err != "") break; + $event['registrations'] = array(); + while($regr = mysql_fetch_assoc($regq)) { + $event['registrations'][] = $regr; + } + } + $events[] = $event; + } + if($err != "") return($err); + return $events; +} + +function getLocationList($conferencesId){ + global $conference; + $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; + } + return $locations; +} + ?> diff --git a/schoolschedule.php b/schoolschedule.php index 47cd28c..802c0b9 100644 --- a/schoolschedule.php +++ b/schoolschedule.php @@ -13,7 +13,7 @@ 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. + 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 @@ -22,50 +22,56 @@ */ ?> minhour; - $endhour=$parameters->maxfinish; + $eventList = getEventList($conference['id'], $school->id); - //do some sanity checks - if($starthour<0 || $starthour>24) $starthour=8; - if($endhour<$starthour) - $endhour=$starthour+10; - if($endhour<0 || $endhour>24) $endhour=15; + // get the minimum and maximum hours from the schedule + $starthour = $endhour = null; + foreach($eventList as $event){ + if($event['date'] == $date){ + $sh = $event['hour']; + $eh = $sh + ceil($event['duration'] / 60); + if($endhour === null || $endhour < $eh) $endhour = $eh; + if($starthour === null || $starthour > $sh) $starthour = $sh; + } + } - //minute increment - $increment=15; + //do some sanity checks + if($starthour<0 || $starthour>24) $starthour=8; + if($endhour<$starthour) + $endhour=$starthour+10; + if($endhour<0 || $endhour>24) $endhour=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; - } + //minute increment + $increment=15; + + 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 ""; @@ -93,69 +99,74 @@ $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(is_array($eventList)){ + foreach($eventList as $event){ + // skip this event if it's not on the day we're looking at + if($event['date'] != $date) continue; - if($r->eventtype=="scienceolympic") { + // some variables for convenience. Used repeatedly + $eid = $event['id']; + $hour = $event['hour']; + $minute = $event['minute']; + $location = $event['locations_id']; + $duration = $event['duration']; + $eventType = $event['eventtype']; + $title = $event['title']; + $starttime = strtotime($hour . ":" . $minute); + $endtime = $starttime + $duration * 60; + + echo "
"; + echo ""; + echo $title; + echo ""; echo "
"; - echo i18n("Capacity").": "; - $regteams=getNumRegistrations($r->id); - $maxteams=$r->somaxteams; - echo i18n("%1 of %2",array($regteams,$maxteams))."
"; - - $regq=mysql_query("SELECT so_teams.name, schedule_registrations.id - FROM schedule_registrations - JOIN so_teams ON so_teams_id=so_teams.id - WHERE schedule_registrations.conferences_id='{$conference['id']}' - AND so_teams.schools_id={$school->id} - AND schedule_registrations.schedule_id='$r->id'"); - echo mysql_error(); - while($regr=mysql_fetch_object($regq)) { - echo "
id}, {$r->events_id});\">"; - echo $regr->name; - echo "
"; + echo format_time($starttime); + echo " to "; + echo format_time($endtime); + + if($eventType == "scienceolympic") { + echo "
"; + echo i18n("Capacity").": "; + $regteams = getNumRegistrations($eid); + $maxteams= $event['somaxteams']; + echo i18n("%1 of %2", array($regteams, $maxteams)) . "
"; + foreach($event['registrations'] as $regr){ + echo "
"; + echo $regr['name']; + echo "
"; + } } - } - echo "
"; - $js.="eventdivs[$r->id]={hour:$r->hour,minute:$r->minute,location:$r->locations_id,duration:$r->duration,title:'".rawurlencode($r->title)."',eventtype:'$r->eventtype'};\n"; - $x++; + echo "
"; + $js .= "eventdivs[$eid]={hour:$hour,minute:$minute,location:$location,duration:$duration,title:'".rawurlencode($title)."',eventtype:'$eventType'};\n"; + } + }else{ + // it's actually an error message + echo $eventList; } echo ""; - }else if($_GET['action']=="loadevent") { +}else if($_GET['action']=="loadevent") { - }else if($_GET['action']=="saveevent") { +}else if($_GET['action']=="saveevent") { - }else if($_GET['action'] == "saveteamlist"){ +}else if($_GET['action'] == "saveteamlist"){ // print_r($_POST); // get a list of all students that could be put on this team - - $results = mysql_query("SELECT * FROM users_student - JOIN users ON users_student.users_id = users.uid - JOIN users_conferences_link ucl ON ucl.users_uid = users_student.users_id - WHERE schools_id = $schoolid - AND ucl.conferences_id={$conference['id']} - AND users.deleted = 'no'"); - + $query = + "SELECT * FROM users" + . " JOIN user_roles ON user_roles.users_id = users.id" + . " JOIN roles ON roles.id = user_roles.roles_id" + . " WHERE schools_id = $schoolid" + . " AND conferences_id = {$conference['id']}" + . " AND deleted = 'no'" + . " AND roles.type = 'student'"; $availList = array(); while($record = mysql_fetch_array($results)){ - $availList[$record['uid']] = $record['firstname'] . ' ' . $record['lastname']; + $availList[$record['accounts_id']] = $record['firstname'] . ' ' . $record['lastname']; } // let's empty the current list of students for this team @@ -173,9 +184,9 @@ $query .= implode(',', $valueSet); $results = mysql_query($query); - }else if($_GET['action'] == "getteamlist"){ - // first we'll get the basic info, and do a quick check that the selected team is in this user's domain - if(!array_key_exists('regId', $_POST)){ +}else if($_GET['action'] == "getteamlist"){ + // first we'll get the basic info, and do a quick check that the selected team is in this user's domain + if(!array_key_exists('regId', $_POST)){ echo "error\n"; return; } @@ -193,16 +204,19 @@ $teamName = $record['name']; // get a list of all students that could be put on this team - $query = 'SELECT * FROM users_student'; - $query .= ' JOIN users ON users_student.users_id = users.uid'; - $query .= ' JOIN users_conferences_link ucl ON ucl.users_uid = users_student.users_id'; - $query .= ' WHERE schools_id = ' . $schoolid; - $query .= ' AND ucl.conferences_id=' . $conference['id']; - $query .= ' AND users.deleted = "no"'; + + $query = + "SELECT * FROM users" + . " JOIN user_roles ON user_roles.users_id = users.id" + . " JOIN roles ON roles.id = user_roles.roles_id" + . " WHERE schools_id = $schoolid" + . " AND conferences_id = {$conference['id']}" + . " AND deleted = 'no'" + . " AND roles.type = 'student'"; $results = mysql_query($query); $availList = array(); while($record = mysql_fetch_array($results)){ - $availList[$record['uid']] = $record['firstname'] . ' ' . $record['lastname']; + $availList[$record['accounts_id']] = $record['firstname'] . ' ' . $record['lastname']; } // now find out which of these students are already selected @@ -210,6 +224,7 @@ $query .= " WHERE users_uid IN ("; $query .= implode(',', array_keys($availList)) . ')'; $query .= " AND schedule_registrations_id = " . $_POST['regId']; + echo "\n[[[ $query ]]]\n"; $results = mysql_query($query); $selectedList = array(); if($results){ @@ -222,8 +237,8 @@ // get the necessary data about the event itself $query = "SELECT sominteamsize, somaxteamsize, title FROM schedule JOIN" - . " schedule_registrations sr ON sr.schedule_id = schedule.id WHERE" - . " sr.id = " . $_POST['regId']; + . " schedule_registrations sr ON sr.schedule_id = schedule.id WHERE" + . " sr.id = " . $_POST['regId']; $results = mysql_fetch_array(mysql_query($query)); $minTeamSize = $results['sominteamsize']; $maxTeamSize = $results['somaxteamsize']; @@ -265,17 +280,17 @@ echo "max_size=" . $results['default_max_team_size'] . ';'; */ echo ''; - }else{ +}else{ - send_header("Event Registration", + send_header("Event Registration", array('School Home' => 'schoolaccess.php'), "events_scheduling" ); - echo "
"; - ?> - - + + function saveEvent() { + var o=$("#edit_event_form").serializeArray(); + //alert(o); + $("#debug").load("schoolschedule.php?action=saveevent",o,function() { + changeDate(); + }); + } + - date; - } - if(count($dates)) - $editdate=$dates[0]; - else - list($editdate,$bla)=explode(" ",$config['dates']['fairdate']); + } + if(count($dates)) + $editdate=$dates[0]; + else + list($editdate,$bla)=explode(" ",$config['dates']['fairdate']); - echo "\n"; - echo i18n("Schedule date").": "; - echo ""; - echo "\n"; - ?> -
-
-
-
+ echo "
\n"; + echo i18n("Schedule date").": "; + echo ""; + echo "\n"; + ?> +
+
+
+
-
-
- +
+ diff --git a/testapi.php b/testapi.php index dfb6aa5..645e63e 100644 --- a/testapi.php +++ b/testapi.php @@ -57,6 +57,13 @@ Date List +

Event Schedule

+Schedule Listing
+Location Listing
+ + + +

Session Variables