diff --git a/NEXT_STEPS.md b/NEXT_STEPS.md index 3e82073..efbd2e8 100644 --- a/NEXT_STEPS.md +++ b/NEXT_STEPS.md @@ -9,15 +9,15 @@ - [x] Validierungsfehler anzeigen ### Package 2: Delete-Funktionen (1h) -- [ ] DELETE-Endpoints für alle Module -- [ ] AJAX-Bestätigung vor Löschen -- [ ] Kaskadierendes Löschen prüfen (z.B. Floor → Racks) +- [x] DELETE-Endpoints für alle Module +- [x] AJAX-Bestätigung vor Löschen +- [x] Kaskadierendes Löschen prüfen (z.B. Floor → Racks) ### Package 3: Port-Management (2-3h) -- [ ] Ports zu Device-Types verwalten -- [ ] Ports zu Devices anzeigen -- [ ] Port-Status (aktiv/inaktiv) -- [ ] VLAN-Zuordnung zu Ports +- [x] Ports zu Device-Types verwalten +- [x] Ports zu Devices anzeigen +- [x] Port-Status (aktiv/inaktiv) +- [x] VLAN-Zuordnung zu Ports ### Package 4: SVG-Editor für Floorplans (4-5h) - [ ] Interaktiver SVG-Editor für Rooms diff --git a/app/modules/connections/delete.php b/app/modules/connections/delete.php index fb0797a..a4d25c8 100644 --- a/app/modules/connections/delete.php +++ b/app/modules/connections/delete.php @@ -2,12 +2,19 @@ /** * app/modules/connections/delete.php * - * Loescht eine Verbindung und leitet zur Liste zurueck. + * Loescht eine Verbindung (AJAX-POST bevorzugt, GET-Fallback fuer Redirects). */ -$connectionId = (int)($_GET['id'] ?? $_POST['id'] ?? 0); +$isPost = ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST'; +$connectionId = (int)($_POST['id'] ?? $_GET['id'] ?? 0); if ($connectionId <= 0) { + if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(400); + echo json_encode(['success' => false, 'message' => 'Ungueltige Verbindungs-ID']); + exit; + } $_SESSION['error'] = 'Ungueltige Verbindungs-ID'; header('Location: ?module=connections&action=list'); exit; @@ -20,6 +27,12 @@ $connection = $sql->single( ); if (!$connection) { + if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(404); + echo json_encode(['success' => false, 'message' => 'Verbindung nicht gefunden']); + exit; + } $_SESSION['error'] = 'Verbindung nicht gefunden'; header('Location: ?module=connections&action=list'); exit; @@ -31,6 +44,17 @@ $rows = $sql->set( [$connectionId] ); +if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + if ($rows > 0) { + echo json_encode(['success' => true, 'message' => 'Verbindung geloescht']); + } else { + http_response_code(500); + echo json_encode(['success' => false, 'message' => 'Verbindung konnte nicht geloescht werden']); + } + exit; +} + if ($rows > 0) { $_SESSION['success'] = 'Verbindung geloescht'; } else { diff --git a/app/modules/connections/list.php b/app/modules/connections/list.php index 9cb4ff3..abde9c5 100644 --- a/app/modules/connections/list.php +++ b/app/modules/connections/list.php @@ -335,11 +335,12 @@ $buildListUrl = static function (array $extra = []) use ($search, $deviceId): st Details Bearbeiten Von/Nach tauschen - + + @@ -382,7 +383,12 @@ $buildListUrl = static function (array $extra = []) use ($search, $deviceId): st
Keine Verbindung ausgewaehlt.
@@ -474,3 +480,35 @@ $buildListUrl = static function (array $extra = []) use ($search, $deviceId): st } } + + diff --git a/app/modules/devices/delete.php b/app/modules/devices/delete.php index 12992be..a4e66da 100644 --- a/app/modules/devices/delete.php +++ b/app/modules/devices/delete.php @@ -3,12 +3,20 @@ * app/modules/devices/delete.php * * Loescht ein Geraet. Bei Abhaengigkeiten ist force=1 erforderlich. + * Unterstuetzt GET-Redirects und AJAX-POST. */ -$deviceId = (int)($_GET['id'] ?? 0); -$forceDelete = (int)($_GET['force'] ?? 0) === 1; +$isPost = ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST'; +$deviceId = (int)($_POST['id'] ?? $_GET['id'] ?? 0); +$forceDelete = (int)($_POST['force'] ?? $_GET['force'] ?? 0) === 1; if ($deviceId <= 0) { + if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(400); + echo json_encode(['success' => false, 'message' => 'Ungueltige Geraete-ID']); + exit; + } $_SESSION['error'] = "Ungueltige Geraete-ID"; header('Location: ?module=devices&action=list'); exit; @@ -21,6 +29,12 @@ $device = $sql->single( ); if (!$device) { + if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(404); + echo json_encode(['success' => false, 'message' => 'Geraet nicht gefunden']); + exit; + } $_SESSION['error'] = "Geraet nicht gefunden"; header('Location: ?module=devices&action=list'); exit; @@ -70,7 +84,23 @@ if ($hasDependencies && !$forceDelete) { $parts[] = $moduleCount . ' Port-Module'; } - $_SESSION['error'] = "Geraet hat abhaengige Daten (" . implode(', ', $parts) . "). Loeschen bitte bestaetigen."; + $dependencyMessage = "Geraet hat abhaengige Daten (" . implode(', ', $parts) . "). Loeschen bitte bestaetigen."; + if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(409); + echo json_encode([ + 'success' => false, + 'requires_force' => true, + 'message' => $dependencyMessage, + 'dependencies' => [ + 'connections' => $connectionCount, + 'ports' => $portCount, + 'modules' => $moduleCount + ] + ]); + exit; + } + $_SESSION['error'] = $dependencyMessage; header('Location: ?module=devices&action=edit&id=' . urlencode((string)$deviceId)); exit; } @@ -91,8 +121,19 @@ $deleted = $sql->set( ); if ($deleted > 0) { + if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['success' => true, 'message' => "Geraet geloescht: " . $device['name']]); + exit; + } $_SESSION['success'] = "Geraet geloescht: " . $device['name']; } else { + if ($isPost) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(500); + echo json_encode(['success' => false, 'message' => 'Geraet konnte nicht geloescht werden']); + exit; + } $_SESSION['error'] = "Geraet konnte nicht geloescht werden"; } diff --git a/app/modules/devices/edit.php b/app/modules/devices/edit.php index 192e4a1..72d87cf 100644 --- a/app/modules/devices/edit.php +++ b/app/modules/devices/edit.php @@ -64,6 +64,19 @@ if ($isEdit) { // ========================= $deviceTypes = $sql->get("SELECT id, name, category FROM device_types ORDER BY name", "", []); $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []); +$devicePorts = []; + +if ($isEdit) { + $devicePorts = $sql->get( + "SELECT dp.id, dp.name, dp.status, dp.mode, dp.vlan_config, pt.name AS port_type_name + FROM device_ports dp + LEFT JOIN port_types pt ON pt.id = dp.port_type_id + WHERE dp.device_id = ? + ORDER BY dp.id", + "i", + [$deviceId] + ); +} ?> @@ -160,6 +173,67 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []); + + @@ -264,34 +338,64 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []); .button:hover { opacity: 0.8; } + +.device-port-table { + width: 100%; + border-collapse: collapse; + margin-top: 10px; +} + +.device-port-table th, +.device-port-table td { + border-bottom: 1px solid #ddd; + padding: 8px; + text-align: left; +} + +.device-port-table input, +.device-port-table select { + width: 100%; + min-width: 120px; +} diff --git a/app/modules/devices/list.php b/app/modules/devices/list.php index 39ebcdf..c41a448 100644 --- a/app/modules/devices/list.php +++ b/app/modules/devices/list.php @@ -1,7 +1,7 @@ 0) { - $where[] = "d.device_type_id = ?"; - $types .= "i"; + $where[] = 'd.device_type_id = ?'; + $types .= 'i'; $params[] = $typeId; } if ($floorId > 0) { - $where[] = "f.id = ?"; - $types .= "i"; + $where[] = 'f.id = ?'; + $types .= 'i'; $params[] = $floorId; } if ($rackId > 0) { - $where[] = "d.rack_id = ?"; - $types .= "i"; + $where[] = 'd.rack_id = ?'; + $types .= 'i'; $params[] = $rackId; } $whereSql = $where ? 'WHERE ' . implode(' AND ', $where) : ''; // ========================= -// Geräte laden +// Geraete laden // ========================= - $devices = $sql->get( - " - SELECT - d.id, - d.name, - d.serial_number, - d.rack_position_he, - d.rack_height_he, - d.web_config_url, - dt.name AS device_type, - dt.image_path, - f.name AS floor_name, - r.name AS rack_name, - ( - SELECT COUNT(*) - FROM device_ports dp - WHERE dp.device_id = d.id - ) AS port_count, - ( - SELECT COUNT(*) - FROM device_port_modules dpm - JOIN device_ports dp2 ON dp2.id = dpm.device_port_id - WHERE dp2.device_id = d.id - ) AS module_count, - ( - SELECT COUNT(*) - FROM connections c - WHERE (c.port_a_type = 'device' AND c.port_a_id IN ( - SELECT dp3.id FROM device_ports dp3 WHERE dp3.device_id = d.id - )) - OR (c.port_b_type = 'device' AND c.port_b_id IN ( - SELECT dp4.id FROM device_ports dp4 WHERE dp4.device_id = d.id - )) - ) AS connection_count +$devices = $sql->get( + " + SELECT + d.id, + d.name, + d.serial_number, + d.rack_position_he, + d.rack_height_he, + d.web_config_url, + dt.name AS device_type, + dt.image_path, + f.name AS floor_name, + r.name AS rack_name, + ( + SELECT COUNT(*) + FROM device_ports dp + WHERE dp.device_id = d.id + ) AS port_count, + ( + SELECT COUNT(*) + FROM device_ports dp + WHERE dp.device_id = d.id + AND dp.status = 'active' + ) AS active_port_count, + ( + SELECT COUNT(*) + FROM device_ports dp + WHERE dp.device_id = d.id + AND dp.status = 'disabled' + ) AS disabled_port_count, + ( + SELECT COUNT(*) + FROM device_ports dp + WHERE dp.device_id = d.id + AND dp.vlan_config IS NOT NULL + AND dp.vlan_config <> '[]' + ) AS vlan_port_count, + ( + SELECT COUNT(*) + FROM device_port_modules dpm + JOIN device_ports dp2 ON dp2.id = dpm.device_port_id + WHERE dp2.device_id = d.id + ) AS module_count, + ( + SELECT COUNT(*) + FROM connections c + WHERE (c.port_a_type = 'device' AND c.port_a_id IN ( + SELECT dp3.id FROM device_ports dp3 WHERE dp3.device_id = d.id + )) + OR (c.port_b_type = 'device' AND c.port_b_id IN ( + SELECT dp4.id FROM device_ports dp4 WHERE dp4.device_id = d.id + )) + ) AS connection_count FROM devices d JOIN device_types dt ON dt.id = d.device_type_id LEFT JOIN racks r ON r.id = d.rack_id @@ -99,22 +118,19 @@ $whereSql = $where ? 'WHERE ' . implode(' AND ', $where) : ''; // ========================= // Filter-Daten laden // ========================= -$deviceTypes = $sql->get("SELECT id, name FROM device_types ORDER BY name", "", []); -$floors = $sql->get("SELECT id, name FROM floors ORDER BY name", "", []); -$racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []); +$deviceTypes = $sql->get('SELECT id, name FROM device_types ORDER BY name', '', []); +$floors = $sql->get('SELECT id, name FROM floors ORDER BY name', '', []); +$racks = $sql->get('SELECT id, name FROM racks ORDER BY name', '', []); ?>Gefundene Geräte:
+Gefundene Geraete:
| Stockwerk | Rack | Position (HE) | +Ports | Seriennummer | Webconfig | Aktionen | @@ -186,28 +200,37 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);- + | - + |
-
+
+ gesamt + aktiv / + inaktiv + VLAN gesetzt: + + |
+
+ + | @@ -216,13 +239,13 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []); Webconfig - — + - | Bearbeiten - Löschen + Loeschen | @@ -231,10 +254,10 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []); @@ -351,33 +374,41 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []); - - - diff --git a/app/modules/devices/save.php b/app/modules/devices/save.php index 18ccd6f..004eb7b 100644 --- a/app/modules/devices/save.php +++ b/app/modules/devices/save.php @@ -25,6 +25,7 @@ $rackHeightHe = (int)($_POST['rack_height_he'] ?? 1); $serialNumber = trim($_POST['serial_number'] ?? ''); $comment = trim($_POST['comment'] ?? ''); $webConfigUrl = trim($_POST['web_config_url'] ?? ''); +$devicePortRows = is_array($_POST['device_ports'] ?? null) ? $_POST['device_ports'] : []; if ($webConfigUrl === '') { $webConfigUrl = null; } @@ -88,6 +89,9 @@ if ($isNewDevice) { if ($isNewDevice && $deviceId > 0) { copyDevicePortsFromType($sql, $deviceId, $deviceTypeId); } +if ($deviceId > 0 && !$isNewDevice && !empty($devicePortRows)) { + syncDevicePorts($sql, $deviceId, $devicePortRows); +} $_SESSION['success'] = "Gerät gespeichert"; @@ -139,3 +143,105 @@ function copyDevicePortsFromType($sql, $deviceId, $deviceTypeId) } } } + +function syncDevicePorts($sql, $deviceId, array $rows) +{ + $ports = $sql->get( + "SELECT id, name FROM device_ports WHERE device_id = ?", + "i", + [$deviceId] + ); + if (empty($ports)) { + return; + } + + $allowedIds = []; + $currentNames = []; + foreach ($ports as $port) { + $portId = (int)($port['id'] ?? 0); + if ($portId <= 0) { + continue; + } + $allowedIds[$portId] = true; + $currentNames[$portId] = (string)($port['name'] ?? ''); + } + + foreach ($rows as $portIdRaw => $row) { + $portId = (int)$portIdRaw; + if ($portId <= 0 || !isset($allowedIds[$portId]) || !is_array($row)) { + continue; + } + + $name = trim((string)($row['name'] ?? '')); + if ($name === '') { + $name = $currentNames[$portId] ?? ('Port ' . $portId); + } + + $status = trim((string)($row['status'] ?? 'active')); + if (!in_array($status, ['active', 'disabled'], true)) { + $status = 'active'; + } + + $mode = trim((string)($row['mode'] ?? '')); + $mode = $mode !== '' ? $mode : null; + $vlanJson = normalizeVlanConfig($row['vlan_config'] ?? ''); + + if ($mode !== null && $vlanJson !== null) { + $sql->set( + "UPDATE device_ports + SET name = ?, status = ?, mode = ?, vlan_config = ? + WHERE id = ? AND device_id = ?", + "ssssii", + [$name, $status, $mode, $vlanJson, $portId, $deviceId] + ); + } elseif ($mode !== null) { + $sql->set( + "UPDATE device_ports + SET name = ?, status = ?, mode = ?, vlan_config = NULL + WHERE id = ? AND device_id = ?", + "sssii", + [$name, $status, $mode, $portId, $deviceId] + ); + } elseif ($vlanJson !== null) { + $sql->set( + "UPDATE device_ports + SET name = ?, status = ?, mode = NULL, vlan_config = ? + WHERE id = ? AND device_id = ?", + "sssii", + [$name, $status, $vlanJson, $portId, $deviceId] + ); + } else { + $sql->set( + "UPDATE device_ports + SET name = ?, status = ?, mode = NULL, vlan_config = NULL + WHERE id = ? AND device_id = ?", + "ssii", + [$name, $status, $portId, $deviceId] + ); + } + } +} + +function normalizeVlanConfig($raw) +{ + $value = trim((string)$raw); + if ($value === '') { + return null; + } + + $parts = preg_split('/[\s,;]+/', $value); + $normalized = []; + foreach ((array)$parts as $part) { + $entry = trim((string)$part); + if ($entry === '') { + continue; + } + $normalized[$entry] = true; + } + + if (empty($normalized)) { + return null; + } + + return json_encode(array_keys($normalized), JSON_UNESCAPED_UNICODE); +} diff --git a/app/modules/floor_infrastructure/delete.php b/app/modules/floor_infrastructure/delete.php index 8b2ce33..14ff363 100644 --- a/app/modules/floor_infrastructure/delete.php +++ b/app/modules/floor_infrastructure/delete.php @@ -2,30 +2,48 @@ /** * app/modules/floor_infrastructure/delete.php * - * Loescht Patchpanels oder Wandbuchsen. + * Loescht Patchpanels oder Wandbuchsen (AJAX-POST bevorzugt). */ -$type = strtolower(trim((string)($_GET['type'] ?? ''))); -$id = (int)($_GET['id'] ?? 0); +$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') { - $sql->set( + $rows = $sql->set( "DELETE FROM floor_patchpanels WHERE id = ?", "i", [$id] ); } else { - $sql->set( + $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; diff --git a/app/modules/floor_infrastructure/list.php b/app/modules/floor_infrastructure/list.php index aff72f7..8bd782a 100644 --- a/app/modules/floor_infrastructure/list.php +++ b/app/modules/floor_infrastructure/list.php @@ -180,7 +180,14 @@ if ($editorFloor) {Bearbeiten - Loeschen + | @@ -226,7 +233,14 @@ if ($editorFloor) {Bearbeiten - Loeschen + | @@ -237,3 +251,38 @@ if ($editorFloor) { + + diff --git a/app/modules/floors/delete.php b/app/modules/floors/delete.php index 2bb7917..95d8766 100644 --- a/app/modules/floors/delete.php +++ b/app/modules/floors/delete.php @@ -25,6 +25,47 @@ if (!$exists) { exit; } +$forceDelete = (int)($_POST['force'] ?? $_GET['force'] ?? 0) === 1; +$dependencyCounts = $sql->single( + "SELECT + (SELECT COUNT(*) FROM rooms WHERE floor_id = ?) AS room_count, + (SELECT COUNT(*) FROM racks WHERE floor_id = ?) AS rack_count, + (SELECT COUNT(*) FROM floor_patchpanels WHERE floor_id = ?) AS patchpanel_count", + "iii", + [$id, $id, $id] +); + +$roomCount = (int)($dependencyCounts['room_count'] ?? 0); +$rackCount = (int)($dependencyCounts['rack_count'] ?? 0); +$patchpanelCount = (int)($dependencyCounts['patchpanel_count'] ?? 0); +$hasDependencies = $roomCount > 0 || $rackCount > 0 || $patchpanelCount > 0; + +if ($hasDependencies && !$forceDelete) { + $parts = []; + if ($roomCount > 0) { + $parts[] = $roomCount . ' Raeume'; + } + if ($rackCount > 0) { + $parts[] = $rackCount . ' Racks'; + } + if ($patchpanelCount > 0) { + $parts[] = $patchpanelCount . ' Patchpanels'; + } + + http_response_code(409); + echo json_encode([ + 'success' => false, + 'requires_force' => true, + 'message' => 'Beim Loeschen werden abhaengige Daten entfernt (' . implode(', ', $parts) . '). Fortfahren?', + 'dependencies' => [ + 'rooms' => $roomCount, + 'racks' => $rackCount, + 'patchpanels' => $patchpanelCount + ] + ]); + exit; +} + $rows = $sql->set("DELETE FROM floors WHERE id = ?", "i", [$id]); if ($rows === false) { http_response_code(500); @@ -32,5 +73,13 @@ if ($rows === false) { exit; } -echo json_encode(['success' => true, 'message' => 'Stockwerk geloescht']); +echo json_encode([ + 'success' => true, + 'message' => 'Stockwerk geloescht', + 'dependencies' => [ + 'rooms' => $roomCount, + 'racks' => $rackCount, + 'patchpanels' => $patchpanelCount + ] +]); diff --git a/app/modules/floors/list.php b/app/modules/floors/list.php index 15a5cdb..b01ed4c 100644 --- a/app/modules/floors/list.php +++ b/app/modules/floors/list.php @@ -233,11 +233,20 @@ $buildings = $sql->get("SELECT id, name FROM buildings ORDER BY name", "", []); diff --git a/app/modules/locations/delete.php b/app/modules/locations/delete.php index 813b39f..aca59ee 100644 --- a/app/modules/locations/delete.php +++ b/app/modules/locations/delete.php @@ -7,6 +7,16 @@ header('Content-Type: application/json; charset=utf-8'); +$method = $_SERVER['REQUEST_METHOD'] ?? 'GET'; +if ($method !== 'POST') { + http_response_code(405); + echo json_encode([ + 'success' => false, + 'message' => 'Methode nicht erlaubt' + ]); + exit; +} + $locationId = (int)($_POST['id'] ?? $_GET['id'] ?? 0); if ($locationId <= 0) { diff --git a/app/modules/port_types/delete.php b/app/modules/port_types/delete.php new file mode 100644 index 0000000..1d83e99 --- /dev/null +++ b/app/modules/port_types/delete.php @@ -0,0 +1,84 @@ + false, 'message' => 'Methode nicht erlaubt']); + exit; +} + +$portTypeId = (int)($_POST['id'] ?? 0); +if ($portTypeId <= 0) { + http_response_code(400); + echo json_encode(['success' => false, 'message' => 'Ungueltige Porttyp-ID']); + exit; +} + +$portType = $sql->single( + "SELECT id, name FROM port_types WHERE id = ?", + "i", + [$portTypeId] +); + +if (!$portType) { + http_response_code(404); + echo json_encode(['success' => false, 'message' => 'Porttyp nicht gefunden']); + exit; +} + +$usage = $sql->single( + "SELECT + (SELECT COUNT(*) FROM device_type_ports WHERE port_type_id = ?) AS device_type_ports_count, + (SELECT COUNT(*) FROM device_ports WHERE port_type_id = ?) AS device_ports_count, + (SELECT COUNT(*) FROM module_ports WHERE port_type_id = ?) AS module_ports_count, + (SELECT COUNT(*) FROM network_outlet_ports WHERE port_type_id = ?) AS outlet_ports_count, + (SELECT COUNT(*) FROM floor_patchpanel_ports WHERE port_type_id = ?) AS patchpanel_ports_count", + "iiiii", + [$portTypeId, $portTypeId, $portTypeId, $portTypeId, $portTypeId] +); + +$references = [ + 'Geraetetyp-Ports' => (int)($usage['device_type_ports_count'] ?? 0), + 'Geraete-Ports' => (int)($usage['device_ports_count'] ?? 0), + 'Modul-Ports' => (int)($usage['module_ports_count'] ?? 0), + 'Netzwerkdosen-Ports' => (int)($usage['outlet_ports_count'] ?? 0), + 'Patchpanel-Ports' => (int)($usage['patchpanel_ports_count'] ?? 0), +]; + +$inUse = array_filter($references, static fn ($count) => $count > 0); +if (!empty($inUse)) { + $parts = []; + foreach ($inUse as $label => $count) { + $parts[] = $label . ': ' . $count; + } + http_response_code(409); + echo json_encode([ + 'success' => false, + 'message' => 'Porttyp wird noch verwendet (' . implode(', ', $parts) . ')' + ]); + exit; +} + +$deleted = $sql->set( + "DELETE FROM port_types WHERE id = ?", + "i", + [$portTypeId] +); + +if ($deleted <= 0) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => 'Porttyp konnte nicht geloescht werden']); + exit; +} + +echo json_encode([ + 'success' => true, + 'message' => 'Porttyp geloescht: ' . (string)$portType['name'] +]); +exit; diff --git a/app/modules/port_types/list.php b/app/modules/port_types/list.php index e462d00..d753636 100644 --- a/app/modules/port_types/list.php +++ b/app/modules/port_types/list.php @@ -69,6 +69,13 @@ $portTypes = $sql->get(Bearbeiten + | @@ -171,3 +178,36 @@ $portTypes = $sql->get( white-space: nowrap; } + +
|---|