Beginnings of Christmas 2011 support
--- a/include/common-template.inc.php
+++ b/include/common-template.inc.php
@@ -175,7 +175,7 @@
<div data-role="content"> ';
if ($GTFSREnabled) {
$overrides = getServiceOverride();
- if ($overrides['service_id']) {
+ if (isset($overrides['service_id'])) {
if ($overrides['service_id'] == "noservice") {
echo '<div id="servicewarning">Buses are <strong>not running today</strong> due to industrial action/public holiday. See <a
href="http://www.action.act.gov.au">http://www.action.act.gov.au</a> for details.</div>';
--- a/include/common-transit.inc.php
+++ b/include/common-transit.inc.php
@@ -18,43 +18,63 @@
$service_periods = Array(
'sunday',
'saturday',
- 'weekday'
+ 'weekday',
+ "Christmas2011","EndOfYearHolidays"
);
-function service_period_day ($spid) {
- $idParts = explode("-",$spid);
- return strtolower($idParts[2]);
-}
+
function service_period($date = "") {
- if (isset($_REQUEST['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']);
- }
-
- switch (date('w', ($date != "" ? $date : time()))) {
- case 0:
- return 'sunday';
- case 6:
- return 'saturday';
- default:
- return 'weekday';
- }
-}
+ if (isset($override['service_id'])) {
+ return strtolower($override['service_id']);
+ }
+ $date = ($date != "" ? $date : time());
+// christmas special cases
+ $ymd = date('Ymd', $date);
+ $dow = date('w', $date);
+ if ($ymd == "20111225") {
+ return "Christmas2011";
+ } if ($ymd == "20111228" || $ymd == "20111229" || $ymd == "20111230") {
+ return "EndOfYearHolidays";
+ } else if (intval($ymd) < "20120203" && $dow != 0 && $dow != 6) {
+ return "Weekday-SchoolVacation";
+ } else {
+ switch ($dow) {
+ case 0:
+ return 'sunday';
+ case 6:
+ return 'saturday';
+ default:
+ return 'weekday';
+ }
+ }
+}
+
function service_ids($service_period) {
switch ($service_period) {
case 'sunday':
- return Array("Sunday","Sunday");
+ return Array("Sunday", "Sunday");
case 'saturday':
- return Array("Saturday","Saturday");
+ return Array("Saturday", "Saturday");
+ case "Christmas2011":
+ return Array("Christmas2011", "Christmas2011");
+ case "EndOfYearHolidays":
+ return Array("Weekday-EndOfYearHolidays", "Weekday-EndOfYearHolidays");
+ case "Weekday-SchoolVacation":
+ return Array("Weekday", "Weekday-SchoolVacation");
default:
//return 'weekday';
- return Array("Weekday","Weekday");
- }
-}
+ return Array("Weekday", "Weekday");
+ }
+}
+
function valid_service_ids() {
- return array_merge(service_ids(""),service_ids('saturday'),service_ids('sunday'));
+ return array_merge(service_ids(""), service_ids('saturday'), service_ids('sunday'),
+ Array("Christmas2011","Weekday-EndOfYearHolidays","Weekday-SchoolVacation"));
}
function midnight_seconds($time = "") {
--- a/index.php
+++ b/index.php
@@ -20,7 +20,7 @@
<div data-role="page">
<div data-role="content">
<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>
<a name="maincontent" id="maincontent"></a>
<a href="tripPlanner.php" data-role="button" data-icon="navigation">Launch Trip Planner...</a>
@@ -38,8 +38,12 @@
<li><a class="nearby" href="routeList.php?nearby=yes">Nearby Routes</a></li>
</ul>
<?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)
?>
--- a/stop.php
+++ b/stop.php
@@ -133,7 +133,7 @@
echo '<li>';
$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>'. (service_period() == "Christmas2011" ? $trip['route_long_name'] : "") . $trip['route_short_name'] . " towards " . $destination['stop_name'] . "</h3><p>";
$viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']);
if ($viaPoints != "")
echo '<br><span class="viaPoints">Via: ' . $viaPoints . '</span>';
--- a/trip.php
+++ b/trip.php
@@ -27,7 +27,7 @@
$tripid = $trip['trip_id'];
} else {
$trip = getTrip($tripid);
- $similarRoutes = getRoutesByNumber($trip['route_short_name'], $trip['direction_id'], service_period_day($trip["service_id"]));
+ $similarRoutes = getRoutesByNumber($trip['route_short_name'], $trip['direction_id'], strtolower($trip["service_id"]));
$routeids = Array();
foreach ($similarRoutes as $similarRoute) {
$routeids[] = $similarRoute['route_id'];
@@ -35,7 +35,7 @@
$routeids = array_unique($routeids);
}
$directionid = $trip['direction_id'];
-$service_period = service_period_day($trip["service_id"]);
+$service_period = strtolower($trip["service_id"]);
$destination = getTripDestination($trip['trip_id']);
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);
@@ -64,11 +64,11 @@
foreach (getRoutesByNumber($trip['route_short_name']) as $row) {
foreach (getRouteHeadsigns($row['route_id']) as $headsign) {
- if ( $headsign['direction_id'] != $directionid || service_period_day($headsign['service_id']) != $service_period) {
- echo "{$headsign['direction_id']} != $directionid || ".service_period_day($headsign['service_id'])." != $service_period <br>";
+ 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 = service_period_day($headsign['service_id']);
+ $serviceday = strtolower($headsign['service_id']);
$key = $row['route_short_name'] . "." . $headsign['direction_id'];
if (isset($filteredRoutes[$key])) {
$filteredRoutes[$key]['route_ids'][] = $row['route_id'];
@@ -102,7 +102,7 @@
echo ' <ul data-role="listview" data-inset="true">';
$stopsGrouped = Array();
$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(service_period_day($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) {
if ($key + 1 > sizeof($tripStopTimes) || stopCompare($tripStopTimes[$key]["stop_name"]) != stopCompare($tripStopTimes[$key + 1]["stop_name"])) {
echo '<li>';
--- a/tripPlanner.php
+++ b/tripPlanner.php
@@ -182,7 +182,99 @@
curl_close($ch);
}
} else {
+ $overrides = getServiceOverride();
+ if (isset($overrides['service_id'])) {
+ echo "Sorry, due to the modified timetable, this trip planner won't work correctly today. Instead, use the Google Maps one below:";
+ echo '
+<script language="javascript">
+ // make some ezamples
+ var startExample = "Gungahlin, ACT";
+ var endExample = "Bunda St, Canberra";
+ var zip = "2600";
+ var urlToGoTo = "http://www.google.com/maps?ie=UTF8&f=d&" ;
+
+ function buildURL(){
+ document.getElementById(\'linkOut\').href = urlToGoTo + "&saddr=" + document.getElementById(\'saddr\').value + "&daddr=" + document.getElementById(\'daddr\').value + "&dirflg=r";
+ }
+
+</script>
+
+<form action="https://www.action.act.gov.au/googletransit/redir_to_google.asp" method="post" name="GoogleTransit" target="_blank" id="GoogleTransit">
+ <table width="226" cellspacing="1" border="1">
+ <tr>
+ <td colspan="2" valign="middle"><a href="http://google.com/transit"><img src="/maps_logo_small_blue.png"width="150" height="55" border="0" alt="Link to Google Transit Trip Planner" align="middle"></a> <br />
+ <B>Transit Trip Planner</B></td>
+ </tr>
+ <tr>
+ <td colspan="2" nowrap><strong>Start</strong> (e.g.
+ <script language="javascript">document.write(startExample)</script>)<br />
+ <input type="text" size="27" name="saddr" id="saddr" maxlength="2048" title="Enter the Origin Address" value="" onFocus="this.value=\'\';" onBlur="if(this.value==\'\')this.value=startExample">
+ <br /><br /> <strong>End</strong> (e.g.
+ <script language="javascript">document.write(endExample)</script>)
+ <BR>
+ <input type="text" size="27" name="daddr" id="daddr" maxlength="2048" title="Enter the Destination Address" onfocus="this.value=\'\';" onBlur="if(this.value==\'\')this.value=endExample">
+ <br>
+ <table>
+ <tr>
+ <td><strong>Date</strong></td>
+ <td><strong>Time</strong></td>
+ </tr>
+ <tr>
+ <td nowrap=""><input type="text" title="Enter the Date in DD/MM/YY format" maxlength="10" value="" name="date" size="10" id="fdate"></td>
+ <td nowrap="nowrap"><input type="text" title="Enter the Time in HH:MM AM or PM format" maxlength="8" value="" name="time" size="5" id="ftime"></td>
+ </tr>
+ </table>
+Plan by:
+ <select name="ttype">
+ <option value="dep">Departure Time</option>
+ <option value="arr">Arrival Time</option>
+ </select>
+ <center>
+ <input name="Submit" type="submit" value="Get directions">
+ </center></td>
+ </tr>
+ </table>
+</form>
+
+<script language="javascript">
+
+// calculate the current time
+
+ var currentTime = new Date() ;
+ var hours = currentTime.getHours() ;
+ var minutes = currentTime.getMinutes() ;
+
+ var currentDay = currentTime.getDate() ;
+ var currentMonth = currentTime.getMonth() + 1 ;
+// var currentYear = currentTime.getYear() ; 07/10/2011 by Vlad
+ var currentYear = currentTime.getFullYear() ;
+
+// account for leading zero
+ if (minutes < 10)
+ minutes = "0" + minutes
+// 07/10/2011 by Vlad
+ if (hours < 10)
+ hours = "0" + hours
+ if (currentDay < 10)
+ currentDay = "0" + currentDay
+ if (currentMonth < 10)
+ currentMonth = "0" + currentMonth
+
+ var displayTime = hours + ":" + minutes ;
+
+// populate the current time
+ document.getElementById(\'ftime\').value = displayTime ;
+
+// populate the address examplates
+ document.getElementById(\'saddr\').value = startExample ;
+ document.getElementById(\'daddr\').value = endExample ;
+ document.getElementById(\'fdate\').value = currentDay + \'/\' + currentMonth + \'/\' + currentYear ;
+
+</script>
+';
+ } else {
tripPlanForm();
+ }
}
include_footer();
?>