#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>

View File

@@ -0,0 +1,64 @@
<?php
/**
* app/modules/rooms/delete.php
*
* Loescht einen Raum.
*/
header('Content-Type: application/json; charset=utf-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode([
'success' => false,
'message' => 'Methode nicht erlaubt'
]);
exit;
}
$roomId = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
if ($roomId <= 0) {
http_response_code(400);
echo json_encode([
'success' => false,
'message' => 'Ungueltige Raum-ID'
]);
exit;
}
$room = $sql->single(
"SELECT id, name FROM rooms WHERE id = ?",
"i",
[$roomId]
);
if (!$room) {
http_response_code(404);
echo json_encode([
'success' => false,
'message' => 'Raum nicht gefunden'
]);
exit;
}
$deleted = $sql->set(
"DELETE FROM rooms WHERE id = ?",
"i",
[$roomId]
);
if ($deleted <= 0) {
http_response_code(500);
echo json_encode([
'success' => false,
'message' => 'Raum konnte nicht geloescht werden'
]);
exit;
}
echo json_encode([
'success' => true,
'message' => 'Raum geloescht'
]);
exit;

234
app/modules/rooms/edit.php Normal file
View File

@@ -0,0 +1,234 @@
<?php
/**
* app/modules/rooms/edit.php
*
* Raum anlegen oder bearbeiten.
* Optional kann ein Raum-Polygon auf der Stockwerkskarte gezeichnet werden.
*/
$roomId = (int)($_GET['id'] ?? 0);
$room = null;
if ($roomId > 0) {
$room = $sql->single(
"SELECT * FROM rooms WHERE id = ?",
"i",
[$roomId]
);
}
$isEdit = !empty($room);
$prefillFloorId = (int)($_GET['floor_id'] ?? 0);
$selectedFloorId = (int)($room['floor_id'] ?? $prefillFloorId);
$floors = $sql->get(
"SELECT f.id, f.name, f.level, f.svg_path, b.name AS building_name, l.name AS location_name
FROM floors f
LEFT JOIN buildings b ON b.id = f.building_id
LEFT JOIN locations l ON l.id = b.location_id
ORDER BY l.name, b.name, f.level, f.name",
"",
[]
);
foreach ($floors as &$floor) {
$svgPath = trim((string)($floor['svg_path'] ?? ''));
$floor['svg_url'] = $svgPath !== '' ? '/' . ltrim($svgPath, "/\\") : '';
}
unset($floor);
$existingPolygon = trim((string)($room['polygon_points'] ?? ''));
$pageTitle = $isEdit ? "Raum bearbeiten: " . htmlspecialchars((string)$room['name']) : "Neuer Raum";
?>
<div class="room-edit">
<h1><?php echo $pageTitle; ?></h1>
<form method="post" action="?module=rooms&action=save" class="edit-form">
<?php if ($isEdit): ?>
<input type="hidden" name="id" value="<?php echo (int)$room['id']; ?>">
<?php endif; ?>
<fieldset>
<legend>Allgemein</legend>
<div class="form-group">
<label for="room-name">Name <span class="required">*</span></label>
<input type="text" id="room-name" name="name" required value="<?php echo htmlspecialchars((string)($room['name'] ?? '')); ?>">
</div>
<div class="form-group">
<label for="room-number">Raum-Nr.</label>
<input type="text" id="room-number" name="number" value="<?php echo htmlspecialchars((string)($room['number'] ?? '')); ?>" placeholder="z.B. EG-101">
</div>
<div class="form-group">
<label for="room-floor-id">Stockwerk <span class="required">*</span></label>
<select id="room-floor-id" name="floor_id" required>
<option value="">- Stockwerk waehlen -</option>
<?php foreach ($floors as $floor): ?>
<option value="<?php echo (int)$floor['id']; ?>"
data-svg-url="<?php echo htmlspecialchars((string)$floor['svg_url']); ?>"
<?php echo ((int)$floor['id'] === $selectedFloorId) ? 'selected' : ''; ?>>
<?php
$label = trim((string)$floor['location_name']) . ' / '
. trim((string)$floor['building_name']) . ' / '
. trim((string)$floor['name']);
if ($floor['level'] !== null) {
$label .= ' (Ebene ' . (string)$floor['level'] . ')';
}
echo htmlspecialchars($label);
?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="room-comment">Kommentar</label>
<textarea id="room-comment" name="comment" rows="3"><?php echo htmlspecialchars((string)($room['comment'] ?? '')); ?></textarea>
</div>
</fieldset>
<fieldset>
<legend>Polygon auf Stockwerkskarte (optional)</legend>
<input type="hidden" id="room-polygon-points" name="polygon_points" value="<?php echo htmlspecialchars($existingPolygon); ?>">
<div class="room-polygon-toolbar">
<label class="inline-checkbox">
<input type="checkbox" id="room-snap-walls" checked>
An Waenden snappen
</label>
<button type="button" class="button" id="room-undo-point">Letzten Punkt entfernen</button>
<button type="button" class="button button-danger" id="room-clear-polygon">Polygon loeschen</button>
</div>
<div class="room-polygon-wrap">
<svg id="room-polygon-canvas" viewBox="0 0 2000 1000" role="img" aria-label="Raumpolygon auf Stockwerkskarte"></svg>
<p class="hint" id="room-map-hint">Waehle zuerst ein Stockwerk mit Karte. Dann Punkte per Klick setzen, Punkte per Drag verschieben.</p>
</div>
</fieldset>
<fieldset class="form-actions">
<button type="submit" class="button button-primary">Speichern</button>
<a href="?module=locations&action=list" class="button">Abbrechen</a>
</fieldset>
</form>
</div>
<style>
.room-edit {
max-width: 1200px;
margin: 20px auto;
padding: 20px;
}
.edit-form {
background: #fff;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
}
.edit-form fieldset {
margin: 20px 0;
padding: 15px;
border: 1px solid #e0e0e0;
border-radius: 4px;
}
.edit-form legend {
padding: 0 10px;
font-weight: bold;
}
.form-group {
margin: 15px 0;
}
.form-group label {
display: block;
margin-bottom: 6px;
font-weight: bold;
}
.form-group input[type="text"],
.form-group select,
.form-group textarea {
width: 100%;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-family: inherit;
}
.room-polygon-toolbar {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 10px;
align-items: center;
}
.room-polygon-wrap {
border: 1px solid #ddd;
border-radius: 6px;
padding: 10px;
background: #fff;
}
#room-polygon-canvas {
width: 100%;
min-height: 560px;
display: block;
border: 1px solid #eee;
background: #fafafa;
cursor: crosshair;
}
.hint {
font-size: 0.85rem;
color: #666;
margin: 8px 0 0;
}
.inline-checkbox {
display: inline-flex;
align-items: center;
gap: 6px;
font-weight: normal;
}
.required {
color: #dc3545;
}
.form-actions {
display: flex;
gap: 10px;
margin-top: 20px;
}
.button {
display: inline-block;
padding: 10px 15px;
background: #007bff;
color: #fff;
text-decoration: none;
border-radius: 4px;
border: none;
cursor: pointer;
font-size: 0.95em;
}
.button-primary {
background: #28a745;
}
.button-danger {
background: #dc3545;
}
</style>
<script src="/assets/js/room-polygon-editor.js" defer></script>

View File

@@ -0,0 +1,12 @@
<?php
/**
* app/modules/rooms/list.php
*
* Raumverwaltung ist in die Standorte-Liste integriert.
*/
?>
<div class="connections-container">
<h1>Raeume</h1>
<p>Die Raumverwaltung befindet sich unter Standorte.</p>
<p><a class="button" href="?module=locations&action=list">Zu Standorte wechseln</a></p>
</div>

115
app/modules/rooms/save.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
/**
* app/modules/rooms/save.php
*
* Speichert oder aktualisiert einen Raum.
*/
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: ?module=locations&action=list');
exit;
}
$roomId = (int)($_POST['id'] ?? 0);
$name = trim((string)($_POST['name'] ?? ''));
$number = trim((string)($_POST['number'] ?? ''));
$floorId = (int)($_POST['floor_id'] ?? 0);
$comment = trim((string)($_POST['comment'] ?? ''));
$rawPolygon = trim((string)($_POST['polygon_points'] ?? ''));
if ($name === '' || $floorId <= 0) {
$redirect = $roomId > 0 ? "?module=rooms&action=edit&id=$roomId" : "?module=rooms&action=edit&floor_id=$floorId";
header("Location: $redirect");
exit;
}
$polygonPoints = [];
$polygonJson = null;
$x = null;
$y = null;
$width = null;
$height = null;
if ($rawPolygon !== '') {
$decoded = json_decode($rawPolygon, true);
if (is_array($decoded)) {
foreach ($decoded as $point) {
if (!is_array($point)) {
continue;
}
$px = isset($point['x']) ? (float)$point['x'] : null;
$py = isset($point['y']) ? (float)$point['y'] : null;
if (!is_finite($px) || !is_finite($py)) {
continue;
}
$polygonPoints[] = [
'x' => (int)round($px),
'y' => (int)round($py),
];
}
}
}
if (count($polygonPoints) >= 3) {
$xs = array_column($polygonPoints, 'x');
$ys = array_column($polygonPoints, 'y');
$minX = min($xs);
$maxX = max($xs);
$minY = min($ys);
$maxY = max($ys);
$x = (int)$minX;
$y = (int)$minY;
$width = (int)max(1, $maxX - $minX);
$height = (int)max(1, $maxY - $minY);
$polygonJson = json_encode($polygonPoints, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
if (roomsHasPolygonColumn($sql)) {
if ($roomId > 0) {
$sql->set(
"UPDATE rooms
SET floor_id = ?, name = ?, number = ?, x = ?, y = ?, width = ?, height = ?, polygon_points = ?, comment = ?
WHERE id = ?",
"issiiiissi",
[$floorId, $name, $number, $x, $y, $width, $height, $polygonJson, $comment, $roomId]
);
} else {
$sql->set(
"INSERT INTO rooms (floor_id, name, number, x, y, width, height, polygon_points, comment)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
"issiiiiss",
[$floorId, $name, $number, $x, $y, $width, $height, $polygonJson, $comment]
);
}
} else {
if ($roomId > 0) {
$sql->set(
"UPDATE rooms
SET floor_id = ?, name = ?, number = ?, x = ?, y = ?, width = ?, height = ?, comment = ?
WHERE id = ?",
"issiiiisi",
[$floorId, $name, $number, $x, $y, $width, $height, $comment, $roomId]
);
} else {
$sql->set(
"INSERT INTO rooms (floor_id, name, number, x, y, width, height, comment)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
"issiiiis",
[$floorId, $name, $number, $x, $y, $width, $height, $comment]
);
}
}
header('Location: ?module=locations&action=list');
exit;
function roomsHasPolygonColumn($sql)
{
static $hasColumn = null;
if ($hasColumn !== null) {
return $hasColumn;
}
$col = $sql->single("SHOW COLUMNS FROM rooms LIKE 'polygon_points'", "", []);
$hasColumn = !empty($col);
return $hasColumn;
}