Add index.php. Already allows station name validation. ^^

This commit is contained in:
Klaus-Uwe Mitterer 2016-08-21 00:27:19 +02:00
parent 1783860872
commit b00a2219d5

57
index.php Normal file
View 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.");
}