0) { // UPDATE if ($svgPath) { $sql->set( "UPDATE floors SET name = ?, building_id = ?, level = ?, comment = ?, svg_path = ? WHERE id = ?", "siissi", [$name, $buildingId, $level, $comment, $svgPath, $floorId] ); } else { $sql->set( "UPDATE floors SET name = ?, building_id = ?, level = ?, comment = ? WHERE id = ?", "siiss", [$name, $buildingId, $level, $comment, $floorId] ); } } else { // INSERT $sql->set( "INSERT INTO floors (name, building_id, level, comment, svg_path) VALUES (?, ?, ?, ?, ?)", "siiss", [$name, $buildingId, $level, $comment, $svgPath] ); } $_SESSION['success'] = "Stockwerk gespeichert"; // ========================= // Redirect // ========================= header('Location: ?module=floors&action=list'); exit; function storeSvgEditorContent($sql, $floorId, $content) { $normalized = trim($content); if ($normalized === '' || stripos($normalized, ' 0) { $existing = $sql->single( "SELECT svg_path FROM floors WHERE id = ?", "i", [$floorId] ); $candidate = trim((string)($existing['svg_path'] ?? '')); if ($candidate !== '') { $relativePath = ltrim($candidate, "/\\"); } } if (!$relativePath) { $relativePath = 'uploads/floorplans/' . uniqid('floor_') . '.svg'; } $absolutePath = __DIR__ . '/../../' . $relativePath; $targetDir = dirname($absolutePath); if (!is_dir($targetDir)) { mkdir($targetDir, 0755, true); } $written = file_put_contents($absolutePath, $normalized); if ($written === false) { return false; } return $relativePath; }