<?php | |
header('Content-Type: application/vnd.google-earth.kml+xml'); | |
include ('../include/common.inc.php'); | |
echo '<?xml version="1.0" encoding="UTF-8"?> | |
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"><Document>'; | |
echo ' | |
<Style id="yellowLineGreenPoly"> | |
<LineStyle> | |
<color>7f00ff00</color> | |
<width>4</width> | |
</LineStyle> | |
<PolyStyle> | |
<color>7f00ffff</color> | |
</PolyStyle> | |
</Style>'; | |
$route = getRoute($routeid); | |
echo "\n<Placemark>\n"; | |
$link = curPageURL()."/../trip.php?routeid=".htmlspecialchars ($route["route_id"]); | |
echo "<name>".$route['route_short_name']."</name>"; | |
echo '<atom:link href="'.$link.'"/>'; | |
echo '<description><![CDATA[ <a href="'.$link.'">'.$route['route_short_name']." ".$route['route_long_name']."</a>]]> </description>"; | |
echo "<styleUrl>#yellowLineGreenPoly</styleUrl>"; | |
$trips = getRouteTrips($routeid); | |
echo getTripShape($trips[0]['trip_id']); | |
echo "</Placemark>\n</Document></kml>\n"; | |
?> | |
<?php | |
header('Content-type: application/vnd.google-earth.kml+xml'); | |
//http://wiki.openstreetmap.org/wiki/OpenLayers_Dynamic_KML | |
// Creates the KML/XML Document. | |
$dom = new DOMDocument('1.0', 'UTF-8'); | |
// Creates the root KML element and appends it to the root document. | |
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml'); | |
$parNode = $dom->appendChild($node); | |
// Creates a KML Document element and append it to the KML element. | |
$dnode = $dom->createElement('Document'); | |
$docNode = $parNode->appendChild($dnode); | |
if ($suburb != "") $result_stops = getStopsBySuburb($suburb); | |
else $result_stops = getStops(); | |
foreach ($result_stops as $stop) { | |
$description = 'http://bus.lambdacomplex.org/' . 'stop.php?stopid=' . $stop['stop_id'] . " <br>"; | |
// Creates a Placemark and append it to the Document. | |
$node = $dom->createElement('Placemark'); | |
$placeNode = $docNode->appendChild($node); | |
// Creates an id attribute and assign it the value of id column. | |
$placeNode->setAttribute('id', 'placemark' . $stop['stop_id']); | |
// Create name, and description elements and assigns them the values of the name and address columns from the results. | |
$nameNode = $dom->createElement('name', htmlentities($stop['stop_name'])); | |
$descriptionNode = $dom->createElement('description', $description); | |
$placeNode->appendChild($nameNode); | |
$placeNode->appendChild($descriptionNode); | |
// Creates a Point element. | |
$pointNode = $dom->createElement('Point'); | |
$placeNode->appendChild($pointNode); | |
// Creates a coordinates element and gives it the value of the lng and lat columns from the results. | |
$coorStr = $stop['stop_lon'] . ',' . $stop['stop_lat']; | |
$coorNode = $dom->createElement('coordinates', $coorStr); | |
$pointNode->appendChild($coorNode); | |
} | |
$kmlOutput = $dom->saveXML(); | |
echo $kmlOutput; | |
?> |
<?php | <?php |
// Copyright 2009 Google Inc. All Rights Reserved. | // Copyright 2009 Google Inc. All Rights Reserved. |
$GA_ACCOUNT = "MO-22173039-1"; | $GA_ACCOUNT = "MO-22173039-1"; |
$GA_PIXEL = "/lib/ga.php"; | $GA_PIXEL = "/lib/ga.php"; |
function googleAnalyticsGetImageUrl() | function googleAnalyticsGetImageUrl() |
{ | { |
global $GA_ACCOUNT, $GA_PIXEL; | global $GA_ACCOUNT, $GA_PIXEL; |
//if (stristr($_SERVER['HTTP_USER_AGENT'], 'Googlebot') return ""; | //if (stristr($_SERVER['HTTP_USER_AGENT'], 'Googlebot') return ""; |
$url = ""; | $url = ""; |
$url.= $GA_PIXEL . "?"; | $url.= $GA_PIXEL . "?"; |
$url.= "utmac=" . $GA_ACCOUNT; | $url.= "utmac=" . $GA_ACCOUNT; |
$url.= "&utmn=" . rand(0, 0x7fffffff); | $url.= "&utmn=" . rand(0, 0x7fffffff); |
$referer = $_SERVER["HTTP_REFERER"]; | $referer = $_SERVER["HTTP_REFERER"]; |
$query = $_SERVER["QUERY_STRING"]; | $query = $_SERVER["QUERY_STRING"]; |
$path = $_SERVER["REQUEST_URI"]; | $path = $_SERVER["REQUEST_URI"]; |
if (empty($referer)) { | if (empty($referer)) { |
$referer = "-"; | $referer = "-"; |
} | } |
$url.= "&utmr=" . urlencode($referer); | $url.= "&utmr=" . urlencode($referer); |
if (!empty($path)) { | if (!empty($path)) { |
$url.= "&utmp=" . urlencode($path); | $url.= "&utmp=" . urlencode($path); |
} | } |
$url.= "&guid=ON"; | $url.= "&guid=ON"; |
return str_replace("&", "&", $url); | return str_replace("&", "&", $url); |
} | } |
function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = false, $datepicker = false) | function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = false, $datepicker = false) |
{ | { |
echo ' | echo ' |
<!DOCTYPE html> | <!DOCTYPE html> |
<html lang="en"> | <html lang="en"> |
<head> | <head> |
<meta charset="UTF-8"> | <meta charset="UTF-8"> |
<title>' . $pageTitle . '</title> | <title>' . $pageTitle . '</title> |
<meta name="google-site-verification" | <meta name="google-site-verification" |
content="-53T5Qn4TB_de1NyfR_ZZkEVdUNcNFSaYKSFkWKx-sY" /> | content="-53T5Qn4TB_de1NyfR_ZZkEVdUNcNFSaYKSFkWKx-sY" /> |
<link rel="stylesheet" href="css/jquery-ui-1.8.12.custom.css" />'; | <link rel="stylesheet" href="css/jquery-ui-1.8.12.custom.css" />'; |
if (isDebugServer()) { | if (isDebugServer()) { |
echo '<link rel="stylesheet" href="css/jquery.mobile-1.0a4.css" /> | echo '<link rel="stylesheet" href="css/jquery.mobile-1.0a4.css" /> |
<script type="text/javascript" src="js/jquery-1.5.js"></script> | <script type="text/javascript" src="js/jquery-1.5.js"></script> |
<script>$(document).bind("mobileinit", function(){ | <script>$(document).bind("mobileinit", function(){ |
$.mobile.ajaxEnabled = false; | $.mobile.ajaxEnabled = false; |
}); | }); |
</script> | </script> |
<script type="text/javascript" src="js/jquery.mobile-1.0a4.js"></script>'; | <script type="text/javascript" src="js/jquery.mobile-1.0a4.js"></script>'; |
} | } |
else { | else { |
echo '<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" /> | echo '<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" /> |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> |
<script>$(document).bind("mobileinit", function(){ | <script>$(document).bind("mobileinit", function(){ |
$.mobile.ajaxEnabled = false; | $.mobile.ajaxEnabled = false; |
}); | }); |
</script> | </script> |
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>'; | <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>'; |
} | } |
echo ' | echo ' |
<script src="js/jquery.ui.autocomplete.min.js"></script> | <script src="js/jquery.ui.autocomplete.min.js"></script> |
<script src="js/jquery.ui.core.min.js"></script> | <script src="js/jquery.ui.core.min.js"></script> |
<script src="js/jquery.ui.position.min.js"></script> | <script src="js/jquery.ui.position.min.js"></script> |
<script src="js/jquery.ui.widget.min.js"></script> | <script src="js/jquery.ui.widget.min.js"></script> |
<script> | <script> |
$(function() { | $(function() { |
$( "#geolocate" ).autocomplete({ | $( "#geolocate" ).autocomplete({ |
source: "lib/autocomplete.php", | source: "lib/autocomplete.php", |
minLength: 2 | minLength: 2 |
}); | }); |
$( "#from" ).autocomplete({ | $( "#from" ).autocomplete({ |
source: "lib/autocomplete.php", | source: "lib/autocomplete.php", |
minLength: 2 | minLength: 2 |
}); | }); |
$( "#to" ).autocomplete({ | $( "#to" ).autocomplete({ |
source: "lib/autocomplete.php", | source: "lib/autocomplete.php", |
minLength: 2 | minLength: 2 |
}); | }); |
}); | }); |
</script> | </script> |
'; | '; |
echo '<style type="text/css"> | echo '<style type="text/css"> |
.ui-navbar { | .ui-navbar { |
width: 100%; | width: 100%; |
} | } |
.ui-btn-inner { | .ui-btn-inner { |
white-space: normal !important; | white-space: normal !important; |
} | } |
.ui-li-heading { | .ui-li-heading { |
white-space: normal !important; | white-space: normal !important; |
} | } |
.ui-listview-filter { | .ui-listview-filter { |
margin: 0 !important; | margin: 0 !important; |
} | } |
.ui-icon-navigation { | .ui-icon-navigation { |
background-image: url(css/images/113-navigation.png); | background-image: url(css/images/113-navigation.png); |
background-position: 1px 0; | background-position: 1px 0; |
} | } |
.ui-icon-beaker { | .ui-icon-beaker { |
background-image: url(css/images/91-beaker-2.png); | background-image: url(css/images/91-beaker-2.png); |
background-position: 1px 0; | background-position: 1px 0; |
} | } |
#footer { | #footer { |
text-size: 0.75em; | text-size: 0.75em; |
text-align: center; | text-align: center; |
} | } |
body { | body { |
background-color: #F0F0F0; | background-color: #F0F0F0; |
} | } |
#jqm-homeheader { | #jqm-homeheader { |
text-align: center; | text-align: center; |
} | } |
.viaPoints { | .viaPoints { |
display: none; | display: none; |
text-size: 0.2em; | text-size: 0.2em; |
} | } |
.min-width-480px .viaPoints { | .min-width-480px .viaPoints { |
display: inline; | display: inline; |
} | } |
#extrainfo { | #extrainfo { |
visibility: hidden; | visibility: hidden; |
display: none; | display: none; |
} | } |
#servicewarning { | #servicewarning { |
padding: 1em; | padding: 1em; |
margin-bottom: 0.5em; | margin-bottom: 0.5em; |
text-size: 0.2em; | text-size: 0.2em; |
background-color: #FF9; | background-color: #FF9; |
-moz-border-radius: 15px; | -moz-border-radius: 15px; |
border-radius: 15px; | border-radius: 15px; |
} | } |
/*#leftcolumn { | |
float: none; | |
} | |
.min-width-768px #leftcolumn { | |
float: left; | |
width: 30%; | |
} | |
#rightcolumn { | |
float: none; | |
} | |
.min-width-768px #rightcolumn { | |
float: right; | |
width: 68%; | |
}*/ | |
#footer { | |
clear:both; | |
text-align:center; | |
} | |
// source http://webaim.org/techniques/skipnav/ | // source http://webaim.org/techniques/skipnav/ |
#skip a, #skip a:hover, #skip a:visited | #skip a, #skip a:hover, #skip a:visited |
{ | { |
position:absolute; | position:absolute; |
left:0px; | left:0px; |
top:-500px; | top:-500px; |
width:1px; | width:1px; |
height:1px; | height:1px; |
overflow:hidden; | overflow:hidden; |
} | } |
#skip a:active, #skip a:focus | #skip a:active, #skip a:focus |
{ | { |
position:static; | position:static; |
width:auto; | width:auto; |
height:auto; | height:auto; |
} | } |
</style>'; | </style>'; |
if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod')) { | if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { |
echo '<meta name="apple-mobile-web-app-capable" content="yes" /> | echo '<meta name="apple-mobile-web-app-capable" content="yes" /> |
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> | <meta name="apple-mobile-web-app-status-bar-style" content="black" /> |
<link rel="apple-touch-startup-image" href="startup.png" /> | <link rel="apple-touch-startup-image" href="startup.png" /> |
<link rel="apple-touch-icon" href="apple-touch-icon.png" />'; | <link rel="apple-touch-icon" href="apple-touch-icon.png" />'; |
} | } |
if ($geolocate) { | if ($geolocate) { |
echo "<script> | echo "<script> |
function success(position) { | function success(position) { |
$('#error').val('Location now detected. Please wait for data to load.'); | $('#error').val('Location now detected. Please wait for data to load.'); |
$('#geolocate').val(position.coords.latitude+','+position.coords.longitude); | $('#geolocate').val(position.coords.latitude+','+position.coords.longitude); |
$.ajax({ url: \"include/common.inc.php?geolocate=yes&lat=\"+position.coords.latitude+\"&lon=\"+position.coords.longitude }); | $.ajax({ url: \"include/common.inc.php?geolocate=yes&lat=\"+position.coords.latitude+\"&lon=\"+position.coords.longitude }); |
location.reload(true); | location.reload(true); |
} | } |
function error(msg) { | function error(msg) { |
$('#error').val('Error: '+msg); | $('#error').val('Error: '+msg); |
} | } |
function geolocate() { | function geolocate() { |
if (navigator.geolocation) { | if (navigator.geolocation) { |
var options = { | var options = { |
enableHighAccuracy: true, | enableHighAccuracy: true, |
timeout: 60000, | timeout: 60000, |
maximumAge: 10000 | maximumAge: 10000 |
} | } |
navigator.geolocation.getCurrentPosition(success, error, options); | navigator.geolocation.getCurrentPosition(success, error, options); |
} | } |
} | } |
$(document).ready(function() { | $(document).ready(function() { |
$('#here').click(function(event) { $('#geolocate').val(geolocate()); return false;}); | $('#here').click(function(event) { $('#geolocate').val(geolocate()); return false;}); |
$('#here').show(); | $('#here').show(); |
/*if ($.mobile.media('screen and (min-width: 768px)')) { | |
$('map a:first').click(); | |
$('#settings a:first').click(); | |
}*/ | |
}); | }); |
"; | "; |
if (!isset($_SESSION['lat']) || $_SESSION['lat'] == "") echo "geolocate();"; | if (!isset($_SESSION['lat']) || $_SESSION['lat'] == "") echo "geolocate();"; |
echo "</script> "; | echo "</script> "; |
} | } |
if (isAnalyticsOn()) echo ' | if (isAnalyticsOn()) echo ' |
<script type="text/javascript">' . " | <script type="text/javascript">' . " |
var _gaq = _gaq || []; | var _gaq = _gaq || []; |
_gaq.push(['_setAccount', 'UA-22173039-1']); | _gaq.push(['_setAccount', 'UA-22173039-1']); |
_gaq.push(['_trackPageview']); | _gaq.push(['_trackPageview']); |
_gaq.push(['_trackPageLoadTime']); | _gaq.push(['_trackPageLoadTime']); |
</script>"; | </script>"; |
echo '</head> | echo '</head> |
<body> | <body> |
<div id="skip"> | <div id="skip"> |
<a href="#maincontent">Skip to content</a> | <a href="#maincontent">Skip to content</a> |
</div> | </div> |
'; | '; |
if ($opendiv) { | if ($opendiv) { |
echo '<div data-role="page"> | echo '<div data-role="page"> |
<div data-role="header" data-position="inline"> | <div data-role="header" data-position="inline"> |
<a href="' . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "javascript:history.go(-1)") . '" data-icon="arrow-l" data-rel="back" class="ui-btn-left">Back</a> | <a href="' . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "javascript:history.go(-1)") . '" data-icon="arrow-l" data-rel="back" class="ui-btn-left">Back</a> |
<h1>' . $pageTitle . '</h1> | <h1>' . $pageTitle . '</h1> |
<a href="/index.php" data-icon="home" class="ui-btn-right">Home</a> | <a href="/index.php" data-icon="home" class="ui-btn-right">Home</a> |
</div><!-- /header --> | </div><!-- /header --> |
<a name="maincontent" id="maincontent"></a> | <a name="maincontent" id="maincontent"></a> |
<div data-role="content"> '; | <div data-role="content"> '; |
$overrides = getServiceOverride(); | $overrides = getServiceOverride(); |
if ($overrides['service_id']) { | if ($overrides['service_id']) { |
if ($overrides['service_id'] == "noservice") { | if ($overrides['service_id'] == "noservice") { |
echo '<div id="servicewarning">Buses are <strong>not running today</strong> due to industrial action/public holiday. See <a | 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>'; | href="http://www.action.act.gov.au">http://www.action.act.gov.au</a> for details.</div>'; |
} | } |
else { | else { |
echo '<div id="servicewarning">Buses are running on an altered timetable today 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>'; | echo '<div id="servicewarning">Buses are running on an altered timetable today 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>'; |
} | } |
} | } |
} | } |
} | } |
function include_footer() | function include_footer() |
{ | { |
echo '<div id="footer"><a href="about.php">About/Contact Us</a> <a href="feedback.php">Feedback/Bug Report</a>'; | echo '<div id="footer"><a href="about.php">About/Contact Us</a> <a href="feedback.php">Feedback/Bug Report</a>'; |
echo '</div>'; | echo '</div>'; |
if (isAnalyticsOn()) { | if (isAnalyticsOn()) { |
echo "<script> (function() { | echo "<script> (function() { |
var ga = document.createElement('script'); ga.type = | var ga = document.createElement('script'); ga.type = |
'text/javascript'; ga.async = true; | 'text/javascript'; ga.async = true; |
ga.src = ('https:' == document.location.protocol ? | ga.src = ('https:' == document.location.protocol ? |
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
var s = document.getElementsByTagName('script')[0]; | var s = document.getElementsByTagName('script')[0]; |
s.parentNode.insertBefore(ga, s); | s.parentNode.insertBefore(ga, s); |
})();</script>"; | })();</script>"; |
$googleAnalyticsImageUrl = googleAnalyticsGetImageUrl(); | $googleAnalyticsImageUrl = googleAnalyticsGetImageUrl(); |
echo '<noscript><img src="' . $googleAnalyticsImageUrl . '" /></noscript>'; | echo '<noscript><img src="' . $googleAnalyticsImageUrl . '" /></noscript>'; |
} | } |
echo "\n</div></div></body></html>"; | echo "\n</div></div></body></html>"; |
} | } |
function timePlaceSettings($geolocate = false) | function timePlaceSettings($geolocate = false) |
{ | { |
global $service_periods; | global $service_periods; |
$geoerror = false; | $geoerror = false; |
if ($geolocate == true) { | if ($geolocate == true) { |
$geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == ""; | $geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == ""; |
} | } |
echo '<div id="error">'; | echo '<div id="error">'; |
if ($geoerror) { | if ($geoerror) { |
echo 'Sorry, but your location could not currently be detected. | echo 'Sorry, but your location could not currently be detected. |
Please allow location permission, wait for your location to be detected, | Please allow location permission, wait for your location to be detected, |
or enter an address/co-ordinates in the box below.'; | or enter an address/co-ordinates in the box below.'; |
} | } |
echo '</div>'; | echo '</div>'; |
echo '<div data-role="collapsible" data-collapsed="' . !$geoerror . '"> | echo '<div id="settings" data-role="collapsible" data-collapsed="' . !$geoerror . '"> |
<h3>Change Time/Place (' . (isset($_SESSION['time']) ? $_SESSION['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...</h3> | <h3>Change Time/Place (' . (isset($_SESSION['time']) ? $_SESSION['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...</h3> |
<form action="' . basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'] . '" method="post"> | <form action="' . basename($_SERVER['PHP_SELF']) . "?" . $_SERVER['QUERY_STRING'] . '" method="post"> |
<div class="ui-body"> | <div class="ui-body"> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="geolocate"> Current Location: </label> | <label for="geolocate"> Current Location: </label> |
<input type="text" id="geolocate" name="geolocate" value="' . (isset($_SESSION['lat']) && isset($_SESSION['lon']) ? $_SESSION['lat'] . "," . $_SESSION['lon'] : "Enter co-ordinates or address here") . '"/> <a href="#" style="display:none" name="here" id="here">Here?</a> | <input type="text" id="geolocate" name="geolocate" value="' . (isset($_SESSION['lat']) && isset($_SESSION['lon']) ? $_SESSION['lat'] . "," . $_SESSION['lon'] : "Enter co-ordinates or address here") . '"/> <a href="#" style="display:none" name="here" id="here">Here?</a> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="time"> Time: </label> | <label for="time"> Time: </label> |
<input type="time" name="time" id="time" value="' . (isset($_SESSION['time']) ? $_SESSION['time'] : date("H:i")) . '"/> | <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> | <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> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="service_period"> Service Period: </label> | <label for="service_period"> Service Period: </label> |
<select name="service_period" id="service_period">'; | <select name="service_period" id="service_period">'; |
foreach ($service_periods as $service_period) { | foreach ($service_periods as $service_period) { |
echo "<option value=\"$service_period\"" . (service_period() === $service_period ? " SELECTED" : "") . '>' . ucwords($service_period) . '</option>'; | echo "<option value=\"$service_period\"" . (service_period() === $service_period ? " SELECTED" : "") . '>' . ucwords($service_period) . '</option>'; |
} | } |
echo '</select> | echo '</select> |
<a href="#" style="display:none" name="currentPeriod" id="currentPeriod">Current Period?</a> | <a href="#" style="display:none" name="currentPeriod" id="currentPeriod">Current Period?</a> |
</div> | </div> |
<input type="submit" value="Update"/> | <input type="submit" value="Update"/> |
</div></form> | </div></form> |
</div>'; | </div>'; |
} | } |
function trackEvent($category, $action, $label = "", $value = - 1) | function trackEvent($category, $action, $label = "", $value = - 1) |
{ | { |
if (isAnalyticsOn()) { | if (isAnalyticsOn()) { |
echo "\n<script> _gaq.push(['_trackEvent', '$category', '$action'" . ($label != "" ? ", '$label'" : "") . ($value != - 1 ? ", $value" : "") . "]);</script>"; | echo "\n<script> _gaq.push(['_trackEvent', '$category', '$action'" . ($label != "" ? ", '$label'" : "") . ($value != - 1 ? ", $value" : "") . "]);</script>"; |
} | } |
} | } |
?> | ?> |
<?php | <?php |
date_default_timezone_set('Australia/ACT'); | date_default_timezone_set('Australia/ACT'); |
$debugOkay = Array( | $debugOkay = Array( |
"session", | "session", |
"json", | "json", |
"phperror", | "phperror", |
"awsotp", | "awsotp", |
//"squallotp", | //"squallotp", |
"vanilleotp", | "vanilleotp", |
"database", | "database", |
"other" | "other" |
); | ); |
$cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6"; | $cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6"; |
$googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q"; | $googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q"; |
$otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/'; |
if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com") { | if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com") { |
$otpAPIurl = 'http://bus-main.lambdacomplex.org:8080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://bus-main.lambdacomplex.org:8080/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("dotcloudotp") || php_uname('n') == "actbus-www") { | if (isDebug("dotcloudotp") || php_uname('n') == "actbus-www") { |
$otpAPIurl = 'http://otp.actbus.dotcloud.com/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://otp.actbus.dotcloud.com/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("squallotp")) { | if (isDebug("squallotp")) { |
$otpAPIurl = 'http://10.0.1.108:5080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://10.0.1.108:5080/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("vanilleotp")) { | if (isDebug("vanilleotp")) { |
$otpAPIurl = 'http://10.0.1.135:8080/opentripplanner-api-webapp/'; | $otpAPIurl = 'http://10.0.1.135:8080/opentripplanner-api-webapp/'; |
} | } |
if (isDebug("phperror")) error_reporting(E_ALL ^ E_NOTICE); | if (isDebug("phperror")) error_reporting(E_ALL ^ E_NOTICE); |
include_once ("common-geo.inc.php"); | include_once ("common-geo.inc.php"); |
include_once ("common-net.inc.php"); | include_once ("common-net.inc.php"); |
include_once ("common-transit.inc.php"); | include_once ("common-transit.inc.php"); |
include_once ("common-db.inc.php"); | include_once ("common-db.inc.php"); |
include_once ("common-request.inc.php"); | include_once ("common-request.inc.php"); |
include_once ("common-session.inc.php"); | include_once ("common-session.inc.php"); |
include_once ("common-template.inc.php"); | include_once ("common-template.inc.php"); |
function isDebugServer() | function isDebugServer() |
{ | { |
return $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || !$_SERVER['SERVER_NAME']; | return $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || !$_SERVER['SERVER_NAME']; |
} | } |
function isAnalyticsOn() | function isAnalyticsOn() |
{ | { |
return !isDebugServer(); | return !isDebugServer(); |
} | } |
function isDebug($debugReason = "other") | function isDebug($debugReason = "other") |
{ | { |
global $debugOkay; | global $debugOkay; |
return in_array($debugReason, $debugOkay, false) && isDebugServer(); | return in_array($debugReason, $debugOkay, false) && isDebugServer(); |
} | } |
function debug($msg, $debugReason = "other") | function debug($msg, $debugReason = "other") |
{ | { |
if (isDebug($debugReason)) echo "\n<!-- " . date(DATE_RFC822) . "\n $msg -->\n"; | if (isDebug($debugReason)) echo "\n<!-- " . date(DATE_RFC822) . "\n $msg -->\n"; |
} | } |
function isJQueryMobileDevice() | function isJQueryMobileDevice() |
{ | { |
// http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897 | // http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897 |
$user_agent = $_SERVER['HTTP_USER_AGENT']; | $user_agent = $_SERVER['HTTP_USER_AGENT']; |
return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5); | return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5); |
} | } |
function isFastDevice() | function isFastDevice() |
{ | { |
$ua = $_SERVER['HTTP_USER_AGENT']; | $ua = $_SERVER['HTTP_USER_AGENT']; |
$fastDevices = Array( | $fastDevices = Array( |
"Mozilla/5.0 (X11;", | "Mozilla/5.0 (X11;", |
"Mozilla/5.0 (Windows;", | "Mozilla/5.0 (Windows;", |
"Mozilla/5.0 (iP", | "Mozilla/5.0 (iP", |
"Mozilla/5.0 (Linux; U; Android", | "Mozilla/5.0 (Linux; U; Android", |
"Mozilla/4.0 (compatible; MSIE" | "Mozilla/4.0 (compatible; MSIE" |
); | ); |
$slowDevices = Array( | $slowDevices = Array( |
"J2ME", | "J2ME", |
"MIDP", | "MIDP", |
"Opera/", | "Opera/", |
"Mozilla/2.0 (compatible;", | "Mozilla/2.0 (compatible;", |
"Mozilla/3.0 (compatible;" | "Mozilla/3.0 (compatible;" |
); | ); |
return true; | return true; |
} | } |
function array_flatten($a, $f = array()) | function array_flatten($a, $f = array()) |
{ | { |
if (!$a || !is_array($a)) return ''; | if (!$a || !is_array($a)) return ''; |
foreach ($a as $k => $v) { | foreach ($a as $k => $v) { |
if (is_array($v)) $f = array_flatten($v, $f); | if (is_array($v)) $f = array_flatten($v, $f); |
else $f[$k] = $v; | else $f[$k] = $v; |
} | } |
return $f; | return $f; |
} | } |
function remove_spaces($string) | function remove_spaces($string) |
{ | { |
return str_replace(' ', '', $string); | return str_replace(' ', '', $string); |
} | } |
function object2array($object) | function object2array($object) |
{ | { |
if (is_object($object)) { | if (is_object($object)) { |
foreach ($object as $key => $value) { | foreach ($object as $key => $value) { |
$array[$key] = $value; | $array[$key] = $value; |
} | } |
} | } |
else { | else { |
$array = $object; | $array = $object; |
} | } |
return $array; | return $array; |
} | } |
function startsWith($haystack, $needle, $case = true) | function startsWith($haystack, $needle, $case = true) |
{ | { |
if ($case) { | if ($case) { |
return (strcmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); | return (strcmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); |
} | } |
return (strcasecmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); | return (strcasecmp(substr($haystack, 0, strlen($needle)) , $needle) === 0); |
} | } |
function endsWith($haystack, $needle, $case = true) | function endsWith($haystack, $needle, $case = true) |
{ | { |
if ($case) { | if ($case) { |
return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); | return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); |
} | } |
return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); | return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)) , $needle) === 0); |
} | } |
function bracketsMeanNewLine($input) | function bracketsMeanNewLine($input) |
{ | { |
return str_replace(")", "</small>", str_replace("(", "<br><small>", $input)); | return str_replace(")", "</small>", str_replace("(", "<br><small>", $input)); |
} | } |
function sksort(&$array, $subkey = "id", $sort_ascending = false) | function sksort(&$array, $subkey = "id", $sort_ascending = false) |
{ | { |
if (count($array)) $temp_array[key($array) ] = array_shift($array); | if (count($array)) $temp_array[key($array) ] = array_shift($array); |
foreach ($array as $key => $val) { | foreach ($array as $key => $val) { |
$offset = 0; | $offset = 0; |
$found = false; | $found = false; |
foreach ($temp_array as $tmp_key => $tmp_val) { | foreach ($temp_array as $tmp_key => $tmp_val) { |
if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { | if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { |
$temp_array = array_merge((array)array_slice($temp_array, 0, $offset) , array( | $temp_array = array_merge((array)array_slice($temp_array, 0, $offset) , array( |
$key => $val | $key => $val |
) , array_slice($temp_array, $offset)); | ) , array_slice($temp_array, $offset)); |
$found = true; | $found = true; |
} | } |
$offset++; | $offset++; |
} | } |
if (!$found) $temp_array = array_merge($temp_array, array( | if (!$found) $temp_array = array_merge($temp_array, array( |
$key => $val | $key => $val |
)); | )); |
} | } |
if ($sort_ascending) $array = array_reverse($temp_array); | if ($sort_ascending) $array = array_reverse($temp_array); |
else $array = $temp_array; | else $array = $temp_array; |
} | } |
function sktimesort(&$array, $subkey = "id", $sort_ascending = false) | function sktimesort(&$array, $subkey = "id", $sort_ascending = false) |
{ | { |
if (count($array)) $temp_array[key($array) ] = array_shift($array); | if (count($array)) $temp_array[key($array) ] = array_shift($array); |
foreach ($array as $key => $val) { | foreach ($array as $key => $val) { |
$offset = 0; | $offset = 0; |
$found = false; | $found = false; |
foreach ($temp_array as $tmp_key => $tmp_val) { | foreach ($temp_array as $tmp_key => $tmp_val) { |
if (!$found and strtotime($val[$subkey]) > strtotime($tmp_val[$subkey])) { | if (!$found and strtotime($val[$subkey]) > strtotime($tmp_val[$subkey])) { |
$temp_array = array_merge((array)array_slice($temp_array, 0, $offset) , array( | $temp_array = array_merge((array)array_slice($temp_array, 0, $offset) , array( |
$key => $val | $key => $val |
) , array_slice($temp_array, $offset)); | ) , array_slice($temp_array, $offset)); |
$found = true; | $found = true; |
} | } |
$offset++; | $offset++; |
} | } |
if (!$found) $temp_array = array_merge($temp_array, array( | if (!$found) $temp_array = array_merge($temp_array, array( |
$key => $val | $key => $val |
)); | )); |
} | } |
if ($sort_ascending) $array = array_reverse($temp_array); | if ($sort_ascending && isset($temp_array)) $array = array_reverse($temp_array); |
else $array = $temp_array; | else $array = $temp_array; |
} | } |
function r_implode( $glue, $pieces ) | function r_implode( $glue, $pieces ) |
{ | { |
foreach( $pieces as $r_pieces ) | foreach( $pieces as $r_pieces ) |
{ | { |
if( is_array( $r_pieces ) ) | if( is_array( $r_pieces ) ) |
{ | { |
$retVal[] = r_implode( $glue, $r_pieces ); | $retVal[] = r_implode( $glue, $r_pieces ); |
} | } |
else | else |
{ | { |
$retVal[] = $r_pieces; | $retVal[] = $r_pieces; |
} | } |
} | } |
return implode( $glue, $retVal ); | return implode( $glue, $retVal ); |
} | } |
?> | ?> |
<?php | <?php |
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 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 = "") | function getRoutesByNumber($routeNumber = "") |
{ | { |
global $conn; | global $conn; |
if ($routeNumber != "") { | 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 = | $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 order by route_short_name;"; | routes.route_id join stop_times on stop_times.trip_id = trips.trip_id where route_short_name = :routeNumber order by route_short_name;"; |
} | } |
else { | else { |
$query = "SELECT DISTINCT route_short_name from routes order by route_short_name"; | $query = "SELECT DISTINCT route_short_name from routes order by route_short_name"; |
} | } |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
if ($routeNumber != "") { | if ($routeNumber != "") { |
$query->bindParam(":routeNumber", $routeNumber); | $query->bindParam(":routeNumber", $routeNumber); |
} | } |
$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) | function getRouteNextTrip($routeID) |
{ | { |
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 | join stop_times on stop_times.trip_id = trips.trip_id where |
arrival_time > :currentTime and routes.route_id = :routeID order by | arrival_time > :currentTime and routes.route_id = :routeID 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(":routeID", $routeID); | $query->bindParam(":routeID", $routeID); |
$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); |
// past last trip of the day special case | // past last trip of the day special case |
if (sizeof($r) < 16) { | if (sizeof($r) < 16) { |
$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 order by | join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID 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->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 getTimeInterpolatedRouteAtStop($routeID, $stop_id) | function getTimeInterpolatedRouteAtStop($routeID, $stop_id) |
{ | { |
$nextTrip = getRouteNextTrip($routeID); | $nextTrip = getRouteNextTrip($routeID); |
if ($nextTrip['trip_id']) { | if ($nextTrip['trip_id']) { |
foreach (getTimeInterpolatedTrip($nextTrip['trip_id']) as $tripStop) { | foreach (getTimeInterpolatedTrip($nextTrip['trip_id']) as $tripStop) { |
if ($tripStop['stop_id'] == $stop_id) return $tripStop; | if ($tripStop['stop_id'] == $stop_id) return $tripStop; |
} | } |
} | } |
return Array(); | return Array(); |
} | } |
function getRouteTrips($routeID) | function getRouteTrips($routeID) |
{ | { |
global $conn; | global $conn; |
$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 routes.route_id = :routeID and stop_sequence = '1' order by | join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID 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->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 == "") $service_period = service_period(); | if ($service_period == "") $service_period = service_period(); |
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_period order by route_short_name"; | WHERE route_long_name = :destination AND service_id=:service_period 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_period order by route_long_name"; | WHERE service_id= :service_period order by route_long_name"; |
} | } |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":service_period", $service_period); | $query->bindParam(":service_period", $service_period); |
if ($destination != "") $query->bindParam(":destination", $destination); | if ($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 == "") $service_period = service_period(); | if ($service_period == "") $service_period = service_period(); |
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 zone_id LIKE ':suburb AND service_id=:service_period ORDER BY route_short_name"; | WHERE zone_id LIKE ':suburb AND service_id=:service_period ORDER BY route_short_name"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":service_period", $service_period); | $query->bindParam(":service_period", $service_period); |
$suburb = "%" . $suburb . ";%"; | $suburb = "%" . $suburb . ";%"; |
$query->bindParam(":suburb", $suburb); | $query->bindParam(":suburb", $suburb); |
$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 getRoutesNearby($lat, $lng, $limit = "", $distance = 500) | function getRoutesNearby($lat, $lng, $limit = "", $distance = 500) |
{ | { |
if ($service_period == "") $service_period = service_period(); | if ($service_period == "") $service_period = service_period(); |
if ($limit != "") $limitSQL = " LIMIT :limit "; | if ($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_period | WHERE service_id=:service_period |
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_period", $service_period); | $query->bindParam(":service_period", $service_period); |
$query->bindParam(":distance", $distance); | $query->bindParam(":distance", $distance); |
$query->bindParam(":limit", $limit); | if ($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 |
function getStop($stopID) | function getStop($stopID) |
{ | { |
global $conn; | global $conn; |
$query = "Select * from stops where stop_id = :stopID LIMIT 1"; | $query = "Select * from stops where stop_id = :stopID LIMIT 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":stopID", $stopID); | $query->bindParam(":stopID", $stopID); |
$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 getStops($timingPointsOnly = false, $firstLetter = "") | function getStops($timingPointsOnly = false, $firstLetter = "") |
{ | { |
global $conn; | global $conn; |
$conditions = Array(); | $conditions = Array(); |
if ($timingPointsOnly) $conditions[] = "substr(stop_code,1,2) != 'Wj'"; | if ($timingPointsOnly) $conditions[] = "substr(stop_code,1,2) != 'Wj'"; |
if ($firstLetter != "") $conditions[] = "substr(stop_name,1,1) = :firstLetter"; | if ($firstLetter != "") $conditions[] = "substr(stop_name,1,1) = :firstLetter"; |
$query = "Select * from stops"; | $query = "Select * from stops"; |
if (sizeof($conditions) > 0) { | if (sizeof($conditions) > 0) { |
if (sizeof($conditions) > 1) { | if (sizeof($conditions) > 1) { |
$query.= " Where " . implode(" AND ", $conditions) . " "; | $query.= " Where " . implode(" AND ", $conditions) . " "; |
} | } |
else { | else { |
$query.= " Where " . $conditions[0] . " "; | $query.= " Where " . $conditions[0] . " "; |
} | } |
} | } |
$query.= " order by stop_name;"; | $query.= " order by stop_name;"; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":firstLetter", $firstLetter); | if ($firstLetter != "") $query->bindParam(":firstLetter", $firstLetter); |
$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 getNearbyStops($lat, $lng, $limit = "", $distance = 1000) | function getNearbyStops($lat, $lng, $limit = "", $distance = 1000) |
{ | { |
if ($lat == null || $lng == null) return Array(); | if ($lat == null || $lng == null) return Array(); |
if ($limit != "") $limitSQL = " LIMIT :limit "; | if ($limit != "") $limitSQL = " LIMIT :limit "; |
global $conn; | global $conn; |
$query = "Select *, ST_Distance(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), FALSE) as distance | $query = "Select *, ST_Distance(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), FALSE) as distance |
from stops WHERE ST_DWithin(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), :distance, FALSE) | from stops WHERE ST_DWithin(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), :distance, FALSE) |
order by distance $limitSQL;"; | order by distance $limitSQL;"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":distance", $distance); | $query->bindParam(":distance", $distance); |
$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(); |
} | } |
function getStopsBySuburb($suburb) | function getStopsBySuburb($suburb) |
{ | { |
global $conn; | global $conn; |
$query = "Select * from stops where zone_id LIKE :suburb order by stop_name;"; | $query = "Select * from stops where zone_id LIKE :suburb order by stop_name;"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$suburb = "%" . $suburb . ";%"; | $suburb = "%" . $suburb . ";%"; |
$query->bindParam(":suburb", $suburb); | $query->bindParam(":suburb", $suburb); |
$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 getStopRoutes($stopID, $service_period) | function getStopRoutes($stopID, $service_period) |
{ | { |
if ($service_period == "") $service_period = service_period(); | if ($service_period == "") $service_period = service_period(); |
global $conn; | global $conn; |
$query = "SELECT service_id,trips.route_id,route_short_name,route_long_name | $query = "SELECT service_id,trips.route_id,route_short_name,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 WHERE stop_id = :stopID AND service_id=:service_period"; | stop_times.trip_id join routes on trips.route_id = routes.route_id WHERE stop_id = :stopID AND service_id=:service_period"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":service_period", $service_period); | $query->bindParam(":service_period", $service_period); |
$query->bindParam(":stopID", $stopID); | $query->bindParam(":stopID", $stopID); |
$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 getStopTrips($stopID, $service_period = "", $afterTime = "") | function getStopTrips($stopID, $service_period = "", $afterTime = "") |
{ | { |
if ($service_period == "") $service_period = service_period(); | if ($service_period == "") $service_period = service_period(); |
global $conn; | global $conn; |
if ($afterTime != "") { | if ($afterTime != "") { |
$query = " SELECT stop_times.trip_id,stop_times.arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,route_short_name,route_long_name, end_times.arrival_time as end_time | $query = " SELECT stop_times.trip_id,stop_times.arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,route_short_name,route_long_name, end_times.arrival_time as end_time |
FROM stop_times | FROM stop_times |
join trips on trips.trip_id = | join trips on trips.trip_id = |
stop_times.trip_id | stop_times.trip_id |
join routes on trips.route_id = routes.route_id , (SELECT trip_id,max(arrival_time) as arrival_time from stop_times | join routes on trips.route_id = routes.route_id , (SELECT trip_id,max(arrival_time) as arrival_time from stop_times |
WHERE stop_times.arrival_time IS NOT NULL group by trip_id) as end_times | WHERE stop_times.arrival_time IS NOT NULL group by trip_id) as end_times |
WHERE stop_times.stop_id = :stopID | WHERE stop_times.stop_id = :stopID |
AND stop_times.trip_id = end_times.trip_id | AND stop_times.trip_id = end_times.trip_id |
AND service_id=:service_period | AND service_id=:service_period |
AND end_times.arrival_time > :afterTime | AND end_times.arrival_time > :afterTime |
ORDER BY end_time"; | ORDER BY end_time"; |
} | } |
else { | else { |
$query = "SELECT stop_times.trip_id,arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,route_short_name,route_long_name | $query = "SELECT stop_times.trip_id,arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,route_short_name,route_long_name |
FROM stop_times | FROM stop_times |
join trips on trips.trip_id = | join trips on trips.trip_id = |
stop_times.trip_id | stop_times.trip_id |
join routes on trips.route_id = routes.route_id | join routes on trips.route_id = routes.route_id |
WHERE stop_times.stop_id = :stopID | WHERE stop_times.stop_id = :stopID |
AND service_id=:service_period | AND service_id=:service_period |
ORDER BY arrival_time"; | ORDER BY arrival_time"; |
} | } |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":service_period", $service_period); | $query->bindParam(":service_period", $service_period); |
$query->bindParam(":stopID", $stopID); | $query->bindParam(":stopID", $stopID); |
if ($afterTime != "") $query->bindParam(":afterTime", $afterTime); | if ($afterTime != "") $query->bindParam(":afterTime", $afterTime); |
$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 getStopTripsWithTimes($stopID, $time = "", $service_period = "", $time_range = "", $limit = "") | function getStopTripsWithTimes($stopID, $time = "", $service_period = "", $time_range = "", $limit = "") |
{ | { |
if ($service_period == "") $service_period = service_period(); | if ($service_period == "") $service_period = service_period(); |
if ($time_range == "") $time_range = (24 * 60 * 60); | if ($time_range == "") $time_range = (24 * 60 * 60); |
if ($time == "") $time = current_time(); | if ($time == "") $time = current_time(); |
if ($limit == "") $limit = 10; | if ($limit == "") $limit = 10; |
$trips = getStopTrips($stopID, $service_period, $time); | $trips = getStopTrips($stopID, $service_period, $time); |
$timedTrips = Array(); | $timedTrips = Array(); |
if ($trips && sizeof($trips) > 0) { | if ($trips && sizeof($trips) > 0) { |
foreach ($trips as $trip) { | foreach ($trips as $trip) { |
if ($trip['arrival_time'] != "") { | if ($trip['arrival_time'] != "") { |
if (strtotime($trip['arrival_time']) > strtotime($time) and strtotime($trip['arrival_time']) < (strtotime($time) + $time_range)) { | if (strtotime($trip['arrival_time']) > strtotime($time) and strtotime($trip['arrival_time']) < (strtotime($time) + $time_range)) { |
$timedTrips[] = $trip; | $timedTrips[] = $trip; |
} | } |
} | } |
else { | else { |
$timedTrip = getTimeInterpolatedTripAtStop($trip['trip_id'], $trip['stop_sequence']); | $timedTrip = getTimeInterpolatedTripAtStop($trip['trip_id'], $trip['stop_sequence']); |
if ($timedTrip['arrival_time'] > $time and strtotime($timedTrip['arrival_time']) < (strtotime($time) + $time_range)) { | if ($timedTrip['arrival_time'] > $time and strtotime($timedTrip['arrival_time']) < (strtotime($time) + $time_range)) { |
$timedTrips[] = $timedTrip; | $timedTrips[] = $timedTrip; |
} | } |
} | } |
if (sizeof($timedTrips) > $limit) break; | if (sizeof($timedTrips) > $limit) break; |
} | } |
sktimesort($timedTrips, "arrival_time", true); | sktimesort($timedTrips, "arrival_time", true); |
} | } |
return $timedTrips; | return $timedTrips; |
} | } |
?> | ?> |
<?php | <?php |
function getTrip($tripID) | function getTrip($tripID) |
{ | { |
global $conn; | global $conn; |
$query = "Select * from trips | $query = "Select * from trips |
join routes on trips.route_id = routes.route_id | join routes on trips.route_id = routes.route_id |
where trip_id = :tripID | where trip_id = :tripID |
LIMIT 1"; | LIMIT 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":tripID", $tripID); | $query->bindParam(":tripID", $tripID); |
$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 getTripShape() | function getTripShape($tripID) |
{ | { |
/* def handle_json_GET_tripstopTimes(self, params): | global $conn; |
schedule = self.server.schedule | $query = "SELECT ST_AsKML(ST_MakeLine(geometry(a.position))) as the_route |
try: | FROM (SELECT position, |
trip = schedule.GetTrip(params.get('trip')) | stop_sequence, trips.trip_id |
except KeyError: | FROM stop_times |
# if a non-existent trip is searched for, the return nothing | join trips on trips.trip_id = stop_times.trip_id |
return | join stops on stops.stop_id = stop_times.stop_id |
time_stops = trip.GetTimeInterpolatedStops() | WHERE trips.trip_id = :tripID ORDER BY stop_sequence) as a group by a.trip_id"; |
stops = [] | debug($query, "database"); |
times = [] | $query = $conn->prepare($query); |
for arr,ts,is_timingpoint in time_stops: | $query->bindParam(":tripID", $tripID); |
stops.append(StopToTuple(ts.stop)) | $query->execute(); |
times.append(arr) | if (!$query) { |
return [stops, times] | databaseError($conn->errorInfo()); |
return Array(); | |
def handle_json_GET_tripshape(self, params): | } |
schedule = self.server.schedule | return $query->fetchColumn(0); |
try: | |
trip = schedule.GetTrip(params.get('trip')) | |
except KeyError: | |
# if a non-existent trip is searched for, the return nothing | |
return | |
points = [] | |
if trip.shape_id: | |
shape = schedule.GetShape(trip.shape_id) | |
for (lat, lon, dist) in shape.points: | |
points.append((lat, lon)) | |
else: | |
time_stops = trip.GetTimeStops() | |
for arr,dep,stop in time_stops: | |
points.append((stop.stop_lat, stop.stop_lon)) | |
return points*/ | |
} | } |
function getTimeInterpolatedTrip($tripID, $range = "") | function getTimeInterpolatedTrip($tripID, $range = "") |
{ | { |
global $conn; | global $conn; |
$query = "SELECT stop_times.trip_id,arrival_time,stop_times.stop_id,stop_lat,stop_lon,stop_name,stop_code, | $query = "SELECT stop_times.trip_id,arrival_time,stop_times.stop_id,stop_lat,stop_lon,stop_name,stop_code, |
stop_sequence,service_id,trips.route_id,route_short_name,route_long_name | stop_sequence,service_id,trips.route_id,route_short_name,route_long_name |
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 trips.trip_id = :tripID $range ORDER BY stop_sequence"; | WHERE trips.trip_id = :tripID $range ORDER BY stop_sequence"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":tripID", $tripID); | $query->bindParam(":tripID", $tripID); |
$query->execute(); | $query->execute(); |
if (!$query) { | if (!$query) { |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
return Array(); | return Array(); |
} | } |
$stopTimes = $query->fetchAll(); | $stopTimes = $query->fetchAll(); |
$cur_timepoint = Array(); | $cur_timepoint = Array(); |
$next_timepoint = Array(); | $next_timepoint = Array(); |
$distance_between_timepoints = 0.0; | $distance_between_timepoints = 0.0; |
$distance_traveled_between_timepoints = 0.0; | $distance_traveled_between_timepoints = 0.0; |
$rv = Array(); | $rv = Array(); |
foreach ($stopTimes as $i => $stopTime) { | foreach ($stopTimes as $i => $stopTime) { |
if ($stopTime['arrival_time'] != "") { | if ($stopTime['arrival_time'] != "") { |
// is timepoint | // is timepoint |
$cur_timepoint = $stopTime; | $cur_timepoint = $stopTime; |
$distance_between_timepoints = 0.0; | $distance_between_timepoints = 0.0; |
$distance_traveled_between_timepoints = 0.0; | $distance_traveled_between_timepoints = 0.0; |
if ($i + 1 < sizeof($stopTimes)) { | if ($i + 1 < sizeof($stopTimes)) { |
$k = $i + 1; | $k = $i + 1; |
$distance_between_timepoints+= distance($stopTimes[$k - 1]["stop_lat"], $stopTimes[$k - 1]["stop_lon"], $stopTimes[$k]["stop_lat"], $stopTimes[$k]["stop_lon"]); | $distance_between_timepoints+= distance($stopTimes[$k - 1]["stop_lat"], $stopTimes[$k - 1]["stop_lon"], $stopTimes[$k]["stop_lat"], $stopTimes[$k]["stop_lon"]); |
while ($stopTimes[$k]["arrival_time"] == "" && $k + 1 < sizeof($stopTimes)) { | while ($stopTimes[$k]["arrival_time"] == "" && $k + 1 < sizeof($stopTimes)) { |
$k+= 1; | $k+= 1; |
//echo "k".$k; | //echo "k".$k; |
$distance_between_timepoints+= distance($stopTimes[$k - 1]["stop_lat"], $stopTimes[$k - 1]["stop_lon"], $stopTimes[$k]["stop_lat"], $stopTimes[$k]["stop_lon"]); | $distance_between_timepoints+= distance($stopTimes[$k - 1]["stop_lat"], $stopTimes[$k - 1]["stop_lon"], $stopTimes[$k]["stop_lat"], $stopTimes[$k]["stop_lon"]); |
} | } |
$next_timepoint = $stopTimes[$k]; | $next_timepoint = $stopTimes[$k]; |
$rv[] = $stopTime; | $rv[] = $stopTime; |
} | } |
} | } |
else { | else { |
// is untimed point | // is untimed point |
//echo "i".$i; | //echo "i".$i; |
$distance_traveled_between_timepoints+= distance($stopTimes[$i - 1]["stop_lat"], $stopTimes[$i - 1]["stop_lon"], $stopTimes[$i]["stop_lat"], $stopTimes[$i]["stop_lon"]); | $distance_traveled_between_timepoints+= distance($stopTimes[$i - 1]["stop_lat"], $stopTimes[$i - 1]["stop_lon"], $stopTimes[$i]["stop_lat"], $stopTimes[$i]["stop_lon"]); |
//echo "$distance_traveled_between_timepoints / $distance_between_timepoints<br>"; | //echo "$distance_traveled_between_timepoints / $distance_between_timepoints<br>"; |
$distance_percent = $distance_traveled_between_timepoints / $distance_between_timepoints; | $distance_percent = $distance_traveled_between_timepoints / $distance_between_timepoints; |
if ($next_timepoint["arrival_time"] != "") { | if ($next_timepoint["arrival_time"] != "") { |
$total_time = strtotime($next_timepoint["arrival_time"]) - strtotime($cur_timepoint["arrival_time"]); | $total_time = strtotime($next_timepoint["arrival_time"]) - strtotime($cur_timepoint["arrival_time"]); |
//echo strtotime($next_timepoint["arrival_time"])." - ".strtotime($cur_timepoint["arrival_time"])."<br>"; | //echo strtotime($next_timepoint["arrival_time"])." - ".strtotime($cur_timepoint["arrival_time"])."<br>"; |
$time_estimate = ($distance_percent * $total_time) + strtotime($cur_timepoint["arrival_time"]); | $time_estimate = ($distance_percent * $total_time) + strtotime($cur_timepoint["arrival_time"]); |
$stopTime["arrival_time"] = date("H:i:s", $time_estimate); | $stopTime["arrival_time"] = date("H:i:s", $time_estimate); |
} | } |
else { | else { |
$stopTime["arrival_time"] = $cur_timepoint["arrival_time"]; | $stopTime["arrival_time"] = $cur_timepoint["arrival_time"]; |
} | } |
$rv[] = $stopTime; | $rv[] = $stopTime; |
//var_dump($rv); | //var_dump($rv); |
} | } |
} | } |
return $rv; | return $rv; |
} | } |
function getTripPreviousTimePoint($tripID, $stop_sequence) | function getTripPreviousTimePoint($tripID, $stop_sequence) |
{ | { |
global $conn; | global $conn; |
$query = " SELECT trip_id,stop_id, | $query = " SELECT trip_id,stop_id, |
stop_sequence | stop_sequence |
FROM stop_times | FROM stop_times |
WHERE trip_id = :tripID and stop_sequence < :stop_sequence | WHERE trip_id = :tripID and stop_sequence < :stop_sequence |
and stop_times.arrival_time IS NOT NULL ORDER BY stop_sequence DESC LIMIT 1"; | and stop_times.arrival_time IS NOT NULL ORDER BY stop_sequence DESC LIMIT 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":tripID", $tripID); | $query->bindParam(":tripID", $tripID); |
$query->bindParam(":stop_sequence", $stop_sequence); | $query->bindParam(":stop_sequence", $stop_sequence); |
$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 getTripNextTimePoint($tripID, $stop_sequence) | function getTripNextTimePoint($tripID, $stop_sequence) |
{ | { |
global $conn; | global $conn; |
$query = " SELECT trip_id,stop_id, | $query = " SELECT trip_id,stop_id, |
stop_sequence | stop_sequence |
FROM stop_times | FROM stop_times |
WHERE trip_id = :tripID and stop_sequence > :stop_sequence | WHERE trip_id = :tripID and stop_sequence > :stop_sequence |
and stop_times.arrival_time IS NOT NULL ORDER BY stop_sequence LIMIT 1"; | and stop_times.arrival_time IS NOT NULL ORDER BY stop_sequence LIMIT 1"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":tripID", $tripID); | $query->bindParam(":tripID", $tripID); |
$query->bindParam(":stop_sequence", $stop_sequence); | $query->bindParam(":stop_sequence", $stop_sequence); |
$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 getTimeInterpolatedTripAtStop($tripID, $stop_sequence) | function getTimeInterpolatedTripAtStop($tripID, $stop_sequence) |
{ | { |
global $conn; | global $conn; |
// limit interpolation to between nearest actual points. | // limit interpolation to between nearest actual points. |
$prevTimePoint = getTripPreviousTimePoint($tripID, $stop_sequence); | $prevTimePoint = getTripPreviousTimePoint($tripID, $stop_sequence); |
$nextTimePoint = getTripNextTimePoint($tripID, $stop_sequence); | $nextTimePoint = getTripNextTimePoint($tripID, $stop_sequence); |
$range = "AND stop_sequence >= '{$prevTimePoint['stop_sequence']}' AND stop_sequence <= '{$nextTimePoint['stop_sequence']}'"; | $range = "AND stop_sequence >= '{$prevTimePoint['stop_sequence']}' AND stop_sequence <= '{$nextTimePoint['stop_sequence']}'"; |
foreach (getTimeInterpolatedTrip($tripID, $range) as $tripStop) { | foreach (getTimeInterpolatedTrip($tripID, $range) as $tripStop) { |
if ($tripStop['stop_sequence'] == $stop_sequence) return $tripStop; | if ($tripStop['stop_sequence'] == $stop_sequence) return $tripStop; |
} | } |
return Array(); | return Array(); |
} | } |
function getTripStartTime($tripID) | function getTripStartTime($tripID) |
{ | { |
global $conn; | global $conn; |
$query = "Select * from stop_times | $query = "Select * from stop_times |
where trip_id = :tripID | where trip_id = :tripID |
AND arrival_time IS NOT NULL | AND arrival_time IS NOT NULL |
AND stop_sequence = '1'"; | AND stop_sequence = '1'"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":tripID", $tripID); | $query->bindParam(":tripID", $tripID); |
$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['arrival_time']; | return $r['arrival_time']; |
} | } |
function getActiveTrips($time) | function getActiveTrips($time) |
{ | { |
global $conn; | global $conn; |
if ($time == "") $time = current_time(); | if ($time == "") $time = current_time(); |
$query = "Select distinct stop_times.trip_id, start_times.arrival_time as start_time, end_times.arrival_time as end_time from stop_times, (SELECT trip_id,arrival_time from stop_times WHERE stop_times.arrival_time IS NOT NULL | $query = "Select distinct stop_times.trip_id, start_times.arrival_time as start_time, end_times.arrival_time as end_time from stop_times, (SELECT trip_id,arrival_time from stop_times WHERE stop_times.arrival_time IS NOT NULL |
AND stop_sequence = '1') as start_times, (SELECT trip_id,max(arrival_time) as arrival_time from stop_times WHERE stop_times.arrival_time IS NOT NULL group by trip_id) as end_times | AND stop_sequence = '1') as start_times, (SELECT trip_id,max(arrival_time) as arrival_time from stop_times WHERE stop_times.arrival_time IS NOT NULL group by trip_id) as end_times |
WHERE start_times.trip_id = end_times.trip_id AND stop_times.trip_id = end_times.trip_id AND :time > start_times.arrival_time AND :time < end_times.arrival_time"; | WHERE start_times.trip_id = end_times.trip_id AND stop_times.trip_id = end_times.trip_id AND :time > start_times.arrival_time AND :time < end_times.arrival_time"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":time", $time); | $query->bindParam(":time", $time); |
$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 viaPoints($tripID, $stop_sequence = "") | function viaPoints($tripID, $stop_sequence = "") |
{ | { |
global $conn; | global $conn; |
$query = "SELECT stops.stop_id, stop_name, arrival_time | $query = "SELECT stops.stop_id, stop_name, arrival_time |
FROM stop_times join stops on stops.stop_id = stop_times.stop_id | FROM stop_times join stops on stops.stop_id = stop_times.stop_id |
WHERE stop_times.trip_id = :tripID | WHERE stop_times.trip_id = :tripID |
" . ($stop_sequence != "" ? " AND stop_sequence > :stop_sequence " : "") . "AND substr(stop_code,1,2) != 'Wj' ORDER BY stop_sequence"; | " . ($stop_sequence != "" ? " AND stop_sequence > :stop_sequence " : "") . "AND substr(stop_code,1,2) != 'Wj' ORDER BY stop_sequence"; |
debug($query, "database"); | debug($query, "database"); |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
if ($stop_sequence != "") $query->bindParam(":stop_sequence", $stop_sequence); | if ($stop_sequence != "") $query->bindParam(":stop_sequence", $stop_sequence); |
$query->bindParam(":tripID", $tripID); | $query->bindParam(":tripID", $tripID); |
$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 viaPointNames($tripid, $stop_sequence = "") | function viaPointNames($tripid, $stop_sequence = "") |
{ | { |
$viaPointNames = Array(); | $viaPointNames = Array(); |
foreach (viaPoints($tripid, $stop_sequence) as $point) { | foreach (viaPoints($tripid, $stop_sequence) as $point) { |
$viaPointNames[] = $point['stop_name']; | $viaPointNames[] = $point['stop_name']; |
} | } |
if (sizeof($viaPointNames) > 0) { | if (sizeof($viaPointNames) > 0) { |
return r_implode(", ", $viaPointNames); | return r_implode(", ", $viaPointNames); |
} | } |
else { | else { |
return ""; | return ""; |
} | } |
} | } |
?> | ?> |
<?php | <?php |
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">Major (Timing Point) Stops</a></li> | <li><a href="stopList.php">Major (Timing Point) Stops</a></li> |
<li><a href="stopList.php?allstops=yes">All Stops</a></li> | <li><a href="stopList.php?allstops=yes">All Stops</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> |
<?php | <?php |
echo timePlaceSettings(); | echo timePlaceSettings(); |
echo ' <a href="labs/index.php" data-role="button" data-icon="beaker">Busness R&D</a>'; | echo ' <a href="labs/index.php" data-role="button" data-icon="beaker">Busness R&D</a>'; |
include_footer(true) | include_footer(true) |
?> | ?> |
<?php | <?php |
include ('../include/common.inc.php'); | include ('../include/common.inc.php'); |
include_header("Busness R&D", "index") | include_header("Busness R&D", "index") |
?> | ?> |
<ul data-role="listview" data-theme="e" data-groupingtheme="e"> | <ul data-role="listview" data-theme="e" data-groupingtheme="e"> |
<li data-role="list-divider" > Experimental Features </li> | <li data-role="list-divider" > Experimental Features </li> |
<li><a href="mywaybalance.php"><h3>MyWay Balance for mobile</h3> | <li><a href="mywaybalance.php"><h3>MyWay Balance for mobile</h3> |
<p>Mobile viewer for MyWay balance. Warning! No HTTPS security.</p></a></li> | <p>Mobile viewer for MyWay balance. Warning! No HTTPS security.</p></a></li> |
<li><a href="networkstats.php"><h3>Route Statistics</h3> | <li><a href="networkstats.php"><h3>Route Statistics</h3> |
<p>Analysis of route timing points</p></a></li> | <p>Analysis of route timing points</p></a></li> |
<li><a href="busstopdensity.php"><h3>Bus Stop Density Map</h3> | <li><a href="busstopdensity.php"><h3>Bus Stop Density Map</h3> |
<p>Analysis of bus stop coverage</p></a></li> | <p>Analysis of bus stop coverage</p></a></li> |
<li><a href="stopBrowser.php"><h3>Bus Stop Browser Map</h3> | |
<p>Bus stop location/route browser</p></a></li> | |
<li>More coming soon!</li> | <li>More coming soon!</li> |
</ul> | </ul> |
</div> | </div> |
<?php | <?php |
include_footer() | include_footer() |
?> | ?> |
<?php | <?php |
function cleanString($subject) | function cleanString($subject) |
{ | { |
$subject = str_replace(" ", " ", $subject); | $subject = str_replace(" ", " ", $subject); |
$subject = str_replace("&", "&", $subject); | $subject = str_replace("&", "&", $subject); |
$subject = preg_replace('/[^\r\n\t\x20-\x7E\xA0-\xFF]/', '', $subject); | $subject = preg_replace('/[^\r\n\t\x20-\x7E\xA0-\xFF]/', '', $subject); |
$subject = str_replace(" ", " ", $subject); | $subject = str_replace(" ", " ", $subject); |
return trim($subject); | return trim($subject); |
} | } |
$return = Array(); | $return = Array(); |
/*if (file_exists("mywayresponse.txt")) { | /*if (file_exists("mywayresponse.txt")) { |
@$fh = fopen("mywayresponse.txt", 'r'); | @$fh = fopen("mywayresponse.txt", 'r'); |
if ($fh) { | if ($fh) { |
$pageHTML = fread($fh, filesize("mywayresponse.txt")); | $pageHTML = fread($fh, filesize("mywayresponse.txt")); |
fclose($fh); | fclose($fh); |
} | } |
}*/ | }*/ |
//set POST variables | //set POST variables |
$url = 'https://www.action.act.gov.au/ARTS/use_Funcs.asp'; | $url = 'https://www.action.act.gov.au/ARTS/use_Funcs.asp'; |
$field_mapping = Array( | $field_mapping = Array( |
"card_number" => "SRNO", | "card_number" => "SRNO", |
"DOBmonth" => "month", | "DOBmonth" => "month", |
"DOBday" => "day", | "DOBday" => "day", |
"DOByear" => "year", | "DOByear" => "year", |
"secret_answer" => "pwrd", | "secret_answer" => "pwrd", |
"button" => "button" | "button" => "Submit" |
); | ); |
foreach (Array( | foreach (Array( |
"card_number", | "card_number", |
"DOBday", | "DOBday", |
"DOBmonth", | "DOBmonth", |
"DOByear" | "DOByear" |
) as $field_name) { | ) as $field_name) { |
if (isset($_REQUEST[$field_name])) { | if (isset($_REQUEST[$field_name])) { |
$fields[$field_name] = filter_var($_REQUEST[$field_name], FILTER_SANITIZE_NUMBER_INT); | $fields[$field_name] = filter_var($_REQUEST[$field_name], FILTER_SANITIZE_NUMBER_INT); |
} | } |
else { | else { |
$return["error"][] = $field_name. " parameter invalid or unspecified"; | $return["error"][] = $field_name. " parameter invalid or unspecified"; |
} | } |
} | } |
if (isset($_REQUEST['secret_answer'])) { | if (isset($_REQUEST['secret_answer'])) { |
$fields['secret_answer'] = filter_var($_REQUEST['secret_answer'], FILTER_SANITIZE_STRING, Array( | $fields['secret_answer'] = filter_var($_REQUEST['secret_answer'], FILTER_SANITIZE_STRING, Array( |
FILTER_FLAG_NO_ENCODE_QUOTES, | FILTER_FLAG_NO_ENCODE_QUOTES, |
FILTER_FLAG_STRIP_HIGH, | FILTER_FLAG_STRIP_HIGH, |
FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_LOW |
)); | )); |
} | } |
else { | else { |
$return["error"][] = "secret_answer parameter invalid or unspecified"; | $return["error"][] = "secret_answer parameter invalid or unspecified"; |
} | } |
$fields['button'] = 'Submit'; | $fields['button'] = 'Submit'; |
$fields_string = ""; | $fields_string = ""; |
//url-ify the data for the POST | //url-ify the data for the POST |
foreach ($fields as $key => $value) { | foreach ($fields as $key => $value) { |
if (sizeof($value) === 0) $return['error'][] = $key . " parameter invalid or unspecified"; | if (sizeof($value) === 0) $return['error'][] = $key . " parameter invalid or unspecified"; |
$fields_string.= $field_mapping[$key] . '=' . $value . '&'; | $fields_string.= $field_mapping[$key] . '=' . $value . '&'; |
} | } |
$fields_string = rtrim($fields_string, '&'); | $fields_string = rtrim($fields_string, '&'); |
if (!isset($return['error'])) { | if (!isset($return['error'])) { |
//open connection | //open connection |
$ch = curl_init(); | $ch = curl_init(); |
//set the url, number of POST vars, POST data | //set the url, number of POST vars, POST data |
curl_setopt($ch, CURLOPT_URL, $url); | curl_setopt($ch, CURLOPT_URL, $url); |
curl_setopt($ch, CURLOPT_POST, count($fields)); | curl_setopt($ch, CURLOPT_POST, count($fields)); |
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); | curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
curl_setopt($ch, CURLOPT_REFERER, "https://www.action.act.gov.au/ARTS/getbalance.asp"); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | curl_setopt($ch, CURLOPT_HEADER, 0); |
curl_setopt($ch, CURLOPT_TIMEOUT, 30); | curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
//execute post | //execute post |
$pageHTML = curl_exec($ch); | $pageHTML = curl_exec($ch); |
if (curl_errno($ch)) $return["error"][] = "Network error " . curl_errno($ch) . " " . curl_error($ch) . " " . $url . $fields_string; | if (curl_errno($ch)) $return["error"][] = "Network error " . curl_errno($ch) . " " . curl_error($ch) . " " . $url . $fields_string; |
//close connection | //close connection |
curl_close($ch); | curl_close($ch); |
} | } |
if (!isset($return['error'])) { | if (!isset($return['error'])) { |
include_once ('lib/simple_html_dom.php'); | include_once ('lib/simple_html_dom.php'); |
//print_r($pageHTML); | |
$page = str_get_html($pageHTML); | $page = str_get_html($pageHTML); |
$pageAlerts = $page->find(".smartCardAlert"); | $pageAlerts = $page->find(".smartCardAlert"); |
if (sizeof($pageAlerts) > 0) { | if (sizeof($pageAlerts) > 0) { |
$return['error'][] = $pageAlerts[0]->plaintext; | $return['error'][] = $pageAlerts[0]->plaintext; |
} | } |
if (!isset($return['error'])) { | if (!isset($return['error'])) { |
$tableNum = 0; | $tableNum = 0; |
$tableName = Array( | $tableName = Array( |
1 => "myway_carddetails", | 1 => "myway_carddetails", |
2 => "myway_transactions" | 2 => "myway_transactions" |
); | ); |
foreach ($page->find("table") as $table) { | foreach ($page->find("table") as $table) { |
$tableNum++; | $tableNum++; |
$tableColumns = Array(); | $tableColumns = Array(); |
$tableColumnNum = 0; | $tableColumnNum = 0; |
foreach ($table->find("th") as $th) { | foreach ($table->find("th") as $th) { |
$tableColumns[$tableColumnNum] = cleanString($th->plaintext); | $tableColumns[$tableColumnNum] = cleanString($th->plaintext); |
$tableColumnNum++; | $tableColumnNum++; |
} | } |
//print_r($tableColumns); | |
$tableRowNum = 0; | $tableRowNum = 0; |
foreach ($table->find("tr") as $tr) { | foreach ($table->find("tr") as $tr) { |
$tableColumnNum = 0; | $tableColumnNum = 0; |
foreach ($tr->find("td") as $td) { | foreach ($tr->find("td") as $td) { |
if ($tableNum == 1) $return[$tableName[$tableNum]][$tableColumns[$tableColumnNum]] = cleanString($td->plaintext); | if ($tableNum == 1) $return[$tableName[$tableNum]][$tableColumns[$tableColumnNum]] = cleanString($td->plaintext); |
else $return[$tableName[$tableNum]][$tableRowNum][$tableColumns[$tableColumnNum]] = cleanString($td->plaintext); | else $return[$tableName[$tableNum]][$tableRowNum][$tableColumns[$tableColumnNum]] = cleanString($td->plaintext); |
//print_r($return); | |
$tableColumnNum++; | $tableColumnNum++; |
} | } |
$tableRowNum++; | $tableRowNum++; |
} | } |
} | } |
} | } |
} | } |
if (sizeof($return) == 0) { | if (sizeof($return) == 0) { |
$return['error'][] = "No data extracted from MyWay website - API may be out of date"; | $return['error'][] = "No data extracted from MyWay website - API may be out of date"; |
} | } |
header('Content-Type: text/javascript; charset=utf8'); | header('Content-Type: text/javascript; charset=utf8'); |
// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/'); | // header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/'); |
header('Access-Control-Max-Age: 3628800'); | header('Access-Control-Max-Age: 3628800'); |
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); | header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); |
if (isset($_GET['callback'])) { | if (isset($_GET['callback'])) { |
$json = '(' . json_encode($return) . ');'; //must wrap in parens and end with semicolon | $json = '(' . json_encode($return) . ');'; //must wrap in parens and end with semicolon |
print_r($_GET['callback'] . $json); //callback is prepended for json-p | print_r($_GET['callback'] . $json); //callback is prepended for json-p |
} | } |
else echo json_encode($return); | else echo json_encode($return); |
?> | ?> |
<?php | <?php |
include ('../include/common.inc.php'); | include ('../include/common.inc.php'); |
include_header("MyWay Balance", "mywayBalance", false, false, true); | include_header("MyWay Balance", "mywayBalance", false, false, true); |
echo '<div data-role="page"> | echo '<div data-role="page"> |
<div data-role="header" data-position="inline"> | <div data-role="header" data-position="inline"> |
<a href="' . $_SERVER["HTTP_REFERER"] . '" data-icon="arrow-l" data-rel="back" class="ui-btn-left">Back</a> | <a href="' . $_SERVER["HTTP_REFERER"] . '" data-icon="arrow-l" data-rel="back" class="ui-btn-left">Back</a> |
<h1>MyWay Balance</h1> | <h1>MyWay Balance</h1> |
<a href="mywaybalance.php?logout=yes" data-icon="delete" class="ui-btn-right">Logout</a> | <a href="mywaybalance.php?logout=yes" data-icon="delete" class="ui-btn-right">Logout</a> |
</div><!-- /header --> | </div><!-- /header --> |
<a name="maincontent" id="maincontent"></a> | <a name="maincontent" id="maincontent"></a> |
<div data-role="content"> '; | <div data-role="content"> '; |
$return = Array(); | $return = Array(); |
function logout() { | function logout() { |
setcookie("card_number", "", time() - 60 * 60 * 24 * 100, "/"); | setcookie("card_number", "", time() - 60 * 60 * 24 * 100, "/"); |
setcookie("date", "", time() - 60 * 60 * 24 * 100, "/"); | setcookie("date", "", time() - 60 * 60 * 24 * 100, "/"); |
setcookie("secret_answer", "", time() - 60 * 60 * 24 * 100, "/"); | setcookie("secret_answer", "", time() - 60 * 60 * 24 * 100, "/"); |
} | } |
function printBalance($cardNumber, $date, $pwrd) | function printBalance($cardNumber, $date, $pwrd) |
{ | { |
global $return; | global $return; |
$return = json_decode(getPage(curPageURL() . "/myway_api.json.php?card_number=$cardNumber&DOBday={$date[0]}&DOBmonth={$date[1]}&DOByear={$date[2]}&secret_answer=$pwrd") , true); | $return = json_decode(getPage(curPageURL() . "/myway_api.json.php?card_number=$cardNumber&DOBday={$date[0]}&DOBmonth={$date[1]}&DOByear={$date[2]}&secret_answer=$pwrd") , true); |
if (isset($return['error'])) { | if (isset($return['error'])) { |
logout(); | logout(); |
echo '<h3><font color="red">' . $return['error'][0] . "</font></h3>"; | echo '<h3><font color="red">' . $return['error'][0] . "</font></h3>"; |
} | } |
else { | else { |
echo "<h2>Balance: " . $return['myway_carddetails']['Card Balance'] . "</h2>"; | echo "<h2>Balance: " . $return['myway_carddetails']['Card Balance'] . "</h2>"; |
echo '<ul data-role="listview" data-inset="true"><li data-role="list-divider"> Recent Transactions </li>'; | echo '<ul data-role="listview" data-inset="true"><li data-role="list-divider"> Recent Transactions </li>'; |
$txCount=0; | $txCount=0; |
foreach ($return['myway_transactions'] as $transaction) { | foreach ($return['myway_transactions'] as $transaction) { |
echo "<li><b>" . $transaction["Date / Time"] . "</b>"; | echo "<li>"; |
echo "<br><small>" . $transaction["TX Reference No / Type"] . "</small>"; | if ($transaction["Deduction Type"] == "DEFAULT") echo '<img src="css/images/warning.png" alt="Failed to tap off: " class="ui-li-icon">'; |
echo"<b>" . $transaction["Date / Time"] . "</b>"; | |
echo "<br><small>" .$transaction["Route"] ." at " . $transaction["Stop Name"]. "<br>". $transaction["TX Reference No / Type"] . "</small>"; | |
echo '<p class="ui-li-aside">' . $transaction["TX Amount"] . '</p>'; | echo '<p class="ui-li-aside">' . $transaction["TX Amount"] . '</p>'; |
echo "</li>"; | echo "</li>"; |
$txCount++; | $txCount++; |
if ($txCount > 10) break; | if ($txCount > 10) break; |
} | } |
echo "</ul>"; | echo "</ul>"; |
} | } |
} | } |
if (isset($_REQUEST['card_number']) && isset($_REQUEST['date']) && isset($_REQUEST['secret_answer'])) { | if (isset($_REQUEST['card_number']) && isset($_REQUEST['date']) && isset($_REQUEST['secret_answer'])) { |
$cardNumber = $_REQUEST['card_number']; | $cardNumber = $_REQUEST['card_number']; |
$date = explode("/", $_REQUEST['date']); | $date = explode("/", $_REQUEST['date']); |
$pwrd = $_REQUEST['secret_answer']; | $pwrd = $_REQUEST['secret_answer']; |
if ($_REQUEST['remember'] == "on") { | if ($_REQUEST['remember'] == "on") { |
setcookie("card_number", $cardNumber, time() + 60 * 60 * 24 * 100, "/"); | setcookie("card_number", $cardNumber, time() + 60 * 60 * 24 * 100, "/"); |
setcookie("date", $_REQUEST['date'], time() + 60 * 60 * 24 * 100, "/"); | setcookie("date", $_REQUEST['date'], time() + 60 * 60 * 24 * 100, "/"); |
setcookie("secret_answer", $pwrd, time() + 60 * 60 * 24 * 100, "/"); | setcookie("secret_answer", $pwrd, time() + 60 * 60 * 24 * 100, "/"); |
} | } |
printBalance($cardNumber, $date, $pwrd); | printBalance($cardNumber, $date, $pwrd); |
} | } |
else if (isset($_REQUEST['logout'])) { | else if (isset($_REQUEST['logout'])) { |
echo '<center><h3> Logged out of MyWay balance </h3><a href="/index.php">Back to main menu...</a><center>'; | echo '<center><h3> Logged out of MyWay balance </h3><a href="/index.php">Back to main menu...</a><center>'; |
} | } |
else if (isset($_COOKIE['card_number']) && isset($_COOKIE['date']) && isset($_COOKIE['secret_answer'])) { | else if (isset($_COOKIE['card_number']) && isset($_COOKIE['date']) && isset($_COOKIE['secret_answer'])) { |
$cardNumber = $_COOKIE['card_number']; | $cardNumber = $_COOKIE['card_number']; |
$date = explode("/", $_COOKIE['date']); | $date = explode("/", $_COOKIE['date']); |
$pwrd = $_COOKIE['secret_answer']; | $pwrd = $_COOKIE['secret_answer']; |
printBalance($cardNumber, $date, $pwrd); | printBalance($cardNumber, $date, $pwrd); |
} | } |
else { | else { |
$date = (isset($_REQUEST['date']) ? filter_var($_REQUEST['date'], FILTER_SANITIZE_STRING) : date("m/d/Y")); | $date = (isset($_REQUEST['date']) ? filter_var($_REQUEST['date'], FILTER_SANITIZE_STRING) : date("m/d/Y")); |
echo '<form action="" method="post"> | echo '<form action="" method="post"> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="card_number">Card number</label> | <label for="card_number">Card number</label> |
<input type="text" name="card_number" id="card_number" value="' . $card_number . '" /> | <input type="text" name="card_number" id="card_number" value="' . $card_number . '" /> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="date"> Date of birth </label> | <label for="date"> Date of birth </label> |
<input type="text" name="date" id="date" value="' . $date . '" /> | <input type="text" name="date" id="date" value="' . $date . '" /> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="secret_answer"> Secret question answer </label> | <label for="secret_answer"> Secret question answer </label> |
<input type="text" name="secret_answer" id="secret_answer" value="' . $secret_answer . '" /> | <input type="text" name="secret_answer" id="secret_answer" value="' . $secret_answer . '" /> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="remember"> Remember these details? </label> | <label for="remember"> Remember these details? </label> |
<input type="checkbox" name="remember" id="remember" checked="yes" /> | <input type="checkbox" name="remember" id="remember" checked="yes" /> |
</div> | </div> |
<input type="submit" value="Go!"></form>'; | <input type="submit" value="Go!"></form>'; |
} | } |
include_footer(); | include_footer(); |
?> | ?> |
<?php | |
header('Content-type: application/vnd.google-earth.kml+xml'); | |
//http://wiki.openstreetmap.org/wiki/OpenLayers_Dynamic_KML | |
// Creates the KML/XML Document. | |
$dom = new DOMDocument('1.0', 'UTF-8'); | |
// Creates the root KML element and appends it to the root document. | |
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml'); | |
$parNode = $dom->appendChild($node); | |
// Creates a KML Document element and append it to the KML element. | |
$dnode = $dom->createElement('Document'); | |
$docNode = $parNode->appendChild($dnode); | |
$bbox = $_GET['bbox']; // get the bbox param from google earth | |
list($bbox_south, $bbox_west, $bbox_north,$bbox_east) = explode(",", $bbox); // west, south, east, north | |
include ('../include/common.inc.php'); | |
$debugOkay = Array(); | |
$contents = getNearbyStops( (($bbox_west+ $bbox_east) /2), ($bbox_south + $bbox_north)/2 ,50, 3000); | |
foreach ($contents as $stop) { | |
$description = 'http://bus.lambdacomplex.org/' . 'stop.php?stopid=' . $stop['stop_id'] ." <br>"; | |
$trips = getStopTripsWithTimes($stop['stop_id'], "", "", "", 3); | |
if ($trips) { | |
foreach ($trips as $key => $row) { | |
if ($key < 3) { | |
$description .= $row['route_short_name'] . ' ' . $row['route_long_name'] . ' @ ' . $row['arrival_time'] . "<br>"; | |
} | |
} | |
} else { | |
$description .= "No more trips today"; | |
} | |
// Creates a Placemark and append it to the Document. | |
$node = $dom->createElement('Placemark'); | |
$placeNode = $docNode->appendChild($node); | |
// Creates an id attribute and assign it the value of id column. | |
$placeNode->setAttribute('id', 'placemark' . $stop['stop_id']); | |
// Create name, and description elements and assigns them the values of the name and address columns from the results. | |
$nameNode = $dom->createElement('name',htmlentities($stop['stop_name'])); | |
$descriptionNode = $dom->createElement('description',$description); | |
$placeNode->appendChild($nameNode); | |
$placeNode->appendChild($descriptionNode); | |
// Creates a Point element. | |
$pointNode = $dom->createElement('Point'); | |
$placeNode->appendChild($pointNode); | |
// Creates a coordinates element and gives it the value of the lng and lat columns from the results. | |
$coorStr = $stop['stop_lon'] . ',' . $stop['stop_lat']; | |
$coorNode = $dom->createElement('coordinates', $coorStr); | |
$pointNode->appendChild($coorNode); | |
} | |
$kmlOutput = $dom->saveXML(); | |
echo $kmlOutput; | |
?> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<script src="openlayers/OpenLayers.js"></script> | |
<SCRIPT TYPE="text/javascript" SRC="OpenStreetMap.js"></SCRIPT> | |
<script type="text/javascript"> | |
var map,select; | |
function init() | |
{ | |
var extent = new OpenLayers.Bounds(148.98, -35.48, 149.25, -35.15); | |
// set up the map options | |
var options = | |
{ | |
maxExtent: extent, | |
numZoomLevels: 20, | |
}; | |
// create the ol map object | |
map = new OpenLayers.Map('map', options); | |
var osmtiles = new OpenLayers.Layer.OSM("OSM"); | |
var nearmap = new OpenLayers.Layer.OSM.NearMap("NearMap"); | |
var stopbrowser = new OpenLayers.Layer.Vector("POI", { | |
projection: new OpenLayers.Projection("EPSG:4326"), | |
strategies: [ | |
new OpenLayers.Strategy.BBOX(), | |
], | |
protocol: new OpenLayers.Protocol.HTTP({ | |
url: "stopBrowser.kml.php", //Note that it is probably worth adding a Math.random() on the end of the URL to stop caching. | |
format: new OpenLayers.Format.KML({ | |
extractStyles: true, | |
extractAttributes: true | |
}), | |
}) | |
}); | |
map.addLayers([osmtiles,stopbrowser,nearmap]); | |
var lonLat = new OpenLayers.LonLat(149.11, -35.28).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); | |
map.setCenter(lonLat, 15); | |
map.addControl( new OpenLayers.Control.LayerSwitcher({'ascending':false})); | |
map.addControl(new OpenLayers.Control.MousePosition( | |
{ | |
displayProjection: new OpenLayers.Projection("EPSG:4326"), | |
suffix: "__________________________________" | |
})); | |
map.addControl(new OpenLayers.Control.MousePosition( | |
{ | |
displayProjection: new OpenLayers.Projection("EPSG:900913") | |
})); | |
select = new OpenLayers.Control.SelectFeature(stopbrowser); | |
stopbrowser.events.on({ | |
"featureselected": onFeatureSelect, | |
"featureunselected": onFeatureUnselect | |
}); | |
map.addControl(select); | |
select.activate(); | |
} | |
function onPopupClose(evt) { | |
select.unselectAll(); | |
} | |
function onFeatureSelect(event) { | |
var feature = event.feature; | |
// Since KML is user-generated, do naive protection against | |
// Javascript. | |
var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description; | |
if (content.search("<script") != -1) { | |
content = "Content contained Javascript! Escaped content below.<br />" + content.replace(/</g, "<"); | |
} | |
popup = new OpenLayers.Popup.FramedCloud("chicken", | |
feature.geometry.getBounds().getCenterLonLat(), | |
new OpenLayers.Size(100,100), | |
content, | |
null, true, onPopupClose); | |
feature.popup = popup; | |
map.addPopup(popup); | |
} | |
function onFeatureUnselect(event) { | |
var feature = event.feature; | |
if(feature.popup) { | |
map.removePopup(feature.popup); | |
feature.popup.destroy(); | |
delete feature.popup; | |
} | |
} | |
</script> | |
</head> | |
<body onload="init()"> | |
<div id="map" width="100%" height="100%" class="smallmap"></div> | |
</body> | |
</html> | |
<?php | <?php |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
$last_updated = date('Y-m-d',@filemtime('cbrfeed.zip')); | $last_updated = date('Y-m-d',@filemtime('cbrfeed.zip')); |
header("Content-Type: text/xml"); | header("Content-Type: text/xml"); |
echo "<?xml version='1.0' encoding='UTF-8'?>"; | echo "<?xml version='1.0' encoding='UTF-8'?>"; |
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; | echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; |
echo " <url><loc>".curPageURL()."index.php</loc><priority>1.0</priority></url>\n"; | echo " <url><loc>".curPageURL()."index.php</loc><priority>1.0</priority></url>\n"; |
foreach (scandir("./") as $file) { | foreach (scandir("./") as $file) { |
if (strpos($file,".php") !== false && $file != "index.php" && $file != "sitemap.xml.php") echo " <url><loc>".curPageURL()."$file</loc><priority>0.3</priority></url>\n"; | if (strpos($file,".php") !== false && $file != "index.php" && $file != "sitemap.xml.php") echo " <url><loc>".curPageURL()."$file</loc><priority>0.3</priority></url>\n"; |
} | } |
foreach (getStops() as $stop) { | foreach (getStops() as $stop) { |
echo " <url><loc>".curPageURL()."stop.php?stopid=".htmlspecialchars ($stop["stop_id"])."</loc>"; | echo " <url><loc>".curPageURL()."stop.php?stopid=".htmlspecialchars ($stop["stop_id"])."</loc>"; |
echo "<lastmod>" . $last_updated . "</lastmod>"; | echo "<lastmod>" . $last_updated . "</lastmod>"; |
echo "<changefreq>monthly</changefreq>"; | echo "<changefreq>monthly</changefreq>"; |
echo "<priority>0.9</priority>"; | echo "<priority>0.9</priority>"; |
echo "</url>\n"; | echo "</url>\n"; |
} | } |
foreach (getRoutes() as $route) { | foreach (getRoutes() as $route) { |
echo " <url><loc>".curPageURL()."trip.php?routeid=".htmlspecialchars ($route["route_id"])."</loc>"; | echo " <url><loc>".curPageURL()."trip.php?routeid=".htmlspecialchars ($route["route_id"])."</loc>"; |
echo "<lastmod>" . $last_updated . "</lastmod>"; | echo "<lastmod>" . $last_updated . "</lastmod>"; |
echo "<changefreq>monthly</changefreq>"; | echo "<changefreq>monthly</changefreq>"; |
echo "<priority>0.9</priority>"; | echo "<priority>0.9</priority>"; |
echo "</url>\n"; | echo "</url>\n"; |
} | } |
// geosite map | |
foreach (getRoutes() as $route) { | |
echo " <url><loc>".curPageURL()."geo/route.kml.php?routeid=".htmlspecialchars ($route["route_id"])."</loc>"; | |
echo "<lastmod>" . $last_updated . "</lastmod>"; | |
echo "<geo:geo> | |
<geo:format>kml</geo:format> | |
</geo:geo>"; | |
echo "</url>\n"; | |
} | |
echo '</urlset>'; | echo '</urlset>'; |
?> | ?> |
<?php | <?php |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
if ($stopid) $stop = getStop($stopid); | if ($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: "; | $stopLinks.= "Individual stop pages: "; |
foreach ($stops as $key => $sub_stop) { | foreach ($stops as $key => $sub_stop) { |
// $stopNames[$key] = $sub_stop[1] . ' Stop #' . ($key + 1); | // $stopNames[$key] = $sub_stop[1] . ' Stop #' . ($key + 1); |
if (strpos($stop["stop_name"], "Station")) { | if (strpos($stop["stop_name"], "Station")) { |
$stopNames[$key] = 'Platform ' . ($key + 1); | $stopNames[$key] = 'Platform ' . ($key + 1); |
$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> '; |
} | } |
else { | else { |
$stopNames[$key] = '#' . ($key + 1); | $stopNames[$key] = '#' . ($key + 1); |
$stopLinks.= '<a href="stop.php?stopid=' . $sub_stop["stop_id"] . '&stopcode=' . $sub_stop["stop_code"] . '">' . $sub_stop["stop_name"] . ' Stop #' . ($key + 1) . '</a> '; | $stopLinks.= '<a href="stop.php?stopid=' . $sub_stop["stop_id"] . '&stopcode=' . $sub_stop["stop_code"] . '">' . $sub_stop["stop_name"] . ' Stop #' . ($key + 1) . '</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"]])) $allStopsTrips[$trip["trip_id"]] = $trip; | if (!isset($allStopsTrips[$trip["trip_id"]])) $allStopsTrips[$trip["trip_id"]] = $trip; |
} | } |
} | } |
//else { | //else { |
// echo "skipped sequence $tripSequence"; | // echo "skipped sequence $tripSequence"; |
//} | //} |
} | } |
} | } |
include_header($stop['stop_name'], "stop"); | include_header($stop['stop_name'], "stop"); |
echo '<span id="leftcolumn">'; | |
timePlaceSettings(); | timePlaceSettings(); |
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"] |
) | ) |
)) ; | )) ; |
} | } |
echo '</span><span id="rightcolumn">'; | |
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); |
} | } |
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>'; |
echo '<a href="trip.php?stopid=' . $stopid . '&tripid=' . $trip['trip_id'] . '"><h3>' . $trip['route_short_name'] . " " . $trip['route_long_name'] . "</h3><p>"; | echo '<a href="trip.php?stopid=' . $stopid . '&tripid=' . $trip['trip_id'] . '"><h3>' . $trip['route_short_name'] . " " . $trip['route_long_name'] . "</h3><p>"; |
$viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); | $viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); |
if ($viaPoints != "") echo '<br><span class="viaPoints">Via: ' . $viaPoints . '</span>'; | if ($viaPoints != "") 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: '; |
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>'; | |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
$routetrips = Array(); | $routetrips = Array(); |
if (isset($routeid) && !isset($tripid)) { | if (isset($routeid) && !isset($tripid)) { |
$trip = getRouteNextTrip($routeid); | $trip = getRouteNextTrip($routeid); |
$tripid = $trip['trip_id']; | $tripid = $trip['trip_id']; |
} else { | } else { |
$trip = getTrip($tripid); | $trip = getTrip($tripid); |
$routeid = $trip["route_id"]; | $routeid = $trip["route_id"]; |
} | } |
$routetrips = getRouteTrips($routeid); | $routetrips = getRouteTrips($routeid); |
include_header("Stops on " . $trip['route_short_name'] . ' ' . $trip['route_long_name'], "trip"); | 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); | trackEvent("Route/Trip View","View Route", $trip['route_short_name'] . ' ' . $trip['route_long_name'], $routeid); |
echo '<span id="leftcolumn">'; | |
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> '; |
foreach (getRouteTrips($routeid) as $othertrip) { | foreach (getRouteTrips($routeid) as $othertrip) { |
echo '<a href="trip.php?tripid=' . $othertrip['trip_id'] . "&routeid=" . $routeid . '">' . 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> '; |
} | } |
flush(); @ob_flush(); | flush(); @ob_flush(); |
echo '<h2>Other directions/timing periods:</h2> '; | echo '<h2>Other directions/timing periods:</h2> '; |
foreach (getRoutesByNumber($trip['route_short_name']) as $row) { | foreach (getRoutesByNumber($trip['route_short_name']) as $row) { |
if ($row['route_id'] != $routeid) echo '<a href="trip.php?routeid=' . $row['route_id'] . '">' . $row['route_long_name'] . ' (' . ucwords($row['service_id']) . ')</a> '; | if ($row['route_id'] != $routeid) echo '<a href="trip.php?routeid=' . $row['route_id'] . '">' . $row['route_long_name'] . ' (' . ucwords($row['service_id']) . ')</a> '; |
} | } |
echo '</span><span id="rightcolumn">'; | |
flush(); @ob_flush(); | flush(); @ob_flush(); |
echo ' <ul data-role="listview" data-inset="true">'; | echo ' <ul data-role="listview" data-inset="true">'; |
$stopsGrouped = Array(); | $stopsGrouped = Array(); |
$tripStopTimes = getTimeInterpolatedTrip($tripid); | $tripStopTimes = getTimeInterpolatedTrip($tripid); |
echo '<li data-role="list-divider">' . $tripStopTimes[0]['arrival_time'] . ' to ' . $tripStopTimes[sizeof($tripStopTimes) - 1]['arrival_time'] . ' ' . $trip['route_long_name'] . ' (' . ucwords($tripStopTimes[0]['service_id']).')</li>'; | echo '<li data-role="list-divider">' . $tripStopTimes[0]['arrival_time'] . ' to ' . $tripStopTimes[sizeof($tripStopTimes) - 1]['arrival_time'] . ' ' . $trip['route_long_name'] . ' (' . ucwords($tripStopTimes[0]['service_id']).')</li>'; |
foreach ($tripStopTimes as $key => $tripStopTime) { | foreach ($tripStopTimes as $key => $tripStopTime) { |
if (($tripStopTimes[$key]["stop_name"] != $tripStopTimes[$key + 1]["stop_name"]) || $key + 1 >= sizeof($tripStopTimes)) { | if (($tripStopTimes[$key]["stop_name"] != $tripStopTimes[$key + 1]["stop_name"]) || $key + 1 >= sizeof($tripStopTimes)) { |
echo '<li>'; | echo '<li>'; |
if (!startsWith($tripStopTime['stop_code'], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">'; | if (!startsWith($tripStopTime['stop_code'], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">'; |
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']; |
echo '</p>'; | |
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 '<br>' . distance($tripStopTime['stop_lat'],$tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; |
} | } |
echo '</p>'; | |
echo bracketsMeanNewLine($tripStopTime["stop_name"]); | echo bracketsMeanNewLine($tripStopTime["stop_name"]); |
echo '</a></li>'; | echo '</a></li>'; |
flush(); @ob_flush(); | 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'] . '</p>'; | echo '<p class="ui-li-aside">' . $tripStopTime['arrival_time']; |
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 '<br>' . distance($tripStopTime['stop_lat'],$tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; |
} | } |
echo '</p>'; | |
echo bracketsMeanNewLine($tripStopTime['stop_name']); | echo bracketsMeanNewLine($tripStopTime['stop_name']); |
echo '</a></li>'; | echo '</a></li>'; |
flush(); @ob_flush(); | flush(); @ob_flush(); |
} | } |
} | } |
else { | else { |
// this is a duplicated line item | // this is a duplicated line item |
if ($key - 1 <= 0 || ($tripStopTimes[$key]['stop_name'] != $tripStopTimes[$key - 1]['stop_name'])) { | if ($key - 1 <= 0 || ($tripStopTimes[$key]['stop_name'] != $tripStopTimes[$key - 1]['stop_name'])) { |
// first duplicate | // first duplicate |
$stopsGrouped = Array( | $stopsGrouped = Array( |
"name" => $tripStopTime['stop_name'], | "name" => $tripStopTime['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>'; | |
include_footer(); | include_footer(); |
?> | ?> |