From: Alexander Sadleir Date: Sun, 11 Sep 2011 06:51:37 +0000 Subject: Labs Tidy up, depreciate old trip planner tester, promote myway balance/service alerts to main site X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=7782f02a084d3e83b767baac665abc2fc9c3b0ce --- Labs Tidy up, depreciate old trip planner tester, promote myway balance/service alerts to main site --- --- /dev/null +++ b/.gitignore @@ -1,1 +1,8 @@ +/labs/tiles/12 +/labs/tiles/13 +/labs/tiles/14 +/labs/tiles/15 +/labs/tiles/16 +/labs/tiles/17 +/labs/tiles/19 --- a/about.php +++ b/about.php @@ -21,6 +21,10 @@ , ACT Buses by David Sullivan) and Android (MyBus 2.0 by Imagine Team)
+GTFS-realtime API; +Alerts and Trip Updates (but only Cancelled or Stop Skipped) +Default format binary but can get JSON by adding ?ascii=yes +

Disclaimer: The content of this website is of a general and informative nature. Please check with printed timetables or those available on http://action.act.gov.au before your trip. Whilst every effort has been made to ensure the high quality and accuracy of the Site, the Author makes no warranty, --- a/aws/awsStartup.sh +++ b/aws/awsStartup.sh @@ -5,38 +5,9 @@ #postgres postgres-server php-pg #http://www.how2forge.org/installing-lighttpd-with-php5-and-mysql-support-on-fedora-12 -cp /root/aws.php /tmp/ -mkdir /var/www/lib/staticmaplite/cache -chcon -h system_u:object_r:httpd_sys_content_t /var/www -chcon -R -h root:object_r:httpd_sys_content_t /var/www/* -chcon -R -t httpd_sys_content_rw_t /var/www/lib/staticmaplite/cache -chmod -R 777 /var/www/lib/staticmaplite/cache -chcon -R -t httpd_sys_content_rw_t /var/www/labs/tiles -chmod -R 777 /var/www/labs/tiles -wget http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip \ --O /var/www/cbrfeed.zip +sh busuiphp.sh +sh busuidb.sh +sh busuiotp.sh -createdb transitdata -createlang -d transitdata plpgsql -psql -d transitdata -f /var/www/lib/postgis.sql -# curl https://github.com/maxious/ACTBus-ui/raw/master/transitdata.cbrfeed.sql.gz -o transitdata.cbrfeed.sql.gz -#made with pg_dump transitdata | gzip -c > transitdata.cbrfeed.sql.gz -gunzip /var/www/transitdata.cbrfeed.sql.gz -psql -d transitdata -f /var/www/transitdata.cbrfeed.sql -#createuser transitdata -SDRP -#password transitdata -#psql -d transitdata -c \"GRANT SELECT ON TABLE agency,calendar,calendar_dates,routes,stop_times,stops,trips TO transitdata;\" -#psql -d transitdata -c "GRANT SELECT,INSERT ON TABLE myway_observations,myway_routes,myway_stops,myway_timingdeltas TO transitdata;" -#psql -d transitdata -c "GRANT SELECT,INSERT,UPDATE ON TABLE myway_routes,myway_stops TO transitdata;" -##psql -d transitdata -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO transitdata;" -php /var/www/updatedb.php -wget http://s3-ap-southeast-1.amazonaws.com/busresources/Graph.obj \ --O /tmp/Graph.obj -rm -rfv /usr/share/tomcat6/webapps/opentripplanner* -wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-webapp.war \ --O /usr/share/tomcat6/webapps/opentripplanner-webapp.war -wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-api-webapp.war \ --O /usr/share/tomcat6/webapps/opentripplanner-api-webapp.war -/etc/init.d/tomcat6 restart --- /dev/null +++ b/aws/busuidb.sh @@ -1,1 +1,14 @@ - +createdb transitdata +createlang -d transitdata plpgsql +psql -d transitdata -f /var/www/lib/postgis.sql +# curl https://github.com/maxious/ACTBus-ui/raw/master/transitdata.cbrfeed.sql.gz -o transitdata.cbrfeed.sql.gz +#made with pg_dump transitdata | gzip -c > transitdata.cbrfeed.sql.gz +gunzip /var/www/transitdata.cbrfeed.sql.gz +psql -d transitdata -f /var/www/transitdata.cbrfeed.sql +#createuser transitdata -SDRP +#password transitdata +#psql -d transitdata -c "GRANT SELECT ON TABLE agency,calendar,calendar_dates,routes,stop_times,stops,trips TO transitdata;" +#psql -d transitdata -c "GRANT SELECT,INSERT ON TABLE myway_observations,myway_routes,myway_stops,myway_timingdeltas TO transitdata;" +#psql -d transitdata -c "GRANT SELECT,INSERT,UPDATE ON TABLE myway_routes,myway_stops TO transitdata;" +##psql -d transitdata -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO transitdata;" +php /var/www/updatedb.php --- /dev/null +++ b/aws/busuiotp.sh @@ -1,1 +1,10 @@ +wget http://s3-ap-southeast-1.amazonaws.com/busresources/Graph.obj \ +-O /tmp/Graph.obj +/etc/init.d/tomcat6 stop +rm -rfv /usr/share/tomcat6/webapps/opentripplanner* +wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-webapp.war \ +-O /usr/share/tomcat6/webapps/opentripplanner-webapp.war +wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-api-webapp.war \ +-O /usr/share/tomcat6/webapps/opentripplanner-api-webapp.war +/etc/init.d/tomcat6 restart --- /dev/null +++ b/aws/busuiotp.testing.sh @@ -1,1 +1,10 @@ +wget http://s3-ap-southeast-1.amazonaws.com/busresources/testing/Graph.obj \ +-O /tmp/Graph.obj +/etc/init.d/tomcat6 stop +rm -rfv /usr/share/tomcat6/webapps/opentripplanner* +wget http://s3-ap-southeast-1.amazonaws.com/busresources/testing/opentripplanner-webapp.war \ +-O /usr/share/tomcat6/webapps/opentripplanner-webapp.war +wget http://s3-ap-southeast-1.amazonaws.com/busresources/testing/opentripplanner-api-webapp.war \ +-O /usr/share/tomcat6/webapps/opentripplanner-api-webapp.war +/etc/init.d/tomcat6 restart --- /dev/null +++ b/aws/busuiphp.sh @@ -1,1 +1,16 @@ +cp /root/aws.php /tmp/ +mkdir /var/www/lib/staticmaplite/cache +chcon -h system_u:object_r:httpd_sys_content_t /var/www +chcon -R -h root:object_r:httpd_sys_content_t /var/www/* +chcon -R -t httpd_sys_content_rw_t /var/www/lib/staticmaplite/cache +chmod -R 777 /var/www/lib/staticmaplite/cache + +chcon -R -t httpd_sys_content_rw_t /var/www/labs/tiles +chmod -R 777 /var/www/labs/tiles + +chcon -R -t httpd_sys_content_rw_t /var/www/lib/openid-php/oid_store +chmod -R 777 /var/www/lib/openid-php/oid_store + +wget http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip \ +-O /var/www/cbrfeed.zip --- /dev/null +++ b/aws/data-sources.xml @@ -1,1 +1,13 @@ + + + + + + + + + + + --- /dev/null +++ b/include/common-auth.inc.php @@ -1,1 +1,83 @@ +begin($oid_identifier); + + // Create attribute request object + // See http://code.google.com/apis/accounts/docs/OpenID.html#Parameters for parameters + // Usage: make($type_uri, $count=1, $required=false, $alias=null) + $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/contact/email', 2, 1, 'email'); + $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/namePerson/first', 1, 1, 'firstname'); + $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/namePerson/last', 1, 1, 'lastname'); + + // Create AX fetch request + $ax = new Auth_OpenID_AX_FetchRequest; + + // Add attributes to AX fetch request + foreach ($attribute as $attr) { + $ax->add($attr); + } + + // Add AX fetch request to authentication request + $auth->addExtension($ax); + $_SESSION['returnURL'] = curPageURL(); + // Redirect to OpenID provider for authentication + $url = $auth->redirectURL(getTrustRoot(), $_SESSION['returnURL']); + header('Location: ' . $url); +} + +function auth() { + if ($_SESSION['authed'] == true) + return true; + + // Create file storage area for OpenID data + $store = new Auth_OpenID_FileStore('lib/openid-php/oid_store'); + // Create OpenID consumer + $consumer = new Auth_OpenID_Consumer($store); + // Create an authentication request to the OpenID provider + $response = $consumer->complete($_SESSION['returnURL']); + + if ($response->status == Auth_OpenID_SUCCESS) { + // Get registration informations + $ax = new Auth_OpenID_AX_FetchResponse(); + $obj = $ax->fromSuccessResponse($response); + $email = $obj->data['http://axschema.org/contact/email'][0]; + var_dump($email); + if ($email != "maxious@gmail.com") { + die("Access Denied"); + } else { + $_SESSION['authed'] = true; + } + } else { + login(); + } +} + +if ($_REQUEST['janrain_nonce']) + auth(); +?> --- a/include/common-geo.inc.php +++ b/include/common-geo.inc.php @@ -1,153 +1,166 @@ $mapPoint) { - if ($twotone && $index == 0) { - $markers.= $mapPoint[0] . "," . $mapPoint[1] . "," . "iconr" . ($index + 1); - $center = "{$mapPoints[0][0]},{$mapPoints[0][1]}"; - } - else { - $markers.= $mapPoint[0] . "," . $mapPoint[1] . "," . $markerImage . ($index + 1); - } - if ($index + 1 != sizeof($mapPoints)) $markers.= "|"; - $dist = distance($mapPoints[0][0], $mapPoint[0][1], $mapPoint[0], $mapPoint[1]); - $mapwidthinmeters = ($dist > $mapwidthinmeters ? $dist : $mapwidthinmeters); - $totalLat+= $mapPoint[0]; - $totalLon+= $mapPoint[1]; - } - if ($zoom == 0) { - $mapwidthinmeters = distance($minlat, $minlon, $minlat, $maxlon); - foreach (array_reverse($metersperpixel, true) as $zoomLevel => $maxdistance) { - if ($zoom == 0 && $mapwidthinmeters * 1.5 < ($maxdistance)) $zoom = $zoomLevel; - } - } - $center = $totalLat / sizeof($mapPoints) . "," . $totalLon / sizeof($mapPoints); - } - $output = ""; - if ($collapsible) $output.= '

Open Map...

'; - $output.= ''; - if ($collapsible) $output.= '
'; - return $output; + +function staticmap($mapPoints, $zoom = 0, $markerImage = "iconb", $collapsible = true, $twotone = false) { + global $basePath; + $width = 300; + $height = 300; + $metersperpixel[9] = 305.492 * $width; + $metersperpixel[10] = 152.746 * $width; + $metersperpixel[11] = 76.373 * $width; + $metersperpixel[12] = 38.187 * $width; + $metersperpixel[13] = 19.093 * $width; + $metersperpixel[14] = 9.547 * $width; + $metersperpixel[15] = 4.773 * $width; + //$metersperpixel[16] = 2.387 * $width; + // $metersperpixel[17]=1.193*$width; + $center = ""; + $markers = ""; + $mapwidthinmeters = 50; + if (sizeof($mapPoints) < 1) + return "map error"; + if (sizeof($mapPoints) === 1) { + if ($zoom == 0) + $zoom = 14; + $markers.= "{$mapPoints[0][0]},{$mapPoints[0][1]},$markerimage"; + $center = "{$mapPoints[0][0]},{$mapPoints[0][1]}"; + } + else { + foreach ($mapPoints as $index => $mapPoint) { + if ($twotone && $index == 0) { + $markers.= $mapPoint[0] . "," . $mapPoint[1] . "," . "iconr" . ($index + 1); + $center = "{$mapPoints[0][0]},{$mapPoints[0][1]}"; + } else { + $markers.= $mapPoint[0] . "," . $mapPoint[1] . "," . $markerImage . ($index + 1); + } + if ($index + 1 != sizeof($mapPoints)) + $markers.= "|"; + $dist = distance($mapPoints[0][0], $mapPoint[0][1], $mapPoint[0], $mapPoint[1]); + $mapwidthinmeters = ($dist > $mapwidthinmeters ? $dist : $mapwidthinmeters); + $totalLat+= $mapPoint[0]; + $totalLon+= $mapPoint[1]; + } + if ($zoom == 0) { + $mapwidthinmeters = distance($minlat, $minlon, $minlat, $maxlon); + foreach (array_reverse($metersperpixel, true) as $zoomLevel => $maxdistance) { + if ($zoom == 0 && $mapwidthinmeters * 1.5 < ($maxdistance)) + $zoom = $zoomLevel; + } + } + $center = $totalLat / sizeof($mapPoints) . "," . $totalLon / sizeof($mapPoints); + } + $output = ""; + if ($collapsible) + $output.= '

Open Map...

'; + $output.= ''; + if ($collapsible) + $output.= '
'; + return $output; } -function distance($lat1, $lng1, $lat2, $lng2, $roundLargeValues = false) -{ - $pi80 = M_PI / 180; - $lat1*= $pi80; - $lng1*= $pi80; - $lat2*= $pi80; - $lng2*= $pi80; - $r = 6372.797; // mean radius of Earth in km - $dlat = $lat2 - $lat1; - $dlng = $lng2 - $lng1; - $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2); - $c = 2 * atan2(sqrt($a) , sqrt(1 - $a)); - $km = $r * $c; - if ($roundLargeValues) { - if ($km < 1) return floor($km * 1000); - else return round($km, 2) . "k"; - } - else return floor($km * 1000); + +function distance($lat1, $lng1, $lat2, $lng2, $roundLargeValues = false) { + $pi80 = M_PI / 180; + $lat1*= $pi80; + $lng1*= $pi80; + $lat2*= $pi80; + $lng2*= $pi80; + $r = 6372.797; // mean radius of Earth in km + $dlat = $lat2 - $lat1; + $dlng = $lng2 - $lng1; + $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2); + $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); + $km = $r * $c; + if ($roundLargeValues) { + if ($km < 1) + return floor($km * 1000); + else + return round($km, 2) . "k"; + } + else + return floor($km * 1000); } -function decodePolylineToArray($encoded) -{ - // source: http://latlongeeks.com/forum/viewtopic.php?f=4&t=5 - $length = strlen($encoded); - $index = 0; - $points = array(); - $lat = 0; - $lng = 0; - while ($index < $length) { - // Temporary variable to hold each ASCII byte. - $b = 0; - // The encoded polyline consists of a latitude value followed by a - // longitude value. They should always come in pairs. Read the - // latitude value first. - $shift = 0; - $result = 0; - do { - // The `ord(substr($encoded, $index++))` statement returns the ASCII - // code for the character at $index. Subtract 63 to get the original - // value. (63 was added to ensure proper ASCII characters are displayed - // in the encoded polyline string, which is `human` readable) - $b = ord(substr($encoded, $index++)) - 63; - // AND the bits of the byte with 0x1f to get the original 5-bit `chunk. - // Then left shift the bits by the required amount, which increases - // by 5 bits each time. - // OR the value into $results, which sums up the individual 5-bit chunks - // into the original value. Since the 5-bit chunks were reversed in - // order during encoding, reading them in this way ensures proper - // summation. - $result|= ($b & 0x1f) << $shift; - $shift+= 5; - } - // Continue while the read byte is >= 0x20 since the last `chunk` - // was not OR'd with 0x20 during the conversion process. (Signals the end) - while ($b >= 0x20); - // Check if negative, and convert. (All negative values have the last bit - // set) - $dlat = (($result & 1) ? ~($result >> 1) : ($result >> 1)); - // Compute actual latitude since value is offset from previous value. - $lat+= $dlat; - // The next values will correspond to the longitude for this point. - $shift = 0; - $result = 0; - do { - $b = ord(substr($encoded, $index++)) - 63; - $result|= ($b & 0x1f) << $shift; - $shift+= 5; - } while ($b >= 0x20); - $dlng = (($result & 1) ? ~($result >> 1) : ($result >> 1)); - $lng+= $dlng; - // The actual latitude and longitude values were multiplied by - // 1e5 before encoding so that they could be converted to a 32-bit - // integer representation. (With a decimal accuracy of 5 places) - // Convert back to original values. - $points[] = array( - $lat * 1e-5, - $lng * 1e-5 - ); - } - return $points; + +function decodePolylineToArray($encoded) { + // source: http://latlongeeks.com/forum/viewtopic.php?f=4&t=5 + $length = strlen($encoded); + $index = 0; + $points = array(); + $lat = 0; + $lng = 0; + while ($index < $length) { + // Temporary variable to hold each ASCII byte. + $b = 0; + // The encoded polyline consists of a latitude value followed by a + // longitude value. They should always come in pairs. Read the + // latitude value first. + $shift = 0; + $result = 0; + do { + // The `ord(substr($encoded, $index++))` statement returns the ASCII + // code for the character at $index. Subtract 63 to get the original + // value. (63 was added to ensure proper ASCII characters are displayed + // in the encoded polyline string, which is `human` readable) + $b = ord(substr($encoded, $index++)) - 63; + // AND the bits of the byte with 0x1f to get the original 5-bit `chunk. + // Then left shift the bits by the required amount, which increases + // by 5 bits each time. + // OR the value into $results, which sums up the individual 5-bit chunks + // into the original value. Since the 5-bit chunks were reversed in + // order during encoding, reading them in this way ensures proper + // summation. + $result|= ($b & 0x1f) << $shift; + $shift+= 5; + } + // Continue while the read byte is >= 0x20 since the last `chunk` + // was not OR'd with 0x20 during the conversion process. (Signals the end) + while ($b >= 0x20); + // Check if negative, and convert. (All negative values have the last bit + // set) + $dlat = (($result & 1) ? ~($result >> 1) : ($result >> 1)); + // Compute actual latitude since value is offset from previous value. + $lat+= $dlat; + // The next values will correspond to the longitude for this point. + $shift = 0; + $result = 0; + do { + $b = ord(substr($encoded, $index++)) - 63; + $result|= ($b & 0x1f) << $shift; + $shift+= 5; + } while ($b >= 0x20); + $dlng = (($result & 1) ? ~($result >> 1) : ($result >> 1)); + $lng+= $dlng; + // The actual latitude and longitude values were multiplied by + // 1e5 before encoding so that they could be converted to a 32-bit + // integer representation. (With a decimal accuracy of 5 places) + // Convert back to original values. + $points[] = array( + $lat * 1e-5, + $lng * 1e-5 + ); + } + return $points; } -function geocode($query, $giveOptions) -{ - global $cloudmadeAPIkey; - $url = "http://geocoding.cloudmade.com/$cloudmadeAPIkey/geocoding/v2/find.js?query=" . urlencode($query) . "&bbox=-35.5,149.00,-35.15,149.1930&return_location=true&bbox_only=true"; - $contents = json_decode(getPage($url)); - if ($giveOptions) return $contents->features; - elseif (isset($contents->features[0]->centroid)) return $contents->features[0]->centroid->coordinates[0] . "," . $contents->features[0]->centroid->coordinates[1]; - else return ""; + +function geocode($query, $giveOptions) { + global $cloudmadeAPIkey; + $url = "http://geocoding.cloudmade.com/$cloudmadeAPIkey/geocoding/v2/find.js?query=" . urlencode($query) . "&bbox=-35.5,149.00,-35.15,149.1930&return_location=true&bbox_only=true"; + $contents = json_decode(getPage($url)); + if ($giveOptions) + return $contents->features; + elseif (isset($contents->features[0]->centroid)) + return $contents->features[0]->centroid->coordinates[0] . "," . $contents->features[0]->centroid->coordinates[1]; + else + return ""; } -function reverseGeocode($lat, $lng) -{ - global $cloudmadeAPIkey; - $url = "http://geocoding.cloudmade.com/$cloudmadeAPIkey/geocoding/v2/find.js?around=" . $lat . "," . $lng . "&distance=closest&object_type=road"; - $contents = json_decode(getPage($url)); - return $contents->features[0]->properties->name; + +function reverseGeocode($lat, $lng) { + global $cloudmadeAPIkey; + $url = "http://geocoding.cloudmade.com/$cloudmadeAPIkey/geocoding/v2/find.js?around=" . $lat . "," . $lng . "&distance=closest&object_type=road"; + $contents = json_decode(getPage($url)); + return $contents->features[0]->properties->name; } + ?> --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -1,64 +1,64 @@ -' . $pageTitle . ' +' . $pageTitle . ' - Canberra Bus Timetable - '; - if (isDebugServer()) { - $jqmcss = $labsPath . 'css/jquery.mobile-1.0b2.css'; - $jqjs = $labsPath . 'js/jquery-1.6.2.min.js'; - $jqmjs = $labsPath . 'js/jquery.mobile-1.0b2.js'; - } - else { - $jqmcss = "//code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css"; - $jqjs = "//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"; - $jqmjs = "//code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"; - } - echo ' - + '; + if (isDebugServer()) { + $jqmcss = $basePath . 'css/jquery.mobile-1.0b2.css'; + $jqjs = $basePath . 'js/jquery-1.6.2.min.js'; + $jqmjs = $basePath . 'js/jquery.mobile-1.0b2.js'; + } else { + $jqmcss = "//code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css"; + $jqjs = "//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"; + $jqmjs = "//code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"; + } + echo ' + - - - - - - + + + + + + '; - echo ''; - echo ''; - if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { - echo ' + echo ''; + echo ''; + if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { + echo ' '; - } - if ($geolocate) { - echo " "; - } - if (isAnalyticsOn()) echo ' + if (!isset($_SESSION['lat']) || $_SESSION['lat'] == "") + echo "geolocate();"; + echo " "; + } + if (isAnalyticsOn()) + echo ' "; - echo ' + echo ' '; - if ($opendiv) { - echo '
+ if ($opendiv) { + echo '
Back

' . $pageTitle . '

- Home + Home
'; - $overrides = getServiceOverride(); - if ($overrides['service_id']) { - if ($overrides['service_id'] == "noservice") { - echo '
Buses are not running today due to industrial action/public holiday. See Buses are not running today due to industrial action/public holiday. See http://www.action.act.gov.au for details.
'; - } - else { - echo '
Buses are running on an altered timetable today due to industrial action/public holiday. See http://www.action.act.gov.au for details.
'; - } - } - } -} -function include_footer() -{ - global $labsPath; - echo ''; - if (isAnalyticsOn()) { - echo ""; - $googleAnalyticsImageUrl = googleAnalyticsGetImageUrl(); - echo ''; - } - echo "\n
"; -} -function placeSettings() -{ - global $service_periods; - $geoerror = false; - $geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == ""; - - echo '
'; - if ($geoerror) { - echo 'Sorry, but your location could not currently be detected. + $googleAnalyticsImageUrl = googleAnalyticsGetImageUrl(); + echo ''; + } + echo "\n
"; +} + +function placeSettings() { + global $service_periods; + $geoerror = false; + $geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == ""; + + echo '
'; + if ($geoerror) { + echo 'Sorry, but your location could not currently be detected. Please allow location permission, wait for your location to be detected, or enter an address/co-ordinates in the box below.'; - } - echo '
'; - echo '
+ } + echo '
'; + echo '

Change Location...

@@ -203,11 +215,12 @@
'; } -function trackEvent($category, $action, $label = "", $value = - 1) -{ - if (isAnalyticsOn()) { - echo "\n"; - } -} + +function trackEvent($category, $action, $label = "", $value = - 1) { + if (isAnalyticsOn()) { + echo "\n"; + } +} + ?> --- a/include/common-transit.inc.php +++ b/include/common-transit.inc.php @@ -45,5 +45,216 @@ return ""; } } +if ($GTFSREnabled) { +$serviceAlertCause = Array( +"UNKNOWN_CAUSE" => "Unknown cause", +"OTHER_CAUSE" => "Other cause", +"TECHNICAL_PROBLEM" => "Technical problem", +"STRIKE" => "Strike", +"DEMONSTRATION" => "Demonstration", +"ACCIDENT" => "Accident", +"HOLIDAY" => "Holiday", +"WEATHER" => "Weather", +"MAINTENANCE" => "Maintenance", +"CONSTRUCTION" => "Construction", +"POLICE_ACTIVITY" => "Police activity", +"MEDICAL_EMERGENCY" => "Medical emergency" +); +$serviceAlertEffect = Array( +"NO_SERVICE" => "No service", +"REDUCED_SERVICE" => "Reduced service", +"SIGNIFICANT_DELAYS" => "Significant delays", +"DETOUR" => "Detour", +"ADDITIONAL_SERVICE" => "Additional service", +"MODIFIED_SERVICE" => "Modified service", +"OTHER_EFFECT" => "Other effect", +"UNKNOWN_EFFECT" => "Unknown effect", +"STOP_MOVED" => "Stop moved"); + +set_include_path(get_include_path() . PATH_SEPARATOR . $labsPath."lib/Protobuf-PHP/library/DrSlump/"); + +include_once("Protobuf.php"); +include_once("Protobuf/Message.php"); +include_once("Protobuf/Registry.php"); +include_once("Protobuf/Descriptor.php"); +include_once("Protobuf/Field.php"); + +include_once($labsPath."lib/Protobuf-PHP/gtfs-realtime.php"); +include_once("Protobuf/CodecInterface.php"); +include_once("Protobuf/Codec/PhpArray.php"); +include_once("Protobuf/Codec/Binary.php"); +include_once("Protobuf/Codec/Binary/Writer.php"); +include_once("Protobuf/Codec/Json.php"); + +function getServiceAlerts($filter_class = "", $filter_id = "") { +/* + + also need last modified epoch of client gtfs + + - add,remove,patch,inform (null) + - stop + - trip + - network + - classes (WHERE=) + - route (short_name or route_id) + - street + - stop + - trip + Currently support: + network inform + trip patch: stop remove + street inform: route inform, trip inform, stop inform + route patch: trip remove + */ + $fm = new transit_realtime\FeedMessage(); +$fh = new transit_realtime\FeedHeader(); +$fh->setGtfsRealtimeVersion(1); +$fh->setTimestamp(time()); +$fm->setHeader($fh); +foreach(getCurrentAlerts() as $alert) { +$fe = new transit_realtime\FeedEntity(); + $fe->setId($alert['id']); + $fe->setIsDeleted(false); + $alert = new transit_realtime\Alert(); + $tr = new transit_realtime\TimeRange(); + $tr->setStart($alert['start']); + $tr->setEnd($alert['end']); + $alert-> addActivePeriod($tr); + $informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']); + if (sizeof($informedEntities) >0) { + $informed = Array(); + $es = new transit_realtime\EntitySelector(); + if ($informedEntity['informed_class'] == "agency") { + $es->setAgencyId($informedEntity['informed_id']); + } + if ($informedEntity['informed_class'] == "stop") { + $es->setStopId($informedEntity['informed_id']); + } + if ($informedEntity['informed_class'] == "route") { + $es->setRouteId($informedEntity['informed_id']); + } + if ($informedEntity['informed_class'] == "trip") { + $td = new transit_realtime\TripDescriptor(); + $td->setTripId($informedEntity['informed_id']); + $es->setTrip($td); + } + $alert-> addInformedEntity($es); + } + $alert->setCause(constant("transit_realtime\Alert\Cause::".$alert['cause'])); + $alert->setEffect(constant("transit_realtime\Alert\Effect::".$alert['effect'])); + $tsUrl = new transit_realtime\TranslatedString(); + $tUrl = new transit_realtime\TranslatedString\Translation(); + $tUrl->setText($alert['url']); + $tUrl->setLanguage("en"); + $tsUrl->addTranslation($tUrl); + $alert->setUrl($tsUrl); + $tsHeaderText= new transit_realtime\TranslatedString(); + $tHeaderText = new transit_realtime\TranslatedString\Translation(); + $tHeaderText->setText($alert['header']); + $tHeaderText->setLanguage("en"); + $tsHeaderText->addTranslation($tHeaderText); + $alert->setHeaderText($tsHeaderText); + $tsDescriptionText= new transit_realtime\TranslatedString(); + $tDescriptionText = new transit_realtime\TranslatedString\Translation(); + $tDescriptionText->setText($alert['description']); + $tDescriptionText->setLanguage("en"); + $tsDescriptionText->addTranslation($tDescriptionText); + $alert->setDescriptionText($tsDescriptionText); + $fe->setAlert($alert); +$fm->addEntity($fe); +} +return $fm; +} +function getServiceAlertsAsArray($filter_class = "", $filter_id = "") { + $codec = new DrSlump\Protobuf\Codec\PhpArray(); + return $codec->encode(getServiceAlerts($filter_class, $filter_id)); +} + +function getServiceAlertsAsBinary($filter_class = "", $filter_id = "") { + $codec = new DrSlump\Protobuf\Codec\Binary(); + return $codec->encode(getServiceAlerts($filter_class, $filter_id)); +} + +function getServiceAlertsAsJSON($filter_class = "", $filter_id = "") { + $codec = new DrSlump\Protobuf\Codec\Json(); + return $codec->encode(getServiceAlerts($filter_class, $filter_id)); +} +function getServiceAlertsByClass() { + $return = Array(); + $alerts = getServiceAlertsAsArray("",""); + foreach ($alerts['entities'] as $entity) { + foreach ($entity['informed'] as $informed) { + foreach($informed as $key => $value){ + if (strpos("_id",$key) > 0) { + $parts = explode($key); + $class = $parts[0]; + $id = $value; + } + } + $return[$class][$id][] = $entity; + } + } +} + +function getTripUpdates($filter_class = "", $filter_id = "") { + $fm = new transit_realtime\FeedMessage(); +$fh = new transit_realtime\FeedHeader(); +$fh->setGtfsRealtimeVersion(1); +$fh->setTimestamp(time()); +$fm->setHeader($fh); +foreach(getCurrentAlerts() as $alert) { + $informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']); + $stops = Array(); + $routestrips = Array(); + if (sizeof($informedEntities) >0) { + if ($informedEntity['informed_class'] == "stop" && $informed["x-action"] == "remove") { + $stops[] = $informedEntity['informed_id']; + } + if (($informedEntity['informed_class'] == "route" || $informedEntity['informed_class'] == "trip") && $informed["x-action"] == "patch" ) { + $routestrips[] = Array( "id" => $informedEntity['informed_id'], + "type"=>$informedEntity['informed_class']); + } + } +foreach ($routestrips as $routetrip) { +$fe = new transit_realtime\FeedEntity(); + $fe->setId($alert['id'].$routetrip['id']); + $fe->setIsDeleted(false); + $tu = new transit_realtime\TripUpdate(); + $td = new transit_realtime\TripDescriptor(); + if ($routetrip['type'] == "route") { + $td->setRouteId($routetrip['id']); + } else if ($routetrip['type'] == "trip") { + $td->setTripId($routetrip['id']); + } + $tu->setTrip($td); + foreach ($stops as $stop) { + $stu = new transit_realtime\TripUpdate\StopTimeUpdate(); + $stu->setStopId($stop); + $stu->setScheduleRelationship(transit_realtime\TripUpdate\StopTimeUpdate\ScheduleRelationship::SKIPPED); + $tu->addStopTimeUpdate($stu); + } + $fe->setTripUpdate($tu); +$fm->addEntity($fe); +} + +} +return $fm; + +} +function getTripUpdatesAsArray($filter_class = "", $filter_id = "") { + $codec = new DrSlump\Protobuf\Codec\PhpArray(); + return $codec->encode(getTripUpdates($filter_class, $filter_id)); +} + +function getTripUpdatesAsBinary($filter_class = "", $filter_id = "") { + $codec = new DrSlump\Protobuf\Codec\Binary(); + return $codec->encode(getTripUpdates($filter_class, $filter_id)); +} + +function getTripUpdatesAsJSON($filter_class = "", $filter_id = "") { + $codec = new DrSlump\Protobuf\Codec\Json(); + return $codec->encode(getTripUpdates($filter_class, $filter_id)); +} +} ?> --- a/include/common.inc.php +++ b/include/common.inc.php @@ -1,38 +1,43 @@ \n"; -} -function isJQueryMobileDevice() -{ - // http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897 - $user_agent = $_SERVER['HTTP_USER_AGENT']; - return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5); -} -function isFastDevice() -{ - $ua = $_SERVER['HTTP_USER_AGENT']; - $fastDevices = Array( - "Mozilla/5.0 (X11;", - "Mozilla/5.0 (Windows;", - "Mozilla/5.0 (iP", - "Mozilla/5.0 (Linux; U; Android", - "Mozilla/4.0 (compatible; MSIE" - ); - $slowDevices = Array( - "J2ME", - "MIDP", - "Opera/", - "Mozilla/2.0 (compatible;", - "Mozilla/3.0 (compatible;" - ); - return true; -} -function array_flatten($a, $f = array()) -{ - if (!$a || !is_array($a)) return ''; - foreach ($a as $k => $v) { - if (is_array($v)) $f = array_flatten($v, $f); - else $f[$k] = $v; - } - return $f; -} -function remove_spaces($string) -{ - return str_replace(' ', '', $string); -} -function object2array($object) -{ - if (is_object($object)) { - foreach ($object as $key => $value) { - $array[$key] = $value; - } - } - else { - $array = $object; - } - return $array; -} -function startsWith($haystack, $needle, $case = true) -{ - if ($case) { - return (strcmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); - } - return (strcasecmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); -} - -function endsWith($haystack, $needle, $case = true) -{ - if ($case) { - return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); - } - return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); -} -function bracketsMeanNewLine($input) -{ - return str_replace(")", "
", str_replace("(", "
", $input)); -} -function sksort(&$array, $subkey = "id", $sort_ascending = false) -{ - if (count($array)) $temp_array[key($array) ] = array_shift($array); - foreach ($array as $key => $val) { - $offset = 0; - $found = false; - foreach ($temp_array as $tmp_key => $tmp_val) { - if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { - $temp_array = array_merge((array)array_slice($temp_array, 0, $offset) , array( - $key => $val - ) , array_slice($temp_array, $offset)); - $found = true; - } - $offset++; - } - if (!$found) $temp_array = array_merge($temp_array, array( - $key => $val - )); - } - if ($sort_ascending) $array = array_reverse($temp_array); - else $array = $temp_array; -} -function sktimesort(&$array, $subkey = "id", $sort_ascending = false) -{ - if (count($array)) $temp_array[key($array) ] = array_shift($array); - foreach ($array as $key => $val) { - $offset = 0; - $found = false; - foreach ($temp_array as $tmp_key => $tmp_val) { - if (!$found and strtotime($val[$subkey]) > strtotime($tmp_val[$subkey])) { - $temp_array = array_merge((array)array_slice($temp_array, 0, $offset) , array( - $key => $val - ) , array_slice($temp_array, $offset)); - $found = true; - } - $offset++; - } - if (!$found) $temp_array = array_merge($temp_array, array( - $key => $val - )); - } - if ($sort_ascending && isset($temp_array)) $array = array_reverse($temp_array); - else $array = $temp_array; -} -function r_implode( $glue, $pieces ) -{ - foreach( $pieces as $r_pieces ) - { - if( is_array( $r_pieces ) ) - { - $retVal[] = r_implode( $glue, $r_pieces ); - } - else - { - $retVal[] = $r_pieces; - } - } - return implode( $glue, $retVal ); -} +function isAnalyticsOn() { + $user_agent = $_SERVER['HTTP_USER_AGENT']; + return!isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) && + !preg_match('/baidu/i', $user_agent); +} + +function isDebug($debugReason = "other") { + global $debugOkay; + return in_array($debugReason, $debugOkay, false) && isDebugServer(); +} + +function debug($msg, $debugReason = "other") { + if (isDebug($debugReason)) + echo "\n\n"; +} + +function isJQueryMobileDevice() { + // http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897 + $user_agent = $_SERVER['HTTP_USER_AGENT']; + return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5); +} + +function isFastDevice() { + $ua = $_SERVER['HTTP_USER_AGENT']; + $fastDevices = Array( + "Mozilla/5.0 (X11;", + "Mozilla/5.0 (Windows;", + "Mozilla/5.0 (iP", + "Mozilla/5.0 (Linux; U; Android", + "Mozilla/4.0 (compatible; MSIE" + ); + $slowDevices = Array( + "J2ME", + "MIDP", + "Opera/", + "Mozilla/2.0 (compatible;", + "Mozilla/3.0 (compatible;" + ); + return true; +} + +function array_flatten($a, $f = array()) { + if (!$a || !is_array($a)) + return ''; + foreach ($a as $k => $v) { + if (is_array($v)) + $f = array_flatten($v, $f); + else + $f[$k] = $v; + } + return $f; +} + +function remove_spaces($string) { + return str_replace(' ', '', $string); +} + +function object2array($object) { + if (is_object($object)) { + foreach ($object as $key => $value) { + $array[$key] = $value; + } + } else { + $array = $object; + } + return $array; +} + +function startsWith($haystack, $needle, $case = true) { + if ($case) { + return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0); + } + return (strcasecmp(substr($haystack, 0, strlen($needle)), $needle) === 0); +} + +function endsWith($haystack, $needle, $case = true) { + if ($case) { + return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); + } + return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); +} + +function bracketsMeanNewLine($input) { + return str_replace(")", "", str_replace("(", "
", $input)); +} + +function sksort(&$array, $subkey = "id", $sort_ascending = false) { + if (count($array)) + $temp_array[key($array)] = array_shift($array); + foreach ($array as $key => $val) { + $offset = 0; + $found = false; + foreach ($temp_array as $tmp_key => $tmp_val) { + if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { + $temp_array = array_merge((array) array_slice($temp_array, 0, $offset), array( + $key => $val + ), array_slice($temp_array, $offset)); + $found = true; + } + $offset++; + } + if (!$found) + $temp_array = array_merge($temp_array, array( + $key => $val + )); + } + if ($sort_ascending) + $array = array_reverse($temp_array); + else + $array = $temp_array; +} + +function sktimesort(&$array, $subkey = "id", $sort_ascending = false) { + if (count($array)) + $temp_array[key($array)] = array_shift($array); + foreach ($array as $key => $val) { + $offset = 0; + $found = false; + foreach ($temp_array as $tmp_key => $tmp_val) { + if (!$found and strtotime($val[$subkey]) > strtotime($tmp_val[$subkey])) { + $temp_array = array_merge((array) array_slice($temp_array, 0, $offset), array( + $key => $val + ), array_slice($temp_array, $offset)); + $found = true; + } + $offset++; + } + if (!$found) + $temp_array = array_merge($temp_array, array( + $key => $val + )); + } + if ($sort_ascending && isset($temp_array)) + $array = array_reverse($temp_array); + else + $array = $temp_array; +} + +function r_implode($glue, $pieces) { + foreach ($pieces as $r_pieces) { + if (is_array($r_pieces)) { + $retVal[] = r_implode($glue, $r_pieces); + } else { + $retVal[] = $r_pieces; + } + } + return implode($glue, $retVal); +} + ?> --- a/include/db/route-dao.inc.php +++ b/include/db/route-dao.inc.php @@ -1,211 +1,222 @@ prepare($query); - $query->bindParam(":routeID", $routeID); - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - return $query->fetch(PDO::FETCH_ASSOC); -} + +{ + global $conn; + $query = "Select * from routes where route_id = :routeID LIMIT 1"; + debug($query, "database"); + $query = $conn -> prepare($query); + $query -> bindParam(":routeID", $routeID); + $query -> execute(); + if (!$query) { + databaseError($conn -> errorInfo()); + return Array(); + } + return $query -> fetch(PDO :: FETCH_ASSOC); + } function getRouteByFullName($routeFullName) -{ - global $conn; - $query = "Select * from routes where route_short_name||route_long_name = :routeFullName LIMIT 1"; - debug($query, "database"); - $query = $conn->prepare($query); - $query->bindParam(":routeFullName", $routeFullName); - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - return $query->fetch(PDO::FETCH_ASSOC); -} + +{ + global $conn; + $query = "Select * from routes where route_short_name||route_long_name = :routeFullName LIMIT 1"; + debug($query, "database"); + $query = $conn -> prepare($query); + $query -> bindParam(":routeFullName", $routeFullName); + $query -> execute(); + if (!$query) { + databaseError($conn -> errorInfo()); + return Array(); + } + return $query -> fetch(PDO :: FETCH_ASSOC); + } function getRoutes() -{ - global $conn; - $query = "Select * from routes order by route_short_name;"; - debug($query, "database"); - $query = $conn->prepare($query); - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - return $query->fetchAll(); -} + +{ + global $conn; + $query = "Select * from routes order by route_short_name;"; + debug($query, "database"); + $query = $conn -> prepare($query); + $query -> execute(); + if (!$query) { + databaseError($conn -> errorInfo()); + return Array(); + } + return $query -> fetchAll(); + } function getRoutesByNumber($routeNumber = "") -{ - global $conn; - if ($routeNumber != "") { - $query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes join trips on trips.route_id = + +{ + global $conn; + if ($routeNumber != "") { + $query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes join trips on trips.route_id = routes.route_id join stop_times on stop_times.trip_id = trips.trip_id where route_short_name = :routeNumber OR route_short_name LIKE :routeNumber2 order by route_short_name;"; - } - else { - $query = "SELECT DISTINCT route_short_name from routes order by route_short_name"; - } - debug($query, "database"); - $query = $conn->prepare($query); - if ($routeNumber != "") { - $query->bindParam(":routeNumber", $routeNumber); - $routeNumber2 = "% ".$routeNumber; - $query->bindParam(":routeNumber2", $routeNumber2); - } - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - return $query->fetchAll(); -} + } + else { + $query = "SELECT DISTINCT route_short_name from routes order by route_short_name"; + } + debug($query, "database"); + $query = $conn -> prepare($query); + if ($routeNumber != "") { + $query -> bindParam(":routeNumber", $routeNumber); + $routeNumber2 = "% " . $routeNumber; + $query -> bindParam(":routeNumber2", $routeNumber2); + } + $query -> execute(); + if (!$query) { + databaseError($conn -> errorInfo()); + return Array(); + } + return $query -> fetchAll(); + } function getRoutesByNumberSeries($routeNumberSeries = "") -{ - global $conn; - if (strlen($routeNumberSeries) == 1) { - return getRoutesByNumber($routeNumberSeries); - } - $seriesMin = substr($routeNumberSeries, 0, -1) . "0"; - $seriesMax = substr($routeNumberSeries, 0, -1) . "9"; - $query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes join trips on trips.route_id = + +{ + global $conn; + if (strlen($routeNumberSeries) == 1) { + return getRoutesByNumber($routeNumberSeries); + } + $seriesMin = substr($routeNumberSeries, 0, -1) . "0"; + $seriesMax = substr($routeNumberSeries, 0, -1) . "9"; + $query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes join trips on trips.route_id = routes.route_id join stop_times on stop_times.trip_id = trips.trip_id where to_number(route_short_name, 'FM999') between :seriesMin and :seriesMax OR route_short_name LIKE :routeNumberSeries order by route_short_name;"; - debug($query, "database"); - $query = $conn->prepare($query); - $query->bindParam(":seriesMin", $seriesMin); - $query->bindParam(":seriesMax", $seriesMax); - $routeNumberSeries = "% ".substr($routeNumberSeries, 0, -1)."%"; - $query->bindParam(":routeNumberSeries", $routeNumberSeries); - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - return $query->fetchAll(); -} + debug($query, "database"); + $query = $conn -> prepare($query); + $query -> bindParam(":seriesMin", $seriesMin); + $query -> bindParam(":seriesMax", $seriesMax); + $routeNumberSeries = "% " . substr($routeNumberSeries, 0, -1) . "%"; + $query -> bindParam(":routeNumberSeries", $routeNumberSeries); + $query -> execute(); + if (!$query) { + databaseError($conn -> errorInfo()); + return Array(); + } + return $query -> fetchAll(); + } function getRouteNextTrip($routeID) -{ - global $conn; - $query = "select * from routes join trips on trips.route_id = routes.route_id + +{ + global $conn; + $query = "select * from routes join trips on trips.route_id = routes.route_id join stop_times on stop_times.trip_id = trips.trip_id where arrival_time > :currentTime and routes.route_id = :routeID order by arrival_time limit 1"; - debug($query, "database"); - $query = $conn->prepare($query); - $query->bindParam(":currentTime", current_time()); - $query->bindParam(":routeID", $routeID); - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - $r = $query->fetch(PDO::FETCH_ASSOC); - - // past last trip of the day special case - if (sizeof($r) < 16) { - $query = "select * from routes join trips on trips.route_id = routes.route_id + debug($query, "database"); + $query = $conn -> prepare($query); + $query -> bindParam(":currentTime", current_time()); + $query -> bindParam(":routeID", $routeID); + $query -> execute(); + if (!$query) { + databaseError($conn -> errorInfo()); + return Array(); + } + $r = $query -> fetch(PDO :: FETCH_ASSOC); + + // past last trip of the day special case + if (sizeof($r) < 16) { + $query = "select * from routes join trips on trips.route_id = routes.route_id join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID order by arrival_time DESC limit 1"; - debug($query, "database"); - $query = $conn->prepare($query); - $query->bindParam(":routeID", $routeID); - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - - $r = $query->fetch(PDO::FETCH_ASSOC); - } - return $r; -} + debug($query, "database"); + $query = $conn -> prepare($query); + $query -> bindParam(":routeID", $routeID); + $query -> execute(); + if (!$query) { + databaseError($conn -> errorInfo()); + return Array(); + } +