löschen
This commit is contained in:
50
app/modules/devices/delete.php
Normal file
50
app/modules/devices/delete.php
Normal 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;
|
||||
Reference in New Issue
Block a user