240 ? ($ret-240) : $ret; } if ($ret>$duration) $ret = $duration; return $ret; } function getEndDateTime($startTime,$endTime,$duration) { if ($endTime!="") return $endTime; if ($duration>0) return $duration; } function showDirections($f,$noRecurse=true, $htmlHeader="") { if ($f["routes"]>0 && $f["gid"]>0) { $q0 = "SELECT * FROM google_directions_legs WHERE parsedemail_item_advice_google_id=".$f["gid"]; $r0 = pg_query($q0); if ($htmlHeader!="") { echo "${htmlHeader}
\n"; } echo "\n"; while ($f0=pg_fetch_assoc($r0)) { echo ""; echo "" ; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; echo "\n"; } echo "
DepartureArrivalDistanceDurationStepsCost
".($f0["departure_time"]==0?'N/A':date("Y-m-d H:i:s",$f0["departure_time"]))."".($f0["arrival_time"]==0?'N/A':date("Y-m-d H:i:s",$f0["arrival_time"]))."".sprintf("%0.01f",$f0["distance"]/1000.0)."km".gmdate("H:i:s", $f0["duration"])."".$f0["steps"]."$".sprintf("%0.02f",0.01*$f0["fare_raw"])."
"; $q1 = "SELECT a.id AS sid,a.*,b.* FROM google_directions_leg_steps a LEFT JOIN google_directions_leg_step_details b ON a.id=b.google_directions_leg_step_id "; $q1.= " WHERE a.google_directions_leg_id=".$f0["id"]; $r1 = pg_query($q1); $i=1; echo ""; echo ""; echo ""; $fare = 0; while ($f1=pg_fetch_assoc($r1)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $q2 = "SELECT * FROM leg_step_quote WHERE google_directions_leg_step_id=".$f1["sid"]; $r2 = pg_query($q2); $f2 = pg_fetch_assoc($r2); if (is_array($f2) && isset($f2["fare"]) && $f2["fare"]!="") { echo ""; echo ""; $fare += $f2["fare_raw"]; } else if (strtolower($f1["vehicle"])=='bus' || strtolower($f1["vehicle"])=='subway' || strtolower($f1["vehicle"])=='scooter') { echo ""; echo ""; } else { echo "\n"; $i++; } if ($fare==0) $fare = $f0["fare_raw"]; echo "\n"; echo "
NTravel ModeDistanceDurationInstructionsStopsLineVehicleDeparture StopArrival StopQuoteDeparture / Arrival
".$i."".$f1["travel_mode"]."".($f1["distance"]<1000 ? $f1["distance"] : sprintf("%0.01fk",$f1["distance"]/1000.0))."m".gmdate("H:i:s", $f1["duration"])."".$f1["html_instructions"]."".$f1["num_stops"]."".$f1["line"]."".$f1["vehicle"]."".$f1["departure_stop"]."".$f1["arrival_stop"]."".sprintf("%0.03f",$f1["location_start_lat"]).",".sprintf("%0.03f",$f1["location_start_lng"]); echo "
".sprintf("%0.03f",$f1["location_end_lat"]).",".sprintf("%0.03f",$f1["location_end_lng"])."
".sprintf("%0.03f",$f1["location_start_lat"]).",".sprintf("%0.03f",$f1["location_start_lng"]); echo "
".sprintf("%0.03f",$f1["location_end_lat"]).",".sprintf("%0.03f",$f1["location_end_lng"])."
N/AN/A"; } echo "
Total:$".sprintf("%0.02f",$fare/100.0)."
\n"; echo "
"; } else { echo " Get google directions routes"; } echo "
"; showTaxi($f,$noRecurse); echo "
"; } function showMenu($id) { echo "Get taxi advice"; echo " | Regular taxi quote"; } function showTaxi($f, $noRecurse=true, $force=false) { $q0 = "SELECT * FROM parsedemail_item_advice WHERE parsedemail_item_id=".$f["id"]; $r0 = pg_query($q0); //echo $q0; if ($noRecurse) { showMenu($f["id"]); } if ($r0 && pg_num_rows($r0) && !$force) { ob_start(); echo "\n"; while ($f0=pg_fetch_assoc($r0)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
TimeProviderProductHighLowDistanceDuration
".strtok($f0["advice_time"],".")."".getTransportProvider($f0["transport_provider_id"])."".$f0["display_name"]."$".sprintf("%0.02f",$f0["high_estimate"]/100.0)."$".sprintf("%0.02f",$f0["low_estimate"]/100.0)."".$f0["distance_estimate"]."".gmdate("H:i:s", $f0["duration_estimate"])."
\n"; if ($force) { showTaxi($f,true,false); } else { ob_end_flush(); } } if ($noRecurse) { //echo "No recurse!"; } else { // Get Advice ob_start(); $result = local_v1_service_call('GET','advice',$f["id"]); ob_end_clean(); //ob_end_flush(); if ($result["code"]==0) { $data = $result["data"]; if (isset($data["error_uber"])) echo $data["error_uber"]."\n"; if (isset($data["error_lyft"])) echo $data["error_lyft"]."\n"; showTaxi($f, true); } else { echo "Invalid service response code!\n"; } } } function getTransportProvider($id) { global $providers; if (!is_array($providers) || !isset($providers[$id])) { $q = "SELECT id,name FROM transport_providers"; $r = pg_query($q); while ($f=pg_fetch_row($r)) $providers[$f[0]] = $f[1]; } return $providers[$id]."(".$id.")"; }