Files
netwatch/app/modules/racks/save.php
fixclean 0d3c6e1ae7 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.
2026-02-11 14:34:07 +01:00

74 lines
1.7 KiB
PHP

<?php
/**
* app/modules/racks/save.php
*
* Speichert / aktualisiert ein Rack
*/
// Nur POST
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: ?module=racks&action=list');
exit;
}
// =========================
// Daten einlesen
// =========================
$rackId = (int)($_POST['id'] ?? 0);
$name = trim($_POST['name'] ?? '');
$floorId = (int)($_POST['floor_id'] ?? 0);
$heightHe = (int)($_POST['height_he'] ?? 42);
$comment = trim($_POST['comment'] ?? '');
// =========================
// Validierung
// =========================
$errors = [];
if (empty($name)) {
$errors[] = "Name ist erforderlich";
}
if ($floorId <= 0) {
$errors[] = "Stockwerk ist erforderlich";
}
if ($heightHe < 1) {
$errors[] = "Höhe muss mindestens 1 HE sein";
}
// Falls Fehler: zurück zum Edit-Formular
if (!empty($errors)) {
$_SESSION['error'] = implode(', ', $errors);
$redirectUrl = $rackId ? "?module=racks&action=edit&id=$rackId" : "?module=racks&action=edit";
header("Location: $redirectUrl");
exit;
}
// =========================
// In DB speichern
// =========================
if ($rackId > 0) {
// UPDATE
$sql->set(
"UPDATE racks SET name = ?, floor_id = ?, height_he = ?, comment = ? WHERE id = ?",
"siisi",
[$name, $floorId, $heightHe, $comment, $rackId]
);
} else {
// INSERT
$sql->set(
"INSERT INTO racks (name, floor_id, height_he, comment) VALUES (?, ?, ?, ?)",
"sii s",
[$name, $floorId, $heightHe, $comment]
);
}
$_SESSION['success'] = "Rack gespeichert";
// =========================
// Redirect
// =========================
header('Location: ?module=racks&action=list');
exit;