#13 räume definieren
This commit is contained in:
64
app/modules/rooms/delete.php
Normal file
64
app/modules/rooms/delete.php
Normal 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
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>
|
||||
12
app/modules/rooms/list.php
Normal file
12
app/modules/rooms/list.php
Normal 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
115
app/modules/rooms/save.php
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user