<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
Licensed under the Apache License, Version 2.0 (the "License"); | Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. | you may not use this file except in compliance with the License. |
You may obtain a copy of the License at | You may obtain a copy of the License at |
http://www.apache.org/licenses/LICENSE-2.0 | http://www.apache.org/licenses/LICENSE-2.0 |
Unless required by applicable law or agreed to in writing, software | Unless required by applicable law or agreed to in writing, software |
distributed under the License is distributed on an "AS IS" BASIS, | distributed under the License is distributed on an "AS IS" BASIS, |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
See the License for the specific language governing permissions and | See the License for the specific language governing permissions and |
limitations under the License. | limitations under the License. |
*/ | */ |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
include_header("About", "about") | include_header("About", "about") |
?> | ?> |
<p> | <p> |
Busness Time - An ACT bus timetable webapp<br /> | Busness Time - An ACT bus timetable webapp<br /> |
Based on the maxious-canberra-transit-feed (<a | Based on the maxious-canberra-transit-feed (<a |
href="http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip">download</a>, | href="http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip">download</a>, |
last updated <?php echo date("F d Y.", @filemtime('cbrfeed.zip')); ?>)<br /> | last updated <?php echo date("F d Y.", @filemtime('cbrfeed.zip')); ?>)<br /> |
Source code for the <a | Source code for the <a |
href="https://github.com/maxious/ACTBus-data">transit | href="https://github.com/maxious/ACTBus-data">transit |
feed</a> and <a href="https://github.com/maxious/ACTBus-ui">this | feed</a> and <a href="https://github.com/maxious/ACTBus-ui">this |
site</a> available from github.<br /> | site</a> available from github.<br /> |
Uses jQuery Mobile, PHP, PostgreSQL, OpenTripPlanner, OpenLayers, OpenStreetMap, Cloudmade Geocoder and Tile Service<br /> | Uses jQuery Mobile, PHP, PostgreSQL, OpenTripPlanner, OpenLayers, OpenStreetMap, Cloudmade Geocoder and Tile Service<br /> |
Suburb Geocoding Based on <A href="http://www.abs.gov.au/AUSSTATS/abs@.nsf/Lookup/1270.0.55.003Main+Features1July%202011?OpenDocument">Australian Bureau of Statistics data.</a><br /> | Suburb Geocoding Based on <A href="http://www.abs.gov.au/AUSSTATS/abs@.nsf/Lookup/1270.0.55.003Main+Features1July%202011?OpenDocument">Australian Bureau of Statistics data.</a><br /> |
Street geocoding based on work by OpenStreetMap contributors<br> | Street geocoding based on work by OpenStreetMap contributors<br> |
<br /> | <br /> |
Feedback encouraged; contact maxious@lambdacomplex.org<br /> | Feedback encouraged; contact maxious@lambdacomplex.org<br /> |
<br /> | <br /> |
Some icons by Joseph Wain / glyphish.com<br /> | Some icons by Joseph Wain / glyphish.com<br /> |
Native clients also available for iPhone(<a href="http://itunes.apple.com/au/app/cbrtimetable/id444287349?mt=8">cbrTimetable by Sandor Kolotenko</a> | Native clients also available for iPhone(<a href="http://itunes.apple.com/au/app/cbrtimetable/id444287349?mt=8">cbrTimetable by Sandor Kolotenko</a> |
, <a href="http://itunes.apple.com/au/app/act-buses/id376634797?mt=8">ACT Buses by David Sullivan</a>) | , <a href="http://itunes.apple.com/au/app/act-buses/id376634797?mt=8">ACT Buses by David Sullivan</a>, <a href="http://itunes.apple.com/app/bus-trips-act/id489146525?mt=8">Bus Trips ACT by Molson Chengalath</a>) |
, Android (<a href="https://market.android.com/details?id=com.action">MyBus 2.0 by Imagine Team</a>, <A href="https://market.android.com/details?id=GetMe2CanberraFree.source">GetMe2 Canberra by | , Android (<a href="https://market.android.com/details?id=com.action">MyBus 2.0 by Imagine Team</a>, <A href="https://market.android.com/details?id=GetMe2CanberraFree.source">GetMe2 Canberra by |
Colin Thompson </a>) | Colin Thompson </a>) |
and Windows Phone 7 (<a href="http://www.windowsphone.com/en-AU/apps/d840375e-429c-4aa4-a358-80eec6ea9e66">TransHub Canberra by Soul Solutions</a>) Other web clients include <a href="http://canberra.itranzit.com/option.html">iTranzit</a>. | and Windows Phone 7 (<a href="http://www.windowsphone.com/en-AU/apps/d840375e-429c-4aa4-a358-80eec6ea9e66">TransHub Canberra by Soul Solutions</a>) Other web clients include <a href="http://canberra.itranzit.com/option.html">iTranzit</a>. |
<br /> | <br /> |
GTFS-realtime API: | GTFS-realtime API: |
Alerts and Trip Updates (but only Cancelled or Stop Skipped) | Alerts and Trip Updates (but only Cancelled or Stop Skipped) |
Default format binary Protocol Buffer but can get JSON by adding ?ascii=yes | Default format binary Protocol Buffer but can get JSON by adding ?ascii=yes |
<br /> | <br /> |
<br /> | <br /> |
<small>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. | <small>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, | Whilst every effort has been made to ensure the high quality and accuracy of the Site, the Author makes no warranty, |
express or implied concerning the topicality, correctness, completeness or quality of the information, which is provided | express or implied concerning the topicality, correctness, completeness or quality of the information, which is provided |
"as is". The Author expressly disclaims all warranties, including but not limited to warranties of fitness for a particular purpose and warranties of merchantability. | "as is". The Author expressly disclaims all warranties, including but not limited to warranties of fitness for a particular purpose and warranties of merchantability. |
All offers are not binding and without obligation. The Author expressly reserves the right, in his discretion, to suspend, | All offers are not binding and without obligation. The Author expressly reserves the right, in his discretion, to suspend, |
change, modify, add or remove portions of the Site and to restrict or terminate the use and accessibility of the Site | change, modify, add or remove portions of the Site and to restrict or terminate the use and accessibility of the Site |
without prior notice. </small> | without prior notice. </small> |
<?php | <?php |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
Licensed under the Apache License, Version 2.0 (the "License"); | Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. | you may not use this file except in compliance with the License. |
You may obtain a copy of the License at | You may obtain a copy of the License at |
http://www.apache.org/licenses/LICENSE-2.0 | http://www.apache.org/licenses/LICENSE-2.0 |
Unless required by applicable law or agreed to in writing, software | Unless required by applicable law or agreed to in writing, software |
distributed under the License is distributed on an "AS IS" BASIS, | distributed under the License is distributed on an "AS IS" BASIS, |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
See the License for the specific language governing permissions and | See the License for the specific language governing permissions and |
limitations under the License. | limitations under the License. |
*/ | */ |
function getRoute($routeID) { | function getRoute($routeID) { |
global $conn; | global $conn; |
$query = "Select * from routes where route_id = :routeID LIMIT 1"; | $query = "Select * from routes where route_id = :routeID LIMIT 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":routeID", $routeID); | $query->bindParam(":routeID", $routeID); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetch(PDO :: FETCH_ASSOC); | return $query->fetch(PDO :: FETCH_ASSOC); |
} | } |
function getRoutesByShortName($routeShortName) { | function getRoutesByShortName($routeShortName) { |
global $conn; | global $conn; |
$query = "Select distinct route_id, route_short_name from routes where route_short_name = :routeShortName"; | $query = "Select distinct route_id, route_short_name from routes where route_short_name = :routeShortName"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":routeShortName", $routeShortName); | $query->bindParam(":routeShortName", $routeShortName); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
function getRouteHeadsigns($routeID) { | function getRouteHeadsigns($routeID) { |
global $conn; | global $conn; |
$query = "select stops.stop_name, trip_headsign, direction_id,max(service_id) as service_id, count(*) | $query = "select stops.stop_name, trip_headsign, direction_id,max(service_id) as service_id, count(*) |
from routes join trips on trips.route_id = routes.route_id | from routes join trips on trips.route_id = routes.route_id |
join stop_times on stop_times.trip_id = trips.trip_id join stops on | join stop_times on stop_times.trip_id = trips.trip_id join stops on |
stop_times.stop_id = stops.stop_id where trips.route_id = :routeID | stop_times.stop_id = stops.stop_id where trips.route_id = :routeID |
and stop_times.stop_sequence = 1 group by stops.stop_name, trip_headsign, direction_id having count(*) > 2"; | and stop_times.stop_sequence = 1 group by stops.stop_name, trip_headsign, direction_id having count(*) > 2"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":routeID", $routeID); | $query->bindParam(":routeID", $routeID); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
function getRouteDescription($routeID, $directionID) { | function getRouteDescription($routeID, $directionID) { |
$trip = getRouteNextTrip($routeID, $directionID); | $trip = getRouteNextTrip($routeID, $directionID); |
$start = getTripStartingPoint($trip['trip_id']); | $start = getTripStartingPoint($trip['trip_id']); |
$end = getTripDestination($trip['trip_id']); | $end = getTripDestination($trip['trip_id']); |
return "From ".$start['stop_name']." to ".$end['stop_name']; | return "From ".$start['stop_name']." to ".$end['stop_name']; |
} | } |
function getRouteByFullName($routeFullName) { | function getRouteByFullName($routeFullName) { |
global $conn; | global $conn; |
$query = "Select * from routes where route_short_name||route_long_name = :routeFullName LIMIT 1"; | $query = "Select * from routes where route_short_name||route_long_name = :routeFullName LIMIT 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":routeFullName", $routeFullName); | $query->bindParam(":routeFullName", $routeFullName); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetch(PDO :: FETCH_ASSOC); | return $query->fetch(PDO :: FETCH_ASSOC); |
} | } |
function getRoutes() { | function getRoutes() { |
global $conn; | global $conn; |
$query = "Select * from routes order by route_short_name;"; | $query = "Select * from routes order by route_short_name;"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
function getRoutesByNumberSeries($routeNumberSeries = "") { | function getRoutesByNumberSeries($routeNumberSeries = "") { |
global $conn; | global $conn; |
if (strlen($routeNumberSeries) == 1) { | if (strlen($routeNumberSeries) == 1) { |
return getRoutesByNumber($routeNumberSeries); | return getRoutesByNumber($routeNumberSeries); |
} | } |
$seriesMin = substr($routeNumberSeries, 0, -1) . "0"; | $seriesMin = substr($routeNumberSeries, 0, -1) . "0"; |
$seriesMax = substr($routeNumberSeries, 0, -1) . "9"; | $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 = | $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;"; | 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"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":seriesMin", $seriesMin); | $query->bindParam(":seriesMin", $seriesMin); |
$query->bindParam(":seriesMax", $seriesMax); | $query->bindParam(":seriesMax", $seriesMax); |
$routeNumberSeries = "% " . substr($routeNumberSeries, 0, -1) . "%"; | $routeNumberSeries = "% " . substr($routeNumberSeries, 0, -1) . "%"; |
$query->bindParam(":routeNumberSeries", $routeNumberSeries); | $query->bindParam(":routeNumberSeries", $routeNumberSeries); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
function getRouteNextTrip($routeID, $directionID) { | function getRouteNextTrip($routeID, $directionID) { |
global $conn; | global $conn; |
$query = "select routes.route_id,direction_id,trips.trip_id,trip_headsign,departure_time from routes join trips on trips.route_id = routes.route_id | $query = "select routes.route_id,direction_id,trips.trip_id,trip_headsign,departure_time 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 between :currentTime and :futureTime | join stop_times on stop_times.trip_id = trips.trip_id where arrival_time between :currentTime and :futureTime |
and routes.route_id = :routeID and trips.direction_id = :directionID order by | and routes.route_id = :routeID and trips.direction_id = :directionID order by |
arrival_time limit 1"; | arrival_time limit 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":currentTime", current_time()); | $query->bindParam(":currentTime", current_time()); |
$futureTime = current_time(strtotime(current_time() ." +2h")); | $futureTime = current_time(strtotime(current_time() ." +2h")); |
if (date("h",strtotime(current_time()) > 22)) $futureTime = "23:59:59"; | if (date("h",strtotime(current_time()) > 22)) $futureTime = "23:59:59"; |
$query->bindParam(":futureTime", $futureTime); | $query->bindParam(":futureTime", $futureTime); |
$query->bindParam(":routeID", $routeID); | $query->bindParam(":routeID", $routeID); |
$query->bindParam(":directionID", $directionID); | $query->bindParam(":directionID", $directionID); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
$r = $query->fetch(PDO :: FETCH_ASSOC); | $r = $query->fetch(PDO :: FETCH_ASSOC); |
return $r; | return $r; |
} | } |
function getRouteFirstTrip($routeID,$directionID) { | function getRouteFirstTrip($routeID,$directionID) { |
global $conn; | global $conn; |
$query = "select * from routes join trips on trips.route_id = routes.route_id | $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 | join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID |
and trips.direction_id = :directionID order by | and trips.direction_id = :directionID order by |
arrival_time DESC limit 1"; | arrival_time DESC limit 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":routeID", $routeID); | $query->bindParam(":routeID", $routeID); |
$query->bindParam(":directionID", $directionID); | $query->bindParam(":directionID", $directionID); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
$r = $query->fetch(PDO :: FETCH_ASSOC); | $r = $query->fetch(PDO :: FETCH_ASSOC); |
return $r; | return $r; |
} | } |
function getRouteAtStop($routeID, $directionID, $stop_id) { | function getRouteAtStop($routeID, $directionID, $stop_id) { |
$nextTrip = getRouteNextTrip($routeID, $directionID); | $nextTrip = getRouteNextTrip($routeID, $directionID); |
if ($nextTrip['trip_id']) { | if ($nextTrip['trip_id']) { |
foreach (getTripStopTimes($nextTrip['trip_id']) as $tripStop) { | foreach (getTripStopTimes($nextTrip['trip_id']) as $tripStop) { |
if ($tripStop['stop_id'] == $stop_id) | if ($tripStop['stop_id'] == $stop_id) |
return $tripStop; | return $tripStop; |
} | } |
} | } |
return Array(); | return Array(); |
} | } |
function getRouteTrips($routeID, $directionID = "", $service_period = "") { | function getRouteTrips($routeID, $directionID = "", $service_period = "") { |
global $conn; | global $conn; |
if ($service_period == "") | if ($service_period == "") |
$service_period = service_period(); | $service_period = service_period(); |
$service_ids = service_ids($service_period); | $service_ids = service_ids($service_period); |
$sidA = $service_ids[0]; | $sidA = $service_ids[0]; |
$sidB = $service_ids[1]; | $sidB = $service_ids[1]; |
$directionSQL = ""; | $directionSQL = ""; |
if ($directionID != "") | if ($directionID != "") |
$directionSQL = " and direction_id = :directionID "; | $directionSQL = " and direction_id = :directionID "; |
$query = "select routes.route_id,trips.trip_id,service_id,arrival_time, stop_id, stop_sequence from routes join trips on trips.route_id = routes.route_id | $query = "select routes.route_id,trips.trip_id,service_id,arrival_time, stop_id, stop_sequence from routes join trips on trips.route_id = routes.route_id |
join stop_times on stop_times.trip_id = trips.trip_id where (service_id=:service_periodA OR service_id=:service_periodB) | join stop_times on stop_times.trip_id = trips.trip_id where (service_id=:service_periodA OR service_id=:service_periodB) |
AND (routes.route_id = :routeID) " . $directionSQL . " and stop_sequence = '1' order by | AND (routes.route_id = :routeID) " . $directionSQL . " and stop_sequence = '1' order by |
arrival_time "; | arrival_time "; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":routeID", $routeID); | $query->bindParam(":routeID", $routeID); |
$query->bindParam(":service_periodA", $sidA); | $query->bindParam(":service_periodA", $sidA); |
$query->bindParam(":service_periodB", $sidB); | $query->bindParam(":service_periodB", $sidB); |
if ($directionSQL != "") | if ($directionSQL != "") |
$query->bindParam(":directionID", $directionID); | $query->bindParam(":directionID", $directionID); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
function getRoutesByDestination($destination = "", $service_period = "") { | function getRoutesByDestination($destination = "", $service_period = "") { |
global $conn; | global $conn; |
if ($service_period == "") | if ($service_period == "") |
$service_period = service_period(); | $service_period = service_period(); |
$service_ids = service_ids($service_period); | $service_ids = service_ids($service_period); |
$sidA = $service_ids[0]; | $sidA = $service_ids[0]; |
$sidB = $service_ids[1]; | $sidB = $service_ids[1]; |
if ($destination != "") { | if ($destination != "") { |
$query = "SELECT DISTINCT trips.route_id,route_short_name,route_long_name, service_id | /* $query = "SELECT DISTINCT trips.route_id,route_short_name,route_long_name, service_id |
FROM stop_times join trips on trips.trip_id = | FROM stop_times join trips on trips.trip_id = |
stop_times.trip_id join routes on trips.route_id = routes.route_id | stop_times.trip_id join routes on trips.route_id = routes.route_id |
WHERE route_long_name = :destination AND (service_id=:service_periodA OR service_id=:service_periodB) | WHERE route_long_name = :destination AND (service_id=:service_periodA OR service_id=:service_periodB) |
order by route_short_name"; | order by route_short_name";*/ |
$query = "select route_id, direction_id, stop_name, b.trip_id, b.stop_sequence from (select route_id, direction_id, max(stop_sequence) as stop_sequence, max(a.trip_id) as trip_id from stop_times inner join (SELECT route_id, direction_id, max(trip_id) as trip_id | |
from trips group by route_id,direction_id) as a on stop_times.trip_id = a.trip_id group by route_id, direction_id) as b inner join stop_times on b.trip_id = stop_times.trip_id inner join stops on stop_times.stop_id = stops.stop_id where stop_times.stop_sequence = b.stop_sequence and stop_name = :destination order by route_id;"; | |
} else { | } else { |
$query = "SELECT DISTINCT route_long_name | $query = "select stop_name from (select route_id, direction_id, max(stop_sequence) as stop_sequence, max(a.trip_id) as trip_id from stop_times inner join (SELECT route_id, direction_id, max(trip_id) as trip_id |
FROM stop_times join trips on trips.trip_id = | from trips group by route_id,direction_id) as a on stop_times.trip_id = a.trip_id group by route_id, direction_id) as b inner join stop_times on b.trip_id = stop_times.trip_id inner join stops on stop_times.stop_id = stops.stop_id where stop_times.stop_sequence = b.stop_sequence group by stop_name order by stop_name;"; |
stop_times.trip_id join routes on trips.route_id = routes.route_id | } |
WHERE (service_id=:service_periodA OR service_id=:service_periodB) | debug($query, "database"); |
order by route_long_name"; | $query = $conn->prepare($query); |
} | |
debug($query, "database"); | //$query->bindParam(":service_periodA", $sidA); |
$query = $conn->prepare($query); | //$query->bindParam(":service_periodB", $sidB); |
$query->bindParam(":service_periodA", $sidA); | |
$query->bindParam(":service_periodB", $sidB); | |
if ($destination != "") | if ($destination != "") |
$query->bindParam(":destination", $destination); | $query->bindParam(":destination", $destination); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
function getRoutesBySuburb($suburb, $service_period = "") { | function getRoutesBySuburb($suburb, $service_period = "") { |
if ($service_period == "") | if ($service_period == "") |
$service_period = service_period(); | $service_period = service_period(); |
$service_ids = service_ids($service_period); | $service_ids = service_ids($service_period); |
$sidA = $service_ids[0]; | $sidA = $service_ids[0]; |
$sidB = $service_ids[1]; | $sidB = $service_ids[1]; |
global $conn; | global $conn; |
$query = "SELECT DISTINCT service_id,trips.route_id,route_short_name,route_long_name | $query = "SELECT DISTINCT service_id,trips.route_id,route_short_name,route_long_name |
FROM stop_times join trips on trips.trip_id = stop_times.trip_id | FROM stop_times join trips on trips.trip_id = stop_times.trip_id |
join routes on trips.route_id = routes.route_id | join routes on trips.route_id = routes.route_id |
join stops on stops.stop_id = stop_times.stop_id | join stops on stops.stop_id = stop_times.stop_id |
WHERE stop_desc LIKE :suburb AND (service_id=:service_periodA OR service_id=:service_periodB) | WHERE stop_desc LIKE :suburb AND (service_id=:service_periodA OR service_id=:service_periodB) |
ORDER BY route_short_name"; | ORDER BY route_short_name"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":service_periodA", $sidA); | $query->bindParam(":service_periodA", $sidA); |
$query->bindParam(":service_periodB", $sidB); | $query->bindParam(":service_periodB", $sidB); |
$suburb = "%Suburb: %" . $suburb . "%"; | $suburb = "%Suburb: %" . $suburb . "%"; |
$query->bindParam(":suburb", $suburb); | $query->bindParam(":suburb", $suburb); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
function getRoutesNearby($lat, $lng, $limit = "", $distance = 500) { | function getRoutesNearby($lat, $lng, $limit = "", $distance = 500) { |
if ($service_period == "") | if ($service_period == "") |
$service_period = service_period(); | $service_period = service_period(); |
$service_ids = service_ids($service_period); | $service_ids = service_ids($service_period); |
$sidA = $service_ids[0]; | $sidA = $service_ids[0]; |
$sidB = $service_ids[1]; | $sidB = $service_ids[1]; |
if ($limit != "") | if ($limit != "") |
$limitSQL = " LIMIT :limit "; | $limitSQL = " LIMIT :limit "; |
global $conn; | global $conn; |
$query = "SELECT service_id,trips.route_id,trips.direction_id,route_short_name,route_long_name,min(stops.stop_id) as stop_id, | $query = "SELECT service_id,trips.route_id,trips.direction_id,route_short_name,route_long_name,min(stops.stop_id) as stop_id, |
min(ST_Distance(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), FALSE)) as distance | min(ST_Distance(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), FALSE)) as distance |
FROM stop_times | FROM stop_times |
join trips on trips.trip_id = stop_times.trip_id | join trips on trips.trip_id = stop_times.trip_id |
join routes on trips.route_id = routes.route_id | join routes on trips.route_id = routes.route_id |
join stops on stops.stop_id = stop_times.stop_id | join stops on stops.stop_id = stop_times.stop_id |
WHERE (service_id=:service_periodA OR service_id=:service_periodB) | WHERE (service_id=:service_periodA OR service_id=:service_periodB) |
AND ST_DWithin(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), :distance, FALSE) | AND ST_DWithin(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), :distance, FALSE) |
group by service_id,trips.route_id,trips.direction_id,route_short_name,route_long_name | group by service_id,trips.route_id,trips.direction_id,route_short_name,route_long_name |
order by distance $limitSQL"; | order by distance $limitSQL"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":service_periodA", $sidA); | $query->bindParam(":service_periodA", $sidA); |
$query->bindParam(":service_periodB", $sidB); | $query->bindParam(":service_periodB", $sidB); |
$query->bindParam(":distance", $distance); | $query->bindParam(":distance", $distance); |
if ($limit != "") | if ($limit != "") |
$query->bindParam(":limit", $limit); | $query->bindParam(":limit", $limit); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
return $query->fetchAll(); | return $query->fetchAll(); |
} | } |
?> | ?> |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
Licensed under the Apache License, Version 2.0 (the "License"); | Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. | you may not use this file except in compliance with the License. |
You may obtain a copy of the License at | You may obtain a copy of the License at |
http://www.apache.org/licenses/LICENSE-2.0 | http://www.apache.org/licenses/LICENSE-2.0 |
Unless required by applicable law or agreed to in writing, software | Unless required by applicable law or agreed to in writing, software |
distributed under the License is distributed on an "AS IS" BASIS, | distributed under the License is distributed on an "AS IS" BASIS, |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
See the License for the specific language governing permissions and | See the License for the specific language governing permissions and |
limitations under the License. | limitations under the License. |
*/ | */ |
include ('../include/common.inc.php'); | include ('../include/common.inc.php'); |
include_header("MyWay Delta Calculate", "mywayDeltaCalc"); | include_header("MyWay Delta Calculate", "mywayDeltaCalc"); |
flush(); | flush(); |
ob_flush(); | ob_flush(); |
function abssort($a, $b) { | function abssort($a, $b) { |
if ($a['timeDiff'] == $b['timeDiff']) { | if ($a['timeDiff'] == $b['timeDiff']) { |
return 0; | return 0; |
} | } |
return (abs($a['timeDiff']) < abs($b['timeDiff'])) ? -1 : 1; | return (abs($a['timeDiff']) < abs($b['timeDiff'])) ? -1 : 1; |
} | } |
//collect all observation not in delta | //collect all observation not in delta |
$query = "select * from myway_observations INNER JOIN myway_stops | $query = "select * from myway_observations INNER JOIN myway_stops |
ON myway_observations.myway_stop=myway_stops.myway_stop INNER JOIN myway_routes | ON myway_observations.myway_stop=myway_stops.myway_stop INNER JOIN myway_routes |
ON myway_observations.myway_route=myway_routes.myway_route | ON myway_observations.myway_route=myway_routes.myway_route |
WHERE observation_id NOT IN | WHERE observation_id NOT IN |
( | ( |
SELECT observation_id | SELECT observation_id |
FROM myway_timingdeltas | FROM myway_timingdeltas |
)"; | )"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
$uncalcdObservations = $query->fetchAll(); | $uncalcdObservations = $query->fetchAll(); |
//Display count | //Display count |
echo "<h3>" . sizeof($uncalcdObservations) . " observations not yet processed</h2>"; | echo "<h3>" . sizeof($uncalcdObservations) . " observations not yet processed</h2>"; |
//foreach observation not in delta | //foreach observation not in delta |
foreach ($uncalcdObservations as $obsv) { | foreach ($uncalcdObservations as $obsv) { |
//var_dump($obsv); | //var_dump($obsv); |
echo "<h3>Observation {$obsv['observation_id']}:</h1> | echo "<h3>Observation {$obsv['observation_id']}:</h1> |
<small>{$obsv['myway_stop']} @ {$obsv['time']} on {$obsv['myway_route']}</small><br>"; | <small>{$obsv['myway_stop']} @ {$obsv['time']} on {$obsv['myway_route']}</small><br>"; |
// convert timestamp into time of day and date | // convert timestamp into time of day and date |
// timezones from http://www.postgresql.org/docs/8.0/static/datetime-keywords.html | // timezones from http://www.postgresql.org/docs/8.0/static/datetime-keywords.html |
$time = date("H:i:s", strtotime($obsv['time'])); | $time = date("H:i:s", strtotime($obsv['time'])); |
$time_tz = date("H:i:s", strtotime($obsv['time'])) . " AESST"; | $time_tz = date("H:i:s", strtotime($obsv['time'])) . " AESST"; |
$search_time = date("H:i:s", strtotime($obsv['time']) - (60 * 60)); // 30 minutes margin | $search_time = date("H:i:s", strtotime($obsv['time']) - (60 * 60)); // 30 minutes margin |
$date = date("c", strtotime($obsv['time'])); | $date = date("c", strtotime($obsv['time'])); |
$timing_period = service_period(strtotime($date)); | $timing_period = service_period(strtotime($date)); |
// little hack for public holidays nolonger active; weekdays and 900+ route numbers don't make sense | |
if ($timing_period == "weekday" && preg_match('/9../',$obsv["route_short_name"])) { | |
echo "Potential public holiday detected, trying Sunday timetable.<br>"; | |
$timing_period = "sunday"; | |
} | |
if (isset($obsv["stop_id"]) && $obsv["stop_id"] != "" && $obsv["stop_id"] != "*") { | if (isset($obsv["stop_id"]) && $obsv["stop_id"] != "" && $obsv["stop_id"] != "*") { |
$potentialStops = Array(getStop($obsv["stop_id"])); | $potentialStops = Array(getStop($obsv["stop_id"])); |
} else { | } else { |
echo "Potential stops are a bus station<br>"; | echo "No stop_id recorded for this stop_name, potential stops are a bus station<br>"; |
$potentialStops = getStops("", trim(str_replace(Array("Arrival","Arrivals","Arrive Platform 3 Set down only.","Arrive","Set Down Only"), "", $obsv["myway_stop"]))); | $potentialStops = getStops("", trim(str_replace(Array("Arrival","Arrivals","Arrive Platform 3 Set down only.","Arrive","Set Down Only"), "", $obsv["myway_stop"]))); |
} | } |
//:get myway_stops records | //:get myway_stops records |
//:search by starts with stopcode and starts with street if street is not null | //:search by starts with stopcode and starts with street if street is not null |
//no result, skip and display error | //no result, skip and display error |
if (sizeof($potentialStops) < 1) { | if (sizeof($potentialStops) < 1) { |
echo "error, potential stops for stopid {$obsv["stop_id"]} unknown"; | echo "error, potential stops for stopid {$obsv["stop_id"]} unknown"; |
continue; | continue; |
} | } |
//print out stops | //print out stops |
echo "Matched stops: "; | echo "Matched stops: "; |
foreach ($potentialStops as $potentialStop) { | foreach ($potentialStops as $potentialStop) { |
echo $potentialStop['stop_id'] . " " . $potentialStop['stop_name'] . " "; | echo $potentialStop['stop_id'] . " " . $potentialStop['stop_name'] . " "; |
} | } |
echo "<br>"; | echo "<br>"; |
//:get myway_route record | //:get myway_route record |
//no result, skip and display error | //no result, skip and display error |
//print out route | //print out route |
$potentialRoutes = getRoutesByShortName($obsv["route_short_name"]); | $potentialRoutes = getRoutesByShortName($obsv["route_short_name"]); |
if (sizeof($potentialRoutes) < 1) { | if (sizeof($potentialRoutes) < 1) { |
echo "error, route '{$obsv["myway_route"]}' unknown"; | echo "error, route '{$obsv["myway_route"]}' unknown"; |
continue; | continue; |
} | } |
$timeDeltas = Array(); | $timeDeltas = Array(); |
foreach ($potentialRoutes as $potentialRoute) { | foreach ($potentialRoutes as $potentialRoute) { |
echo "Matched route: {$potentialRoute['route_id']} {$potentialRoute['route_short_name']}{$potentialRoute['route_long_name']} {$timing_period}<br>"; | echo "Matched route: {$potentialRoute['route_id']} {$potentialRoute['route_short_name']}{$potentialRoute['route_long_name']} {$timing_period}<br>"; |
foreach ($potentialStops as $potentialStop) { | foreach ($potentialStops as $potentialStop) { |
$stopRoutes = getStopRoutes($potentialStop['stop_id'], $timing_period); | $stopRoutes = getStopRoutes($potentialStop['stop_id'], $timing_period); |
$foundRoute = Array(); | $foundRoute = Array(); |
foreach ($stopRoutes as $stopRoute) { | foreach ($stopRoutes as $stopRoute) { |
//Check if this route stops at each stop | //Check if this route stops at each stop |
if ($stopRoute['route_id'] == $potentialRoute['route_id']) { | if ($stopRoute['route_id'] == $potentialRoute['route_id']) { |
echo "Matching route {$stopRoute['route_id']} found at stop #{$potentialStop['stop_id']}<br>"; | echo "Matching route {$stopRoute['route_id']} found at stop #{$potentialStop['stop_id']}<br>"; |
$foundRoute = $stopRoute; | $foundRoute = $stopRoute; |
//if does get tripstoptimes for this route | //if does get tripstoptimes for this route |
$trips = getStopTrips($potentialStop['stop_id'], $timing_period, $search_time, 10, $potentialRoute['route_short_name']); | $trips = getStopTrips($potentialStop['stop_id'], $timing_period, $search_time, 10, $potentialRoute['route_short_name']); |
foreach ($trips as $trip) { | foreach ($trips as $trip) { |
//echo $trip['route_id']." ".$stopRoute['route_id'].";"; | //echo $trip['route_id']." ".$stopRoute['route_id'].";"; |
if ($trip['route_id'] == $stopRoute['route_id']) { | if ($trip['route_id'] == $stopRoute['route_id']) { |
$timedTrip = getTripAtStop($trip['trip_id'], $trip['stop_sequence']); | $timedTrip = getTripAtStop($trip['trip_id'], $trip['stop_sequence']); |
$actual_time = strtotime($time); | $actual_time = strtotime($time); |
$trip_time = strtotime($timedTrip['arrival_time']); | $trip_time = strtotime($timedTrip['arrival_time']); |
$timeDiff = $actual_time - $trip_time; | $timeDiff = $actual_time - $trip_time; |
//work out time delta, put into array with index of delta | //work out time delta, put into array with index of delta |
$timeDeltas[] = Array( | $timeDeltas[] = Array( |
"timeDiff" => $timeDiff, | "timeDiff" => $timeDiff, |
"stop_id" => $potentialStop['stop_id'], | "stop_id" => $potentialStop['stop_id'], |
"stop_sequence" => $trip['stop_sequence'], | "stop_sequence" => $trip['stop_sequence'], |
"route_name" => "{$trip['route_short_name']} {$trip['trip_headsign']}", | "route_name" => "{$trip['route_short_name']} {$trip['trip_headsign']}", |
"route_id" => $trip['route_id'] | "route_id" => $trip['route_id'] |
); | ); |
echo "Found trip {$trip['trip_id']} at stop {$potentialStop['stop_id']} (#{$potentialStop['stop_name']}, sequence #{$trip['stop_sequence']})<br>"; | echo "Found trip {$trip['trip_id']} at stop {$potentialStop['stop_id']} (#{$potentialStop['stop_name']}, sequence #{$trip['stop_sequence']})<br>"; |
echo "Arriving at {$timedTrip['arrival_time']}, difference of " . round($timeDiff / 60, 2) . " minutes<br>"; | echo "Arriving at {$timedTrip['arrival_time']}, difference of " . round($timeDiff / 60, 2) . " minutes<br>"; |
} else { | } else { |
echo "{$trip['route_id']} != {$stopRoute['route_id']}<br>"; | echo "{$trip['route_id']} != {$stopRoute['route_id']}<br>"; |
} | } |
} | } |
if (sizeof($timeDeltas) == 0) echo "Error, no trips found.<bR>"; | if (sizeof($timeDeltas) == 0) echo "Error, no trips found.<bR>"; |
break; // because have found route | break; // because have found route |
} | } |
} | } |
if (sizeof($foundRoute) < 1) { | if (sizeof($foundRoute) < 1) { |
//print out that stops/does not stop | //print out that stops/does not stop |
echo "No matching routes found at {$potentialStop['stop_id']}<br>"; | echo "No matching routes found at {$potentialStop['stop_id']}<br>"; |
//var_dump($stopRoutes); | //var_dump($stopRoutes); |
flush(); | flush(); |
} | } |
} | } |
} | } |
// lowest delta is recorded delta | // lowest delta is recorded delta |
usort($timeDeltas, "abssort"); | usort($timeDeltas, "abssort"); |
$lowestDelta = $timeDeltas[0]["timeDiff"]; | $lowestDelta = $timeDeltas[0]["timeDiff"]; |
if (sizeof($timeDeltas) != 0) { | if (sizeof($timeDeltas) != 0) { |
if (abs($lowestDelta) > 9999) { | if (abs($lowestDelta) > 9999) { |
echo "Difference of " . round($lowestDelta / 60, 2) . " minutes is too high. Will not record this observation<br>"; | echo "Difference of " . round($lowestDelta / 60, 2) . " minutes is too high. Will not record this observation<br>"; |
} else { | } else { |
echo "Lowest difference of " . round($lowestDelta / 60, 2) . " minutes will be recorded for this observation<br>"; | echo "Lowest difference of " . round($lowestDelta / 60, 2) . " minutes will be recorded for this observation<br>"; |
$observation_id = $obsv['observation_id']; | $observation_id = $obsv['observation_id']; |
$route_name = $timeDeltas[0]["route_name"]; | $route_name = $timeDeltas[0]["route_name"]; |
$route_id = $timeDeltas[0]["route_id"]; | $route_id = $timeDeltas[0]["route_id"]; |
$stop_id = $timeDeltas[0]["stop_id"]; | $stop_id = $timeDeltas[0]["stop_id"]; |
$myway_stop = $obsv["myway_stop"]; | $myway_stop = $obsv["myway_stop"]; |
$stop_sequence = $timeDeltas[0]["stop_sequence"]; | $stop_sequence = $timeDeltas[0]["stop_sequence"]; |
$stmt = $conn->prepare("insert into myway_timingdeltas (observation_id, route_id, stop_id, timing_delta, time, date, timing_period, stop_sequence,myway_stop,route_name) | $stmt = $conn->prepare("insert into myway_timingdeltas (observation_id, route_id, stop_id, timing_delta, time, date, timing_period, stop_sequence,myway_stop,route_name) |
values (:observation_id, :route_id, :stop_id, :timing_delta, :time, :date, :timing_period, :stop_sequence,:myway_stop,:route_name)"); | values (:observation_id, :route_id, :stop_id, :timing_delta, :time, :date, :timing_period, :stop_sequence,:myway_stop,:route_name)"); |
$stmt->bindParam(':observation_id', $observation_id); | $stmt->bindParam(':observation_id', $observation_id); |
$stmt->bindParam(':route_id', $route_id); | $stmt->bindParam(':route_id', $route_id); |
$stmt->bindParam(':route_name', $route_name); | $stmt->bindParam(':route_name', $route_name); |
$stmt->bindParam(':stop_id', $stop_id); | $stmt->bindParam(':stop_id', $stop_id); |
$stmt->bindParam(':myway_stop', $myway_stop); | $stmt->bindParam(':myway_stop', $myway_stop); |
$stmt->bindParam(':timing_delta', $lowestDelta); | $stmt->bindParam(':timing_delta', $lowestDelta); |
$stmt->bindParam(':time', $time_tz); | $stmt->bindParam(':time', $time_tz); |
$stmt->bindParam(':date', $date); | $stmt->bindParam(':date', $date); |
$stmt->bindParam(':timing_period', $timing_period); | $stmt->bindParam(':timing_period', $timing_period); |
$stmt->bindParam(':stop_sequence', $stop_sequence); | $stmt->bindParam(':stop_sequence', $stop_sequence); |
// insert a record | // insert a record |
$stmt->execute(); | $stmt->execute(); |
if ($stmt->rowCount() > 0) { | if ($stmt->rowCount() > 0) { |
echo "Recorded.<br>"; | echo "Recorded.<br>"; |
} | } |
var_dump($conn->errorInfo()); | var_dump($conn->errorInfo()); |
flush(); | flush(); |
} | } |
} | } |
flush(); | flush(); |
} | } |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
Licensed under the Apache License, Version 2.0 (the "License"); | Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. | you may not use this file except in compliance with the License. |
You may obtain a copy of the License at | You may obtain a copy of the License at |
http://www.apache.org/licenses/LICENSE-2.0 | http://www.apache.org/licenses/LICENSE-2.0 |
Unless required by applicable law or agreed to in writing, software | Unless required by applicable law or agreed to in writing, software |
distributed under the License is distributed on an "AS IS" BASIS, | distributed under the License is distributed on an "AS IS" BASIS, |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
See the License for the specific language governing permissions and | See the License for the specific language governing permissions and |
limitations under the License. | limitations under the License. |
*/ | */ |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
function navbar() { | function navbar() { |
echo ' | echo ' |
<div data-role="navbar"> | <div data-role="navbar"> |
<ul> | <ul> |
<li><a href="routeList.php">By Final Destination...</a></li> | <li><a href="routeList.php">By Final Destination...</a></li> |
<li><a href="routeList.php?bynumber=yes">By Number... </a></li> | <li><a href="routeList.php?bynumber=yes">By Number... </a></li> |
<li><a href="routeList.php?bysuburbs=yes">By Suburb... </a></li> | <li><a href="routeList.php?bysuburbs=yes">By Suburb... </a></li> |
<li><a href="routeList.php?nearby=yes">Nearby... </a></li> | <li><a href="routeList.php?nearby=yes">Nearby... </a></li> |
</ul> | </ul> |
</div> | </div> |
'; | '; |
} | } |
function displayRoutes($routes) { | function displayRoutes($routes) { |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
foreach ($routes as $route) { | foreach ($routes as $route) { |
foreach (getRouteHeadsigns($route['route_id']) as $headsign) { | foreach (getRouteHeadsigns($route['route_id']) as $headsign) { |
//print_r($route); | //print_r($route); |
echo '<li> <a href="trip.php?routeid=' . $route['route_id'] . '&directionid=' . $headsign['direction_id'] . '"><h3>' . $route['route_short_name'] . "</h3> | echo '<li> <a href="trip.php?routeid=' . $route['route_id'] . '&directionid=' . $headsign['direction_id'] . '"><h3>' . $route['route_id'] . "</h3> |
<p>" . $headsign['trip_headsign'] . (strstr($headsign['trip_headsign'], "bound") === false ? "bound" : "") . ", starting at " . $headsign['stop_name'] . " (" . ucwords($headsign['service_id']) . ")</p>"; | <p>" . $headsign['trip_headsign'] . (strstr($headsign['trip_headsign'], "bound") === false ? "bound" : "") . ", starting at " . $headsign['stop_name'] . " (" . ucwords($headsign['service_id']) . ")</p>"; |
echo" </a></li>\n"; | echo" </a></li>\n"; |
} | } |
} | } |
} | } |
function displayNearbyRoutes($routes) { | function displayNearbyRoutes($routes) { |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
foreach ($routes as $route) { | foreach ($routes as $route) { |
$time = getRouteAtStop($route['route_id'], $route['direction_id'], $route['stop_id']); | $time = getRouteAtStop($route['route_id'], $route['direction_id'], $route['stop_id']); |
$start = getTripStartingPoint($time['trip_id']); | $start = getTripStartingPoint($time['trip_id']); |
$end = getTripDestination($time['trip_id']); | $end = getTripDestination($time['trip_id']); |
//print_r($route); | //print_r($route); |
echo '<li> <a href="trip.php?routeid=' . $route['route_id'] . '&directionid=' . $route['direction_id'] . '"><h3>' . $route['route_short_name'] . "</h3> | echo '<li> <a href="trip.php?routeid=' . $route['route_id'] . '&directionid=' . $route['direction_id'] . '"><h3>' . $route['route_short_name'] . "</h3> |
<p>" . $time['trip_headsign'] . (strstr($time['trip_headsign'], "bound") === false ? "bound" : "") . " from ".$start['stop_name']." to ".$end['stop_name'] . " (" . ucwords($time['service_id']) . ")</p>"; | <p>" . $time['trip_headsign'] . (strstr($time['trip_headsign'], "bound") === false ? "bound" : "") . " from ".$start['stop_name']." to ".$end['stop_name'] . " (" . ucwords($time['service_id']) . ")</p>"; |
$stop = getStop($route['stop_id']); | $stop = getStop($route['stop_id']); |
echo "<p>Board at ".$stop['stop_name']."</p>"; | echo "<p>Board at ".$stop['stop_name']."</p>"; |
echo '<span class="ui-li-count">' . ($time['arrival_time'] ? $time['arrival_time'] : "No more trips today") . "<br>" . floor($route['distance']) . 'm away</span>'; | echo '<span class="ui-li-count">' . ($time['arrival_time'] ? $time['arrival_time'] : "No more trips today") . "<br>" . floor($route['distance']) . 'm away</span>'; |
echo" </a></li>\n"; | echo" </a></li>\n"; |
} | } |
} | } |
if (isset($bysuburbs)) { | if (isset($bysuburbs)) { |
include_header("Routes by Suburb", "routeList"); | include_header("Routes by Suburb", "routeList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
if (!isset($firstLetter)) { | if (!isset($firstLetter)) { |
foreach (range('A', 'Z') as $letter) { | foreach (range('A', 'Z') as $letter) { |
echo "<li><a href=\"routeList.php?firstLetter=$letter&bysuburbs=yes\">$letter...</a></li>\n"; | echo "<li><a href=\"routeList.php?firstLetter=$letter&bysuburbs=yes\">$letter...</a></li>\n"; |
} | } |
} else { | } else { |
foreach ($suburbs as $suburb) { | foreach ($suburbs as $suburb) { |
if (startsWith($suburb, $firstLetter)) { | if (startsWith($suburb, $firstLetter)) { |
echo '<li><a href="routeList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; | echo '<li><a href="routeList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; |
} | } |
} | } |
} | } |
echo '</ul>'; | echo '</ul>'; |
} else if (isset($suburb)) { | } else if (isset($suburb)) { |
if ($suburb) { | if ($suburb) { |
include_header($suburb . " - " . ucwords(service_period()), "routeList"); | include_header($suburb . " - " . ucwords(service_period()), "routeList"); |
navbar(); | navbar(); |
timeSettings(); | timeSettings(); |
trackEvent("Route Lists", "Routes By Suburb", $suburb); | trackEvent("Route Lists", "Routes By Suburb", $suburb); |
displayRoutes(getRoutesBySuburb($suburb)); | displayRoutes(getRoutesBySuburb($suburb)); |
} | } |
} else if (isset($nearby)) { | } else if (isset($nearby)) { |
$routes = Array(); | $routes = Array(); |
include_header("Routes Nearby", "routeList", true, true); | include_header("Routes Nearby", "routeList", true, true); |
trackEvent("Route Lists", "Routes Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']); | trackEvent("Route Lists", "Routes Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']); |
navbar(); | navbar(); |
placeSettings(); | placeSettings(); |
if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") { | if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") { |
include_footer(); | include_footer(); |
die(); | die(); |
} | } |
$routes = getRoutesNearby($_SESSION['lat'], $_SESSION['lon']); | $routes = getRoutesNearby($_SESSION['lat'], $_SESSION['lon']); |
if (sizeof($routes) > 0) { | if (sizeof($routes) > 0) { |
displayNearbyRoutes($routes); | displayNearbyRoutes($routes); |
} else { | } else { |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
echo "<li style='text-align: center;'> No routes nearby.</li>"; | echo "<li style='text-align: center;'> No routes nearby.</li>"; |
} | } |
} else if (isset($bynumber) || isset($numberSeries)) { | } else if (isset($bynumber) || isset($numberSeries)) { |
include_header("Routes by Number", "routeList"); | include_header("Routes by Number", "routeList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-inset="true">'; | echo ' <ul data-role="listview" data-inset="true">'; |
if (isset($bynumber)) { | if (isset($bynumber)) { |
$routes = getRoutes(); | $routes = getRoutes(); |
$routeSeries = Array(); | $routeSeries = Array(); |
$seriesRange = Array(); | $seriesRange = Array(); |
foreach ($routes as $key => $routeNumber) { | foreach ($routes as $key => $routeNumber) { |
foreach (explode(" ", $routeNumber['route_short_name']) as $routeNumber) { | foreach (explode(" ", $routeNumber['route_short_name']) as $routeNumber) { |
$seriesNum = substr($routeNumber, 0, -1) . "0"; | $seriesNum = substr($routeNumber, 0, -1) . "0"; |
if ($seriesNum == "0") | if ($seriesNum == "0") |
$seriesNum = $routeNumber; | $seriesNum = $routeNumber; |
$finalDigit = substr($routeNumber, sizeof($routeNumber) - 1, 1); | $finalDigit = substr($routeNumber, sizeof($routeNumber) - 1, 1); |
if (isset($seriesRange[$seriesNum])) { | if (isset($seriesRange[$seriesNum])) { |
if ($finalDigit < $seriesRange[$seriesNum]['max']) | if ($finalDigit < $seriesRange[$seriesNum]['max']) |
$seriesRange[$seriesNum]['max'] = $routeNumber; | $seriesRange[$seriesNum]['max'] = $routeNumber; |
if ($finalDigit > $seriesRange[$seriesNum]['min']) | if ($finalDigit > $seriesRange[$seriesNum]['min']) |
$seriesRange[$seriesNum]['min'] = $routeNumber; | $seriesRange[$seriesNum]['min'] = $routeNumber; |
} | } |
else { | else { |
$seriesRange[$seriesNum]['max'] = $routeNumber; | $seriesRange[$seriesNum]['max'] = $routeNumber; |
$seriesRange[$seriesNum]['min'] = $routeNumber; | $seriesRange[$seriesNum]['min'] = $routeNumber; |
} | } |
$routeSeries[$seriesNum][$seriesNum . "-" . $row[1] . "-" . $row[0]] = $row; | $routeSeries[$seriesNum][$seriesNum . "-" . $row[1] . "-" . $row[0]] = $row; |
} | } |
} | } |
ksort($routeSeries); | ksort($routeSeries); |
ksort($seriesRange); | ksort($seriesRange); |
foreach ($routeSeries as $series => $routes) { | foreach ($routeSeries as $series => $routes) { |
echo '<li><a href="' . curPageURL() . '/routeList.php?numberSeries=' . $series . '">'; | echo '<li><a href="' . curPageURL() . '/routeList.php?numberSeries=' . $series . '">'; |
if ($series <= 9) | if ($series <= 9) |
echo $series; | echo $series; |
else | else |
echo "{$seriesRange[$series]['min']}-{$seriesRange[$series]['max']}"; | echo "{$seriesRange[$series]['min']}-{$seriesRange[$series]['max']}"; |
echo "</a></li>\n"; | echo "</a></li>\n"; |
} | } |
} | } |
else if ($numberSeries) { | else if ($numberSeries) { |
displayRoutes(getRoutesByNumberSeries($numberSeries)); | displayRoutes(getRoutesByNumberSeries($numberSeries)); |
} | } |
} else { | } else { |
include_header("Routes by Destination", "routeList"); | include_header("Routes by Destination", "routeList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-inset="true">'; | echo ' <ul data-role="listview" data-inset="true">'; |
if (isset($routeDestination)) { | if (isset($routeDestination)) { |
displayRoutes(getRoutesByDestination($routeDestination)); | displayRoutes(getRoutesByDestination($routeDestination)); |
} else { | } else { |
foreach (getRoutesByDestination() as $destination) { | foreach (getRoutesByDestination() as $destination) { |
echo '<li><a href="' . curPageURL() . '/routeList.php?routeDestination=' . urlencode($destination['route_long_name']) . '">' . $destination['route_long_name'] . "... </a></li>\n"; | echo '<li><a href="' . curPageURL() . '/routeList.php?routeDestination=' . urlencode($destination['stop_name']) . '">' . $destination['stop_name'] . "... </a></li>\n"; |
} | } |
} | } |
} | } |
echo "</ul>\n"; | echo "</ul>\n"; |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
Licensed under the Apache License, Version 2.0 (the "License"); | Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. | you may not use this file except in compliance with the License. |
You may obtain a copy of the License at | You may obtain a copy of the License at |
http://www.apache.org/licenses/LICENSE-2.0 | http://www.apache.org/licenses/LICENSE-2.0 |
Unless required by applicable law or agreed to in writing, software | Unless required by applicable law or agreed to in writing, software |
distributed under the License is distributed on an "AS IS" BASIS, | distributed under the License is distributed on an "AS IS" BASIS, |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
See the License for the specific language governing permissions and | See the License for the specific language governing permissions and |
limitations under the License. | limitations under the License. |
*/ | */ |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
if ($stopid) | if ($stopid) |
$stop = getStop($stopid); | $stop = getStop($stopid); |
/* if ($stopcode != "" && $stop[5] != $stopcode) { | /* if ($stopcode != "" && $stop[5] != $stopcode) { |
$url = $APIurl . "/json/stopcodesearch?q=" . $stopcode; | $url = $APIurl . "/json/stopcodesearch?q=" . $stopcode; |
$stopsearch = json_decode(getPage($url)); | $stopsearch = json_decode(getPage($url)); |
$stopid = $stopsearch[0][0]; | $stopid = $stopsearch[0][0]; |
$url = $APIurl . "/json/stop?stop_id=" . $stopid; | $url = $APIurl . "/json/stop?stop_id=" . $stopid; |
$stop = json_decode(getPage($url)); | $stop = json_decode(getPage($url)); |
} | } |
if (!startsWith($stop[5], "Wj") && strpos($stop[1], "Platform") === false) { | if (!startsWith($stop[5], "Wj") && strpos($stop[1], "Platform") === false) { |
// expand out to all platforms | // expand out to all platforms |
} */ | } */ |
$stops = Array(); | $stops = Array(); |
$stopPositions = Array(); | $stopPositions = Array(); |
$stopNames = Array(); | $stopNames = Array(); |
$tripStopNumbers = Array(); | $tripStopNumbers = Array(); |
$allStopsTrips = Array(); | $allStopsTrips = Array(); |
$fetchedTripSequences = Array(); | $fetchedTripSequences = Array(); |
$stopLinks = ""; | $stopLinks = ""; |
if (isset($stopids)) { | if (isset($stopids)) { |
foreach ($stopids as $sub_stopid) { | foreach ($stopids as $sub_stopid) { |
$stops[] = getStop($sub_stopid); | $stops[] = getStop($sub_stopid); |
} | } |
$stop = $stops[0]; | $stop = $stops[0]; |
$stopid = $stops[0]["stop_id"]; | $stopid = $stops[0]["stop_id"]; |
$stopLinks.= "Individual stop pages: <br>"; | $stopLinks.= "Individual stop pages: <br>"; |
foreach ($stops as $key => $sub_stop) { | foreach ($stops as $key => $sub_stop) { |
$stopNames[$key] = $sub_stop["stop_name"]; | $stopNames[$key] = $sub_stop["stop_name"]; |
$stopLinks.= '<a href="stop.php?stopid=' . $sub_stop["stop_id"] . '&stopcode=' . $sub_stop["stop_code"] . '">' . $sub_stop["stop_name"] . '</a> '; | $stopLinks.= '<a href="stop.php?stopid=' . $sub_stop["stop_id"] . '&stopcode=' . $sub_stop["stop_code"] . '">' . $sub_stop["stop_name"] . '</a> '; |
$stopPositions[$key] = Array( | $stopPositions[$key] = Array( |
$sub_stop["stop_lat"], | $sub_stop["stop_lat"], |
$sub_stop["stop_lon"] | $sub_stop["stop_lon"] |
); | ); |
$trips = getStopTrips($sub_stop["stop_id"]); | $trips = getStopTrips($sub_stop["stop_id"]); |
$tripSequence = ""; | $tripSequence = ""; |
foreach ($trips as $trip) { | foreach ($trips as $trip) { |
$tripSequence.= "{$trip['trip_id']},"; | $tripSequence.= "{$trip['trip_id']},"; |
$tripStopNumbers[$trip['trip_id']][] = $key; | $tripStopNumbers[$trip['trip_id']][] = $key; |
} | } |
if (!in_array($tripSequence, $fetchedTripSequences)) { | if (!in_array($tripSequence, $fetchedTripSequences)) { |
// only fetch new trip sequences | // only fetch new trip sequences |
$fetchedTripSequences[] = $tripSequence; | $fetchedTripSequences[] = $tripSequence; |
$trips = getStopTripsWithTimes($sub_stop["stop_id"]); | $trips = getStopTripsWithTimes($sub_stop["stop_id"]); |
foreach ($trips as $trip) { | foreach ($trips as $trip) { |
if (!isset($allStopsTrips[$trip["trip_id"]])) | if (!isset($allStopsTrips[$trip["trip_id"]])) |
$allStopsTrips[$trip["trip_id"]] = $trip; | $allStopsTrips[$trip["trip_id"]] = $trip; |
} | } |
} | } |
//else { | //else { |
// echo "skipped sequence $tripSequence"; | // echo "skipped sequence $tripSequence"; |
//} | //} |
} | } |
} | } |
if (sizeof($stops) > 0) { | |
$stopDescParts = explode("<br>",$stop['stop_desc']); | $stopDescParts = explode("<br>",$stop['stop_desc']); |
include_header(trim(str_replace("Street: ","",$stopDescParts[0])), "stop"); | include_header(trim(str_replace("Street: ","",$stopDescParts[0])), "stop"); |
} else { | |
include_header($stop['stop_name']); | |
} | |
/* $serviceAlerts = json_decode(getPage(curPageURL() . "/servicealerts_api.php?filter_class=stop&filter_id=".$stopid) , true); | /* $serviceAlerts = json_decode(getPage(curPageURL() . "/servicealerts_api.php?filter_class=stop&filter_id=".$stopid) , true); |
foreach($serviceAlerts['entities'] as $serviceAlert) { | foreach($serviceAlerts['entities'] as $serviceAlert) { |
echo '<div id="servicewarning">'.$serviceAlert['alert']['description']['translation'].'</div>'; | echo '<div id="servicewarning">'.$serviceAlert['alert']['description']['translation'].'</div>'; |
} */ | } */ |
echo '<span class="content-secondary">'; | echo '<span class="content-secondary">'; |
echo $stopLinks; | echo $stopLinks; |
if (sizeof($stops) > 0) { | if (sizeof($stops) > 0) { |
trackEvent("View Stops", "View Combined Stops", $stop["stop_name"], $stop["stop_id"]); | trackEvent("View Stops", "View Combined Stops", $stop["stop_name"], $stop["stop_id"]); |
echo staticmap($stopPositions); | echo staticmap($stopPositions); |
} else { | } else { |
trackEvent("View Stops", "View Single Stop", $stop["stop_name"], $stop["stop_id"]); | trackEvent("View Stops", "View Single Stop", $stop["stop_name"], $stop["stop_id"]); |
echo staticmap(Array( | echo staticmap(Array( |
0 => Array( | 0 => Array( |
$stop["stop_lat"], | $stop["stop_lat"], |
$stop["stop_lon"] | $stop["stop_lon"] |
) | ) |
)); | )); |
} | } |
timeSettings(); | timeSettings(); |
echo '</span><span class="content-primary">'; | echo '</span><span class="content-primary">'; |
echo ' <ul data-role="listview" data-inset="true">'; | echo ' <ul data-role="listview" data-inset="true">'; |
if (sizeof($allStopsTrips) > 0) { | if (sizeof($allStopsTrips) > 0) { |
sktimesort($allStopsTrips, "arrival_time", true); | sktimesort($allStopsTrips, "arrival_time", true); |
$trips = $allStopsTrips; | $trips = $allStopsTrips; |
} else { | } else { |
$trips = getStopTripsWithTimes($stopid); | $trips = getStopTripsWithTimes($stopid); |
} | } |
echo "<div class='ui-header' style='overflow: visible; height: 2.5em'>"; | echo "<div class='ui-header' style='overflow: visible; height: 2.5em'>"; |
// if we have too many trips, cut down to size. | // if we have too many trips, cut down to size. |
if (sizeof($trips) > 10) { | if (sizeof($trips) > 10) { |
$trips = array_splice($trips, 0,10); | $trips = array_splice($trips, 0,10); |
} | } |
// later/earlier button setup | // later/earlier button setup |
if (sizeof($trips) == 0) { | if (sizeof($trips) == 0) { |
$time = isset($_REQUEST['time']) ? strtotime($_REQUEST['time']) : time(); | $time = isset($_REQUEST['time']) ? strtotime($_REQUEST['time']) : time(); |
$earlierTime = $time - (90 * 60); | $earlierTime = $time - (90 * 60); |
$laterTime = $time + (90 * 60); | $laterTime = $time + (90 * 60); |
} else { | } else { |
$tripsKeys = array_keys($trips); | $tripsKeys = array_keys($trips); |
$earlierTime = strtotime($trips[$tripsKeys[0]]['arrival_time']) - (90 * 60); | $earlierTime = strtotime($trips[$tripsKeys[0]]['arrival_time']) - (90 * 60); |
$laterTime = strtotime($trips[$tripsKeys[sizeof($trips) - 1]]['arrival_time']) - 60; | $laterTime = strtotime($trips[$tripsKeys[sizeof($trips) - 1]]['arrival_time']) - 60; |
} | } |
if (sizeof($stopids) > 0) { | if (sizeof($stopids) > 0) { |
$stopidurl = "stopids=" . implode(",", $stopids); | $stopidurl = "stopids=" . implode(",", $stopids); |
} else { | } else { |
$stopidurl = "stopid=$stopid"; | $stopidurl = "stopid=$stopid"; |
} | } |
if (sizeof($trips) >= 10) { | if (sizeof($trips) >= 10) { |
echo '<a href="stop.php?' . $stopidurl . '&service_period=' . service_period() . '&time=' . date("H:i", $laterTime) . '" data-icon="arrow-r" class="ui-btn-right">Later Trips</a>'; | echo '<a href="stop.php?' . $stopidurl . '&service_period=' . service_period() . '&time=' . date("H:i", $laterTime) . '" data-icon="arrow-r" class="ui-btn-right">Later Trips</a>'; |
} | } |
echo '<a href="stop.php?' . $stopidurl . '&service_period=' . service_period() . '&time=' . date("H:i", $earlierTime) . '" data-icon="arrow-l" class="ui-btn-left">Earlier Trips</a>'; | echo '<a href="stop.php?' . $stopidurl . '&service_period=' . service_period() . '&time=' . date("H:i", $earlierTime) . '" data-icon="arrow-l" class="ui-btn-left">Earlier Trips</a>'; |
echo "</div>"; | echo "</div>"; |
if (sizeof($trips) == 0) { | if (sizeof($trips) == 0) { |
echo "<li style='text-align: center;'>No trips in the near future.</li>"; | echo "<li style='text-align: center;'>No trips in the near future.</li>"; |
} else { | } else { |
foreach ($trips as $trip) { | foreach ($trips as $trip) { |
echo '<li>'; | echo '<li>'; |
$destination = getTripDestination($trip['trip_id']); | $destination = getTripDestination($trip['trip_id']); |
echo '<a href="trip.php?stopid=' . $stopid . '&tripid=' . $trip['trip_id'] . '"><h3>'. $trip['route_short_name'] . " towards " . $destination['stop_name'] . "</h3><p>"; | echo '<a href="trip.php?stopid=' . $stopid . '&tripid=' . $trip['trip_id'] . '"><h3>'. $trip['route_short_name'] . " towards " . $destination['stop_name'] . "</h3><p>"; |
$viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); | $viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); |
if ($viaPoints != "") | if ($viaPoints != "") |
echo '<br><span class="viaPoints">Via: ' . $viaPoints . '</span>'; | echo '<br><span class="viaPoints">Via: ' . $viaPoints . '</span>'; |
if (sizeof($tripStopNumbers) > 0) { | if (sizeof($tripStopNumbers) > 0) { |
echo '<br><small>Boarding At: '; | echo '<br><small>Boarding At: '; |
if (sizeof($tripStopNumbers[$trip['trip_id']]) == sizeof($stopids)) { | if (sizeof($tripStopNumbers[$trip['trip_id']]) == sizeof($stopids)) { |
echo "All Stops"; | echo "All Stops"; |
} else { | } else { |
foreach ($tripStopNumbers[$trip['trip_id']] as $key) { | foreach ($tripStopNumbers[$trip['trip_id']] as $key) { |
echo $stopNames[$key] . ', '; | echo $stopNames[$key] . ', '; |
} | } |
} | } |
echo '</small>'; | echo '</small>'; |
} | } |
echo '</p>'; | echo '</p>'; |
echo '<p class="ui-li-aside"><strong>' . $trip['arrival_time'] . '</strong></p>'; | echo '<p class="ui-li-aside"><strong>' . $trip['arrival_time'] . '</strong></p>'; |
echo '</a></li>'; | echo '</a></li>'; |
flush(); | flush(); |
@ob_flush(); | @ob_flush(); |
} | } |
} | } |
echo '</ul>'; | echo '</ul>'; |
echo '</span>'; | echo '</span>'; |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
/* | /* |
* Copyright 2010,2011 Alexander Sadleir | * Copyright 2010,2011 Alexander Sadleir |
Licensed under the Apache License, Version 2.0 (the "License"); | Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. | you may not use this file except in compliance with the License. |
You may obtain a copy of the License at | You may obtain a copy of the License at |
http://www.apache.org/licenses/LICENSE-2.0 | http://www.apache.org/licenses/LICENSE-2.0 |
Unless required by applicable law or agreed to in writing, software | Unless required by applicable law or agreed to in writing, software |
distributed under the License is distributed on an "AS IS" BASIS, | distributed under the License is distributed on an "AS IS" BASIS, |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
See the License for the specific language governing permissions and | See the License for the specific language governing permissions and |
limitations under the License. | limitations under the License. |
*/ | */ |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
$stops = Array(); | $stops = Array(); |
function navbar() { | function navbar() { |
echo ' | echo ' |
<div data-role="navbar"> | <div data-role="navbar"> |
<ul> | <ul> |
<li><a href="stopList.php">Stops by Name</a></li> | <li><a href="stopList.php">Stops by Name</a></li> |
<li><a href="stopList.php?bysuburbs=yes">By Suburb</a></li> | <li><a href="stopList.php?bysuburbs=yes">By Suburb</a></li> |
<li><a href="stopList.php?nearby=yes">Nearby Stops</a></li> | <li><a href="stopList.php?nearby=yes">Nearby Stops</a></li> |
</ul> | </ul> |
</div> | </div> |
'; | '; |
} | } |
// By suburb | // By suburb |
if (isset($bysuburbs)) { | if (isset($bysuburbs)) { |
include_header("Stops by Suburb", "stopList"); | include_header("Stops by Suburb", "stopList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
if (!isset($firstLetter)) { | if (!isset($firstLetter)) { |
foreach (range('A', 'Z') as $letter) { | foreach (range('A', 'Y') as $letter) { // no suburbs start with J, Q, U, V, X or Z |
echo "<li><a href=\"stopList.php?firstLetter=$letter&bysuburbs=yes\">$letter...</a></li>\n"; | if ($letter != "J" && $letter != "Q" && $letter != "U" && $letter != "V" && $letter != "X") echo "<li><a href=\"stopList.php?firstLetter=$letter&bysuburbs=yes\">$letter...</a></li>\n"; |
} | } |
} else { | } else { |
foreach ($suburbs as $suburb) { | foreach ($suburbs as $suburb) { |
if (startsWith($suburb, $firstLetter)) { | if (startsWith($suburb, $firstLetter)) { |
echo '<li><a href="stopList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; | echo '<li><a href="stopList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; |
} | } |
} | } |
} | } |
echo '</ul>'; | echo '</ul>'; |
} else { | } else { |
// Timing Points / All stops | // Timing Points / All stops |
if (isset($nearby)) { | if (isset($nearby)) { |
$listType = 'nearby=yes'; | $listType = 'nearby=yes'; |
include_header("Nearby Stops", "stopList", true, true); | include_header("Nearby Stops", "stopList", true, true); |
trackEvent("Stop Lists", "Stops Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']); | trackEvent("Stop Lists", "Stops Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']); |
navbar(); | navbar(); |
if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") { | if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") { |
placeSettings(); | placeSettings(); |
include_footer(); | include_footer(); |
die(); | die(); |
} | } |
$stops = getNearbyStops($_SESSION['lat'], $_SESSION['lon'], 15); | $stops = getNearbyStops($_SESSION['lat'], $_SESSION['lon'], 15); |
echo '<span class="content-secondary">'; | echo '<span class="content-secondary">'; |
$stopPositions[] = Array( | $stopPositions[] = Array( |
$_SESSION['lat'], | $_SESSION['lat'], |
$_SESSION['lon'] | $_SESSION['lon'] |
); | ); |
foreach ($stops as $sub_stop) { | foreach ($stops as $sub_stop) { |
$stopPositions[] = Array( | $stopPositions[] = Array( |
$sub_stop["stop_lat"], | $sub_stop["stop_lat"], |
$sub_stop["stop_lon"] | $sub_stop["stop_lon"] |
); | ); |
} | } |
echo staticmap($stopPositions, true, true); | echo staticmap($stopPositions, true, true); |
placeSettings(); | placeSettings(); |
echo '</span><span class="content-primary">'; | echo '</span><span class="content-primary">'; |
} else if (isset($suburb)) { | } else if (isset($suburb)) { |
$stops = getStopsBySuburb($suburb); | $stops = getStopsBySuburb($suburb); |
include_header("Stops in " . ucwords($suburb), "stopList"); | include_header("Stops in " . ucwords($suburb), "stopList"); |
navbar(); | navbar(); |
trackEvent("Stop Lists", "Stops By Suburb", $suburb); | trackEvent("Stop Lists", "Stops By Suburb", $suburb); |
} else { | } else { |
$listType = 'allstops=yes'; | $listType = 'allstops=yes'; |
$stops = getStops($firstLetter); | $stops = getStops($firstLetter); |
include_header("Stops by Name", "stopList"); | include_header("Stops by Name", "stopList"); |
navbar(); | navbar(); |
} | } |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
if (!isset($firstLetter) && !isset($suburb) && !isset($nearby)) { | if (!isset($firstLetter) && !isset($suburb) && !isset($nearby)) { // all stops by letter |
foreach (range('A', 'Z') as $letter) { | foreach (range('A', 'Y') as $letter) { // no streets start with X or Z |
echo "<li><a href=\"stopList.php?firstLetter=$letter&$listType\">$letter...</a></li>\n"; | if ($letter != "X") echo "<li><a href=\"stopList.php?firstLetter=$letter&$listType\">$letter...</a></li>\n"; |
} | } |
} else { | } else { |
//var_dump($stops); | //var_dump($stops); |
$stopsGrouped = Array(); | $stopsGrouped = Array(); |
foreach ($stops as $key => $stop) { | foreach ($stops as $key => $stop) { |
if (stopCompare($stops[$key]["stop_name"]) | if (stopCompare($stops[$key]["stop_name"]) |
!= stopCompare($stops[$key + 1]["stop_name"]) | != stopCompare($stops[$key + 1]["stop_name"]) |
|| $key + 1 >= sizeof($stops)) { | || $key + 1 >= sizeof($stops)) { |
if (sizeof($stopsGrouped) > 0) { | if (sizeof($stopsGrouped) > 0) { |
// print and empty grouped stops | // print and empty grouped stops |
// subsequent duplicates | // subsequent duplicates |
$stopsGrouped["stop_ids"][] = $stop['stop_id']; | $stopsGrouped["stop_ids"][] = $stop['stop_id']; |
echo '<li>'; | echo '<li>'; |
echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '&stopcodes=' . implode(",", $stopsGrouped['stop_codes']) . '">'; | echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '&stopcodes=' . implode(",", $stopsGrouped['stop_codes']) . '">'; |
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { | if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { |
echo '<span class="ui-li-count">' . distance($stop['stop_lat'], $stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; | echo '<span class="ui-li-count">' . distance($stop['stop_lat'], $stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; |
} | } |
echo stopGroupTitle($stop['stop_name'],$stop['stop_desc']) . '<br><small>' . sizeof($stopsGrouped["stop_ids"]) . ' stops</small>'; | echo stopGroupTitle($stop['stop_name'],$stop['stop_desc']) . '<br><small>' . sizeof($stopsGrouped["stop_ids"]) . ' stops</small>'; |
echo "</a></li>\n"; | echo "</a></li>\n"; |
flush(); | flush(); |
@ob_flush(); | @ob_flush(); |
$stopsGrouped = Array(); | $stopsGrouped = Array(); |
} else { | } else { |
// just a normal stop | // just a normal stop |
echo '<li>'; | echo '<li>'; |
echo '<a href="stop.php?stopid=' . $stop['stop_id'] . '&stopcode=' . $stop['stop_code'] . '">'; | echo '<a href="stop.php?stopid=' . $stop['stop_id'] . '&stopcode=' . $stop['stop_code'] . '">'; |
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { | if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { |
echo '<span class="ui-li-count">' . distance($stop['stop_lat'], $stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; | echo '<span class="ui-li-count">' . distance($stop['stop_lat'], $stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; |
} | } |
echo $stop['stop_name']; | echo $stop['stop_name']; |
echo "</a></li>\n"; | echo "</a></li>\n"; |
flush(); | flush(); |
@ob_flush(); | @ob_flush(); |
} | } |
} else { | } else { |
// this is a duplicated line item | // this is a duplicated line item |
if ($key - 1 <= 0 || stopCompare($stops[$key]['stop_name']) != stopCompare($stops[$key - 1]['stop_name'])) { | if ($key - 1 <= 0 || stopCompare($stops[$key]['stop_name']) != stopCompare($stops[$key - 1]['stop_name'])) { |
// first duplicate | // first duplicate |
$stopsGrouped = Array( | $stopsGrouped = Array( |
"name" => trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])), | "name" => trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])), |
"stop_ids" => Array( | "stop_ids" => Array( |
$stop['stop_id'] | $stop['stop_id'] |
), | ), |
"stop_codes" => Array( | "stop_codes" => Array( |
$stop['stop_code'] | $stop['stop_code'] |
) | ) |
); | ); |
} else { | } else { |
// subsequent duplicates | // subsequent duplicates |
$stopsGrouped["stop_ids"][] = $stop['stop_id']; | $stopsGrouped["stop_ids"][] = $stop['stop_id']; |
} | } |
} | } |
} | } |
} | } |
echo '</ul>'; | echo '</ul>'; |
if (isset($nearby)) | if (isset($nearby)) |
echo '</span>'; | echo '</span>'; |
} | } |
include_footer(); | include_footer(); |
?> | ?> |