Files
netwatch/app/modules/buildings/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

50 lines
1.2 KiB
PHP

<?php
/**
* app/modules/buildings/save.php
*/
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: ?module=buildings&action=list');
exit;
}
$buildingId = (int)($_POST['id'] ?? 0);
$name = trim($_POST['name'] ?? '');
$locationId = (int)($_POST['location_id'] ?? 0);
$comment = trim($_POST['comment'] ?? '');
$errors = [];
if (empty($name)) {
$errors[] = "Name ist erforderlich";
}
if ($locationId <= 0) {
$errors[] = "Standort ist erforderlich";
}
if (!empty($errors)) {
$_SESSION['error'] = implode(', ', $errors);
$redirectUrl = $buildingId ? "?module=buildings&action=edit&id=$buildingId" : "?module=buildings&action=edit";
header("Location: $redirectUrl");
exit;
}
if ($buildingId > 0) {
$sql->set(
"UPDATE buildings SET name = ?, location_id = ?, comment = ? WHERE id = ?",
"sisi",
[$name, $locationId, $comment, $buildingId]
);
} else {
$sql->set(
"INSERT INTO buildings (name, location_id, comment) VALUES (?, ?, ?)",
"sis",
[$name, $locationId, $comment]
);
}
$_SESSION['success'] = "Gebäude gespeichert";
header('Location: ?module=buildings&action=list');
exit;