get("SELECT id, name FROM locations ORDER BY name", "", []); $buildings = $sql->get("SELECT id, name, location_id FROM buildings ORDER BY name", "", []); $floors = $sql->get( "SELECT f.*, b.name AS building_name, b.location_id, l.name AS location_name FROM floors f LEFT JOIN buildings b ON b.id = f.building_id LEFT JOIN locations l ON l.id = b.location_id ORDER BY l.name, b.name, f.level, f.name", "", [] ); $rooms = $sql->get( "SELECT r.id, r.name, r.floor_id, f.name AS floor_name, f.svg_path, b.id AS building_id, l.id AS location_id FROM rooms r LEFT JOIN floors f ON f.id = r.floor_id LEFT JOIN buildings b ON b.id = f.building_id LEFT JOIN locations l ON l.id = b.location_id ORDER BY l.name, b.name, f.level, f.name, r.name", "", [] ); $locationMap = []; foreach ($locations as $location) { $locationMap[$location['id']] = $location['name']; } foreach ($floors as &$floor) { $paths = trim((string)($floor['svg_path'] ?? '')); $floor['svg_url'] = $paths !== '' ? '/' . ltrim($paths, '/\\') : ''; } unset($floor); foreach ($rooms as &$room) { $roomPath = trim((string)($room['svg_path'] ?? '')); $room['floor_svg_url'] = $roomPath !== '' ? '/' . ltrim($roomPath, '/\\') : ''; } unset($room); $floorIndex = []; foreach ($floors as $floor) { $floorIndex[$floor['id']] = $floor; } $panel = null; $outlet = null; $pageTitle = $type === 'outlet' ? 'Wandbuchse bearbeiten' : 'Patchpanel bearbeiten'; if ($type === 'patchpanel' && $id > 0) { $panel = $sql->single( "SELECT * FROM floor_patchpanels WHERE id = ?", "i", [$id] ); if ($panel) { $pageTitle = "Patchpanel bearbeiten: " . htmlspecialchars($panel['name']); } } if ($type === 'outlet' && $id > 0) { $outlet = $sql->single( "SELECT * FROM network_outlets WHERE id = ?", "i", [$id] ); if ($outlet) { $pageTitle = "Wandbuchse bearbeiten: " . htmlspecialchars($outlet['name']); } } $panel = $panel ?? []; $outlet = $outlet ?? []; $selectedLocationId = 0; $selectedBuildingId = 0; $selectedFloorId = 0; if ($type === 'patchpanel') { $selectedFloorId = (int)($panel['floor_id'] ?? 0); if ($selectedFloorId && isset($floorIndex[$selectedFloorId])) { $selectedBuildingId = (int)($floorIndex[$selectedFloorId]['building_id'] ?? 0); $selectedLocationId = (int)($floorIndex[$selectedFloorId]['location_id'] ?? 0); } } $defaultPanelSize = ['width' => 140, 'height' => 40]; $defaultOutletSize = 32; $showPanelPlacementFields = $type === 'patchpanel' && $selectedFloorId > 0; if ($type === 'patchpanel') { $panel['width'] = $panel['width'] ?? $defaultPanelSize['width']; $panel['height'] = $panel['height'] ?? $defaultPanelSize['height']; } $markerWidth = $type === 'patchpanel' ? $panel['width'] : $defaultOutletSize; $markerHeight = $type === 'patchpanel' ? $panel['height'] : $defaultOutletSize; ?>