Files

50 lines
1.3 KiB
PHP

<?php
/**
* app/modules/floor_infrastructure/delete.php
*
* Loescht Patchpanels oder Wandbuchsen (AJAX-POST bevorzugt).
*/
$isPost = ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST';
$type = strtolower(trim((string)($_POST['type'] ?? $_GET['type'] ?? '')));
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
if ($id <= 0 || !in_array($type, ['patchpanel', 'outlet'], true)) {
if ($isPost) {
header('Content-Type: application/json; charset=utf-8');
http_response_code(400);
echo json_encode(['success' => false, 'message' => 'Ungueltige Anfrage']);
exit;
}
header('Location: ?module=floor_infrastructure&action=list');
exit;
}
if ($type === 'patchpanel') {
$rows = $sql->set(
"DELETE FROM floor_patchpanels WHERE id = ?",
"i",
[$id]
);
} else {
$rows = $sql->set(
"DELETE FROM network_outlets WHERE id = ?",
"i",
[$id]
);
}
if ($isPost) {
header('Content-Type: application/json; charset=utf-8');
if ($rows > 0) {
echo json_encode(['success' => true, 'message' => 'Infrastrukturobjekt geloescht']);
} else {
http_response_code(404);
echo json_encode(['success' => false, 'message' => 'Infrastrukturobjekt nicht gefunden oder bereits geloescht']);
}
exit;
}
header('Location: ?module=floor_infrastructure&action=list');
exit;