Unify route list rendering
--- a/include/common-session.inc.php
+++ b/include/common-session.inc.php
@@ -17,14 +17,6 @@
*/
// you have to open the session to be able to modify or remove it
session_start();
-if (isset($_REQUEST['service_period'])) {
- $_SESSION['service_period'] = filter_var($_REQUEST['service_period'], FILTER_SANITIZE_STRING);
- sessionUpdated();
-}
-if (isset($_REQUEST['time'])) {
- $_SESSION['time'] = filter_var($_REQUEST['time'], FILTER_SANITIZE_STRING);
- sessionUpdated();
-}
if (isset($_REQUEST['geolocate']) && $_REQUEST['geolocate'] != "Enter co-ordinates or address here") {
$geocoded = false;
if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) {
@@ -70,7 +62,7 @@
//debug(print_r($_SESSION, true) , "session");
function current_time() {
- return ($_SESSION['time'] ? $_SESSION['time'] : date("H:i:s"));
+ return ($_REQUEST['time'] ? $_REQUEST['time'] : date("H:i:s"));
}
?>
--- a/include/common-template.inc.php
+++ b/include/common-template.inc.php
@@ -212,9 +212,37 @@
}
echo "\n</div></div></body></html>";
}
-
+function timeSettings() {
+ global $service_periods;
+echo '<div id="settings" data-role="collapsible" data-collapsed="true">
+<h3>Change Time (' . (isset($_REQUEST['time']) ? $_REQUEST['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...</h3>
+ <form action="' . basename($_SERVER['PHP_SELF']) . '" method="GET">
+ <input type="hidden" name="suburb" id="suburb" value="' . (isset($_REQUEST['suburb']) ? $_REQUEST['suburb'] : "") . '"/>
+
+ <input type="hidden" name="stopid" id="stopid" value="' . (isset($_REQUEST['stopid']) ? $_REQUEST['stopid'] : "") . '"/>
+ <input type="hidden" name="stopcode" id="stopcode" value="' . (isset($_REQUEST['stopcode']) ? $_REQUEST['stopcode'] : "") . '"/>
+ <div class="ui-body">
+ <div data-role="fieldcontain">
+ <label for="time"> Time: </label>
+ <input type="time" name="time" id="time" value="' . (isset($_REQUEST['time']) ? $_REQUEST['time'] : date("H:i")) . '"/>
+ <a href="#" name="currentTime" id="currentTime" onClick="var d = new Date();' . "$('#time').val(d.getHours() +':'+ (d.getMinutes().toString().length == 1 ? '0'+ d.getMinutes(): d.getMinutes()));" . '">Current Time?</a>
+ </div>
+ <div data-role="fieldcontain">
+ <label for="service_period"> Service Period: </label>
+ <select name="service_period" id="service_period">';
+foreach ($service_periods as $service_period) {
+ echo "<option value=\"$service_period\"" . (service_period() === $service_period ? " SELECTED" : "") . '>' . ucwords($service_period) . '</option>';
+}
+echo '</select>
+ <a href="#" style="display:none" name="currentPeriod" id="currentPeriod">Current Period?</a>
+ </div>
+
+ <input type="submit" value="Update"/>
+ </div></form>
+ </div>';
+}
function placeSettings() {
- global $service_periods;
+
$geoerror = false;
$geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "";
--- a/include/common-transit.inc.php
+++ b/include/common-transit.inc.php
@@ -26,8 +26,8 @@
}
function service_period($date = "") {
- if (isset($_SESSION['service_period']))
- return $_SESSION['service_period'];
+ if (isset($_REQUEST['service_period']))
+ return $_REQUEST['service_period'];
$override = getServiceOverride($date);
if ($override['service_id']) {
return service_period_day ($override['service_id']);
--- a/include/db/route-dao.inc.php
+++ b/include/db/route-dao.inc.php
@@ -46,11 +46,11 @@
function getRouteHeadsigns($routeID) {
global $conn;
- $query = "select stops.stop_name, 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
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
-and stop_times.stop_sequence = 1 group by stops.stop_name, 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");
$query = $conn->prepare($query);
$query->bindParam(":routeID", $routeID);
@@ -260,25 +260,24 @@
$service_ids = service_ids($service_period);
$sidA = $service_ids[0];
$sidB = $service_ids[1];
+
global $conn;
$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
join routes on trips.route_id = routes.route_id
join stops on stops.stop_id = stop_times.stop_id
-WHERE zone_id 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";
debug($query, "database");
$query = $conn->prepare($query);
$query->bindParam(":service_periodA", $sidA);
$query->bindParam(":service_periodB", $sidB);
- $query->bindParam(":service_period", $service_period);
- $suburb = "%" . $suburb . ";%";
+ $suburb = "%Suburb: %" . $suburb . "%";
$query->bindParam(":suburb", $suburb);
$query->execute();
- if (!$query) {
- databaseError($conn->errorInfo());
- return Array();
- }
+
+ databaseError($conn->errorInfo());
+
return $query->fetchAll();
}
--- a/routeList.php
+++ b/routeList.php
@@ -18,6 +18,7 @@
include ('include/common.inc.php');
function navbar() {
+
echo '
<div data-role="navbar">
<ul>
@@ -28,6 +29,42 @@
</ul>
</div>
';
+}
+
+function displayRoutes($routes) {
+ global $nearby;
+ echo ' <ul data-role="listview" data-filter="true" data-inset="true" >';
+ $filteredRoutes = Array();
+ foreach ($routes as $route) {
+ foreach (getRouteHeadsigns($route['route_id']) as $headsign) {
+ $start = $headsign['stop_name'];
+ $serviceday = service_period_day($headsign['service_id']);
+ $key = $route['route_short_name'] . "." . $headsign['direction_id'];
+ 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>";
+ if (isset($nearby)) {
+ $time = getRouteAtStop($route['route_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" </a></li>\n";
+ }
}
if (isset($bysuburbs)) {
@@ -46,37 +83,32 @@
}
}
echo '</ul>';
-} else if (isset($nearby) || isset($suburb)) {
- $routes = Array();
+} else if (isset($suburb)) {
+
if ($suburb) {
include_header($suburb . " - " . ucwords(service_period()), "routeList");
navbar();
- timePlaceSettings();
+ timeSettings();
trackEvent("Route Lists", "Routes By Suburb", $suburb);
- $routes = getRoutesBySuburb($suburb);
+ displayRoutes(getRoutesBySuburb($suburb));
}
- if (isset($nearby)) {
- include_header("Routes Nearby", "routeList", true, true);
- trackEvent("Route Lists", "Routes Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']);
- navbar();
- placeSettings();
- if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") {
- include_footer();
- die();
- }
- $routes = getRoutesNearby($_SESSION['lat'], $_SESSION['lon']);
+} else if (isset($nearby)) {
+ $routes = Array();
+ include_header("Routes Nearby", "routeList", true, true);
+ trackEvent("Route Lists", "Routes Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']);
+ navbar();
+ placeSettings();
+ if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") {
+ include_footer();
+ die();
}
- echo ' <ul data-role="listview" data-filter="true" data-inset="true" >';
- if ($routes) {
- foreach ($routes as $route) {
- echo '<li><a href="trip.php?routeid=' . $route['route_id'] . '"><h3>' . $route['route_short_name'] . "</h3><p>" . $route['route_long_name'] . " (" . ucwords($route['service_id']) . ")</p>";
- if (isset($nearby)) {
- $time = getRouteAtStop($route['route_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 "</a></li>\n";
- }
+ $routes = getRoutesNearby($_SESSION['lat'], $_SESSION['lon']);
+
+
+ if (sizeof($routes) > 0) {
+ displayRoutes($routes);
} else {
+ echo ' <ul data-role="listview" data-filter="true" data-inset="true" >';
echo "<li style='text-align: center;'> No routes nearby.</li>";
}
} else if (isset($bynumber) || isset($numberSeries)) {
@@ -118,39 +150,14 @@
}
}
else if ($numberSeries) {
- $routes = getRoutesByNumberSeries($numberSeries);
- $filteredRoutes = Array();
- foreach ($routes as $route) {
- foreach (getRouteHeadsigns($route['route_id']) as $headsign) {
- $start = $headsign['stop_name'];
- $serviceday = service_period_day ( $headsign['service_id']);
- $key = $route['route_short_name'].".".$headsign['direction_id'];
- 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]['direction_id'] = $headsign['direction_id'];
- }
- }
- }
- 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['route_long_name'] . " (" . ucwords($route['service_id']) . ")</p>
- </a></li>\n";
- }
+ displayRoutes(getRoutesByNumberSeries($numberSeries));
}
} else {
include_header("Routes by Destination", "routeList");
navbar();
echo ' <ul data-role="listview" data-inset="true">';
if (isset($routeDestination)) {
- foreach (getRoutesByDestination($routeDestination) as $route) {
- echo '<li><a href="trip.php?routeid=' . $route["route_id"] . '"><h3>' . $route["route_short_name"] . '</h3><p>' . $route["route_long_name"] . " (" . ucwords($route['service_id']) . ")</p></a></li>\n";
- }
+ displayRoutes(getRoutesByDestination($routeDestination));
} else {
foreach (getRoutesByDestination() as $destination) {
echo '<li><a href="' . curPageURL() . '/routeList.php?routeDestination=' . urlencode($destination['route_long_name']) . '">' . $destination['route_long_name'] . "... </a></li>\n";
--- a/stop.php
+++ b/stop.php
@@ -96,29 +96,7 @@
));
}
-// time settings
-echo '<div id="settings" data-role="collapsible" data-collapsed="true">
-<h3>Change Time (' . (isset($_SESSION['time']) ? $_SESSION['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...</h3>
- <form action="' . basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'] . '" method="post">
- <div class="ui-body">
- <div data-role="fieldcontain">
- <label for="time"> Time: </label>
- <input type="time" name="time" id="time" value="' . (isset($_SESSION['time']) ? $_SESSION['time'] : date("H:i")) . '"/>
- <a href="#" name="currentTime" id="currentTime" onClick="var d = new Date();' . "$('#time').val(d.getHours() +':'+ (d.getMinutes().toString().length == 1 ? '0'+ d.getMinutes(): d.getMinutes()));" . '">Current Time?</a>
- </div>
- <div data-role="fieldcontain">
- <label for="service_period"> Service Period: </label>
- <select name="service_period" id="service_period">';
-foreach ($service_periods as $service_period) {
- echo "<option value=\"$service_period\"" . (service_period() === $service_period ? " SELECTED" : "") . '>' . ucwords($service_period) . '</option>';
-}
-echo '</select>
- <a href="#" style="display:none" name="currentPeriod" id="currentPeriod">Current Period?</a>
- </div>
-
- <input type="submit" value="Update"/>
- </div></form>
- </div>';
+timeSettings();
echo '</span><span class="content-primary">';
echo ' <ul data-role="listview" data-inset="true">';
@@ -128,13 +106,33 @@
} else {
$trips = getStopTripsWithTimes($stopid);
}
+echo "<div class='ui-header' style='overflow: visible; height: 2.5em'>";
+// later/earlier button setup
+if (sizeof($trips) == 0) {
+ $time = isset($_REQUEST['time']) ? strtotime($_REQUEST['time']) : time();
+ $earlierTime = $time - (90 * 60);
+ $laterTime = $time + (90 * 60);
+} else {
+ $earlierTime = strtotime($trips[0]['arrival_time']) - (90 * 60);
+ $laterTime = strtotime($trips[sizeof($trips) - 1]['arrival_time']) - 60;
+}
+if (sizeof($stopids) > 0) {
+ $stopidurl = "stopids=" . implode(",", $stopids);
+} else {
+ $stopidurl = "stopid=$stopid";
+}
+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", $earlierTime) . '" data-icon="arrow-l" class="ui-btn-left">Earlier Trips</a>';
+echo "</div>";
if (sizeof($trips) == 0) {
echo "<li style='text-align: center;'>No trips in the near future.</li>";
} else {
foreach ($trips as $trip) {
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>";
$viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']);
if ($viaPoints != "")
--- a/stopList.php
+++ b/stopList.php
@@ -102,7 +102,7 @@
// subsequent duplicates
$stopsGrouped["stop_ids"][] = $stop['stop_id'];
echo '<li>';
- echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '">';
+ echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '&stopcodes=' . implode(",", $stopsGrouped['stop_codes']) . '">';
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>';
}
--- a/trip.php
+++ b/trip.php
@@ -83,7 +83,7 @@
}
}
foreach ($filteredRoutes as $key => $row) {
- echo '<a href="trip.php?routeids=' . implode(",",$row['route_ids']) . '&directionid='.$row['direction_id'].'">' . $row['route_long_name'] . ' (' . ucwords($row['service_id']) . ')</a> ';
+ 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++;
}