drag drop update
This commit is contained in:
@@ -19,6 +19,7 @@ $name = trim($_POST['name'] ?? '');
|
||||
$buildingId = (int)($_POST['building_id'] ?? 0);
|
||||
$level = isset($_POST['level']) ? (int)$_POST['level'] : null;
|
||||
$comment = trim($_POST['comment'] ?? '');
|
||||
$floorSvgContent = trim($_POST['floor_svg_content'] ?? '');
|
||||
|
||||
// =========================
|
||||
// Validierung
|
||||
@@ -79,6 +80,17 @@ if (!empty($_FILES['svg_file']['name'])) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($floorSvgContent !== '') {
|
||||
$storedSvgPath = storeSvgEditorContent($sql, $floorId, $floorSvgContent);
|
||||
if ($storedSvgPath === false) {
|
||||
$_SESSION['error'] = "SVG aus dem Editor konnte nicht gespeichert werden";
|
||||
$redirectUrl = $floorId ? "?module=floors&action=edit&id=$floorId" : "?module=floors&action=edit";
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
}
|
||||
$svgPath = $storedSvgPath;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// In DB speichern
|
||||
// =========================
|
||||
@@ -113,3 +125,41 @@ $_SESSION['success'] = "Stockwerk gespeichert";
|
||||
// =========================
|
||||
header('Location: ?module=floors&action=list');
|
||||
exit;
|
||||
|
||||
function storeSvgEditorContent($sql, $floorId, $content)
|
||||
{
|
||||
$normalized = trim($content);
|
||||
if ($normalized === '' || stripos($normalized, '<svg') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$relativePath = null;
|
||||
if ($floorId > 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user