- 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.
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* modules/devices/save.php
|
|
*
|
|
* Speichert / aktualisiert ein Gerät
|
|
* - Basisdaten
|
|
* - Rack-Zuordnung
|
|
*/
|
|
|
|
// Nur POST
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: ?module=devices&action=list');
|
|
exit;
|
|
}
|
|
|
|
// =========================
|
|
// Daten einlesen
|
|
// =========================
|
|
$deviceId = (int)($_POST['id'] ?? 0);
|
|
$name = trim($_POST['name'] ?? '');
|
|
$deviceTypeId = (int)($_POST['device_type_id'] ?? 0);
|
|
$rackId = (int)($_POST['rack_id'] ?? 0);
|
|
$rackPositionHe = (int)($_POST['rack_position_he'] ?? 0);
|
|
$rackHeightHe = (int)($_POST['rack_height_he'] ?? 1);
|
|
$serialNumber = trim($_POST['serial_number'] ?? '');
|
|
$comment = trim($_POST['comment'] ?? '');
|
|
|
|
// =========================
|
|
// Validierung
|
|
// =========================
|
|
$errors = [];
|
|
|
|
if (empty($name)) {
|
|
$errors[] = "Name ist erforderlich";
|
|
}
|
|
|
|
if ($deviceTypeId <= 0) {
|
|
$errors[] = "Gerätetyp ist erforderlich";
|
|
}
|
|
|
|
if ($rackId <= 0) {
|
|
$errors[] = "Rack ist erforderlich";
|
|
}
|
|
|
|
if ($rackPositionHe <= 0) {
|
|
$errors[] = "Rack-Position muss >= 1 sein";
|
|
}
|
|
|
|
if ($rackHeightHe < 1) {
|
|
$errors[] = "Höhe muss >= 1 sein";
|
|
}
|
|
|
|
// Falls Fehler: zurück zum Edit-Formular
|
|
if (!empty($errors)) {
|
|
$_SESSION['error'] = implode(', ', $errors);
|
|
$redirectUrl = $deviceId ? "?module=devices&action=edit&id=$deviceId" : "?module=devices&action=edit";
|
|
header("Location: $redirectUrl");
|
|
exit;
|
|
}
|
|
|
|
// =========================
|
|
// In DB speichern
|
|
// =========================
|
|
if ($deviceId > 0) {
|
|
// UPDATE
|
|
$sql->set(
|
|
"UPDATE devices SET name = ?, device_type_id = ?, rack_id = ?, rack_position_he = ?, rack_height_he = ?, serial_number = ?, comment = ? WHERE id = ?",
|
|
"siiiissi",
|
|
[$name, $deviceTypeId, $rackId, $rackPositionHe, $rackHeightHe, $serialNumber, $comment, $deviceId]
|
|
);
|
|
} else {
|
|
// INSERT
|
|
$sql->set(
|
|
"INSERT INTO devices (name, device_type_id, rack_id, rack_position_he, rack_height_he, serial_number, comment) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
|
"siiiiss",
|
|
[$name, $deviceTypeId, $rackId, $rackPositionHe, $rackHeightHe, $serialNumber, $comment]
|
|
);
|
|
$deviceId = $sql->h->insert_id;
|
|
}
|
|
|
|
$_SESSION['success'] = "Gerät gespeichert";
|
|
|
|
// =========================
|
|
// Redirect
|
|
// =========================
|
|
header('Location: ?module=devices&action=list');
|
|
exit;
|