This commit is contained in:
Troy Grunt
2026-02-11 21:59:13 +01:00
parent 23b687c7a2
commit 88ff04aa01
5 changed files with 57 additions and 10 deletions

View File

@@ -30,7 +30,7 @@ $action = $_GET['action'] ?? 'list';
$validModules = ['dashboard', 'locations', 'buildings', 'device_types', 'devices', 'racks', 'floors', 'connections'];
// Whitelist der Aktionen
$validActions = ['list', 'edit', 'save', 'ports'];
$validActions = ['list', 'edit', 'save', 'ports', 'delete'];
// Prüfen auf gültige Werte
if (!in_array($module, $validModules)) {
@@ -44,9 +44,9 @@ if (!in_array($action, $validActions)) {
}
/* =========================
* Template-Header laden (nur für non-save Aktionen)
* Template-Header laden (nur für View-Aktionen)
* ========================= */
if ($action !== 'save') {
if (!in_array($action, ['save', 'delete'], true)) {
require_once __DIR__ . '/templates/header.php';
}
@@ -65,8 +65,8 @@ if (file_exists($modulePath)) {
}
/* =========================
* Template-Footer laden (nur für non-save Aktionen)
* Template-Footer laden (nur für View-Aktionen)
* ========================= */
if ($action !== 'save') {
if (!in_array($action, ['save', 'delete'], true)) {
require_once __DIR__ . '/templates/footer.php';
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* app/modules/devices/delete.php
*
* Löscht ein Gerät inkl. abhängiger Verbindungen.
*/
$deviceId = (int)($_GET['id'] ?? 0);
if ($deviceId <= 0) {
$_SESSION['error'] = "Ungültige Geräte-ID";
header('Location: ?module=devices&action=list');
exit;
}
$device = $sql->single(
"SELECT id, name FROM devices WHERE id = ?",
"i",
[$deviceId]
);
if (!$device) {
$_SESSION['error'] = "Gerät nicht gefunden";
header('Location: ?module=devices&action=list');
exit;
}
// Verbindungen auf Ports dieses Geräts entfernen (keine FK auf device_ports in connections).
$sql->set(
"DELETE FROM connections
WHERE (port_a_type = 'device' AND port_a_id IN (SELECT id FROM device_ports WHERE device_id = ?))
OR (port_b_type = 'device' AND port_b_id IN (SELECT id FROM device_ports WHERE device_id = ?))",
"ii",
[$deviceId, $deviceId]
);
$deleted = $sql->set(
"DELETE FROM devices WHERE id = ?",
"i",
[$deviceId]
);
if ($deleted > 0) {
$_SESSION['success'] = "Gerät gelöscht: " . $device['name'];
} else {
$_SESSION['error'] = "Gerät konnte nicht gelöscht werden";
}
header('Location: ?module=devices&action=list');
exit;

View File

@@ -235,8 +235,7 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
<script>
function confirmDelete(id) {
if (confirm('Dieses Gerät wirklich löschen?')) {
// TODO: AJAX-Delete implementieren
alert('Löschen noch nicht implementiert');
window.location.href = '?module=devices&action=delete&id=' + encodeURIComponent(id);
}
}
</script>

View File

@@ -331,8 +331,7 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
<script>
function confirmDelete(id) {
if (confirm('Dieses Gerät wirklich löschen?')) {
// TODO: AJAX-Delete implementieren
alert('Löschen noch nicht implementiert');
window.location.href = '?module=devices&action=delete&id=' + encodeURIComponent(id);
}
}
</script>