439 lines
13 KiB
PHP
439 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>
|
|
<?php
|
|
//TODO design schlecht, mach es hübscher
|
|
?>
|
|
|
|
<section class="hierarchy-section">
|
|
<h2>Gebäude & Stockwerke nach Standorten</h2>
|
|
<?php if (!empty($locations)): ?>
|
|
<ul class="hierarchy-list">
|
|
<?php foreach ($locations as $location): ?>
|
|
<li class="hierarchy-list__item">
|
|
<div class="hierarchy-location">
|
|
<div class="hierarchy-location__info">
|
|
<span class="hierarchy-location__name"><?php echo htmlspecialchars($location['name']); ?></span>
|
|
<span class="hierarchy-location__meta"><?php echo $location['building_count']; ?> Gebäude</span>
|
|
</div>
|
|
<div class="hierarchy-actions">
|
|
<a href="?module=buildings&action=edit&location_id=<?php echo $location['id']; ?>" class="button button-small">+ Gebäude</a>
|
|
</div>
|
|
</div>
|
|
<?php $locationBuildings = $buildingsByLocation[$location['id']] ?? []; ?>
|
|
<?php if (!empty($locationBuildings)): ?>
|
|
<ul class="hierarchy-sublist">
|
|
<?php foreach ($locationBuildings as $building): ?>
|
|
<li class="hierarchy-sublist__item">
|
|
<div class="hierarchy-building">
|
|
<div class="hierarchy-building__info">
|
|
<span class="hierarchy-building__name"><?php echo htmlspecialchars($building['name']); ?></span>
|
|
<?php if (!empty($building['comment'])): ?>
|
|
<span class="hierarchy-building__meta"><?php echo htmlspecialchars($building['comment']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="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>
|
|
</div>
|
|
</div>
|
|
<?php $buildingFloors = $floorsByBuilding[$building['id']] ?? []; ?>
|
|
<?php if (!empty($buildingFloors)): ?>
|
|
<ul class="hierarchy-sublist hierarchy-sublist--nested">
|
|
<?php foreach ($buildingFloors as $floor): ?>
|
|
<li>
|
|
<div class="hierarchy-floor">
|
|
<div class="hierarchy-floor__info">
|
|
<span class="hierarchy-floor__name"><?php echo htmlspecialchars($floor['name']); ?></span>
|
|
<?php if ($floor['level'] !== null): ?>
|
|
<span class="hierarchy-floor__meta">Ebene <?php echo htmlspecialchars($floor['level']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="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>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else: ?>
|
|
<p class="hierarchy-empty">Keine Stockwerke für dieses Gebäude.</p>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else: ?>
|
|
<p class="hierarchy-empty">Für diesen Standort sind noch keine Gebäude hinterlegt.</p>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?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-list {
|
|
list-style: none;
|
|
padding: 0;
|
|
margin: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
.hierarchy-list__item {
|
|
padding: 15px;
|
|
border: 1px solid #e0e0e0;
|
|
border-radius: 8px;
|
|
background: #fafafa;
|
|
}
|
|
|
|
.hierarchy-location,
|
|
.hierarchy-building,
|
|
.hierarchy-floor {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
gap: 10px;
|
|
}
|
|
|
|
.hierarchy-location__info,
|
|
.hierarchy-building__info,
|
|
.hierarchy-floor__info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
|
|
.hierarchy-location__name,
|
|
.hierarchy-building__name,
|
|
.hierarchy-floor__name {
|
|
font-weight: 600;
|
|
}
|
|
|
|
.hierarchy-location__meta,
|
|
.hierarchy-building__meta,
|
|
.hierarchy-floor__meta {
|
|
color: #666;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.hierarchy-sublist {
|
|
list-style: none;
|
|
margin: 10px 0 0 20px;
|
|
padding: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
}
|
|
|
|
.hierarchy-sublist--nested {
|
|
margin-left: 20px;
|
|
}
|
|
|
|
.hierarchy-empty {
|
|
margin: 10px 0 0 20px;
|
|
color: #888;
|
|
font-size: 0.9rem;
|
|
}
|
|
.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>
|
|
|