oebb/index.php

58 lines
1.3 KiB
PHP
Raw Normal View History

<?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) {
2016-08-20 22:52:11 +00:00
print("<station><id>" . $station["id"] . "</id><name>" . $station["value"] . "</name></station>\n");
}
print("</stations>");
} else {
error("Unknown request type provided.");
}