--- a/busui/tripPlanner.php +++ b/busui/tripPlanner.php @@ -1,48 +1,131 @@ From: {$tripplan->plan->from->name} "; - echo "

To: {$tripplan->plan->to->name}

"; - echo "

At: {$tripplan->plan->date}

"; - foreach ($tripplan->plan->itineraries->itinerary as $itineraryNumber => $itinerary ){ - echo "

Option #".($itineraryNumber+1)."

"; - echo "Duration: ".floor($itinerary->duration/60000)." minutes ({$itinerary->startTime} to {$itinerary->endTime})
\n"; - echo "Walking time: ".floor($itinerary->walkTime/60000)." minutes ({$itinerary->walkDistance} meters)
\n"; - echo "Transit time: ".floor($itinerary->transitTime/60000)." minutes
\n"; - echo "Waiting time: ".floor($itinerary->waitingTime/60000)." minutes
\n"; - $legMarkers = Array(); - foreach ($itinerary->legs->leg as $legNumber => $leg ){ - $legMarkers[] = Array($leg->from->lat,$leg->from->lon); - } - echo staticmap($legMarkers)."
\n"; - foreach ($itinerary->legs->leg as $legNumber => $leg ){ - echo "Leg #".($legNumber+1)." (from: {$leg->from->name} to {$leg->to->name}, ".floor($leg->duration/60000)." minutes)
\n"; - $legArray = object2array($leg); - if ($legArray["@mode"] === "BUS") { - echo "Take bus {$legArray['@route']} ".str_replace("To","towards",$legArray['@headsign'])."
"; - } - else { - foreach ($leg->steps->walkSteps as $stepNumber => $step ){ - echo "Walking step $stepNumber $step->absoluteDirection / $step->relativeDirection on $step->streetName for $step->distance meters / ".floor($step->duration/60000)." minutes
\n"; - } - } - } - } -} else { - echo '
I would like to go from to - on at -
'; + include('common.inc.php'); + include_header("Trip Planner", true, true); + function tripPlanForm($errorMessage = "") + { + $from = (isset($_REQUEST['from']) ? $_REQUEST['from'] : "Brigalow"); + $to = (isset($_REQUEST['to']) ? $_REQUEST['to'] : "Barry"); + $date = (isset($_REQUEST['date']) ? $_REQUEST['date'] : date("m/d/Y")); + $time = (isset($_REQUEST['time']) ? $_REQUEST['time'] : date("H:m")); + # todo: convert date from form to h:ia? + echo "$errorMessage"; + echo '
+
+ + + +
+
+ + + +
+
+ + +
+
+ + +
+
'; + echo ""; + } + + function processItinerary($itineraryNumber, $itinerary) + { + echo '
0 ? 'data-collapsed="true"' : "") . '>

Option #' . ($itineraryNumber + 1) . ": " . floor($itinerary->duration / 60000) . " minutes ({$itinerary->startTime} to {$itinerary->endTime})

"; + echo "Walking time: " . floor($itinerary->walkTime / 60000) . " minutes (" . floor($itinerary->walkDistance) . " meters)
\n"; + echo "Transit time: " . floor($itinerary->transitTime / 60000) . " minutes
\n"; + echo "Waiting time: " . floor($itinerary->waitingTime / 60000) . " minutes
\n"; + -} - include_footer(); + + if (is_array($itinerary->legs->leg)) { + $legMarkers = array(); + foreach ($itinerary->legs->leg as $legNumber => $leg) { + $legMarkers[] = array($leg->from->lat, $leg->from->lon); + } + echo '' . staticmap($legMarkers) . "
\n"; + echo '

"; + } else { + echo '' . staticmap(array(array($itinerary->legs->leg->from->lat, $itinerary->legs->leg->from->lon))) . "
\n"; + processLeg(0, $itinerary->legs->leg); + } + + echo "

"; + } + + function processLeg($legNumber, $leg) { + $legArray = object2array($leg); + echo '

Leg #' . ($legNumber + 1) . " ( {$legArray['@mode']} from: {$leg->from->name} to {$leg->to->name}, " . floor($leg->duration / 60000) . " minutes)

\n"; + if ($legArray["@mode"] === "BUS") { + echo "Take bus {$legArray['@route']} " . str_replace("To", "towards", $legArray['@headsign']) . "
"; + } else { + $walkStepMarkers = array(); + foreach ($leg->steps->walkSteps as $stepNumber => $step) { + $walkStepMarkers[] = array($step->lat, $step->lon); + } + echo "" . staticmap($walkStepMarkers, "icong") . "
\n"; + foreach ($leg->steps->walkSteps as $stepNumber => $step) { + echo "Walking step " . ($stepNumber + 1) . " $step->absoluteDirection / $step->relativeDirection on $step->streetName for " . floor($step->distance) . " meters
\n"; + } + } + } + + if ($_REQUEST['time']) { + $toPlace = (startsWith($_REQUEST['to'], "-") ? $_REQUEST['to'] : geocode(urlencode($_REQUEST['to']), false)); + $fromPlace = (startsWith($_REQUEST['from'], "-") ? $_REQUEST['from'] : geocode(urlencode($_REQUEST['from']), false)); + if ($toPlace == "" || $fromPlace == "") { + $errorMessage = ""; + if ($toPlace === "") + $errorMessage .= urlencode($_REQUEST['to']) . " not found.
\n"; + if ($fromPlace === "") + $errorMessage .= urlencode($_REQUEST['from']) . " not found.
\n"; + tripPlanForm($errorMessage); + } else { + $url = "http://10.1.0.243:5080/opentripplanner-api-webapp/ws/plan?_dc=1290254798856&arriveBy=false&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); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json")); + curl_setopt($ch,CURLOPT_TIMEOUT,5); + $page = curl_exec($ch); + + if(curl_errno($ch)) { tripPlanForm("Trip planner temporarily unavailable: ".curl_errno($ch)." ".curl_error($ch));} + else { + $tripplan = json_decode($page); + debug(print_r($triplan,true)); + echo "

From: {$tripplan->plan->from->name} To: {$tripplan->plan->to->name}

"; + echo "

At: {$tripplan->plan->date}

"; + + if (is_array($tripplan->plan->itineraries->itinerary)) { + echo '
'; + foreach ($tripplan->plan->itineraries->itinerary as $itineraryNumber => $itinerary) { + processItinerary($itineraryNumber, $itinerary); + } + echo "
"; + } else { + processItinerary(0, $tripplan->plan->itineraries->itinerary); + } + } + curl_close($ch); + } + } else { + tripPlanForm(); + } + include_footer(); ?> +