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, r.x, r.y, r.width, r.height, r.polygon_points, 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' => 20, 'height' => 5]; $defaultOutletSize = 10; $showPanelPlacementFields = $type === 'patchpanel' && $selectedFloorId > 0; if ($type === 'patchpanel') { $panel['width'] = $defaultPanelSize['width']; $panel['height'] = $defaultPanelSize['height']; $panel['pos_x'] = $panel['pos_x'] ?? 30; $panel['pos_y'] = $panel['pos_y'] ?? 30; } else { $outlet['x'] = $outlet['x'] ?? 30; $outlet['y'] = $outlet['y'] ?? 30; } $markerWidth = $type === 'patchpanel' ? $panel['width'] : $defaultOutletSize; $markerHeight = $type === 'patchpanel' ? $panel['height'] : $defaultOutletSize; $mapPatchPanels = $sql->get( "SELECT id, floor_id, name, pos_x, pos_y, width, height FROM floor_patchpanels ORDER BY floor_id, name", "", [] ); $mapOutlets = $sql->get( "SELECT o.id, r.floor_id, o.name, o.x, o.y FROM network_outlets o JOIN rooms r ON r.id = o.room_id ORDER BY r.floor_id, o.name", "", [] ); $patchpanelPortOptions = $sql->get( "SELECT fpp.id, fpp.name, fp.name AS patchpanel_name, fp.floor_id, f.name AS floor_name, EXISTS( SELECT 1 FROM connections c WHERE ((c.port_a_type = 'patchpanel' OR c.port_a_type = 'floor_patchpanel_ports') AND c.port_a_id = fpp.id) OR ((c.port_b_type = 'patchpanel' OR c.port_b_type = 'floor_patchpanel_ports') AND c.port_b_id = fpp.id) ) AS is_occupied FROM floor_patchpanel_ports fpp JOIN floor_patchpanels fp ON fp.id = fpp.patchpanel_id LEFT JOIN floors f ON f.id = fp.floor_id ORDER BY f.name, fp.name, fpp.name", "", [] ); $selectedBindPatchpanelPortId = 0; if ($type === 'outlet' && $id > 0) { $selectedBindPatchpanelPortId = (int)($sql->single( "SELECT CASE WHEN (c.port_a_type = 'patchpanel' OR c.port_a_type = 'floor_patchpanel_ports') THEN c.port_a_id WHEN (c.port_b_type = 'patchpanel' OR c.port_b_type = 'floor_patchpanel_ports') THEN c.port_b_id ELSE 0 END AS patchpanel_port_id FROM connections c JOIN network_outlet_ports nop ON ( ((c.port_a_type = 'outlet' OR c.port_a_type = 'network_outlet_ports') AND c.port_a_id = nop.id) OR ((c.port_b_type = 'outlet' OR c.port_b_type = 'network_outlet_ports') AND c.port_b_id = nop.id) ) WHERE nop.outlet_id = ? AND ( c.port_a_type = 'patchpanel' OR c.port_a_type = 'floor_patchpanel_ports' OR c.port_b_type = 'patchpanel' OR c.port_b_type = 'floor_patchpanel_ports' ) ORDER BY c.id LIMIT 1", "i", [$id] )['patchpanel_port_id'] ?? 0); } ?>