--- a/trip.php +++ b/trip.php @@ -1,93 +1,86 @@ midnight_seconds()) { - $tripid = $trip[1]; - break; - } - } - if ($tripid == 0) $tripid = $routetrips[0][1]; + +if (isset($routeid) && !isset($tripid)) { + $trip = getRouteNextTrip($routeid); + $tripid = $trip['trip_id']; +} else { + $trip = getTrip($tripid); + $routeid = $trip["route_id"]; } -$url = $APIurl . "/json/triprows?trip=" . $tripid; -$trips = array_flatten(json_decode(getPage($url))); -if (sizeof($routetrips) == 0) { - $routeid = $trips[1]->route_id; - $url = $APIurl . "/json/routetrips?route_id=" . $trips[1]->route_id; - $routetrips = json_decode(getPage($url)); + +$routetrips = getRouteTrips($routeid); + +include_header("Stops on " . $trip['route_short_name'] . ' ' . $trip['route_long_name'], "trip"); +trackEvent("Route/Trip View","View Route", $trip['route_short_name'] . ' ' . $trip['route_long_name'], $routeid); + + +echo '
' . midnight_seconds_to_time($stopsGrouped['startTime']) . ' to ' . midnight_seconds_to_time($stopsGrouped['endTime']) . '
'; - echo bracketsMeanNewLine($row[1]); + echo '' . $stopsGrouped['startTime'] . ' to ' . $stopsGrouped['endTime']; + echo '
'; + if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { + echo '' . distance($stop['stop_lat'],$stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; + } + echo bracketsMeanNewLine($tripStopTime["stop_name"]); echo '' . midnight_seconds_to_time($times[$key]) . '
'; - echo bracketsMeanNewLine($row[1]); + echo ''; + echo '' . $tripStopTime['arrival_time'] . '
'; + if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { + echo '' . distance($stop['stop_lat'],$stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; + } + echo bracketsMeanNewLine($tripStopTime['stop_name']); echo ''; + flush(); @ob_flush(); } } else { // this is a duplicated line item - if ($key - 1 <= 0 || ($stops[$key][1] != $stops[$key - 1][1])) { + if ($key - 1 <= 0 || ($tripStopTimes[$key]['stop_name'] != $tripStopTimes[$key - 1]['stop_name'])) { // first duplicate $stopsGrouped = Array( - "name" => $row[1], - "startTime" => $times[$key], + "name" => $tripStopTime['stop_name'], + "startTime" => $tripStopTime['arrival_time'], "stop_ids" => Array( - $row[0] + $tripStopTime['stop_id'] ) ); } else { // subsequent duplicates - $stopsGrouped["stop_ids"][] = $row[0]; - $stopsGrouped["endTime"] = $times[$key]; + $stopsGrouped["stop_ids"][] = $tripStopTime['stop_id']; + $stopsGrouped["endTime"] = $tripStopTime['arrival_time']; } } }