257 lines
6.0 KiB
PHP
257 lines
6.0 KiB
PHP
<?php
|
|
/**
|
|
* app/modules/floors/list.php
|
|
*
|
|
* Übersicht aller Floors / Stockwerke
|
|
* - Anzeigen, Bearbeiten, Löschen
|
|
* - SVG-Floorplan Vorschau (optional)
|
|
*/
|
|
|
|
// =========================
|
|
// Filter einlesen
|
|
// =========================
|
|
$search = trim($_GET['search'] ?? ');
|
|
|
|
// =========================
|
|
// Floors laden
|
|
// =========================
|
|
$whereClause = "";
|
|
$types = "";
|
|
$params = [];
|
|
|
|
if ($search !== ') {
|
|
$whereClause = "WHERE f.name LIKE ? OR f.comment LIKE ?";
|
|
$types = "ss";
|
|
$params = ["%$search%", "%$search%"];
|
|
}
|
|
|
|
$floors = $sql->get(
|
|
"SELECT f.*, b.name AS building_name, COUNT(r.id) AS room_count, COUNT(rk.id) AS rack_count
|
|
FROM floors f
|
|
LEFT JOIN buildings b ON f.building_id = b.id
|
|
LEFT JOIN rooms r ON r.floor_id = f.id
|
|
LEFT JOIN racks rk ON rk.floor_id = f.id
|
|
$whereClause
|
|
GROUP BY f.id
|
|
ORDER BY b.name, f.level",
|
|
$types,
|
|
$params
|
|
);
|
|
|
|
// =========================
|
|
// Filter-Daten
|
|
// =========================
|
|
$buildings = $sql->get("SELECT id, name FROM buildings ORDER BY name", "", []);
|
|
|
|
?>
|
|
|
|
<div class="floors-container">
|
|
<h1>Stockwerke</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="floors">
|
|
<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=floors&action=list" class="button">Reset</a>
|
|
<a href="?module=floors&action=edit" class="button button-primary" style="margin-left: auto;">+ Neues Stockwerk</a>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- =========================
|
|
Floors-Tabelle
|
|
========================= -->
|
|
<?php if (!empty($floors)): ?>
|
|
<table class="floor-list">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Gebäude</th>
|
|
<th>Ebene</th>
|
|
<th>Räume</th>
|
|
<th>Racks</th>
|
|
<th>Beschreibung</th>
|
|
<th>Aktionen</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($floors as $floor): ?>
|
|
<tr>
|
|
<td>
|
|
<strong><?php echo htmlspecialchars($floor['name']); ?></strong>
|
|
</td>
|
|
|
|
<td>
|
|
<?php echo htmlspecialchars($floor['building_name'] ?? '—'); ?>
|
|
</td>
|
|
|
|
<td>
|
|
<?php echo $floor['level'] ?? '—'; ?>
|
|
</td>
|
|
|
|
<td>
|
|
<?php echo $floor['room_count']; ?>
|
|
</td>
|
|
|
|
<td>
|
|
<?php echo $floor['rack_count']; ?>
|
|
</td>
|
|
|
|
<td>
|
|
<small><?php echo htmlspecialchars($floor['comment'] ?? '); ?></small>
|
|
</td>
|
|
|
|
<td class="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="confirmDelete(<?php echo $floor['id']; ?>)">Löschen</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php else: ?>
|
|
<div class="empty-state">
|
|
<p>Keine Stockwerke gefunden.</p>
|
|
<p>
|
|
<a href="?module=floors&action=edit" class="button button-primary">
|
|
Erstes Stockwerk anlegen
|
|
</a>
|
|
</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<style>
|
|
.floors-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;
|
|
}
|
|
|
|
.floor-list {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin: 15px 0;
|
|
}
|
|
|
|
.floor-list th {
|
|
background: #f5f5f5;
|
|
padding: 12px;
|
|
text-align: left;
|
|
border-bottom: 2px solid #ddd;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.floor-list td {
|
|
padding: 12px;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
|
|
.floor-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 Stockwerk wirklich loeschen? Alle Raeume und Racks werden geloescht.')) {
|
|
fetch('?module=floors&action=delete', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
|
body: 'id=' + encodeURIComponent(id)
|
|
})
|
|
.then((res) => res.json())
|
|
.then((data) => {
|
|
if (data && data.success) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => {
|
|
alert('Loeschen fehlgeschlagen');
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
|