Compare commits

..

2 Commits

Author SHA1 Message Date
d1d89dd4e3 location list fix 2026-02-16 11:11:56 +01:00
2a1732323d #13 räume definieren 2026-02-16 10:59:29 +01:00
11 changed files with 1233 additions and 362 deletions

View File

@@ -0,0 +1,187 @@
.locations-container {
padding: 20px;
max-width: 1000px;
margin: 0 auto;
}
.locations-filter-form {
display: flex;
gap: 10px;
flex-wrap: wrap;
align-items: center;
}
.locations-filter-add {
margin-left: auto;
}
.search-input {
flex: 1;
min-width: 250px;
}
.locations-list {
width: 100%;
border-collapse: collapse;
margin: 15px 0;
}
.locations-list th {
background: #f5f5f5;
padding: 12px;
text-align: left;
border-bottom: 2px solid #ddd;
font-weight: bold;
}
.locations-list td {
padding: 12px;
border-bottom: 1px solid #ddd;
}
.locations-list tr:hover {
background: #f9f9f9;
}
.actions {
white-space: nowrap;
}
.button {
display: inline-block;
padding: 8px 12px;
background: #007bff;
color: #fff;
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;
}
.hierarchy-section {
padding: 20px;
max-width: 1200px;
margin: 30px auto;
border-top: 1px solid #ddd;
}
.hierarchy-section h2 {
margin-bottom: 15px;
font-size: 1.3rem;
}
.hierarchy-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
border: 1px solid #d8dee5;
border-radius: 10px;
overflow: hidden;
}
.hierarchy-table th {
background: #f3f6fa;
padding: 10px 12px;
text-align: left;
font-size: 0.9rem;
font-weight: 600;
border-bottom: 1px solid #d8dee5;
}
.hierarchy-table td {
padding: 9px 12px;
border-bottom: 1px solid #eef2f6;
vertical-align: top;
}
.hierarchy-row:last-child td {
border-bottom: none;
}
.hierarchy-row--empty {
background: #fcfcfc;
}
.hierarchy-cell {
white-space: nowrap;
}
.hierarchy-cell--location {
background: #fbfcfe;
font-weight: 600;
min-width: 170px;
}
.hierarchy-cell--building {
padding-left: 18px;
min-width: 180px;
}
.hierarchy-cell--floor {
padding-left: 24px;
min-width: 190px;
}
.hierarchy-cell--room {
padding-left: 56px;
min-width: 190px;
}
.hierarchy-cell--empty {
background: #fafbfd;
width: 20px;
}
.hierarchy-meta {
color: #4e5c6b;
font-size: 0.88rem;
}
.hierarchy-meta--muted {
color: #8a94a3;
}
.hierarchy-actions {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.hierarchy-actions .button {
padding: 4px 10px;
font-size: 0.8rem;
}

View File

@@ -0,0 +1,78 @@
(() => {
function postDelete(url) {
return fetch(url, {
method: 'POST',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
}).then((response) => response.json());
}
function handleLocationDelete(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 handleBuildingDelete() {
if (confirm('Dieses Gebaeude wirklich loeschen? Alle Stockwerke werden geloescht.')) {
alert('Loeschen noch nicht implementiert');
}
}
function handleFloorDelete() {
if (confirm('Dieses Stockwerk wirklich loeschen? Alle Raeume und Racks werden geloescht.')) {
alert('Loeschen noch nicht implementiert');
}
}
function handleRoomDelete(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'));
}
function bindDeleteButtons() {
document.querySelectorAll('.js-delete-location').forEach((button) => {
button.addEventListener('click', () => {
handleLocationDelete(Number(button.dataset.locationId || 0));
});
});
document.querySelectorAll('.js-delete-building').forEach((button) => {
button.addEventListener('click', () => {
handleBuildingDelete(Number(button.dataset.buildingId || 0));
});
});
document.querySelectorAll('.js-delete-floor').forEach((button) => {
button.addEventListener('click', () => {
handleFloorDelete(Number(button.dataset.floorId || 0));
});
});
document.querySelectorAll('.js-delete-room').forEach((button) => {
button.addEventListener('click', () => {
handleRoomDelete(Number(button.dataset.roomId || 0));
});
});
}
document.addEventListener('DOMContentLoaded', bindDeleteButtons);
})();

View File

@@ -0,0 +1,377 @@
(() => {
const SVG_NS = 'http://www.w3.org/2000/svg';
const DEFAULT_VIEWBOX = { x: 0, y: 0, width: 2000, height: 1000 };
const SNAP_TOLERANCE = 16;
function initRoomPolygonEditor() {
const floorSelect = document.getElementById('room-floor-id');
const canvas = document.getElementById('room-polygon-canvas');
const polygonInput = document.getElementById('room-polygon-points');
const snapWalls = document.getElementById('room-snap-walls');
const undoButton = document.getElementById('room-undo-point');
const clearButton = document.getElementById('room-clear-polygon');
const mapHint = document.getElementById('room-map-hint');
if (!floorSelect || !canvas || !polygonInput) {
return;
}
const state = {
viewBox: { ...DEFAULT_VIEWBOX },
wallPoints: [],
floorLayerNodes: [],
points: parsePoints(polygonInput.value),
draggingIndex: null
};
const updateInput = () => {
if (state.points.length >= 3) {
polygonInput.value = JSON.stringify(state.points.map((point) => ({
x: Math.round(point.x),
y: Math.round(point.y)
})));
} else {
polygonInput.value = '';
}
};
const render = () => {
canvas.innerHTML = '';
canvas.setAttribute(
'viewBox',
`${state.viewBox.x} ${state.viewBox.y} ${state.viewBox.width} ${state.viewBox.height}`
);
const bg = createSvgElement('rect');
bg.setAttribute('x', String(state.viewBox.x));
bg.setAttribute('y', String(state.viewBox.y));
bg.setAttribute('width', String(state.viewBox.width));
bg.setAttribute('height', String(state.viewBox.height));
bg.setAttribute('fill', '#f7f7f7');
bg.setAttribute('stroke', '#e1e1e1');
canvas.appendChild(bg);
if (state.floorLayerNodes.length > 0) {
const floorLayer = createSvgElement('g');
floorLayer.setAttribute('opacity', '0.55');
floorLayer.setAttribute('pointer-events', 'none');
state.floorLayerNodes.forEach((node) => {
floorLayer.appendChild(node.cloneNode(true));
});
canvas.appendChild(floorLayer);
}
if (state.points.length >= 2) {
const polyline = createSvgElement('polyline');
polyline.setAttribute('fill', state.points.length >= 3 ? 'rgba(13, 110, 253, 0.16)' : 'none');
polyline.setAttribute('stroke', '#0d6efd');
polyline.setAttribute('stroke-width', '3');
polyline.setAttribute('points', buildPointString(state.points));
if (state.points.length >= 3) {
polyline.setAttribute('stroke-linejoin', 'round');
polyline.setAttribute('stroke-linecap', 'round');
polyline.setAttribute('points', `${buildPointString(state.points)} ${state.points[0].x},${state.points[0].y}`);
}
canvas.appendChild(polyline);
}
state.points.forEach((point, index) => {
const vertex = createSvgElement('circle');
vertex.setAttribute('cx', String(point.x));
vertex.setAttribute('cy', String(point.y));
vertex.setAttribute('r', '9');
vertex.setAttribute('fill', '#ffffff');
vertex.setAttribute('stroke', '#dc3545');
vertex.setAttribute('stroke-width', '3');
vertex.setAttribute('data-vertex-index', String(index));
canvas.appendChild(vertex);
});
updateInput();
};
const snapPoint = (point) => {
if (!snapWalls || !snapWalls.checked || state.wallPoints.length === 0) {
return point;
}
let nearest = null;
let nearestDist = Number.POSITIVE_INFINITY;
state.wallPoints.forEach((wallPoint) => {
const dx = wallPoint.x - point.x;
const dy = wallPoint.y - point.y;
const dist = Math.sqrt((dx * dx) + (dy * dy));
if (dist < nearestDist) {
nearestDist = dist;
nearest = wallPoint;
}
});
if (nearest && nearestDist <= SNAP_TOLERANCE) {
return { x: nearest.x, y: nearest.y };
}
return point;
};
const addPoint = (event) => {
const point = toSvgPoint(canvas, event);
if (!point) {
return;
}
state.points.push(snapPoint(point));
render();
};
const onPointerDown = (event) => {
const target = event.target;
if (!(target instanceof SVGElement)) {
return;
}
const vertex = target.closest('[data-vertex-index]');
if (vertex) {
const vertexIndex = Number(vertex.getAttribute('data-vertex-index'));
if (Number.isInteger(vertexIndex)) {
state.draggingIndex = vertexIndex;
vertex.setPointerCapture(event.pointerId);
}
return;
}
addPoint(event);
};
const onPointerMove = (event) => {
if (state.draggingIndex === null) {
return;
}
const point = toSvgPoint(canvas, event);
if (!point) {
return;
}
state.points[state.draggingIndex] = snapPoint(point);
render();
};
const stopDragging = () => {
state.draggingIndex = null;
};
const parseFloorSvg = (rawSvg) => {
const parser = new DOMParser();
const doc = parser.parseFromString(rawSvg, 'image/svg+xml');
const root = doc.documentElement;
if (!root || root.nodeName.toLowerCase() === 'parsererror') {
return null;
}
return root;
};
const readViewBox = (svgRoot) => {
const vb = (svgRoot.getAttribute('viewBox') || '').trim();
if (vb) {
const parts = vb.split(/\s+/).map((value) => Number(value));
if (parts.length === 4 && parts.every((value) => Number.isFinite(value))) {
return {
x: parts[0],
y: parts[1],
width: parts[2],
height: parts[3]
};
}
}
const width = Number(svgRoot.getAttribute('width'));
const height = Number(svgRoot.getAttribute('height'));
if (Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0) {
return { x: 0, y: 0, width, height };
}
return { ...DEFAULT_VIEWBOX };
};
const collectSnapPoints = (svgRoot) => {
const points = [];
const addPointValue = (x, y) => {
if (!Number.isFinite(x) || !Number.isFinite(y)) {
return;
}
points.push({ x: Math.round(x), y: Math.round(y) });
};
svgRoot.querySelectorAll('line').forEach((line) => {
addPointValue(Number(line.getAttribute('x1')), Number(line.getAttribute('y1')));
addPointValue(Number(line.getAttribute('x2')), Number(line.getAttribute('y2')));
});
svgRoot.querySelectorAll('polyline, polygon').forEach((shape) => {
parsePointString(shape.getAttribute('points') || '').forEach((point) => addPointValue(point.x, point.y));
});
svgRoot.querySelectorAll('rect').forEach((rect) => {
const x = Number(rect.getAttribute('x'));
const y = Number(rect.getAttribute('y'));
const width = Number(rect.getAttribute('width'));
const height = Number(rect.getAttribute('height'));
addPointValue(x, y);
addPointValue(x + width, y);
addPointValue(x + width, y + height);
addPointValue(x, y + height);
});
svgRoot.querySelectorAll('path').forEach((path) => {
const d = path.getAttribute('d') || '';
const numbers = (d.match(/-?\d+(\.\d+)?/g) || []).map((value) => Number(value));
for (let i = 0; i < numbers.length - 1; i += 2) {
addPointValue(numbers[i], numbers[i + 1]);
}
});
return dedupePoints(points);
};
const loadFloor = async () => {
const selected = floorSelect.selectedOptions[0];
const svgUrl = selected ? (selected.dataset.svgUrl || '') : '';
state.viewBox = { ...DEFAULT_VIEWBOX };
state.wallPoints = [];
state.floorLayerNodes = [];
if (!svgUrl) {
if (mapHint) {
mapHint.textContent = 'Fuer dieses Stockwerk ist keine Karte hinterlegt. Polygon kann trotzdem frei gezeichnet werden.';
}
render();
return;
}
try {
const response = await fetch(svgUrl, { credentials: 'same-origin' });
if (!response.ok) {
throw new Error('SVG not available');
}
const raw = await response.text();
const root = parseFloorSvg(raw);
if (!root) {
throw new Error('Invalid SVG');
}
state.viewBox = readViewBox(root);
state.wallPoints = collectSnapPoints(root);
state.floorLayerNodes = Array.from(root.childNodes)
.filter((node) => node.nodeType === Node.ELEMENT_NODE)
.map((node) => node.cloneNode(true));
if (mapHint) {
mapHint.textContent = state.wallPoints.length > 0
? 'Klick setzt Punkte. Punkte sind per Drag verschiebbar. Snap nutzt Wandpunkte aus der Stockwerkskarte.'
: 'Klick setzt Punkte. Punkte sind per Drag verschiebbar.';
}
} catch (error) {
if (mapHint) {
mapHint.textContent = 'Stockwerkskarte konnte nicht geladen werden. Polygon kann frei gezeichnet werden.';
}
}
render();
};
canvas.addEventListener('pointerdown', onPointerDown);
canvas.addEventListener('pointermove', onPointerMove);
canvas.addEventListener('pointerup', stopDragging);
canvas.addEventListener('pointercancel', stopDragging);
canvas.addEventListener('pointerleave', stopDragging);
floorSelect.addEventListener('change', () => {
loadFloor();
});
if (undoButton) {
undoButton.addEventListener('click', () => {
if (state.points.length === 0) {
return;
}
state.points.pop();
render();
});
}
if (clearButton) {
clearButton.addEventListener('click', () => {
state.points = [];
render();
});
}
render();
loadFloor();
}
function parsePoints(raw) {
if (!raw) {
return [];
}
try {
const parsed = JSON.parse(raw);
if (!Array.isArray(parsed)) {
return [];
}
return parsed
.map((point) => ({
x: Number(point && point.x),
y: Number(point && point.y)
}))
.filter((point) => Number.isFinite(point.x) && Number.isFinite(point.y));
} catch (error) {
return [];
}
}
function parsePointString(pointsAttr) {
return pointsAttr
.trim()
.split(/\s+/)
.map((pair) => {
const values = pair.split(',');
if (values.length !== 2) {
return null;
}
const x = Number(values[0]);
const y = Number(values[1]);
if (!Number.isFinite(x) || !Number.isFinite(y)) {
return null;
}
return { x, y };
})
.filter(Boolean);
}
function dedupePoints(points) {
const map = new Map();
points.forEach((point) => {
const key = `${Math.round(point.x)}:${Math.round(point.y)}`;
if (!map.has(key)) {
map.set(key, { x: Math.round(point.x), y: Math.round(point.y) });
}
});
return Array.from(map.values());
}
function buildPointString(points) {
return points.map((point) => `${Math.round(point.x)},${Math.round(point.y)}`).join(' ');
}
function createSvgElement(name) {
return document.createElementNS(SVG_NS, name);
}
function toSvgPoint(svg, event) {
const pt = svg.createSVGPoint();
pt.x = event.clientX;
pt.y = event.clientY;
const ctm = svg.getScreenCTM();
if (!ctm) {
return null;
}
const transformed = pt.matrixTransform(ctm.inverse());
return { x: transformed.x, y: transformed.y };
}
document.addEventListener('DOMContentLoaded', initRoomPolygonEditor);
})();

View File

@@ -27,7 +27,7 @@ $module = $_GET['module'] ?? 'dashboard';
$action = $_GET['action'] ?? 'list';
// Whitelist der Module
$validModules = ['dashboard', 'locations', 'buildings', 'device_types', 'devices', 'racks', 'floors', 'floor_infrastructure', 'connections', 'port_types'];
$validModules = ['dashboard', 'locations', 'buildings', 'rooms', 'device_types', 'devices', 'racks', 'floors', 'floor_infrastructure', 'connections', 'port_types'];
// Whitelist der Aktionen
$validActions = ['list', 'edit', 'save', 'ports', 'delete'];

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,59 +32,77 @@ $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,
CASE WHEN r.number IS NULL OR r.number = '' THEN 1 ELSE 0 END,
r.number,
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">
<link rel="stylesheet" href="/assets/css/locations-list.css">
<script src="/assets/js/locations-list.js" defer></script>
<h1>Standorte</h1>
<!-- =========================
Toolbar
========================= -->
<div class="filter-form">
<form method="GET" style="display: flex; gap: 10px; flex-wrap: wrap; align-items: center;">
<form method="GET" class="locations-filter-form">
<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>
<a href="?module=locations&action=list" class="button">Reset</a>
<a href="?module=locations&action=edit" class="button button-primary" style="margin-left: auto;">+ Neuer Standort</a>
<a href="?module=locations&action=edit" class="button button-primary locations-filter-add">+ Neuer Standort</a>
</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,111 +110,137 @@ 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>
<button type="button" class="button button-small button-danger js-delete-location" data-location-id="<?php echo (int)$location['id']; ?>">Loeschen</button>
</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>Gebaeude</th>
<th>Stockwerk</th>
<th>Raum</th>
<th>Details</th>
<th class="actions">Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($locations as $location): ?>
<?php $locationBuildings = $buildingsByLocation[$location['id']] ?? []; ?>
<?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($location['name']); ?></strong>
<span class="hierarchy-meta">(<?php echo (int) $location['building_count']; ?> Gebäude)</span>
<td class="hierarchy-cell hierarchy-cell--location" colspan="4">
<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 $location['id']; ?>" class="button button-small">+ Gebäude</a>
<a href="?module=buildings&action=edit&location_id=<?php echo (int)$location['id']; ?>" class="button button-small">+ Gebaeude</a>
</td>
</tr>
<?php if (!empty($locationBuildings)): ?>
<?php foreach ($locationBuildings as $building): ?>
<?php $buildingFloors = $floorsByBuilding[$building['id']] ?? []; ?>
<?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--building" colspan="2"><?php echo htmlspecialchars($building['name']); ?></td>
<td class="hierarchy-cell hierarchy-cell--building" colspan="3"><?php echo htmlspecialchars((string)$building['name']); ?></td>
<td>
<?php if (!empty($building['comment'])): ?>
<span class="hierarchy-meta"><?php echo htmlspecialchars($building['comment']); ?></span>
<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 $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>
<a href="?module=buildings&action=edit&id=<?php echo (int)$building['id']; ?>" class="button button-small">Bearbeiten</a>
<button type="button" class="button button-small button-danger js-delete-building" data-building-id="<?php echo (int)$building['id']; ?>">Loeschen</button>
<a href="?module=floors&action=edit&building_id=<?php echo (int)$building['id']; ?>" class="button button-small">+ Stockwerk</a>
</td>
</tr>
<?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($floor['name']); ?></td>
<td class="hierarchy-cell hierarchy-cell--floor" colspan="2"><?php echo htmlspecialchars((string)$floor['name']); ?></td>
<td>
<?php if ($floor['level'] !== null): ?>
<span class="hierarchy-meta">Ebene <?php echo htmlspecialchars($floor['level']); ?></span>
<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 $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>
<a href="?module=floors&action=edit&id=<?php echo (int)$floor['id']; ?>" class="button button-small">Bearbeiten</a>
<button type="button" class="button button-small button-danger js-delete-floor" data-floor-id="<?php echo (int)$floor['id']; ?>">Loeschen</button>
<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--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>
<button type="button" class="button button-small button-danger js-delete-room" data-room-id="<?php echo (int)$room['id']; ?>">Loeschen</button>
</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" colspan="2">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 Gebäude</td>
<td><span class="hierarchy-meta hierarchy-meta--muted">Für diesen Standort sind noch keine Gebäude vorhanden.</span></td>
<td class="hierarchy-cell hierarchy-cell--empty" colspan="3">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; ?>
@@ -213,239 +251,3 @@ foreach ($floors as $floor) {
<p>Keine Standorte gefunden.</p>
<?php endif; ?>
</section>
<?php
//TODO style in css file
?>
<style>
.locations-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;
}
.locations-list {
width: 100%;
border-collapse: collapse;
margin: 15px 0;
}
.locations-list th {
background: #f5f5f5;
padding: 12px;
text-align: left;
border-bottom: 2px solid #ddd;
font-weight: bold;
}
.locations-list td {
padding: 12px;
border-bottom: 1px solid #ddd;
}
.locations-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;
}
.hierarchy-section {
padding: 20px;
max-width: 1000px;
margin: 30px auto;
border-top: 1px solid #ddd;
}
.hierarchy-section h2 {
margin-bottom: 15px;
font-size: 1.3rem;
}
.hierarchy-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
border: 1px solid #d8dee5;
border-radius: 10px;
overflow: hidden;
}
.hierarchy-table th {
background: #f3f6fa;
padding: 10px 12px;
text-align: left;
font-size: 0.9rem;
font-weight: 600;
border-bottom: 1px solid #d8dee5;
}
.hierarchy-table td {
padding: 9px 12px;
border-bottom: 1px solid #eef2f6;
vertical-align: top;
}
.hierarchy-row:last-child td {
border-bottom: none;
}
.hierarchy-row--empty {
background: #fcfcfc;
}
.hierarchy-cell {
white-space: nowrap;
}
.hierarchy-cell--location {
background: #fbfcfe;
font-weight: 600;
min-width: 170px;
}
.hierarchy-cell--building {
padding-left: 18px;
min-width: 180px;
}
.hierarchy-cell--floor {
padding-left: 24px;
min-width: 160px;
}
.hierarchy-cell--empty {
background: #fafbfd;
width: 20px;
}
.hierarchy-meta {
color: #4e5c6b;
font-size: 0.9rem;
}
.hierarchy-meta--muted {
color: #8a94a3;
}
.hierarchy-actions {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.hierarchy-actions .button {
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 confirmBuildingDelete(id) {
if (confirm('Dieses Gebäude wirklich löschen? Alle Stockwerke werden gelöscht.')) {
alert('Löschen 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');
}
}
</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;
}

View File

@@ -69,6 +69,7 @@ Ein Raum innerhalb eines Stockwerks.
**Grafische Attribute**
- `x`, `y`, `width`, `height` zur visuellen Darstellung im Stockwerks-SVG
- `polygon_points` (JSON) fuer optionale Freiform-Polygone auf Basis der Stockwerkskarte
---

View File

@@ -428,6 +428,7 @@ CREATE TABLE `rooms` (
`y` int(11) DEFAULT NULL,
`width` int(11) DEFAULT NULL,
`height` int(11) DEFAULT NULL,
`polygon_points` longtext DEFAULT NULL,
`comment` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;