'device', 'device_ports' => 'device', 'module' => 'module', 'module_ports' => 'module', 'outlet' => 'outlet', 'network_outlet_ports' => 'outlet', 'patchpanel' => 'patchpanel', 'floor_patchpanel' => 'patchpanel', 'floor_patchpanel_ports' => 'patchpanel', ]; $key = strtolower(trim($value)); return $map[$key] ?? $key; }; $portAType = $normalizePortType((string)$portAType); $portBType = $normalizePortType((string)$portBType); // ========================= // Validierung (einfach) // ========================= $errors = []; if ($portAId <= 0 || $portBId <= 0) { $errors[] = "Beide Ports sind erforderlich"; } if (!empty($errors)) { $_SESSION['error'] = implode(', ', $errors); $redirectUrl = $connId ? "?module=connections&action=edit&id=$connId" : "?module=connections&action=list"; header("Location: $redirectUrl"); exit; } // ========================= // In DB speichern // ========================= $vlanJson = $vlanConfig ? json_encode(explode(',', $vlanConfig)) : null; if ($connId > 0) { // UPDATE $sql->set( "UPDATE connections SET port_a_type = ?, port_a_id = ?, port_b_type = ?, port_b_id = ?, vlan_config = ?, comment = ? WHERE id = ?", "siisisi", [$portAType, $portAId, $portBType, $portBId, $vlanJson, $comment, $connId] ); } else { // INSERT $sql->set( "INSERT INTO connections (port_a_type, port_a_id, port_b_type, port_b_id, vlan_config, comment) VALUES (?, ?, ?, ?, ?, ?)", "siisis", [$portAType, $portAId, $portBType, $portBId, $vlanJson, $comment] ); } $_SESSION['success'] = "Verbindung gespeichert"; // ========================= // Redirect // ========================= header('Location: ?module=connections&action=list'); exit;