<?php
include 'config.php';
include 'functions.php';

// CORS
header("Access-Control-Allow-Origin: *");
header('Access-Control-Max-Age: 86400');    // cache for 1 day
if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
	http_response_code(204);
	header("Access-Control-Allow-Headers: origin, content-type, accept");
	header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
	header("Access-Control-Allow-Private-Network: true");
	exit(0);
}

if (!isset($_GET['id']))
	die(return_error(400, "Keine ID angegeben."));

$id = (int)$_GET['id'];

$dbconn = pg_connect($dbconnstring)
	or die(return_error(500, 'Datenbankfehler: ' . pg_last_error()));

$query = "DELETE FROM tests WHERE id=" . $id;
$result = pg_query($dbconn, $query)
	or die(return_error('Datenbankfehler: ' . pg_last_error()));

pg_close($dbconn);

echo return_success();

?>
