#13 räume definieren
This commit is contained in:
234
app/modules/rooms/edit.php
Normal file
234
app/modules/rooms/edit.php
Normal 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>
|
||||
Reference in New Issue
Block a user