feat: Implement floors, locations, and racks management

- Added list, edit, and save functionalities for floors, locations, and racks.
- Enhanced UI with search and filter options for better usability.
- Implemented SVG upload for floor plans in the floors module.
- Added validation for required fields in the save processes.
- Improved navigation in the header to reflect new modules.
- Styled forms and tables for a consistent look and feel across modules.
This commit is contained in:
2026-02-11 14:34:07 +01:00
parent 2f341bff9f
commit 0d3c6e1ae7
26 changed files with 3753 additions and 1045 deletions

115
app/modules/floors/save.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
/**
* app/modules/floors/save.php
*
* Speichert / aktualisiert ein Stockwerk
*/
// Nur POST
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: ?module=floors&action=list');
exit;
}
// =========================
// Daten einlesen
// =========================
$floorId = (int)($_POST['id'] ?? 0);
$name = trim($_POST['name'] ?? '');
$buildingId = (int)($_POST['building_id'] ?? 0);
$level = isset($_POST['level']) ? (int)$_POST['level'] : null;
$comment = trim($_POST['comment'] ?? '');
// =========================
// Validierung
// =========================
$errors = [];
if (empty($name)) {
$errors[] = "Name ist erforderlich";
}
if ($buildingId <= 0) {
$errors[] = "Gebäude ist erforderlich";
}
// Falls Fehler: zurück zum Edit-Formular
if (!empty($errors)) {
$_SESSION['error'] = implode(', ', $errors);
$redirectUrl = $floorId ? "?module=floors&action=edit&id=$floorId" : "?module=floors&action=edit";
header("Location: $redirectUrl");
exit;
}
// =========================
// SVG-Upload verarbeiten (optional)
// =========================
$svgPath = null;
if (!empty($_FILES['svg_file']['name'])) {
$file = $_FILES['svg_file'];
$tmpName = $file['tmp_name'];
$originalName = basename($file['name']);
$fileExt = strtolower(pathinfo($originalName, PATHINFO_EXTENSION));
// Nur SVG erlaubt
if ($fileExt !== 'svg') {
$_SESSION['error'] = "Nur SVG-Dateien sind erlaubt";
$redirectUrl = $floorId ? "?module=floors&action=edit&id=$floorId" : "?module=floors&action=edit";
header("Location: $redirectUrl");
exit;
}
// Zielverzeichnis
$uploadDir = __DIR__ . '/../../uploads/floorplans/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
// Eindeutiger Dateiname
$newFileName = uniqid('floor_') . '.svg';
$destPath = $uploadDir . $newFileName;
if (move_uploaded_file($tmpName, $destPath)) {
$svgPath = 'uploads/floorplans/' . $newFileName;
} else {
$_SESSION['error'] = "Datei-Upload fehlgeschlagen";
$redirectUrl = $floorId ? "?module=floors&action=edit&id=$floorId" : "?module=floors&action=edit";
header("Location: $redirectUrl");
exit;
}
}
// =========================
// In DB speichern
// =========================
if ($floorId > 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;