- 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
138 lines
4.5 KiB
PHP
138 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* app/modules/floor_infrastructure/save.php
|
|
*
|
|
* Speichert Patchpanel- und Wandbuchsen-Einträge
|
|
*/
|
|
|
|
$type = $_POST['type'] ?? '';
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
|
|
if ($type === 'patchpanel') {
|
|
$fixedPanelWidth = 20;
|
|
$fixedPanelHeight = 5;
|
|
|
|
$name = trim($_POST['name'] ?? '');
|
|
$floorId = (int)($_POST['floor_id'] ?? 0);
|
|
$posX = (int)($_POST['pos_x'] ?? 0);
|
|
$posY = (int)($_POST['pos_y'] ?? 0);
|
|
$width = $fixedPanelWidth;
|
|
$height = $fixedPanelHeight;
|
|
$portCount = (int)($_POST['port_count'] ?? 0);
|
|
$comment = trim($_POST['comment'] ?? '');
|
|
$errors = [];
|
|
|
|
if ($name === '') {
|
|
$errors[] = 'Name ist erforderlich';
|
|
}
|
|
if ($floorId <= 0) {
|
|
$errors[] = 'Stockwerk ist erforderlich';
|
|
}
|
|
if ($portCount < 0) {
|
|
$errors[] = 'Port-Anzahl darf nicht negativ sein';
|
|
}
|
|
if (!empty($errors)) {
|
|
$_SESSION['error'] = implode(', ', $errors);
|
|
$_SESSION['validation_errors'] = $errors;
|
|
$redirectUrl = $id > 0 ? "?module=floor_infrastructure&action=edit&type=patchpanel&id=$id" : "?module=floor_infrastructure&action=edit&type=patchpanel";
|
|
header("Location: $redirectUrl");
|
|
exit;
|
|
}
|
|
|
|
$panelId = $id;
|
|
|
|
if ($id > 0) {
|
|
$sql->set(
|
|
"UPDATE floor_patchpanels SET name = ?, floor_id = ?, pos_x = ?, pos_y = ?, width = ?, height = ?, port_count = ?, comment = ? WHERE id = ?",
|
|
"siiiiisii",
|
|
[$name, $floorId, $posX, $posY, $width, $height, $portCount, $comment, $id]
|
|
);
|
|
} else {
|
|
$panelId = (int)$sql->set(
|
|
"INSERT INTO floor_patchpanels (name, floor_id, pos_x, pos_y, width, height, port_count, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
|
"siiiiiss",
|
|
[$name, $floorId, $posX, $posY, $width, $height, $portCount, $comment],
|
|
true
|
|
);
|
|
}
|
|
|
|
if ($panelId > 0 && $portCount > 0) {
|
|
$existingCount = (int)($sql->single(
|
|
"SELECT COUNT(*) AS cnt FROM floor_patchpanel_ports WHERE patchpanel_id = ?",
|
|
"i",
|
|
[$panelId]
|
|
)['cnt'] ?? 0);
|
|
|
|
if ($existingCount < $portCount) {
|
|
for ($i = $existingCount + 1; $i <= $portCount; $i++) {
|
|
$sql->set(
|
|
"INSERT INTO floor_patchpanel_ports (patchpanel_id, name) VALUES (?, ?)",
|
|
"is",
|
|
[$panelId, 'Port ' . $i]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
$_SESSION['success'] = $id > 0 ? 'Patchpanel gespeichert' : 'Patchpanel erstellt';
|
|
} elseif ($type === 'outlet') {
|
|
$name = trim($_POST['name'] ?? '');
|
|
$roomId = (int)($_POST['room_id'] ?? 0);
|
|
$x = (int)($_POST['x'] ?? 0);
|
|
$y = (int)($_POST['y'] ?? 0);
|
|
$comment = trim($_POST['comment'] ?? '');
|
|
$outletId = $id;
|
|
$errors = [];
|
|
|
|
if ($name === '') {
|
|
$errors[] = 'Name ist erforderlich';
|
|
}
|
|
if ($roomId <= 0) {
|
|
$errors[] = 'Raum ist erforderlich';
|
|
}
|
|
if (!empty($errors)) {
|
|
$_SESSION['error'] = implode(', ', $errors);
|
|
$_SESSION['validation_errors'] = $errors;
|
|
$redirectUrl = $id > 0 ? "?module=floor_infrastructure&action=edit&type=outlet&id=$id" : "?module=floor_infrastructure&action=edit&type=outlet";
|
|
header("Location: $redirectUrl");
|
|
exit;
|
|
}
|
|
|
|
if ($id > 0) {
|
|
$sql->set(
|
|
"UPDATE network_outlets SET name = ?, room_id = ?, x = ?, y = ?, comment = ? WHERE id = ?",
|
|
"siiisi",
|
|
[$name, $roomId, $x, $y, $comment, $id]
|
|
);
|
|
} else {
|
|
$outletId = (int)$sql->set(
|
|
"INSERT INTO network_outlets (name, room_id, x, y, comment) VALUES (?, ?, ?, ?, ?)",
|
|
"siiis",
|
|
[$name, $roomId, $x, $y, $comment],
|
|
true
|
|
);
|
|
}
|
|
|
|
if ($outletId > 0) {
|
|
$existingPortCount = (int)($sql->single(
|
|
"SELECT COUNT(*) AS cnt FROM network_outlet_ports WHERE outlet_id = ?",
|
|
"i",
|
|
[$outletId]
|
|
)['cnt'] ?? 0);
|
|
|
|
if ($existingPortCount === 0) {
|
|
$sql->set(
|
|
"INSERT INTO network_outlet_ports (outlet_id, name) VALUES (?, 'Port 1')",
|
|
"i",
|
|
[$outletId]
|
|
);
|
|
}
|
|
}
|
|
$_SESSION['success'] = $id > 0 ? 'Wandbuchse gespeichert' : 'Wandbuchse erstellt';
|
|
} else {
|
|
$_SESSION['error'] = 'Ungueltiger Infrastrukturobjekt-Typ';
|
|
$_SESSION['validation_errors'] = ['Ungueltiger Infrastrukturobjekt-Typ'];
|
|
}
|
|
|
|
header('Location: ?module=floor_infrastructure&action=list');
|
|
exit;
|