265 lines
6.3 KiB
PHP
265 lines
6.3 KiB
PHP
<?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 Gebaeude wirklich loeschen?')) {
|
|
fetch('?module=buildings&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.status === 'ok') {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
alert((data && data.error) ? data.error : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => {
|
|
alert('Loeschen fehlgeschlagen');
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
|