Files
netwatch/app/modules/buildings/delete.php
2026-02-16 13:56:01 +01:00

36 lines
860 B
PHP

<?php
/**
* app/modules/buildings/delete.php
*/
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['error' => 'Methode nicht erlaubt']);
exit;
}
header('Content-Type: application/json');
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
if ($id <= 0) {
http_response_code(400);
echo json_encode(['error' => 'ID fehlt']);
exit;
}
$exists = $sql->single("SELECT id FROM buildings WHERE id = ?", "i", [$id]);
if (!$exists) {
http_response_code(404);
echo json_encode(['error' => 'Gebaeude nicht gefunden']);
exit;
}
$rows = $sql->set("DELETE FROM buildings WHERE id = ?", "i", [$id]);
if ($rows === false) {
http_response_code(500);
echo json_encode(['error' => 'Loeschen fehlgeschlagen']);
exit;
}
echo json_encode(['status' => 'ok', 'success' => true, 'rows' => $rows]);