Add index.php. Already allows station name validation. ^^
This commit is contained in:
parent
1783860872
commit
b00a2219d5
1 changed files with 57 additions and 0 deletions
57
index.php
Normal file
57
index.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once($apipath);
|
||||
require_once($pqpath);
|
||||
|
||||
$api = new oebbApi();
|
||||
|
||||
function error($string, $code = 400) {
|
||||
http_response_code($code);
|
||||
die($string);
|
||||
}
|
||||
|
||||
function prepare() {
|
||||
global $output;
|
||||
header("Content-type: application/" . $output . "; charset=utf-8");
|
||||
if ($output == "xml") {
|
||||
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<stations>\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET["debug"])) {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
|
||||
$output = (isset($_GET["output"]) ? strtolower($_GET["output"]) :
|
||||
(isset($_POST["output"]) ? strtolower($_POST["output"]) :
|
||||
$output = "xml"));
|
||||
|
||||
if ($output != "xml") {
|
||||
error("Unknown output type provided.");
|
||||
}
|
||||
|
||||
if (!isset($_GET["type"]) && !isset($_POST["type"])) {
|
||||
error("No request type provided.");
|
||||
}
|
||||
|
||||
$type = strtolower((isset($_GET["type"]) ? $_GET["type"] : $_POST["type"]));
|
||||
|
||||
if ($type == "validate") {
|
||||
if (!isset($_GET["name"]) && !isset($_POST["name"])) {
|
||||
error("No station name provided for verification.");
|
||||
}
|
||||
|
||||
prepare();
|
||||
|
||||
foreach($api->validate(isset($_GET["name"]) ? $_GET["name"] : $_POST["name"]) as $station) {
|
||||
print("<station id=\"" . $station["id"] . "\"><name>" . $station["value"] . "</name></station>\n");
|
||||
}
|
||||
|
||||
print("</stations>");
|
||||
|
||||
} else {
|
||||
error("Unknown request type provided.");
|
||||
}
|
Loading…
Reference in a new issue