51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?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;
|