diff --git a/BUGS.md b/BUGS.md
index 249a5c2..703d0ba 100644
--- a/BUGS.md
+++ b/BUGS.md
@@ -1,5 +1,4 @@
# gefundene bugs
-- device-webconfig link ist nicht korrekt
- device löschen geht nicht
- device_types svg modul malen
- ports drag n drop funktioniert nicht
\ No newline at end of file
diff --git a/app/index.php b/app/index.php
index c663dee..78c3bbc 100644
--- a/app/index.php
+++ b/app/index.php
@@ -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';
}
diff --git a/app/modules/devices/delete.php b/app/modules/devices/delete.php
new file mode 100644
index 0000000..c5b8b0b
--- /dev/null
+++ b/app/modules/devices/delete.php
@@ -0,0 +1,50 @@
+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;
diff --git a/app/modules/devices/edit.php b/app/modules/devices/edit.php
index 34665bb..e903f88 100644
--- a/app/modules/devices/edit.php
+++ b/app/modules/devices/edit.php
@@ -235,8 +235,7 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
diff --git a/app/modules/devices/list.php b/app/modules/devices/list.php
index adb454d..fb4512e 100644
--- a/app/modules/devices/list.php
+++ b/app/modules/devices/list.php
@@ -331,8 +331,7 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);