#13 räume definieren

This commit is contained in:
2026-02-16 10:59:29 +01:00
parent f80ab4aaa9
commit 2a1732323d
9 changed files with 1007 additions and 178 deletions

View File

@@ -1,25 +1,19 @@
<?php
<?php
/**
* app/modules/locations/list.php
*
* Übersicht aller Standorte
* Uebersicht aller Standorte inkl. Gebaeude, Stockwerke und Raeume.
*/
// =========================
// Filter einlesen
// =========================
$search = trim($_GET['search'] ?? '');
$search = trim((string)($_GET['search'] ?? ''));
// =========================
// Standorte laden
// =========================
$where = '';
$types = '';
$params = [];
if ($search !== '') {
$where = "WHERE name LIKE ? OR comment LIKE ?";
$types = "ss";
$where = "WHERE l.name LIKE ? OR l.comment LIKE ?";
$types = 'ss';
$params = ["%$search%", "%$search%"];
}
@@ -38,42 +32,57 @@ $buildings = $sql->get(
"SELECT b.id, b.location_id, b.name, b.comment
FROM buildings b
ORDER BY b.location_id, b.name",
"",
'',
[]
);
$floors = $sql->get(
"SELECT f.id, f.building_id, f.name, f.level,
COUNT(r.id) AS room_count
FROM floors f
LEFT JOIN rooms r ON r.floor_id = f.id
GROUP BY f.id
ORDER BY f.building_id, f.level, f.name",
'',
[]
);
$rooms = $sql->get(
"SELECT r.id, r.floor_id, r.name, r.number, r.comment,
COUNT(no.id) AS outlet_count
FROM rooms r
LEFT JOIN network_outlets no ON no.room_id = r.id
GROUP BY r.id
ORDER BY r.floor_id, r.name",
'',
[]
);
$buildingsByLocation = [];
foreach ($buildings as $building) {
$buildingsByLocation[$building['location_id']][] = $building;
$buildingsByLocation[(int)$building['location_id']][] = $building;
}
$floors = $sql->get(
"SELECT f.id, f.building_id, f.name, f.level
FROM floors f
ORDER BY f.building_id, f.level",
"",
[]
);
$floorsByBuilding = [];
foreach ($floors as $floor) {
$floorsByBuilding[$floor['building_id']][] = $floor;
$floorsByBuilding[(int)$floor['building_id']][] = $floor;
}
$roomsByFloor = [];
foreach ($rooms as $room) {
$roomsByFloor[(int)$room['floor_id']][] = $room;
}
?>
<div class="locations-container">
<h1>Standorte</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="locations">
<input type="hidden" name="action" value="list">
<input type="text" name="search" placeholder="Suche nach Name…"
<input type="text" name="search" placeholder="Suche nach Name..."
value="<?php echo htmlspecialchars($search); ?>" class="search-input">
<button type="submit" class="button">Filter</button>
@@ -82,15 +91,12 @@ foreach ($floors as $floor) {
</form>
</div>
<!-- =========================
Standorte-Tabelle
========================= -->
<?php if (!empty($locations)): ?>
<table class="locations-list">
<thead>
<tr>
<th>Name</th>
<th>Gebäude</th>
<th>Gebaeude</th>
<th>Beschreibung</th>
<th>Aktionen</th>
</tr>
@@ -98,125 +104,147 @@ foreach ($floors as $floor) {
<tbody>
<?php foreach ($locations as $location): ?>
<tr>
<td>
<strong><?php echo htmlspecialchars($location['name']); ?></strong>
</td>
<td>
<?php echo $location['building_count']; ?>
</td>
<td>
<small><?php echo htmlspecialchars($location['comment'] ?? ''); ?></small>
</td>
<td><strong><?php echo htmlspecialchars((string)$location['name']); ?></strong></td>
<td><?php echo (int)$location['building_count']; ?></td>
<td><small><?php echo htmlspecialchars((string)($location['comment'] ?? '')); ?></small></td>
<td class="actions">
<a href="?module=locations&action=edit&id=<?php echo $location['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger" onclick="confirmDelete(<?php echo $location['id']; ?>)">Löschen</a>
<a href="?module=locations&action=edit&id=<?php echo (int)$location['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger" onclick="confirmLocationDelete(<?php echo (int)$location['id']; ?>)">Loeschen</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div class="empty-state">
<p>Keine Standorte gefunden.</p>
<p>
<a href="?module=locations&action=edit" class="button button-primary">
Ersten Standort anlegen
</a>
</p>
<p><a href="?module=locations&action=edit" class="button button-primary">Ersten Standort anlegen</a></p>
</div>
<?php endif; ?>
</div>
<section class="hierarchy-section">
<h2>Gebäude &amp; Stockwerke nach Standorten</h2>
<h2>Gebaeude, Stockwerke und Raeume</h2>
<?php if (!empty($locations)): ?>
<table class="hierarchy-table">
<thead>
<tr>
<th>Standort</th>
<th>Gebäude</th>
<th>Stockwerk</th>
<th>Details</th>
<th class="actions">Aktionen</th>
<table class="hierarchy-table">
<thead>
<tr>
<th>Standort</th>
<th>Gebaeude</th>
<th>Stockwerk / Raum</th>
<th>Details</th>
<th class="actions">Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($locations as $location): ?>
<?php $locationBuildings = $buildingsByLocation[(int)$location['id']] ?? []; ?>
<tr class="hierarchy-row hierarchy-row--location">
<td class="hierarchy-cell hierarchy-cell--location" colspan="3">
<strong><?php echo htmlspecialchars((string)$location['name']); ?></strong>
<span class="hierarchy-meta">(<?php echo (int)$location['building_count']; ?> Gebaeude)</span>
</td>
<td></td>
<td class="actions hierarchy-actions">
<a href="?module=buildings&action=edit&location_id=<?php echo (int)$location['id']; ?>" class="button button-small">+ Gebaeude</a>
</td>
</tr>
</thead>
<tbody>
<?php foreach ($locations as $location): ?>
<?php $locationBuildings = $buildingsByLocation[$location['id']] ?? []; ?>
<tr class="hierarchy-row hierarchy-row--location">
<td class="hierarchy-cell hierarchy-cell--location" colspan="3">
<strong><?php echo htmlspecialchars($location['name']); ?></strong>
<span class="hierarchy-meta">(<?php echo (int) $location['building_count']; ?> Gebäude)</span>
</td>
<td></td>
<td class="actions hierarchy-actions">
<a href="?module=buildings&action=edit&location_id=<?php echo $location['id']; ?>" class="button button-small">+ Gebäude</a>
</td>
</tr>
<?php if (!empty($locationBuildings)): ?>
<?php foreach ($locationBuildings as $building): ?>
<?php $buildingFloors = $floorsByBuilding[$building['id']] ?? []; ?>
<tr class="hierarchy-row hierarchy-row--building">
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--building" colspan="2"><?php echo htmlspecialchars($building['name']); ?></td>
<td>
<?php if (!empty($building['comment'])): ?>
<span class="hierarchy-meta"><?php echo htmlspecialchars($building['comment']); ?></span>
<?php else: ?>
<span class="hierarchy-meta hierarchy-meta--muted">Kein Kommentar</span>
<?php endif; ?>
</td>
<td class="actions hierarchy-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="confirmBuildingDelete(<?php echo $building['id']; ?>)">Löschen</a>
<a href="?module=floors&action=edit&building_id=<?php echo $building['id']; ?>" class="button button-small">+ Stockwerk</a>
</td>
</tr>
<?php if (!empty($buildingFloors)): ?>
<?php foreach ($buildingFloors as $floor): ?>
<tr class="hierarchy-row hierarchy-row--floor">
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--floor"><?php echo htmlspecialchars($floor['name']); ?></td>
<td>
<?php if ($floor['level'] !== null): ?>
<span class="hierarchy-meta">Ebene <?php echo htmlspecialchars($floor['level']); ?></span>
<?php else: ?>
<span class="hierarchy-meta hierarchy-meta--muted">Keine Ebene</span>
<?php endif; ?>
</td>
<td class="actions hierarchy-actions">
<a href="?module=floors&action=edit&id=<?php echo $floor['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger" onclick="confirmFloorDelete(<?php echo $floor['id']; ?>)">Löschen</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<tr class="hierarchy-row hierarchy-row--empty">
<?php if (!empty($locationBuildings)): ?>
<?php foreach ($locationBuildings as $building): ?>
<?php $buildingFloors = $floorsByBuilding[(int)$building['id']] ?? []; ?>
<tr class="hierarchy-row hierarchy-row--building">
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">Keine Gebäude</td>
<td><span class="hierarchy-meta hierarchy-meta--muted">Für diesen Standort sind noch keine Gebäude vorhanden.</span></td>
<td></td>
<td class="hierarchy-cell hierarchy-cell--building" colspan="2"><?php echo htmlspecialchars((string)$building['name']); ?></td>
<td>
<?php if (!empty($building['comment'])): ?>
<span class="hierarchy-meta"><?php echo htmlspecialchars((string)$building['comment']); ?></span>
<?php else: ?>
<span class="hierarchy-meta hierarchy-meta--muted">Kein Kommentar</span>
<?php endif; ?>
</td>
<td class="actions hierarchy-actions">
<a href="?module=buildings&action=edit&id=<?php echo (int)$building['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger" onclick="confirmBuildingDelete(<?php echo (int)$building['id']; ?>)">Loeschen</a>
<a href="?module=floors&action=edit&building_id=<?php echo (int)$building['id']; ?>" class="button button-small">+ Stockwerk</a>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php if (!empty($buildingFloors)): ?>
<?php foreach ($buildingFloors as $floor): ?>
<?php $floorRooms = $roomsByFloor[(int)$floor['id']] ?? []; ?>
<tr class="hierarchy-row hierarchy-row--floor">
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--floor"><?php echo htmlspecialchars((string)$floor['name']); ?></td>
<td>
<?php if ($floor['level'] !== null): ?>
<span class="hierarchy-meta">Ebene <?php echo htmlspecialchars((string)$floor['level']); ?></span>
<?php else: ?>
<span class="hierarchy-meta hierarchy-meta--muted">Keine Ebene</span>
<?php endif; ?>
<span class="hierarchy-meta"> | <?php echo (int)$floor['room_count']; ?> Raeume</span>
</td>
<td class="actions hierarchy-actions">
<a href="?module=floors&action=edit&id=<?php echo (int)$floor['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger" onclick="confirmFloorDelete(<?php echo (int)$floor['id']; ?>)">Loeschen</a>
<a href="?module=rooms&action=edit&floor_id=<?php echo (int)$floor['id']; ?>" class="button button-small">+ Raum</a>
</td>
</tr>
<?php if (!empty($floorRooms)): ?>
<?php foreach ($floorRooms as $room): ?>
<tr class="hierarchy-row hierarchy-row--room">
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--room">
<?php echo htmlspecialchars((string)$room['name']); ?>
<?php if (!empty($room['number'])): ?>
<span class="hierarchy-meta">(<?php echo htmlspecialchars((string)$room['number']); ?>)</span>
<?php endif; ?>
</td>
<td>
<span class="hierarchy-meta"><?php echo (int)$room['outlet_count']; ?> Dosen</span>
<?php if (!empty($room['comment'])): ?>
<span class="hierarchy-meta"> | <?php echo htmlspecialchars((string)$room['comment']); ?></span>
<?php endif; ?>
</td>
<td class="actions hierarchy-actions">
<a href="?module=rooms&action=edit&id=<?php echo (int)$room['id']; ?>" class="button button-small">Bearbeiten</a>
<a href="#" class="button button-small button-danger" onclick="confirmRoomDelete(<?php echo (int)$room['id']; ?>)">Loeschen</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr class="hierarchy-row hierarchy-row--empty">
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--room hierarchy-meta hierarchy-meta--muted">Keine Raeume</td>
<td><span class="hierarchy-meta hierarchy-meta--muted">Fuer dieses Stockwerk sind noch keine Raeume angelegt.</span></td>
<td></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<tr class="hierarchy-row hierarchy-row--empty">
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">&nbsp;</td>
<td class="hierarchy-cell hierarchy-cell--empty">Keine Gebaeude</td>
<td><span class="hierarchy-meta hierarchy-meta--muted">Fuer diesen Standort sind noch keine Gebaeude vorhanden.</span></td>
<td></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>Keine Standorte gefunden.</p>
<?php endif; ?>
</section>
<?php
//TODO style in css file
?>
<style>
.locations-container {
padding: 20px;
@@ -224,23 +252,6 @@ foreach ($floors as $floor) {
margin: 0 auto;
}
.filter-form {
margin: 20px 0;
}
.filter-form form {
display: flex;
gap: 10px;
flex-wrap: wrap;
align-items: center;
}
.filter-form input {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
}
.search-input {
flex: 1;
min-width: 250px;
@@ -277,7 +288,7 @@ foreach ($floors as $floor) {
display: inline-block;
padding: 8px 12px;
background: #007bff;
color: white;
color: #fff;
text-decoration: none;
border-radius: 4px;
border: none;
@@ -320,7 +331,7 @@ foreach ($floors as $floor) {
.hierarchy-section {
padding: 20px;
max-width: 1000px;
max-width: 1200px;
margin: 30px auto;
border-top: 1px solid #ddd;
}
@@ -379,7 +390,12 @@ foreach ($floors as $floor) {
.hierarchy-cell--floor {
padding-left: 24px;
min-width: 160px;
min-width: 190px;
}
.hierarchy-cell--room {
padding-left: 32px;
min-width: 190px;
}
.hierarchy-cell--empty {
@@ -389,12 +405,13 @@ foreach ($floors as $floor) {
.hierarchy-meta {
color: #4e5c6b;
font-size: 0.9rem;
font-size: 0.88rem;
}
.hierarchy-meta--muted {
color: #8a94a3;
}
.hierarchy-actions {
display: flex;
gap: 6px;
@@ -405,47 +422,55 @@ foreach ($floors as $floor) {
padding: 4px 10px;
font-size: 0.8rem;
}
.hierarchy-actions .button-danger {
background: #dc3545;
}
</style>
<script>
function confirmDelete(id) {
if (confirm('Diesen Standort wirklich löschen?')) {
fetch('?module=locations&action=delete&id=' + encodeURIComponent(id), {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
if (data && data.success) {
window.location.reload();
return;
}
alert((data && data.message) ? data.message : 'Löschen fehlgeschlagen');
})
.catch(() => {
alert('Löschen fehlgeschlagen');
});
function postDelete(url) {
return fetch(url, {
method: 'POST',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
}).then((response) => response.json());
}
function confirmLocationDelete(id) {
if (!confirm('Diesen Standort wirklich loeschen?')) {
return;
}
postDelete('?module=locations&action=delete&id=' + encodeURIComponent(id))
.then((data) => {
if (data && data.success) {
window.location.reload();
return;
}
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
})
.catch(() => alert('Loeschen fehlgeschlagen'));
}
function confirmBuildingDelete(id) {
if (confirm('Dieses Gebäude wirklich löschen? Alle Stockwerke werden gelöscht.')) {
alert('Löschen noch nicht implementiert');
if (confirm('Dieses Gebaeude wirklich loeschen? Alle Stockwerke werden geloescht.')) {
alert('Loeschen noch nicht implementiert');
}
}
function confirmFloorDelete(id) {
if (confirm('Dieses Stockwerk wirklich löschen? Alle Räume und Racks werden gelöscht.')) {
alert('Löschen noch nicht implementiert');
if (confirm('Dieses Stockwerk wirklich loeschen? Alle Raeume und Racks werden geloescht.')) {
alert('Loeschen noch nicht implementiert');
}
}
function confirmRoomDelete(id) {
if (!confirm('Diesen Raum wirklich loeschen? Zugeordnete Dosen werden mitgeloescht.')) {
return;
}
postDelete('?module=rooms&action=delete&id=' + encodeURIComponent(id))
.then((data) => {
if (data && data.success) {
window.location.reload();
return;
}
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
})
.catch(() => alert('Loeschen fehlgeschlagen'));
}
</script>