Files
netwatch/app/modules/locations/list.php
2026-02-13 13:09:12 +01:00

452 lines
13 KiB
PHP

<?php
/**
* app/modules/locations/list.php
*
* Übersicht aller Standorte
*/
// =========================
// Filter einlesen
// =========================
$search = trim($_GET['search'] ?? '');
// =========================
// Standorte laden
// =========================
$where = '';
$types = '';
$params = [];
if ($search !== '') {
$where = "WHERE name LIKE ? OR comment LIKE ?";
$types = "ss";
$params = ["%$search%", "%$search%"];
}
$locations = $sql->get(
"SELECT l.*, COUNT(b.id) AS building_count
FROM locations l
LEFT JOIN buildings b ON b.location_id = l.id
$where
GROUP BY l.id
ORDER BY l.name",
$types,
$params
);
$buildings = $sql->get(
"SELECT b.id, b.location_id, b.name, b.comment
FROM buildings b
ORDER BY b.location_id, b.name",
"",
[]
);
$buildingsByLocation = [];
foreach ($buildings as $building) {
$buildingsByLocation[$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;
}
?>
<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…"
value="<?php echo htmlspecialchars($search); ?>" class="search-input">
<button type="submit" class="button">Filter</button>
<a href="?module=locations&action=list" class="button">Reset</a>
<a href="?module=locations&action=edit" class="button button-primary" style="margin-left: auto;">+ Neuer Standort</a>
</form>
</div>
<!-- =========================
Standorte-Tabelle
========================= -->
<?php if (!empty($locations)): ?>
<table class="locations-list">
<thead>
<tr>
<th>Name</th>
<th>Gebäude</th>
<th>Beschreibung</th>
<th>Aktionen</th>
</tr>
</thead>
<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 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>
</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>
</div>
<?php endif; ?>
</div>
<section class="hierarchy-section">
<h2>Gebäude &amp; Stockwerke nach Standorten</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>
</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">
<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>
</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;
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 {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
}
.search-input {
flex: 1;
min-width: 250px;
}
.locations-list {
width: 100%;
border-collapse: collapse;
margin: 15px 0;
}
.locations-list th {
background: #f5f5f5;
padding: 12px;
text-align: left;
border-bottom: 2px solid #ddd;
font-weight: bold;
}
.locations-list td {
padding: 12px;
border-bottom: 1px solid #ddd;
}
.locations-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;
}
.hierarchy-section {
padding: 20px;
max-width: 1000px;
margin: 30px auto;
border-top: 1px solid #ddd;
}
.hierarchy-section h2 {
margin-bottom: 15px;
font-size: 1.3rem;
}
.hierarchy-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
border: 1px solid #d8dee5;
border-radius: 10px;
overflow: hidden;
}
.hierarchy-table th {
background: #f3f6fa;
padding: 10px 12px;
text-align: left;
font-size: 0.9rem;
font-weight: 600;
border-bottom: 1px solid #d8dee5;
}
.hierarchy-table td {
padding: 9px 12px;
border-bottom: 1px solid #eef2f6;
vertical-align: top;
}
.hierarchy-row:last-child td {
border-bottom: none;
}
.hierarchy-row--empty {
background: #fcfcfc;
}
.hierarchy-cell {
white-space: nowrap;
}
.hierarchy-cell--location {
background: #fbfcfe;
font-weight: 600;
min-width: 170px;
}
.hierarchy-cell--building {
padding-left: 18px;
min-width: 180px;
}
.hierarchy-cell--floor {
padding-left: 24px;
min-width: 160px;
}
.hierarchy-cell--empty {
background: #fafbfd;
width: 20px;
}
.hierarchy-meta {
color: #4e5c6b;
font-size: 0.9rem;
}
.hierarchy-meta--muted {
color: #8a94a3;
}
.hierarchy-actions {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.hierarchy-actions .button {
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 confirmBuildingDelete(id) {
if (confirm('Dieses Gebäude wirklich löschen? Alle Stockwerke werden gelöscht.')) {
alert('Löschen 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');
}
}
</script>