- add session validation_errors bootstrap initialization - render global flash + validation messages in header - remove footer alert-based flash handling - persist structured validation errors across save handlers - mark NEXT_STEPS package 1 tasks as done
51 lines
1.2 KiB
PHP
51 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);
|
|
$_SESSION['validation_errors'] = $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;
|