From fdbadea14af6aaaba534ab1aac92651651196953 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Mon, 22 Aug 2016 09:22:20 +0200 Subject: [PATCH] Add support for timetable queries --- index.php | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 027fc14..57dbeb2 100644 --- a/index.php +++ b/index.php @@ -15,7 +15,7 @@ function prepare() { global $output; header("Content-type: application/" . $output . "; charset=utf-8"); if ($output == "xml") { - print("\n\n"); + print("\n"); } } @@ -46,12 +46,83 @@ if ($type == "validate") { prepare(); + print(""); + foreach($api->validate(isset($_GET["name"]) ? $_GET["name"] : $_POST["name"]) as $station) { print("" . $station["id"] . "" . $station["value"] . "\n"); } print(""); +} else if ($type == "conn" || $type == "connection" || $type == "connections") { + if ((isset($_GET["from"]) && isset($_GET["to"])) || (isset($_POST["from"]) && isset($_POST["to"]))) { + prepare(); + $from = (isset($_GET["from"]) && isset($_GET["to"]) ? $_GET["from"] : $_POST["from"]); + $to = (isset($_GET["from"]) && isset($_GET["to"]) ? $_GET["to"] : $_POST["to"]); + $count = (isset($_GET["count"]) ? $_GET["count"] : (isset($_POST["count"]) ? $_POST["count"] : 3)); + $date = (isset($_GET["date"]) ? $_GET["date"] : (isset($_POST["date"]) ? $_POST["date"] : null)); + $time = (isset($_GET["time"]) ? $_GET["time"] : (isset($_POST["time"]) ? $_POST["time"] : null)); + $mode = (isset($_GET["mode"]) ? $_GET["mode"] : (isset($_POST["mode"]) ? $_POST["mode"] : null)); + + print("\n"); + +/* foreach ($api->get($from, $to, $count, $date, $time, $mode) as $conn) { + print("Connection"); + var_dump($conn); + print("Details"); + var_dump($api->getDetails($conn["id"])); + print("Coords"); + var_dump($api->getCoords()); + } */ + + foreach ($api->get($from, $to, $count, $date, $time, $mode) as $conn) { + print(" \n"); + print(" " . $conn["startStation"] . "" . $api->validate($conn["startStation"])[0]["id"] . "\n"); + print(" " . $conn["endStation"] . "" . $api->validate($conn["endStation"])[0]["id"] . "\n"); + print("
\n"); + print(" " . $conn["startDate"] . "\n"); + print(" " . $conn["endDate"] . "\n"); + print(" " . $conn["duration"] . "\n"); + print(" " . $conn["changes"] . "\n"); + print(" \n"); + print("
\n"); + + print(" \n"); + + $order = 0; + + foreach ($api->getDetails($conn["id"]) as $service) { + print(" \n"); + print(" " . $service["data"]["productName"] . "\n"); + print(" \n"); + print(" " . $service["start"]["station"] . "" . $api->validate($service["start"]["station"])[0]["id"] . "\n"); + print(" " . $service["start"]["date"] . "\n"); + print(" " . $service["start"]["plattform"] . "\n"); + print(" "); + print(" \n"); + + print(" \n"); + print(" " . $service["end"]["station"] . "" . $api->validate($service["end"]["station"])[0]["id"] . "\n"); + print(" " . $service["end"]["date"] . "\n"); + print(" " . $service["end"]["plattform"] . "\n"); + print(" \n"); + + print(" \n"); + print(" \n"); + $order++; + } + + print(" \n"); + + print("
\n"); + } + + print("
\n"); + + } else { + error("Required 'from' and/or 'to' arguments missing."); + } + } else { error("Unknown request type provided."); }