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.
This commit is contained in:
2026-02-11 14:34:07 +01:00
parent 2f341bff9f
commit 0d3c6e1ae7
26 changed files with 3753 additions and 1045 deletions

View File

@@ -0,0 +1,178 @@
<?php
/**
* app/modules/buildings/edit.php
*/
// =========================
// Kontext bestimmen
// =========================
$buildingId = (int)($_GET['id'] ?? 0);
$building = null;
if ($buildingId > 0) {
$building = $sql->single(
"SELECT * FROM buildings WHERE id = ?",
"i",
[$buildingId]
);
}
$isEdit = !empty($building);
$pageTitle = $isEdit ? "Gebäude bearbeiten: " . htmlspecialchars($building['name']) : "Neues Gebäude";
// =========================
// Standorte laden
// =========================
$locations = $sql->get("SELECT id, name FROM locations ORDER BY name", "", []);
?>
<div class="building-edit">
<h1><?php echo $pageTitle; ?></h1>
<form method="post" action="?module=buildings&action=save" class="edit-form">
<?php if ($isEdit): ?>
<input type="hidden" name="id" value="<?php echo $buildingId; ?>">
<?php endif; ?>
<!-- =========================
Basisdaten
========================= -->
<fieldset>
<legend>Allgemein</legend>
<div class="form-group">
<label for="name">Name <span class="required">*</span></label>
<input type="text" id="name" name="name" required
value="<?php echo htmlspecialchars($building['name'] ?? ''); ?>"
placeholder="z.B. Gebäude A, Verwaltungsgebäude">
</div>
<div class="form-group">
<label for="location_id">Standort <span class="required">*</span></label>
<select id="location_id" name="location_id" required>
<option value="">- Wählen -</option>
<?php foreach ($locations as $location): ?>
<option value="<?php echo $location['id']; ?>"
<?php echo ($building['location_id'] ?? 0) == $location['id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($location['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="comment">Beschreibung</label>
<textarea id="comment" name="comment" rows="3"
placeholder="Adresse, Besonderheiten, etc."><?php echo htmlspecialchars($building['comment'] ?? ''); ?></textarea>
</div>
</fieldset>
<!-- =========================
Aktionen
========================= -->
<fieldset class="form-actions">
<button type="submit" class="button button-primary">Speichern</button>
<a href="?module=buildings&action=list" class="button">Abbrechen</a>
<?php if ($isEdit): ?>
<a href="#" class="button button-danger" onclick="confirmDelete(<?php echo $buildingId; ?>)">Löschen</a>
<?php endif; ?>
</fieldset>
</form>
</div>
<style>
.building-edit {
max-width: 800px;
margin: 20px auto;
padding: 20px;
}
.edit-form {
background: white;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
}
.edit-form fieldset {
margin: 20px 0;
padding: 15px;
border: 1px solid #e0e0e0;
border-radius: 4px;
}
.edit-form legend {
padding: 0 10px;
font-weight: bold;
font-size: 1.1em;
}
.form-group {
margin: 15px 0;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input[type="text"],
.form-group select,
.form-group textarea {
width: 100%;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-family: inherit;
}
.form-group textarea {
resize: vertical;
}
.required {
color: red;
}
.form-actions {
display: flex;
gap: 10px;
margin-top: 30px;
}
.button {
padding: 10px 15px;
background: #007bff;
color: white;
text-decoration: none;
border-radius: 4px;
border: none;
cursor: pointer;
font-size: 0.95em;
}
.button-primary {
background: #28a745;
}
.button-danger {
background: #dc3545;
}
.button:hover {
opacity: 0.8;
}
</style>
<script>
function confirmDelete(id) {
if (confirm('Dieses Gebäude wirklich löschen? Alle Stockwerke werden gelöscht.')) {
// TODO: AJAX-Delete implementieren
alert('Löschen noch nicht implementiert');
}
}
</script>

View File

@@ -0,0 +1,249 @@
<?php
/**
* app/modules/buildings/list.php
*
* Übersicht aller Gebäude
*/
// =========================
// Filter einlesen
// =========================
$search = trim($_GET['search'] ?? '');
$locationId = (int)($_GET['location_id'] ?? 0);
// =========================
// WHERE-Clause bauen
// =========================
$where = [];
$types = '';
$params = [];
if ($search !== '') {
$where[] = "b.name LIKE ? OR b.comment LIKE ?";
$types .= "ss";
$params[] = "%$search%";
$params[] = "%$search%";
}
if ($locationId > 0) {
$where[] = "b.location_id = ?";
$types .= "i";
$params[] = $locationId;
}
$whereSql = $where ? "WHERE " . implode(" AND ", $where) : "";
$buildings = $sql->get(
"SELECT b.*, l.name AS location_name, COUNT(f.id) AS floor_count
FROM buildings b
LEFT JOIN locations l ON b.location_id = l.id
LEFT JOIN floors f ON f.building_id = b.id
$whereSql
GROUP BY b.id
ORDER BY l.name, b.name",
$types,
$params
);
// =========================
// Filter-Daten
// =========================
$locations = $sql->get("SELECT id, name FROM locations ORDER BY name", "", []);
?>
<div class="buildings-container">
<h1>Gebäude</h1>
<!-- =========================
Toolbar
========================= -->
<div class="filter-form">
<form method="GET" style="display: flex; gap: 10px; flex-wrap: wrap; align-items: center;">
<input type="hidden" name="module" value="buildings">
<input type="hidden" name="action" value="list">
<input type="text" name="search" placeholder="Suche nach Name…"
value="<?php echo htmlspecialchars($search); ?>" class="search-input">
<select name="location_id">
<option value="">- Alle Standorte -</option>
<?php foreach ($locations as $loc): ?>
<option value="<?php echo $loc['id']; ?>"
<?php echo $loc['id'] === $locationId ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($loc['name']); ?>
</option>
<?php endforeach; ?>
</select>
<button type="submit" class="button">Filter</button>
<a href="?module=buildings&action=list" class="button">Reset</a>
<a href="?module=buildings&action=edit" class="button button-primary" style="margin-left: auto;">+ Neues Gebäude</a>
</form>
</div>
<!-- =========================
Gebäude-Tabelle
========================= -->
<?php if (!empty($buildings)): ?>
<table class="buildings-list">
<thead>
<tr>
<th>Name</th>
<th>Standort</th>
<th>Stockwerke</th>
<th>Beschreibung</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($buildings as $building): ?>
<tr>
<td>
<strong><?php echo htmlspecialchars($building['name']); ?></strong>
</td>
<td>
<?php echo htmlspecialchars($building['location_name'] ?? '—'); ?>
</td>
<td>
<?php echo $building['floor_count']; ?>
</td>
<td>
<small><?php echo htmlspecialchars($building['comment'] ?? ''); ?></small>
</td>
<td class="actions">
<a href="?module=buildings&action=edit&id=<?php echo $building['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger" onclick="confirmDelete(<?php echo $building['id']; ?>)">Löschen</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div class="empty-state">
<p>Keine Gebäude gefunden.</p>
<p>
<a href="?module=buildings&action=edit" class="button button-primary">
Erstes Gebäude anlegen
</a>
</p>
</div>
<?php endif; ?>
</div>
<style>
.buildings-container {
padding: 20px;
max-width: 1000px;
margin: 0 auto;
}
.filter-form {
margin: 20px 0;
}
.filter-form form {
display: flex;
gap: 10px;
flex-wrap: wrap;
align-items: center;
}
.filter-form input,
.filter-form select {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
}
.search-input {
flex: 1;
min-width: 250px;
}
.buildings-list {
width: 100%;
border-collapse: collapse;
margin: 15px 0;
}
.buildings-list th {
background: #f5f5f5;
padding: 12px;
text-align: left;
border-bottom: 2px solid #ddd;
font-weight: bold;
}
.buildings-list td {
padding: 12px;
border-bottom: 1px solid #ddd;
}
.buildings-list tr:hover {
background: #f9f9f9;
}
.actions {
white-space: nowrap;
}
.button {
display: inline-block;
padding: 8px 12px;
background: #007bff;
color: white;
text-decoration: none;
border-radius: 4px;
border: none;
cursor: pointer;
font-size: 0.9em;
}
.button:hover {
background: #0056b3;
}
.button-primary {
background: #28a745;
}
.button-primary:hover {
background: #218838;
}
.button-small {
padding: 4px 8px;
font-size: 0.85em;
}
.button-danger {
background: #dc3545;
}
.button-danger:hover {
background: #c82333;
}
.empty-state {
text-align: center;
padding: 40px 20px;
background: #f9f9f9;
border: 1px solid #eee;
border-radius: 8px;
}
</style>
<script>
function confirmDelete(id) {
if (confirm('Dieses Gebäude wirklich löschen?')) {
// TODO: AJAX-Delete implementieren
alert('Löschen noch nicht implementiert');
}
}
</script>

View File

@@ -0,0 +1,49 @@
<?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;