<?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. |
*/ | */ |
if (isset($_REQUEST['firstLetter'])) { | if (isset($_REQUEST['firstLetter'])) { |
$firstLetter = filter_var($_REQUEST['firstLetter'], FILTER_SANITIZE_STRING); | $firstLetter = filter_var($_REQUEST['firstLetter'], FILTER_SANITIZE_STRING); |
} | } |
if (isset($_REQUEST['bysuburbs'])) { | if (isset($_REQUEST['bysuburbs'])) { |
$bysuburbs = true; | $bysuburbs = true; |
} | } |
if (isset($_REQUEST['bynumber'])) { | if (isset($_REQUEST['bynumber'])) { |
$bynumber = true; | $bynumber = true; |
} | } |
if (isset($_REQUEST['allstops'])) { | if (isset($_REQUEST['allstops'])) { |
$allstops = true; | $allstops = true; |
} | } |
if (isset($_REQUEST['nearby'])) { | if (isset($_REQUEST['nearby'])) { |
$nearby = true; | $nearby = true; |
} | } |
if (isset($_REQUEST['suburb'])) { | if (isset($_REQUEST['suburb'])) { |
$suburb = $_REQUEST['suburb']; | $suburb = $_REQUEST['suburb']; |
} | } |
if (isset($_REQUEST['pageKey'])) { | if (isset($_REQUEST['pageKey'])) { |
$pageKey = filter_var($_REQUEST['pageKey'], FILTER_SANITIZE_NUMBER_INT); | $pageKey = filter_var($_REQUEST['pageKey'], FILTER_SANITIZE_NUMBER_INT); |
} | } |
if (isset($_REQUEST['lat'])) { | if (isset($_REQUEST['lat'])) { |
$lat = filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); | $lat = filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
} | } |
if (isset($_REQUEST['lon'])) { | if (isset($_REQUEST['lon'])) { |
$lon = filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); | $lon = filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
} | } |
if (isset($_REQUEST['radius'])) { | if (isset($_REQUEST['radius'])) { |
$max_distance = filter_var($_REQUEST['radius'], FILTER_SANITIZE_NUMBER_INT); | $max_distance = filter_var($_REQUEST['radius'], FILTER_SANITIZE_NUMBER_INT); |
} | } |
if (isset($_REQUEST['numberSeries'])) { | if (isset($_REQUEST['numberSeries'])) { |
$numberSeries = filter_var($_REQUEST['numberSeries'], FILTER_SANITIZE_NUMBER_INT); | $numberSeries = filter_var($_REQUEST['numberSeries'], FILTER_SANITIZE_NUMBER_INT); |
} | } |
if (isset($_REQUEST['routeDestination'])) { | if (isset($_REQUEST['routeDestination'])) { |
$routeDestination = urldecode(filter_var($_REQUEST['routeDestination'], FILTER_SANITIZE_ENCODED)); | $routeDestination = urldecode(filter_var($_REQUEST['routeDestination'], FILTER_SANITIZE_ENCODED)); |
} | } |
if (isset($_REQUEST['stopcode'])) { | if (isset($_REQUEST['stopcode'])) { |
$stopcode = filter_var($_REQUEST['stopcode'], FILTER_SANITIZE_STRING); | $stopcode = filter_var($_REQUEST['stopcode'], FILTER_SANITIZE_STRING); |
} | } |
if (isset($_REQUEST['stopids'])) { | if (isset($_REQUEST['stopids'])) { |
$stopids = explode(",", filter_var($_REQUEST['stopids'], FILTER_SANITIZE_STRING)); | $stopids = explode(",", filter_var($_REQUEST['stopids'], FILTER_SANITIZE_STRING)); |
} | } |
if (isset($_REQUEST['routeids'])) { | |
$routeids = explode(",", filter_var($_REQUEST['routeids'], FILTER_SANITIZE_STRING)); | |
} | |
if (isset($_REQUEST['tripid'])) { | if (isset($_REQUEST['tripid'])) { |
$tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_STRING); | $tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_STRING); |
} | |
if (isset($_REQUEST['routeid'])) { | |
$routeid = filter_var($_REQUEST['routeid'], FILTER_SANITIZE_STRING); | |
} | |
if (isset($_REQUEST['directionid'])) { | |
$directionid = filter_var($_REQUEST['directionid'], FILTER_SANITIZE_STRING); | |
} | } |
if (isset($_REQUEST['stopid'])) { | if (isset($_REQUEST['stopid'])) { |
$stopid = filter_var($_REQUEST['stopid'], FILTER_SANITIZE_NUMBER_INT); | $stopid = filter_var($_REQUEST['stopid'], FILTER_SANITIZE_NUMBER_INT); |
} | } |
if (isset($_REQUEST['geolocate'])) { | if (isset($_REQUEST['geolocate'])) { |
$geolocate = filter_var($_REQUEST['geolocate'], FILTER_SANITIZE_URL); | $geolocate = filter_var($_REQUEST['geolocate'], FILTER_SANITIZE_URL); |
} | } |
?> | ?> |
<?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. |
*/ | */ |
// you have to open the session to be able to modify or remove it | // you have to open the session to be able to modify or remove it |
session_start(); | session_start(); |
if (isset($_REQUEST['geolocate']) && $_REQUEST['geolocate'] != "Enter co-ordinates or address here") { | if (isset($_REQUEST['geolocate']) && $_REQUEST['geolocate'] != "Enter co-ordinates or address here") { |
$geocoded = false; | $geocoded = false; |
if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) { | if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) { |
$_SESSION['lat'] = trim(filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); | $_SESSION['lat'] = trim(filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); |
$_SESSION['lon'] = trim(filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); | $_SESSION['lon'] = trim(filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); |
} else { | } else { |
if (startsWith($geolocate, "-")) { | if (startsWith($geolocate, "-")) { |
$locateparts = explode(",", $geolocate); | $locateparts = explode(",", $geolocate); |
$_SESSION['lat'] = $locateparts[0]; | $_SESSION['lat'] = $locateparts[0]; |
$_SESSION['lon'] = $locateparts[1]; | $_SESSION['lon'] = $locateparts[1]; |
} else if (strpos($geolocate, "(") !== false) { | } else if (strpos($geolocate, "(") !== false) { |
$geoParts = explode("(", $geolocate); | $geoParts = explode("(", $geolocate); |
$locateparts = explode(",", str_replace(")", "", $geoParts[1])); | $locateparts = explode(",", str_replace(")", "", $geoParts[1])); |
$_SESSION['lat'] = $locateparts[0]; | $_SESSION['lat'] = $locateparts[0]; |
$_SESSION['lon'] = $locateparts[1]; | $_SESSION['lon'] = $locateparts[1]; |
} else { | } else { |
$contents = geocode($geolocate, true); | $contents = geocode($geolocate, true); |
print_r($contents); | print_r($contents); |
if (isset($contents[0]->centroid)) { | if (isset($contents[0]->centroid)) { |
$geocoded = true; | $geocoded = true; |
$_SESSION['lat'] = $contents[0]->centroid->coordinates[0]; | $_SESSION['lat'] = $contents[0]->centroid->coordinates[0]; |
$_SESSION['lon'] = $contents[0]->centroid->coordinates[1]; | $_SESSION['lon'] = $contents[0]->centroid->coordinates[1]; |
} else { | } else { |
$_SESSION['lat'] = ""; | $_SESSION['lat'] = ""; |
$_SESSION['lon'] = ""; | $_SESSION['lon'] = ""; |
} | } |
} | } |
} | } |
sessionUpdated(); | sessionUpdated(); |
} | } |
function sessionUpdated() { | function sessionUpdated() { |
$_SESSION['lastUpdated'] = time(); | $_SESSION['lastUpdated'] = time(); |
} | } |
// timeoutSession | // timeoutSession |
$TIMEOUT_LIMIT = 60 * 5; // 5 minutes | $TIMEOUT_LIMIT = 60 * 5; // 5 minutes |
if (isset($_SESSION['lastUpdated']) && $_SESSION['lastUpdated'] + $TIMEOUT_LIMIT < time()) { | if (isset($_SESSION['lastUpdated']) && $_SESSION['lastUpdated'] + $TIMEOUT_LIMIT < time()) { |
debug("Session timeout " . ($_SESSION['lastUpdated'] + $TIMEOUT_LIMIT) . ">" . time(), "session"); | debug("Session timeout " . ($_SESSION['lastUpdated'] + $TIMEOUT_LIMIT) . ">" . time(), "session"); |
session_destroy(); | session_destroy(); |
session_start(); | session_start(); |
} | } |
//debug(print_r($_SESSION, true) , "session"); | //debug(print_r($_SESSION, true) , "session"); |
function current_time() { | function current_time($time = "") { |
return ($_REQUEST['time'] ? $_REQUEST['time'] : date("H:i:s")); | if ($_REQUEST['time']) return $_REQUEST['time']; |
else if ($time != "") date("H:i:s",$time); | |
else return date("H:i:s"); | |
} | } |
?> | ?> |
<?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) { | function getRouteDescription($routeID) { |
$trip = getRouteNextTrip($routeID); | $trip = getRouteNextTrip($routeID); |
$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 getRoutesByNumber($routeNumber = "", $directionID = "",$service_period = "") { | |
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(); | |
} | |
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) { | function getRouteNextTrip($routeID, $directionID) { |
global $conn; | global $conn; |
$query = "select routes.route_id,direction_id,trips.trip_id,departure_time from routes join trips on trips.route_id = routes.route_id | $query = "select routes.route_id,direction_id,trips.trip_id,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 > :currentTime and routes.route_id = :routeID order by | 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 | |
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()); |
$query->bindParam(":futureTime", current_time(strtotime(current_time() ." +2h"))); | |
$query->bindParam(":routeID", $routeID); | $query->bindParam(":routeID", $routeID); |
$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; | |
// 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 | function getRouteFirstTrip($routeID,$directionID) { |
join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID order by | 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 routes.route_id = :routeID | |
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->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, $stop_id) { | $nextTrip = getRouteNextTrip($routeID, $directionID); |
$nextTrip = getRouteNextTrip($routeID); | |
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 getRoutesTrips($routeIDs, $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 = :routeIDA OR routes.route_id = :routeIDB) " . $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(":routeIDA", $routeIDs[0]); | $query->bindParam(":routeID", $routeID); |
$query->bindParam(":routeIDB", $routeIDs[1]); | |
$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"; |
} else { | } else { |
$query = "SELECT DISTINCT route_long_name | $query = "SELECT DISTINCT route_long_name |
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 (service_id=:service_periodA OR service_id=:service_periodB) | WHERE (service_id=:service_periodA OR service_id=:service_periodB) |
order by route_long_name"; | order by route_long_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); |
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,route_short_name,route_long_name,min(stops.stop_id) as stop_id, | $query = "SELECT service_id,trips.route_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,route_short_name,route_long_name | group by service_id,trips.route_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("bus.lambdacomplex.org", "index", false) | include_header("bus.lambdacomplex.org", "index", false) |
?> | ?> |
<div data-role="page"> | <div data-role="page"> |
<div data-role="content"> | <div data-role="content"> |
<div id="jqm-homeheader"> | <div id="jqm-homeheader"> |
<h1>busness time</h1><br><small>Canberra Bus Timetables and Trip Planner</small> | <h1>busness time</h1><br><small>Canberra Bus Timetables and Trip Planner</small> |
</div> | </div> |
<a name="maincontent" id="maincontent"></a> | <a name="maincontent" id="maincontent"></a> |
<a href="tripPlanner.php" data-role="button" data-icon="navigation">Launch Trip Planner...</a> | <a href="tripPlanner.php" data-role="button" data-icon="navigation">Launch Trip Planner...</a> |
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b"> | <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b"> |
<li data-role="list-divider">Timetables - Stops</li> | <li data-role="list-divider">Timetables - Stops</li> |
<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">Stops By Suburb</a></li> | <li><a href="stopList.php?bysuburbs=yes">Stops By Suburb</a></li> |
<li><a class="nearby" href="stopList.php?nearby=yes">Nearby Stops</a></li> | <li><a class="nearby" href="stopList.php?nearby=yes">Nearby Stops</a></li> |
</ul> | </ul> |
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b"> | <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b"> |
<li data-role="list-divider">Timetables - Routes</li> | <li data-role="list-divider">Timetables - Routes</li> |
<li><a href="routeList.php">Routes By Final Destination</a></li> | <li><a href="routeList.php">Routes By Final Destination</a></li> |
<li><a href="routeList.php?bynumber=yes">Routes By Number</a></li> | <li><a href="routeList.php?bynumber=yes">Routes By Number</a></li> |
<li><a href="routeList.php?bysuburbs=yes">Routes By Suburb</a></li> | <li><a href="routeList.php?bysuburbs=yes">Routes By Suburb</a></li> |
<li><a class="nearby" href="routeList.php?nearby=yes">Nearby Routes</a></li> | <li><a class="nearby" href="routeList.php?nearby=yes">Nearby Routes</a></li> |
</ul> | </ul> |
<a href="labs/index.php" data-role="button" data-icon="beaker">Busness R&D</a> | |
<a href="myway/index.php" data-role="button">MyWay Balance and Timeliness Survey Results</a> | |
<?php | <?php |
print_r(getServiceOverride(time())); | |
echo service_period(time()); | |
print_r(service_ids(service_period(time()))); | |
echo ' <a href="labs/index.php" data-role="button" data-icon="beaker">Busness R&D</a>'; | |
echo ' <a href="myway/index.php" data-role="button">MyWay Balance and Timeliness Survey Results</a>'; | |
include_footer(true) | include_footer(true) |
?> | ?> |
<?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) { |
global $nearby; | global $nearby; |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
$filteredRoutes = Array(); | $filteredRoutes = Array(); |
foreach ($routes as $route) { | foreach ($routes as $route) { |
foreach (getRouteHeadsigns($route['route_id']) as $headsign) { | foreach (getRouteHeadsigns($route['route_id']) as $headsign) { |
$start = $headsign['stop_name']; | |
$serviceday = service_period_day($headsign['service_id']); | //print_r($route); |
$key = $route['route_short_name'] . "." . $headsign['direction_id']; | echo '<li> <a href="trip.php?routeid=' . $route['route_id'] . '&directionid=' . $headsign['direction_id'] . '"><h3>' . $route['route_short_name'] . "</h3> |
if (isset($filteredRoutes[$key])) { | |
$filteredRoutes[$key]['route_ids'][] = $route['route_id']; | |
$filteredRoutes[$key]['route_ids'] = array_unique($filteredRoutes[$key]['route_ids']); | |
} else { | |
$filteredRoutes[$key]['route_short_name'] = $route['route_short_name']; | |
$filteredRoutes[$key]['route_long_name'] = "starting at " . $start; | |
$filteredRoutes[$key]['service_id'] = $serviceday; | |
$filteredRoutes[$key]['trip_headsign'] = $headsign['trip_headsign'].(strstr($headsign['trip_headsign'], "bound") ===false ?"bound":""); | |
$filteredRoutes[$key]['direction_id'] = $headsign['direction_id']; | |
if (isset($nearby)) { | |
$filteredRoutes[$key]['distance'] = $route['distance']; | |
} | |
} | |
} | |
} | |
foreach ($filteredRoutes as $key => $route) { | |
echo '<li> <a href="trip.php?routeids=' . implode(",", $route['route_ids']) . '&directionid=' . $route['direction_id'] . '"><h3>' . $route['route_short_name'] . "</h3> | |
<p>" . $route['trip_headsign'].", ". $route['route_long_name'] . " (" . ucwords($route['service_id']) . ")</p>"; | <p>" . $headsign['trip_headsign'].(strstr($headsign['trip_headsign'], "bound") ===false ?"bound":"").", starting at " . $headsign['stop_name'] . " (" . ucwords($headsign['service_id']) . ")</p>"; |
if (isset($nearby)) { | if (isset($nearby)) { |
$time = getRouteAtStop($route['route_id'], $route['stop_id']); | $time = getRouteAtStop($route['route_id'], $headsign['direction_id'], $route['stop_id']); |
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) { |
displayRoutes($routes); | displayRoutes($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 = getRoutesByNumber(); | $routes = getRoutesByNumber(); |
$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['route_long_name']) . '">' . $destination['route_long_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'); |
$routetrips = Array(); | $routetrips = Array(); |
if (isset($routeids) && !isset($tripid)) { | if (isset($routeid) && !isset($tripid)) { |
foreach ($routeids as $routeid) { | $trip = getRouteNextTrip($routeid,$directionid); |
$possibleTrip = getRouteNextTrip($routeid); | |
if (!isset($trip) || strtotime($possibleTrip['departure_time']) < strtotime($trip['departure_time'])) { | if (!($trip)) { |
$trip = getRouteNextTrip($routeid); | $trip = getRouteFirstTrip($routeid,$directionid); |
} | |
} | } |
$tripid = $trip['trip_id']; | $tripid = $trip['trip_id']; |
} else { | } else { |
$trip = getTrip($tripid); | $trip = getTrip($tripid); |
$similarRoutes = getRoutesByNumber($trip['route_short_name'], $trip['direction_id'], strtolower($trip["service_id"])); | $routeid = $trip['route_id']; |
$routeids = Array(); | |
foreach ($similarRoutes as $similarRoute) { | |
$routeids[] = $similarRoute['route_id']; | |
} | |
$routeids = array_unique($routeids); | |
} | } |
$directionid = $trip['direction_id']; | $directionid = $trip['direction_id']; |
$service_period = strtolower($trip["service_id"]); | $service_period = strtolower($trip["service_id"]); |
$destination = getTripDestination($trip['trip_id']); | $destination = getTripDestination($trip['trip_id']); |
include_header("Stops on " . $trip['route_short_name'] . ' ' . $destination['stop_name'], "trip"); | include_header("Stops on " . $trip['route_short_name'] . ' ' . $destination['stop_name'], "trip"); |
trackEvent("Route/Trip View", "View Route", $trip['route_short_name'] . ' ' . $destination['stop_name'], $routeid); | trackEvent("Route/Trip View", "View Route", $trip['route_short_name'] . ' ' . $destination['stop_name'], $routeid); |
echo '<span class="content-secondary">'; | echo '<span class="content-secondary">'; |
echo '<a href="' . $trip['route_url'] . '">View Original Timetable/Map</a>'; | echo '<a href="' . $trip['route_url'] . '">View Original Timetable/Map</a>'; |
echo '<h2>Via:</h2> <small>' . viaPointNames($tripid) . '</small>'; | echo '<h2>Via:</h2> <small>' . viaPointNames($tripid) . '</small>'; |
echo '<h2>Other Trips:</h2> '; | echo '<h2>Other Trips:</h2> '; |
echo "getRoutesTrips(".print_r($routeids,true).", {$trip['direction_id']}, $service_period) $tripid"; | $routeTrips = getRouteTrips($routeid, $trip['direction_id'], $service_period); |
$routeTrips = getRoutesTrips($routeids, $trip['direction_id'], $service_period); | |
foreach ($routeTrips as $key => $othertrip) { | foreach ($routeTrips as $key => $othertrip) { |
// if ($othertrip['trip_id'] != $tripid) { | // if ($othertrip['trip_id'] != $tripid) { |
echo '<a href="trip.php?tripid=' . $othertrip['trip_id'] . "&routeids=" . implode(",", $routeids) . '">' . str_replace(" ", ":00", str_replace(":00", " ", $othertrip['arrival_time'])) . '</a> '; | echo '<a href="trip.php?tripid=' . $othertrip['trip_id'] . "&routeid=" . $routeid . '">' . str_replace(" ", ":00", str_replace(":00", " ", $othertrip['arrival_time'])) . '</a> '; |
// } else { | // } else { |
// skip this trip but look forward/back | // skip this trip but look forward/back |
if ($key - 1 > 0) | if ($key - 1 > 0) |
$prevTrip = $routeTrips[$key - 1]['trip_id']; | $prevTrip = $routeTrips[$key - 1]['trip_id']; |
if ($key + 1 < sizeof($routeTrips)) | if ($key + 1 < sizeof($routeTrips)) |
$nextTrip = $routeTrips[$key + 1]['trip_id']; | $nextTrip = $routeTrips[$key + 1]['trip_id']; |
// } | // } |
} | } |
flush(); | flush(); |
@ob_flush(); | @ob_flush(); |
echo '<h2>Other directions/timing periods:</h2> '; | echo '<h2>Other directions/timing periods:</h2> '; |
$otherDir = 0; | $otherDir = 0; |
$filteredRoutes = Array(); | |
foreach (getRoutesByNumber($trip['route_short_name']) as $row) { | |
foreach (getRouteHeadsigns($row['route_id']) as $headsign) { | foreach (getRouteHeadsigns($routeid) as $headsign) { |
if ( $headsign['direction_id'] != $directionid || strtolower($headsign['service_id']) != $service_period) { | if ($headsign['direction_id'] != $directionid || strtolower($headsign['service_id']) != $service_period) { |
echo "{$headsign['direction_id']} != $directionid || ".strtolower($headsign['service_id'])." != $service_period <br>"; | |
$start = $headsign['stop_name']; | |
$serviceday = strtolower($headsign['service_id']); | echo '<a href="trip.php?routeid=' . $routeid . '&directionid=' . $headsign['direction_id'] . '&service_period=' . $headsign['service_id'] . '"> Starting at ' . $headsign['stop_name'] . ' (' . $headsign['service_id'] . ')</a> '; |
$key = $row['route_short_name'] . "." . $headsign['direction_id']; | $otherDir++; |
if (isset($filteredRoutes[$key])) { | |
$filteredRoutes[$key]['route_ids'][] = $row['route_id']; | |
$filteredRoutes[$key]['route_ids'] = array_unique($filteredRoutes[$key]['route_ids']); | |
} else { | |
$filteredRoutes[$key]['route_short_name'] = $row['route_short_name']; | |
$filteredRoutes[$key]['route_long_name'] = "Starting at " . $start; | |
$filteredRoutes[$key]['service_id'] = $serviceday; | |
$filteredRoutes[$key]['direction_id'] = $headsign['direction_id']; | |
} | |
} | } |
} | } |
} | |
foreach ($filteredRoutes as $key => $row) { | |
echo '<a href="trip.php?routeids=' . implode(",",$row['route_ids']) . '&directionid='.$row['direction_id'].'&service_period='.$row['service_id'].'">' . $row['route_long_name'] . ' (' . ucwords($row['service_id']) . ')</a> '; | |
$otherDir++; | |
} | |
if ($otherDir == 0) { | if ($otherDir == 0) { |
echo "None"; | echo "None"; |
} | } |
echo '</span><span class="content-primary">'; | echo '</span><span class="content-primary">'; |
flush(); | flush(); |
@ob_flush(); | @ob_flush(); |
echo "<div class='ui-header' style='overflow: visible; height: 1.5em'>"; | echo "<div class='ui-header' style='overflow: visible; height: 1.5em'>"; |
if ($nextTrip) | if ($nextTrip) |
echo '<a href="trip.php?tripid=' . $nextTrip . "&routeids=" . implode(",", $routeids) . '" data-icon="arrow-r" class="ui-btn-right">Next Trip</a>'; | echo '<a href="trip.php?tripid=' . $nextTrip . "&routeid=" . $routeid . '" data-icon="arrow-r" class="ui-btn-right">Next Trip</a>'; |
if ($prevTrip) | if ($prevTrip) |
echo '<a href="trip.php?tripid=' . $prevTrip . "&routeids=" . implode(",", $routeids) . '" data-icon="arrow-l" class="ui-btn-left">Previous Trip</a>'; | echo '<a href="trip.php?tripid=' . $prevTrip . "&routeid=" . $routeid . '" data-icon="arrow-l" class="ui-btn-left">Previous Trip</a>'; |
echo "</div>"; | echo "</div>"; |
echo ' <ul data-role="listview" data-inset="true">'; | echo ' <ul data-role="listview" data-inset="true">'; |
$stopsGrouped = Array(); | $stopsGrouped = Array(); |
$tripStopTimes = getTripStopTimes($tripid); | $tripStopTimes = getTripStopTimes($tripid); |
echo '<li data-role="list-divider">' . $tripStopTimes[0]['arrival_time'] . ' to ' . $tripStopTimes[sizeof($tripStopTimes) - 1]['arrival_time'] . ' towards ' . $destination['stop_name'] . ' (' . ucwords(strtolower($tripStopTimes[0]['service_id'])) . ')</li>'; | echo '<li data-role="list-divider">' . $tripStopTimes[0]['arrival_time'] . ' to ' . $tripStopTimes[sizeof($tripStopTimes) - 1]['arrival_time'] . ' towards ' . $destination['stop_name'] . ' (' . ucwords(strtolower($tripStopTimes[0]['service_id'])) . ')</li>'; |
foreach ($tripStopTimes as $key => $tripStopTime) { | foreach ($tripStopTimes as $key => $tripStopTime) { |
if ($key + 1 > sizeof($tripStopTimes) || stopCompare($tripStopTimes[$key]["stop_name"]) != stopCompare($tripStopTimes[$key + 1]["stop_name"])) { | if ($key + 1 > sizeof($tripStopTimes) || stopCompare($tripStopTimes[$key]["stop_name"]) != stopCompare($tripStopTimes[$key + 1]["stop_name"])) { |
echo '<li>'; | echo '<li>'; |
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"][] = $tripStopTime['stop_id']; | $stopsGrouped["stop_ids"][] = $tripStopTime['stop_id']; |
$stopsGrouped["endTime"] = $tripStopTime['arrival_time']; | $stopsGrouped["endTime"] = $tripStopTime['arrival_time']; |
echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '">'; | echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '">'; |
echo '<p class="ui-li-aside">' . $stopsGrouped['startTime'] . ' to ' . $stopsGrouped['endTime']; | echo '<p class="ui-li-aside">' . $stopsGrouped['startTime'] . ' to ' . $stopsGrouped['endTime']; |
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { | if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { |
echo '<br>' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; | echo '<br>' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; |
} | } |
echo '</p>'; | echo '</p>'; |
echo stopGroupTitle($tripStopTime['stop_name'], $tripStopTime['stop_desc']) . '<br><small>' . sizeof($stopsGrouped["stop_ids"]) . ' stops</small>'; | echo stopGroupTitle($tripStopTime['stop_name'], $tripStopTime['stop_desc']) . '<br><small>' . sizeof($stopsGrouped["stop_ids"]) . ' stops</small>'; |
echo '</a></li>'; | echo '</a></li>'; |
flush(); | flush(); |
@ob_flush(); | @ob_flush(); |
$stopsGrouped = Array(); | $stopsGrouped = Array(); |
} else { | } else { |
// just a normal stop | // just a normal stop |
echo '<a href="stop.php?stopid=' . $tripStopTime['stop_id'] . (startsWith($tripStopTime['stop_code'], "Wj") ? '&stopcode=' . $tripStopTime['stop_code'] : "") . '">'; | echo '<a href="stop.php?stopid=' . $tripStopTime['stop_id'] . (startsWith($tripStopTime['stop_code'], "Wj") ? '&stopcode=' . $tripStopTime['stop_code'] : "") . '">'; |
echo '<p class="ui-li-aside">' . $tripStopTime['arrival_time']; | echo '<p class="ui-li-aside">' . $tripStopTime['arrival_time']; |
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { | if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { |
echo '<br>' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; | echo '<br>' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; |
} | } |
echo '</p>'; | echo '</p>'; |
echo $tripStopTime['stop_name']; | echo $tripStopTime['stop_name']; |
echo '</a></li>'; | echo '</a></li>'; |
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($tripStopTimes[$key]['stop_name']) != stopCompare($tripStopTimes[$key - 1]['stop_name'])) { | if ($key - 1 <= 0 || stopCompare($tripStopTimes[$key]['stop_name']) != stopCompare($tripStopTimes[$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'])), |
"startTime" => $tripStopTime['arrival_time'], | "startTime" => $tripStopTime['arrival_time'], |
"stop_ids" => Array( | "stop_ids" => Array( |
$tripStopTime['stop_id'] | $tripStopTime['stop_id'] |
) | ) |
); | ); |
} else { | } else { |
// subsequent duplicates | // subsequent duplicates |
$stopsGrouped["stop_ids"][] = $tripStopTime['stop_id']; | $stopsGrouped["stop_ids"][] = $tripStopTime['stop_id']; |
$stopsGrouped["endTime"] = $tripStopTime['arrival_time']; | $stopsGrouped["endTime"] = $tripStopTime['arrival_time']; |
} | } |
} | } |
} | } |
echo '</ul>'; | echo '</ul>'; |
echo '</span>'; | echo '</span>'; |
include_footer(); | include_footer(); |
?> | ?> |