<?php | <?php |
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> | <html> |
<head> | <head> |
<title>' . $pageTitle . '</title>'; | <title>' . $pageTitle . '</title>'; |
if ($datepicker) echo '<link rel="stylesheet" href="css/jquery.ui.datepicker.mobile.css" />'; | if ($datepicker) echo '<link rel="stylesheet" href="css/jquery.ui.datepicker.mobile.css" />'; |
if (isDebugServer()) echo '<link rel="stylesheet" href="css/jquery-mobile-1.0a3.css" /> | if (isDebugServer()) echo '<link rel="stylesheet" href="css/jquery-mobile-1.0a3.css" /> |
<script type="text/javascript" src="js/jquery-1.5.js"></script> | <script type="text/javascript" src="js/jquery-1.5.js"></script> |
<script type="text/javascript" src="js/jquery-mobile-1.0a3.js"></script>'; | <script type="text/javascript" src="js/jquery-mobile-1.0a3.js"></script>'; |
else echo '<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" /> | else echo '<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" /> |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script> | <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script> |
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>'; | <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>'; |
if ($datepicker) echo '<script> | if ($datepicker) echo '<script> |
//reset type=date inputs to text | //reset type=date inputs to text |
$( document ).bind( "mobileinit", function(){ | $( document ).bind( "mobileinit", function(){ |
$.mobile.page.prototype.options.degradeInputs.date = true; | $.mobile.page.prototype.options.degradeInputs.date = true; |
}); | }); |
</script> | </script> |
<script src="js/jQuery.ui.datepicker.js"></script>'; | <script src="js/jQuery.ui.datepicker.js"></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; |
} | } |
#footer { | #footer { |
text-size: 0.75em; | text-size: 0.75em; |
text-align: center; | text-align: center; |
} | } |
body { | body { |
background-color: #F0F0F0; | background-color: #F0F0F0; |
} | } |
</style> | </style>'; |
<meta name="apple-mobile-web-app-capable" content="yes" /> | if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod')) { |
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) { |
$('#geolocate').val(position.coords.latitude+','+position.coords.longitude); | $('#geolocate').val(position.coords.latitude+','+position.coords.longitude); |
$.ajax({ url: \"common.inc.php?geolocate=yes&lat=\"+position.coords.latitude+\"&lon=\"+position.coords.longitude }); | $.ajax({ url: \"common.inc.php?geolocate=yes&lat=\"+position.coords.latitude+\"&lon=\"+position.coords.longitude }); |
$('#here').click(function(event) { $('#geolocate').val(doAJAXrequestForGeolocSessionHere()); return false;}); | $('#here').click(function(event) { $('#geolocate').val(doAJAXrequestForGeolocSessionHere()); return false;}); |
$('#here').show(); | $('#here').show(); |
} | } |
function error(msg) { | function error(msg) { |
console.log(msg); | console.log(msg); |
} | } |
if (navigator.geolocation) { | if (navigator.geolocation) { |
var options = { | var options = { |
enableHighAccuracy: false, | enableHighAccuracy: false, |
timeout: 60000, | timeout: 60000, |
maximumAge: 10000 | maximumAge: 10000 |
} | } |
navigator.geolocation.getCurrentPosition(success, error, options); | navigator.geolocation.getCurrentPosition(success, error, options); |
} | } |
</script> "; | </script> "; |
} | } |
echo '</head> | echo '</head> |
<body> | <body> |
'; | '; |
if ($opendiv) { | if ($opendiv) { |
echo '<div data-role="page"> | echo '<div data-role="page"> |
<script> | <script> |
$(document).ready(function () | $(document).ready(function () |
{ | { |
document.title = "' . $pageTitle . '"; | document.title = "' . $pageTitle . '"; |
}); | }); |
</script> | </script> |
<div data-role="header"> | <div data-role="header"> |
<h1>' . $pageTitle . '</h1> | <h1>' . $pageTitle . '</h1> |
</div><!-- /header --> | </div><!-- /header --> |
<div data-role="content"> '; | <div data-role="content"> '; |
} | } |
} | } |
function include_footer() | function include_footer() |
{ | { |
if ($geolocate && isset($_SESSION['lat'])) { | if ($geolocate && isset($_SESSION['lat'])) { |
echo "<script> | echo "<script> |
$('#here').click(function(event) { $('#geolocate').val(doAJAXrequestForGeolocSessionHere()); return false;}); | $('#here').click(function(event) { $('#geolocate').val(doAJAXrequestForGeolocSessionHere()); return false;}); |
$('#here').show(); | $('#here').show(); |
</script>"; | </script>"; |
} | } |
echo '<div id="footer"><a href="about.php">About/Contact Us</a> <a href="feedback.php">Feedback/Bug Report</a></a>'; | echo '<div id="footer"><a href="about.php">About/Contact Us</a> <a href="feedback.php">Feedback/Bug Report</a></a>'; |
echo '</div>'; | echo '</div>'; |
} | } |
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'] == ""; |
} | } |
if ($geoerror) { | if ($geoerror) { |
echo '<div class="error">Sorry, but your location could not currently be detected. | echo '<div class="error">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.</div>'; | or enter an address/co-ordinates in the box below.</div>'; |
} | } |
echo '<div data-role="collapsible" data-collapsed="' . !$geoerror . '"> | echo '<div 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="" method="post"> | <form action="" 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")) . '"/> <a href="#" name="currentTime" id="currentTime"/>Current Time?</a> | <input type="time" name="time" id="time" value="' . (isset($_SESSION['time']) ? $_SESSION['time'] : date("H:i")) . '"/> <a href="#" name="currentTime" id="currentTime"/>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">'; | <select name="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"/> |
</form> | </form> |
</div></div>'; | </div></div>'; |
} | } |
?> | ?> |
<?php | <?php |
date_default_timezone_set('Australia/ACT'); | date_default_timezone_set('Australia/ACT'); |
$APIurl = "http://localhost:8765"; | $APIurl = "http://localhost:8765"; |
$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/'; |
//$debugOkay = Array("session","json","phperror","other"); | //$debugOkay = Array("session","json","phperror","other"); |
$debugOkay = Array( | $debugOkay = Array( |
"session", | "session", |
"json", | "json", |
"phperror", | "phperror", |
"other" | "other" |
); | ); |
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-template.inc.php"); | include_once ("common-template.inc.php"); |
include_once ("common-transit.inc.php"); | include_once ("common-transit.inc.php"); |
// you have to open the session to be able to modify or remove it | // you have to open the session to be able to modify or remove it |
session_start(); | session_start(); |
if (isset($_REQUEST['service_period'])) { | if (isset($_REQUEST['service_period'])) { |
$_SESSION['service_period'] = filter_var($_REQUEST['service_period'], FILTER_SANITIZE_STRING); | $_SESSION['service_period'] = filter_var($_REQUEST['service_period'], FILTER_SANITIZE_STRING); |
} | } |
if (isset($_REQUEST['time'])) { | if (isset($_REQUEST['time'])) { |
$_SESSION['time'] = filter_var($_REQUEST['time'], FILTER_SANITIZE_STRING); | $_SESSION['time'] = filter_var($_REQUEST['time'], FILTER_SANITIZE_STRING); |
} | } |
if (isset($_REQUEST['geolocate'])) { | if (isset($_REQUEST['geolocate'])) { |
$geocoded = false; | $geocoded = false; |
if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) { | if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) { |
$_SESSION['lat'] = trim(filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); | $_SESSION['lat'] = trim(filter_var($_REQUEST['lat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); |
$_SESSION['lon'] = trim(filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); | $_SESSION['lon'] = trim(filter_var($_REQUEST['lon'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); |
} | } |
else { | else { |
$geolocate = filter_var($_REQUEST['geolocate'], FILTER_SANITIZE_URL); | $geolocate = filter_var($_REQUEST['geolocate'], FILTER_SANITIZE_URL); |
echo $_REQUEST['geolocate']; | echo $_REQUEST['geolocate']; |
if (startsWith($geolocate, "-")) { | if (startsWith($geolocate, "-")) { |
$locateparts = explode(",",$geolocate); | $locateparts = explode(",", $geolocate); |
$_SESSION['lat'] = $locateparts[0]; | $_SESSION['lat'] = $locateparts[0]; |
$_SESSION['lon'] =$locateparts[1]; | $_SESSION['lon'] = $locateparts[1]; |
} else { | |
$contents = geocode($geolocate, true); | |
print_r($contents); | |
if (isset($contents[0]->centroid)) { | |
$geocoded = true; | |
$_SESSION['lat'] = $contents[0]->centroid->coordinates[0]; | |
$_SESSION['lon'] = $contents[0]->centroid->coordinates[1]; | |
} | } |
else { | else { |
$_SESSION['lat'] = ""; | $contents = geocode($geolocate, true); |
$_SESSION['lon'] = ""; | print_r($contents); |
} | if (isset($contents[0]->centroid)) { |
$geocoded = true; | |
$_SESSION['lat'] = $contents[0]->centroid->coordinates[0]; | |
$_SESSION['lon'] = $contents[0]->centroid->coordinates[1]; | |
} | |
else { | |
$_SESSION['lat'] = ""; | |
$_SESSION['lon'] = ""; | |
} | |
} | } |
} | } |
} | } |
debug(print_r($_SESSION, true) , "session"); | debug(print_r($_SESSION, true) , "session"); |
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 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() | |
{ | |
// 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']; | |
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)) | foreach ($array as $key => $val) { |
$temp_array[key($array)] = array_shift($array); | $offset = 0; |
$found = false; | |
foreach($array as $key => $val){ | foreach ($temp_array as $tmp_key => $tmp_val) { |
$offset = 0; | if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { |
$found = false; | $temp_array = array_merge((array)array_slice($temp_array, 0, $offset) , array( |
foreach($temp_array as $tmp_key => $tmp_val) | $key => $val |
{ | ) , array_slice($temp_array, $offset)); |
if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) | $found = true; |
{ | } |
$temp_array = array_merge( (array)array_slice($temp_array,0,$offset), | $offset++; |
array($key => $val), | } |
array_slice($temp_array,$offset) | if (!$found) $temp_array = array_merge($temp_array, array( |
); | $key => $val |
$found = true; | )); |
} | } |
$offset++; | if ($sort_ascending) $array = array_reverse($temp_array); |
} | else $array = $temp_array; |
if(!$found) $temp_array = array_merge($temp_array, array($key => $val)); | |
} | |
if ($sort_ascending) $array = array_reverse($temp_array); | |
else $array = $temp_array; | |
} | } |
?> | ?> |
<?php | <?php |
include ('common.inc.php'); | include ('common.inc.php'); |
function navbar() | function navbar() |
{ | { |
echo ' | echo ' |
<div data-role="navbar"> | <div data-role="navbar"> |
<ul> | <ul> |
<li><a href="routeList.php">By Final Destination...</a></li> | <li><a href="routeList.php">By Final Destination...</a></li> |
<li><a href="routeList.php?bynumber=yes">By Number... </a></li> | <li><a href="routeList.php?bynumber=yes">By Number... </a></li> |
<li><a href="routeList.php?bysuburb=yes">By Suburb... </a></li> | <li><a href="routeList.php?bysuburb=yes">By Suburb... </a></li> |
<li><a href="routeList.php?nearby=yes">Nearby... </a></li> | <li><a href="routeList.php?nearby=yes">Nearby... </a></li> |
</ul> | </ul> |
</div> | </div> |
'; | '; |
} | } |
if ($_REQUEST['bysuburb']) { | if ($_REQUEST['bysuburb']) { |
include_header("Routes by Suburb", "routeList"); | include_header("Routes by Suburb", "routeList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
foreach ($suburbs as $suburb) { | if (!isset($_REQUEST['firstLetter'])) { |
if (!isset($_REQUEST['firstLetter'])) { | foreach (range('A', 'Z') as $letter) { |
foreach (range('A', 'Z') as $letter) { | echo "<li><a href=\"routeList.php?firstLetter=$letter&bysuburb=yes\">$letter...</a></li>\n"; |
echo "<li><a href=\"routeList.php?firstLetter=$letter&bysuburb=yes\">$letter...</a></li>\n"; | } |
} | |
else { | |
foreach ($suburbs as $suburb) { | |
if (startsWith($suburb, $_REQUEST['firstLetter'])) { | |
echo '<li><a href="routeList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; | |
} | } |
} | |
else if (startsWith($suburb, $_REQUEST['firstLetter'])) { | |
echo '<li><a href="routeList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; | |
} | } |
} | } |
echo '</ul>'; | echo '</ul>'; |
} | } |
else if ($_REQUEST['nearby'] || $_REQUEST['suburb']) { | else if ($_REQUEST['nearby'] || $_REQUEST['suburb']) { |
if ($_REQUEST['suburb']) { | if ($_REQUEST['suburb']) { |
$suburb = filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING); | $suburb = filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING); |
$url = $APIurl . "/json/stopzonesearch?q=" . $suburb; | $url = $APIurl . "/json/stopzonesearch?q=" . $suburb; |
include_header("Routes by Suburb", "routeList"); | include_header("Routes by Suburb", "routeList"); |
} | } |
if ($_REQUEST['nearby']) { | if ($_REQUEST['nearby']) { |
$url = $APIurl . "/json/neareststops?lat={$_SESSION['lat']}&lon={$_SESSION['lon']}&limit=15"; | $url = $APIurl . "/json/neareststops?lat={$_SESSION['lat']}&lon={$_SESSION['lon']}&limit=15"; |
include_header("Routes Nearby", "routeList"); | include_header("Routes Nearby", "routeList"); |
} | } |
$stops = json_decode(getPage($url)); | $stops = json_decode(getPage($url)); |
$routes = Array(); | $routes = Array(); |
foreach ($stops as $stop) { | foreach ($stops as $stop) { |
$url = $APIurl . "/json/stoproutes?stop=" . $stop[0]; | $url = $APIurl . "/json/stoproutes?stop=" . $stop[0]; |
$stoproutes = json_decode(getPage($url)); | $stoproutes = json_decode(getPage($url)); |
foreach ($stoproutes as $route) { | foreach ($stoproutes as $route) { |
if (!isset($routes[$route[0]])) $routes[$route[0]] = $route; | if (!isset($routes[$route[0]])) $routes[$route[0]] = $route; |
} | } |
} | } |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
sksort($routes, 1, true); | sksort($routes, 1, true); |
foreach ($routes as $row) { | foreach ($routes as $row) { |
echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[4]) . ")</a></li>\n"; | echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[4]) . ")</a></li>\n"; |
} | } |
} | } |
else if ($_REQUEST['bynumber']) { | else if ($_REQUEST['bynumber']) { |
include_header("Routes by Number", "routeList"); | include_header("Routes by Number", "routeList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-inset="true">'; | echo ' <ul data-role="listview" data-inset="true">'; |
$url = $APIurl . "/json/routes"; | $url = $APIurl . "/json/routes"; |
$contents = json_decode(getPage($url)); | $contents = json_decode(getPage($url)); |
$routeSeries = Array(); | $routeSeries = Array(); |
$seriesRange = Array(); | $seriesRange = Array(); |
foreach ($contents as $key => $row) { | foreach ($contents as $key => $row) { |
foreach (explode(" ", $row[1]) as $routeNumber) { | foreach (explode(" ", $row[1]) as $routeNumber) { |
$seriesNum = substr($routeNumber, 0, -1) . "0"; | $seriesNum = substr($routeNumber, 0, -1) . "0"; |
if ($seriesNum == "0") $seriesNum = $routeNumber; | if ($seriesNum == "0") $seriesNum = $routeNumber; |
$finalDigit = substr($routeNumber, sizeof($routeNumber) - 1, 1); | $finalDigit = substr($routeNumber, sizeof($routeNumber) - 1, 1); |
if (isset($seriesRange[$seriesNum])) { | if (isset($seriesRange[$seriesNum])) { |
if ($finalDigit < $seriesRange[$seriesNum]['max']) $seriesRange[$seriesNum]['max'] = $routeNumber; | if ($finalDigit < $seriesRange[$seriesNum]['max']) $seriesRange[$seriesNum]['max'] = $routeNumber; |
if ($finalDigit > $seriesRange[$seriesNum]['min']) $seriesRange[$seriesNum]['min'] = $routeNumber; | if ($finalDigit > $seriesRange[$seriesNum]['min']) $seriesRange[$seriesNum]['min'] = $routeNumber; |
} | } |
else { | else { |
$seriesRange[$seriesNum]['max'] = $routeNumber; | $seriesRange[$seriesNum]['max'] = $routeNumber; |
$seriesRange[$seriesNum]['min'] = $routeNumber; | $seriesRange[$seriesNum]['min'] = $routeNumber; |
} | } |
$routeSeries[$seriesNum][$seriesNum . "-" . $row[1] . "-" . $row[0]] = $row; | $routeSeries[$seriesNum][$seriesNum . "-" . $row[1] . "-" . $row[0]] = $row; |
} | } |
} | } |
ksort($routeSeries); | ksort($routeSeries); |
ksort($seriesRange); | ksort($seriesRange); |
echo '<div class="noscriptnav"> Go to route numbers: '; | echo '<div class="noscriptnav"> Go to route numbers: '; |
foreach ($seriesRange as $series => $range) { | foreach ($seriesRange as $series => $range) { |
if ($range['min'] == $range['max']) echo "<a href=\"#$series\">$series</a> "; | if ($range['min'] == $range['max']) echo "<a href=\"#$series\">$series</a> "; |
else echo "<a href=\"#$series\">{$range['min']}-{$range['max']}</a> "; | else echo "<a href=\"#$series\">{$range['min']}-{$range['max']}</a> "; |
} | } |
echo "</div> | echo "</div> |
<script> | <script> |
$('.noscriptnav').hide(); | $('.noscriptnav').hide(); |
</script>"; | </script>"; |
foreach ($routeSeries as $series => $routes) { | foreach ($routeSeries as $series => $routes) { |
echo '<a name="' . $series . '"></a>'; | echo '<a name="' . $series . '"></a>'; |
if ($series <= 9) echo '<li>' . $series . "<ul>\n"; | if ($series <= 9) echo '<li>' . $series . "<ul>\n"; |
else echo "<li>{$seriesRange[$series]['min']}-{$seriesRange[$series]['max']}<ul>\n"; | else echo "<li>{$seriesRange[$series]['min']}-{$seriesRange[$series]['max']}<ul>\n"; |
foreach ($routes as $row) { | foreach ($routes as $row) { |
echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[3]) . ")</a></li>\n"; | echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[3]) . ")</a></li>\n"; |
} | } |
echo "</ul></li>\n"; | echo "</ul></li>\n"; |
} | } |
} | } |
else { | else { |
include_header("Routes by Destination", "routeList"); | include_header("Routes by Destination", "routeList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-inset="true">'; | echo ' <ul data-role="listview" data-inset="true">'; |
$url = $APIurl . "/json/routes"; | $url = $APIurl . "/json/routes"; |
$contents = json_decode(getPage($url)); | $contents = json_decode(getPage($url)); |
// by destination! | // by destination! |
foreach ($contents as $key => $row) { | foreach ($contents as $key => $row) { |
$routeDestinations[$row[2]][] = $row; | $routeDestinations[$row[2]][] = $row; |
} | } |
echo '<div class="noscriptnav"> Go to Destination: '; | echo '<div class="noscriptnav"> Go to Destination: '; |
foreach (ksort($routeDestinations) as $destination => $routes) { | foreach (ksort($routeDestinations) as $destination => $routes) { |
echo "<a href=\"#$destination\">$destination</a> "; | echo "<a href=\"#$destination\">$destination</a> "; |
} | } |
echo "</div> | echo "</div> |
<script> | <script> |
$('.noscriptnav').hide(); | $('.noscriptnav').hide(); |
</script>"; | </script>"; |
foreach ($routeDestinations as $destination => $routes) { | foreach ($routeDestinations as $destination => $routes) { |
echo '<a name="' . $destination . '"></a>'; | echo '<a name="' . $destination . '"></a>'; |
echo '<li>' . $destination . "... <ul>\n"; | echo '<li>' . $destination . "... <ul>\n"; |
foreach ($routes as $row) { | foreach ($routes as $row) { |
echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[3]) . ")</a></li>\n"; | echo '<li>' . $row[1] . ' <a href="trip.php?routeid=' . $row[0] . '">' . $row[2] . " (" . ucwords($row[3]) . ")</a></li>\n"; |
} | } |
echo "</ul></li>\n"; | echo "</ul></li>\n"; |
} | } |
} | } |
echo "</ul>\n"; | echo "</ul>\n"; |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
include ('common.inc.php'); | include ('common.inc.php'); |
function filterByFirstLetter($var) { | function filterByFirstLetter($var) |
return $var[1][0] == $_REQUEST['firstLetter']; | { |
return $var[1][0] == $_REQUEST['firstLetter']; | |
} | } |
function navbar() | function navbar() |
{ | { |
echo ' | echo ' |
<div data-role="navbar"> | <div data-role="navbar"> |
<ul> | <ul> |
<li><a href="stopList.php">Timing Points</a></li> | <li><a href="stopList.php">Timing Points</a></li> |
<li><a href="stopList.php?suburbs=yes">By Suburb</a></li> | <li><a href="stopList.php?suburbs=yes">By Suburb</a></li> |
<li><a href="stopList.php?nearby=yes">Nearby Stops</a></li> | <li><a href="stopList.php?nearby=yes">Nearby 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> |
</ul> | </ul> |
</div> | </div> |
'; | '; |
} | } |
// By suburb | // By suburb |
if (isset($_REQUEST['suburbs'])) { | if (isset($_REQUEST['suburbs'])) { |
include_header("Stops by Suburb", "stopList"); | include_header("Stops by Suburb", "stopList"); |
navbar(); | navbar(); |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
foreach ($suburbs as $suburb) { | if (!isset($_REQUEST['firstLetter'])) { |
if (!isset($_REQUEST['firstLetter'])) { | foreach (range('A', 'Z') as $letter) { |
foreach (range('A', 'Z') as $letter) { | echo "<li><a href=\"stopList.php?firstLetter=$letter&suburbs=yes\">$letter...</a></li>\n"; |
echo "<li><a href=\"stopList.php?firstLetter=$letter&suburbs=yes\">$letter...</a></li>\n"; | } |
} | |
else { | |
foreach ($suburbs as $suburb) { | |
if (startsWith($suburb, $_REQUEST['firstLetter'])) { | |
echo '<li><a href="stopList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; | |
} | } |
} | |
else if (startsWith($suburb, $_REQUEST['firstLetter'])) { | |
echo '<li><a href="stopList.php?suburb=' . urlencode($suburb) . '">' . $suburb . '</a></li>'; | |
} | } |
} | } |
echo '</ul>'; | echo '</ul>'; |
} | } |
else { | else { |
// Timing Points / All stops | // Timing Points / All stops |
if ($_REQUEST['allstops']) { | if ($_REQUEST['allstops']) { |
$listType = 'allstops=yes'; | $listType = 'allstops=yes'; |
$url = $APIurl . "/json/stops"; | $url = $APIurl . "/json/stops"; |
include_header("All Stops", "stopList"); | include_header("All Stops", "stopList"); |
navbar(); | navbar(); |
timePlaceSettings(); | timePlaceSettings(); |
} | } |
else if ($_REQUEST['nearby']) { | else if ($_REQUEST['nearby']) { |
$listType = 'nearby=yes'; | $listType = 'nearby=yes'; |
$url = $APIurl . "/json/neareststops?lat={$_SESSION['lat']}&lon={$_SESSION['lon']}&limit=15"; | $url = $APIurl . "/json/neareststops?lat={$_SESSION['lat']}&lon={$_SESSION['lon']}&limit=15"; |
include_header("Nearby Stops", "stopList"); | include_header("Nearby Stops", "stopList"); |
navbar(); | navbar(); |
timePlaceSettings(true); | timePlaceSettings(true); |
if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") { | |
include_footer(); | |
die(); | |
} | |
} | } |
else if ($_REQUEST['suburb']) { | else if ($_REQUEST['suburb']) { |
$suburb = filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING); | $suburb = filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING); |
$listType = "suburb=$suburb"; | $listType = "suburb=$suburb"; |
$url = $APIurl . "/json/stopzonesearch?q=" . $suburb; | $url = $APIurl . "/json/stopzonesearch?q=" . $suburb; |
include_header("Stops in " . ucwords($suburb) , "stopList"); | include_header("Stops in " . ucwords($suburb) , "stopList"); |
navbar(); | navbar(); |
} | } |
else { | else { |
$url = $APIurl . "/json/timingpoints"; | $url = $APIurl . "/json/timingpoints"; |
include_header("Timing Points / Major Stops", "stopList"); | include_header("Timing Points / Major Stops", "stopList"); |
navbar(); | navbar(); |
timePlaceSettings(); | timePlaceSettings(); |
} | } |
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; | echo ' <ul data-role="listview" data-filter="true" data-inset="true" >'; |
if (!isset($_REQUEST['firstLetter']) && !$_REQUEST['suburb'] && !$_REQUEST['nearby']) { | if (!isset($_REQUEST['firstLetter']) && !$_REQUEST['suburb'] && !$_REQUEST['nearby']) { |
foreach (range('A', 'Z') as $letter) { | foreach (range('A', 'Z') as $letter) { |
echo "<li><a href=\"stopList.php?firstLetter=$letter&$listType\">$letter...</a></li>\n"; | echo "<li><a href=\"stopList.php?firstLetter=$letter&$listType\">$letter...</a></li>\n"; |
} | } |
} | } |
else { | else { |
$stops = json_decode(getPage($url)); | $stops = json_decode(getPage($url)); |
foreach ($stops as $key => $row) { | foreach ($stops as $key => $row) { |
$stopName[$key] = $row[1]; | $stopName[$key] = $row[1]; |
} | } |
// Sort the stops by name | // Sort the stops by name |
array_multisort($stopName, SORT_ASC, $stops); | array_multisort($stopName, SORT_ASC, $stops); |
if (!isset($_REQUEST['suburb']) && !isset($_REQUEST['nearby'])){ | if (!isset($_REQUEST['suburb']) && !isset($_REQUEST['nearby'])) { |
$stops = array_filter($stops, "filterByFirstLetter"); | $stops = array_filter($stops, "filterByFirstLetter"); |
} | } |
$stopsGrouped = Array(); | $stopsGrouped = Array(); |
foreach ($stops as $key => $row) { | foreach ($stops as $key => $row) { |
if ((trim(preg_replace("/\(Platform.*/","",$stops[$key][1])) != trim(preg_replace("/\(Platform.*/","",$stops[$key + 1][1]))) || $key + 1 >= sizeof($stops)) { | if ((trim(preg_replace("/\(Platform.*/", "", $stops[$key][1])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key + 1][1]))) || $key + 1 >= sizeof($stops)) { |
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"][] = $row[0]; | $stopsGrouped["stop_ids"][] = $row[0]; |
echo '<li>'; | echo '<li>'; |
if (!startsWith($stopsGrouped['stop_codes'][0], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point: " class="ui-li-icon">'; | |
if (!startsWith($stopsGrouped['stop_codes'][0], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">'; | echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '">'; |
echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '">'; | if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { |
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { | echo '<span class="ui-li-count">' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; |
echo '<span class="ui-li-count">' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; | |
} | |
echo bracketsMeanNewLine(trim(preg_replace("/\(Platform.*/","",$row[1])) . '(' . sizeof($stopsGrouped["stop_ids"]) . ' stops)'); | |
echo "</a></li>\n"; | |
$stopsGrouped = Array(); | |
} | } |
else { | echo bracketsMeanNewLine(trim(preg_replace("/\(Platform.*/", "", $row[1])) . '(' . sizeof($stopsGrouped["stop_ids"]) . ' stops)'); |
// just a normal stop | echo "</a></li>\n"; |
echo '<li>'; | $stopsGrouped = Array(); |
if (!startsWith($row[5], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">'; | } |
echo '<a href="stop.php?stopid=' . $row[0] . (startsWith($row[5], "Wj") ? '&stopcode=' . $row[5] : "") . '">'; | else { |
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { | // just a normal stop |
echo '<span class="ui-li-count">' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; | echo '<li>'; |
} | if (!startsWith($row[5], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">'; |
echo bracketsMeanNewLine($row[1]); | echo '<a href="stop.php?stopid=' . $row[0] . (startsWith($row[5], "Wj") ? '&stopcode=' . $row[5] : "") . '">'; |
echo "</a></li>\n"; | if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) { |
echo '<span class="ui-li-count">' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>'; | |
} | } |
echo bracketsMeanNewLine($row[1]); | |
} else { | echo "</a></li>\n"; |
} | |
} | |
else { | |
// this is a duplicated line item | // this is a duplicated line item |
if ($key - 1 <= 0 || (trim(preg_replace("/\(Platform.*/","",$stops[$key][1])) != trim(preg_replace("/\(Platform.*/","",$stops[$key - 1][1])))) { | if ($key - 1 <= 0 || (trim(preg_replace("/\(Platform.*/", "", $stops[$key][1])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key - 1][1])))) { |
// first duplicate | // first duplicate |
$stopsGrouped = Array( | $stopsGrouped = Array( |
"name" => trim(preg_replace("/\(Platform.*/","",$row[1])), | "name" => trim(preg_replace("/\(Platform.*/", "", $row[1])) , |
"stop_ids" => Array( | "stop_ids" => Array( |
$row[0] | $row[0] |
), | ) , |
"stop_codes" => Array( | "stop_codes" => Array( |
$row[5] | $row[5] |
) | ) |
); | ); |
} | } |
else { | else { |
// subsequent duplicates | // subsequent duplicates |
$stopsGrouped["stop_ids"][] = $row[0]; | $stopsGrouped["stop_ids"][] = $row[0]; |
} | } |
} | } |
} | |
} | |
} | } |
echo '</ul>'; | echo '</ul>'; |
} | } |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
include ('common.inc.php'); | include ('common.inc.php'); |
include_header("Trip Planner", "tripPlanner", true, true, true); | include_header("Trip Planner", "tripPlanner", true, true, true); |
$from = (isset($_REQUEST['from']) ? filter_var($_REQUEST['from'], FILTER_SANITIZE_STRING) : "Brigalow"); | $from = (isset($_REQUEST['from']) ? filter_var($_REQUEST['from'], FILTER_SANITIZE_STRING) : "Brigalow"); |
$to = (isset($_REQUEST['to']) ? filter_var($_REQUEST['to'], FILTER_SANITIZE_STRING) : "Barry"); | $to = (isset($_REQUEST['to']) ? filter_var($_REQUEST['to'], FILTER_SANITIZE_STRING) : "Barry"); |
$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")); |
$time = (isset($_REQUEST['time']) ? filter_var($_REQUEST['time'], FILTER_SANITIZE_STRING) : date("H:i")); | $time = (isset($_REQUEST['time']) ? filter_var($_REQUEST['time'], FILTER_SANITIZE_STRING) : date("H:i")); |
// todo: convert date from form to h:ia? | function formatTime($timeString) { |
$timeParts = explode("T",$timeString); | |
return str_replace("Z","",$timeParts[1]); | |
} | |
function tripPlanForm($errorMessage = "") | function tripPlanForm($errorMessage = "") |
{ | { |
global $date, $time, $from, $to; | global $date, $time, $from, $to; |
echo "<font color=red>$errorMessage</font>"; | echo "<font color=red>$errorMessage</font>"; |
echo '<form action="tripPlanner.php" method="post"> | echo '<form action="tripPlanner.php" method="post"> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="from">I would like to go from</label> | <label for="from">I would like to go from</label> |
<input type="text" name="from" id="from" value="' . $from . '" /> | <input type="text" name="from" id="from" value="' . $from . '" /> |
<a href="#" style="display:none" name="fromHere" id="fromHere"/>Here?</a> | <a href="#" style="display:none" name="fromHere" id="fromHere"/>Here?</a> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="to"> to </label> | <label for="to"> to </label> |
<input type="text" name="to" id="to" value="' . $to . '" /> | <input type="text" name="to" id="to" value="' . $to . '" /> |
<a href="#" style="display:none" name="toHere" id="toHere"/>Here?</a> | <a href="#" style="display:none" name="toHere" id="toHere"/>Here?</a> |
</div> | </div> |
<div data-role="fieldcontain"> | <div data-role="fieldcontain"> |
<label for="date"> on </label> | <label for="date"> on </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="time"> at </label> | <label for="time"> at </label> |
<input type="time" name="time" id="time" value="' . $time . '" /> | <input type="time" name="time" id="time" value="' . $time . '" /> |
</div> | </div> |
<input type="submit" value="Go!"></form>'; | <input type="submit" value="Go!"></form>'; |
echo "<script> | echo "<script> |
$('#toHere').click(function(event) { $('#to').val(getCookie('geolocate')); return false;}); | $('#toHere').click(function(event) { $('#to').val(getCookie('geolocate')); return false;}); |
$('#toHere').show(); | $('#toHere').show(); |
$('#fromHere').click(function(event) { $('#from').val(getCookie('geolocate')); return false;}); | $('#fromHere').click(function(event) { $('#from').val(getCookie('geolocate')); return false;}); |
$('#fromHere').show(); | $('#fromHere').show(); |
</script>"; | </script>"; |
} | } |
function processItinerary($itineraryNumber, $itinerary) | function processItinerary($itineraryNumber, $itinerary) |
{ | { |
echo '<div data-role="collapsible" ' . ($itineraryNumber > 0 ? 'data-collapsed="true"' : "") . '> <h3> Option #' . ($itineraryNumber + 1) . ": " . floor($itinerary->duration / 60000) . " minutes ({$itinerary->startTime} to {$itinerary->endTime})</h3><p>"; | echo '<div data-role="collapsible" ' . ($itineraryNumber > 0 ? 'data-collapsed="true"' : "") . '> <h3> Option #' . ($itineraryNumber + 1) . ": " . floor($itinerary->duration / 60000) . " minutes (".formatTime($itinerary->startTime)." to ".formatTime($itinerary->endTime).")</h3><p>"; |
echo "Walking time: " . floor($itinerary->walkTime / 60000) . " minutes (" . floor($itinerary->walkDistance) . " meters)<br>\n"; | echo "Walking time: " . floor($itinerary->walkTime / 60000) . " minutes (" . floor($itinerary->walkDistance) . " meters)<br>\n"; |
echo "Transit time: " . floor($itinerary->transitTime / 60000) . " minutes<br>\n"; | echo "Transit time: " . floor($itinerary->transitTime / 60000) . " minutes<br>\n"; |
echo "Waiting time: " . floor($itinerary->waitingTime / 60000) . " minutes<br>\n"; | echo "Waiting time: " . floor($itinerary->waitingTime / 60000) . " minutes<br>\n"; |
if (is_array($itinerary->legs->leg)) { | if (is_array($itinerary->legs->leg)) { |
$legMarkers = array(); | $legMarkers = array(); |
foreach ($itinerary->legs->leg as $legNumber => $leg) { | foreach ($itinerary->legs->leg as $legNumber => $leg) { |
$legMarkers[] = array( | $legMarkers[] = array( |
$leg->from->lat, | $leg->from->lat, |
$leg->from->lon | $leg->from->lon |
); | ); |
} | } |
echo '' . staticmap($legMarkers, 0, "iconb", false) . "<br>\n"; | echo '' . staticmap($legMarkers, 0, "iconb", false) . "<br>\n"; |
echo '<ul>'; | echo '<ul>'; |
foreach ($itinerary->legs->leg as $legNumber => $leg) { | foreach ($itinerary->legs->leg as $legNumber => $leg) { |
echo '<li>'; | echo '<li>'; |
processLeg($legNumber, $leg); | processLeg($legNumber, $leg); |
echo "</li>"; | echo "</li>"; |
} | } |
echo "</ul>"; | echo "</ul>"; |
} | } |
else { | else { |
echo '' . staticmap(array( | echo '' . staticmap(array( |
array( | array( |
$itinerary->legs->leg->from->lat, | $itinerary->legs->leg->from->lat, |
$itinerary->legs->leg->from->lon | $itinerary->legs->leg->from->lon |
) | ) |
) , 0, "iconb", false) . "<br>\n"; | ) , 0, "iconb", false) . "<br>\n"; |
processLeg(0, $itinerary->legs->leg); | processLeg(0, $itinerary->legs->leg); |
} | } |
echo "</p></div>"; | echo "</p></div>"; |
} | } |
function processLeg($legNumber, $leg) | function processLeg($legNumber, $leg) |
{ | { |
$legArray = object2array($leg); | $legArray = object2array($leg); |
echo '<h3>Leg #' . ($legNumber + 1) . " ( {$legArray['@mode']} from: {$leg->from->name} to {$leg->to->name}, " . floor($leg->duration / 60000) . " minutes) </h3>\n"; | echo '<h3>Leg #' . ($legNumber + 1) . " ( {$legArray['@mode']} from: {$leg->from->name} to {$leg->to->name}, " . floor($leg->duration / 60000) . " minutes) </h3>\n"; |
if ($legArray["@mode"] === "BUS") { | if ($legArray["@mode"] === "BUS") { |
echo "Take bus {$legArray['@route']} " . str_replace("To", "towards", $legArray['@headsign']) . "<br>"; | echo "Take bus {$legArray['@route']} " . str_replace("To", "towards", $legArray['@headsign']) . "<br>"; |
} | } |
else { | else { |
$walkStepMarkers = array(); | $walkStepMarkers = array(); |
foreach ($leg->steps->walkSteps as $stepNumber => $step) { | foreach ($leg->steps->walkSteps as $stepNumber => $step) { |
$walkStepMarkers[] = array( | $walkStepMarkers[] = array( |
$step->lat, | $step->lat, |
$step->lon | $step->lon |
); | ); |
} | } |
echo "" . staticmap($walkStepMarkers, 0, "icong", false) . "<br>\n"; | echo "" . staticmap($walkStepMarkers, 0, "icong", false) . "<br>\n"; |
foreach ($leg->steps->walkSteps as $stepNumber => $step) { | foreach ($leg->steps->walkSteps as $stepNumber => $step) { |
echo "Walking step " . ($stepNumber + 1) . " $step->absoluteDirection / $step->relativeDirection on $step->streetName for " . floor($step->distance) . " meters<br>\n"; | echo "Walking step " . ($stepNumber + 1) . " $step->absoluteDirection / $step->relativeDirection on $step->streetName for " . floor($step->distance) . " meters<br>\n"; |
} | } |
} | } |
} | } |
if ($_REQUEST['time']) { | if ($_REQUEST['time']) { |
$toPlace = (startsWith($to, "-") ? $to : geocode($to, false)); | $toPlace = (startsWith($to, "-") ? $to : geocode($to, false)); |
$fromPlace = (startsWith($from, "-") ? $from : geocode($from, false)); | $fromPlace = (startsWith($from, "-") ? $from : geocode($from, false)); |
if ($toPlace == "" || $fromPlace == "") { | if ($toPlace == "" || $fromPlace == "") { |
$errorMessage = ""; | $errorMessage = ""; |
if ($toPlace === "") $errorMessage.= urlencode($to) . " not found.<br>\n"; | if ($toPlace === "") $errorMessage.= urlencode($to) . " not found.<br>\n"; |
if ($fromPlace === "") $errorMessage.= urlencode($from) . " not found.<br>\n"; | if ($fromPlace === "") $errorMessage.= urlencode($from) . " not found.<br>\n"; |
tripPlanForm($errorMessage); | tripPlanForm($errorMessage); |
} | } |
else { | else { |
$url = $otpAPIurl . "ws/plan?date=" . urlencode($_REQUEST['date']) . "&time=" . urlencode($_REQUEST['time']) . "&mode=TRANSIT%2CWALK&optimize=QUICK&maxWalkDistance=840&wheelchair=false&toPlace=$toPlace&fromPlace=$fromPlace&intermediatePlaces="; | $url = $otpAPIurl . "ws/plan?date=" . urlencode($_REQUEST['date']) . "&time=" . urlencode($_REQUEST['time']) . "&mode=TRANSIT%2CWALK&optimize=QUICK&maxWalkDistance=840&wheelchair=false&toPlace=$toPlace&fromPlace=$fromPlace&intermediatePlaces="; |
$ch = curl_init($url); | $ch = curl_init($url); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
curl_setopt($ch, CURLOPT_HEADER, 0); | curl_setopt($ch, CURLOPT_HEADER, 0); |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
"Accept: application/json" | "Accept: application/json" |
)); | )); |
curl_setopt($ch, CURLOPT_TIMEOUT, 5); | curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
$page = curl_exec($ch); | $page = curl_exec($ch); |
if (curl_errno($ch)) { | if (curl_errno($ch)) { |
tripPlanForm("Trip planner temporarily unavailable: " . curl_errno($ch) . " " . curl_error($ch)); | tripPlanForm("Trip planner temporarily unavailable: " . curl_errno($ch) . " " . curl_error($ch)); |
} | } |
else { | else { |
$tripplan = json_decode($page); | $tripplan = json_decode($page); |
debug(print_r($triplan, true)); | debug(print_r($triplan, true)); |
echo "<h1> From: {$tripplan->plan->from->name} To: {$tripplan->plan->to->name} </h1>"; | echo "<h1> From: {$tripplan->plan->from->name} To: {$tripplan->plan->to->name} </h1>"; |
echo "<h1> At: {$tripplan->plan->date} </h1>"; | echo "<h1> At: ".formatTime($tripplan->plan->date)." </h1>"; |
if (is_array($tripplan->plan->itineraries->itinerary)) { | if (is_array($tripplan->plan->itineraries->itinerary)) { |
echo '<div data-role="collapsible-set">'; | echo '<div data-role="collapsible-set">'; |
foreach ($tripplan->plan->itineraries->itinerary as $itineraryNumber => $itinerary) { | foreach ($tripplan->plan->itineraries->itinerary as $itineraryNumber => $itinerary) { |
processItinerary($itineraryNumber, $itinerary); | processItinerary($itineraryNumber, $itinerary); |
} | } |
echo "</div>"; | echo "</div>"; |
} | } |
else { | else { |
processItinerary(0, $tripplan->plan->itineraries->itinerary); | processItinerary(0, $tripplan->plan->itineraries->itinerary); |
} | } |
} | } |
curl_close($ch); | curl_close($ch); |
} | } |
} | } |
else { | else { |
tripPlanForm(); | tripPlanForm(); |
} | } |
include_footer(); | include_footer(); |
?> | ?> |