feat: Implement floors, locations, and racks management
- Added list, edit, and save functionalities for floors, locations, and racks. - Enhanced UI with search and filter options for better usability. - Implemented SVG upload for floor plans in the floors module. - Added validation for required fields in the save processes. - Improved navigation in the header to reflect new modules. - Styled forms and tables for a consistent look and feel across modules.
This commit is contained in:
@@ -1,156 +1,234 @@
|
||||
<?php
|
||||
/**
|
||||
* app/devices/edit.php
|
||||
* app/modules/devices/edit.php
|
||||
*
|
||||
* Konkretes Gerät anlegen / bearbeiten
|
||||
* - Name, Beschreibung, Standort (Rack / Floor)
|
||||
* - Name, Seriennummer
|
||||
* - Gerätetyp wählen
|
||||
* - Ports automatisch vom Device-Type übernehmen
|
||||
* - SVG-Position im Rack / Floor
|
||||
* - Optional: Notizen / Kommentare
|
||||
* - Standort (Rack, HE-Position)
|
||||
*/
|
||||
|
||||
// TODO: bootstrap laden
|
||||
// require_once __DIR__ . '/../../bootstrap.php';
|
||||
|
||||
// TODO: Auth erzwingen
|
||||
// requireAuth();
|
||||
|
||||
// =========================
|
||||
// Kontext bestimmen
|
||||
// =========================
|
||||
$deviceId = (int)($_GET['id'] ?? 0);
|
||||
$device = null;
|
||||
|
||||
// Gerät-ID aus GET
|
||||
// $deviceId = (int)($_GET['id'] ?? 0);
|
||||
if ($deviceId > 0) {
|
||||
$device = $sql->single(
|
||||
"SELECT d.* FROM devices d WHERE d.id = ?",
|
||||
"i",
|
||||
[$deviceId]
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Gerät aus DB laden, falls ID vorhanden
|
||||
// $device = null;
|
||||
$isEdit = !empty($device);
|
||||
$pageTitle = $isEdit ? "Gerät bearbeiten: " . htmlspecialchars($device['name']) : "Neues Gerät";
|
||||
|
||||
// TODO: Alle Device-Types laden
|
||||
// $deviceTypes = $sql->get("SELECT * FROM device_types ORDER BY name", "", []);
|
||||
|
||||
// TODO: Wenn Gerät vorhanden, Ports laden (vom Device-Type)
|
||||
$ports = []; // TODO: Ports vorbereiten
|
||||
// =========================
|
||||
// Optionen laden
|
||||
// =========================
|
||||
$deviceTypes = $sql->get("SELECT id, name, category FROM device_types ORDER BY name", "", []);
|
||||
$racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
|
||||
|
||||
?>
|
||||
|
||||
<h2>Gerät bearbeiten</h2>
|
||||
<div class="device-edit">
|
||||
<h1><?php echo $pageTitle; ?></h1>
|
||||
|
||||
<form method="post" action="/devices/save" enctype="multipart/form-data">
|
||||
<form method="post" action="?module=devices&action=save" class="edit-form">
|
||||
|
||||
<!-- =========================
|
||||
Basisdaten
|
||||
========================= -->
|
||||
<?php if ($isEdit): ?>
|
||||
<input type="hidden" name="id" value="<?php echo $deviceId; ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<fieldset>
|
||||
<legend>Allgemein</legend>
|
||||
<!-- =========================
|
||||
Basisdaten
|
||||
========================= -->
|
||||
<fieldset>
|
||||
<legend>Allgemein</legend>
|
||||
|
||||
<label>
|
||||
Name<br>
|
||||
<input type="text" name="name" value="">
|
||||
<!-- TODO: Name vorbelegen -->
|
||||
</label>
|
||||
<div class="form-group">
|
||||
<label for="name">Name <span class="required">*</span></label>
|
||||
<input type="text" id="name" name="name" required
|
||||
value="<?php echo htmlspecialchars($device['name'] ?? ''); ?>"
|
||||
placeholder="z.B. Core Switch 1">
|
||||
</div>
|
||||
|
||||
<br><br>
|
||||
<div class="form-group">
|
||||
<label for="device_type_id">Gerätetyp <span class="required">*</span></label>
|
||||
<select id="device_type_id" name="device_type_id" required>
|
||||
<option value="">- Wählen -</option>
|
||||
<?php foreach ($deviceTypes as $type): ?>
|
||||
<option value="<?php echo $type['id']; ?>"
|
||||
<?php echo ($device['device_type_id'] ?? 0) == $type['id'] ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($type['name']); ?>
|
||||
<small>(<?php echo $type['category']; ?>)</small>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<label>
|
||||
Beschreibung<br>
|
||||
<textarea name="description"></textarea>
|
||||
<!-- TODO: Beschreibung vorbelegen -->
|
||||
</label>
|
||||
<div class="form-group">
|
||||
<label for="serial_number">Seriennummer</label>
|
||||
<input type="text" id="serial_number" name="serial_number"
|
||||
value="<?php echo htmlspecialchars($device['serial_number'] ?? ''); ?>"
|
||||
placeholder="Optionales Feld">
|
||||
</div>
|
||||
|
||||
<br><br>
|
||||
<div class="form-group">
|
||||
<label for="comment">Kommentar</label>
|
||||
<textarea id="comment" name="comment" rows="3"
|
||||
placeholder="Notizen zu diesem Gerät"><?php echo htmlspecialchars($device['comment'] ?? ''); ?></textarea>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<label>
|
||||
Gerätetyp<br>
|
||||
<select name="device_type_id">
|
||||
<!-- TODO: Device-Types aus DB -->
|
||||
<option value="1">Switch</option>
|
||||
</select>
|
||||
</label>
|
||||
</fieldset>
|
||||
<!-- =========================
|
||||
Standort im Rack
|
||||
========================= -->
|
||||
<fieldset>
|
||||
<legend>Standort</legend>
|
||||
|
||||
<!-- =========================
|
||||
Standort / Rack / Floor
|
||||
========================= -->
|
||||
<div class="form-group">
|
||||
<label for="rack_id">Rack <span class="required">*</span></label>
|
||||
<select id="rack_id" name="rack_id" required>
|
||||
<option value="">- Wählen -</option>
|
||||
<?php foreach ($racks as $rack): ?>
|
||||
<option value="<?php echo $rack['id']; ?>"
|
||||
<?php echo ($device['rack_id'] ?? 0) == $rack['id'] ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($rack['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<small>Wählen Sie das Rack, in dem sich das Gerät befindet.</small>
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<legend>Standort</legend>
|
||||
<div class="form-group">
|
||||
<label for="rack_position_he">Position im Rack (HE) <span class="required">*</span></label>
|
||||
<input type="number" id="rack_position_he" name="rack_position_he" required min="1"
|
||||
value="<?php echo htmlspecialchars($device['rack_position_he'] ?? ''); ?>"
|
||||
placeholder="Höheneinheit von oben">
|
||||
</div>
|
||||
|
||||
<label>
|
||||
Stockwerk<br>
|
||||
<select name="floor_id">
|
||||
<!-- TODO: Floors laden -->
|
||||
</select>
|
||||
</label>
|
||||
<div class="form-group">
|
||||
<label for="rack_height_he">Höhe (HE) <span class="required">*</span></label>
|
||||
<input type="number" id="rack_height_he" name="rack_height_he" required min="1"
|
||||
value="<?php echo htmlspecialchars($device['rack_height_he'] ?? '1'); ?>"
|
||||
placeholder="Anzahl Höheneinheiten">
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<br><br>
|
||||
<!-- =========================
|
||||
Aktionen
|
||||
========================= -->
|
||||
<fieldset class="form-actions">
|
||||
<button type="submit" class="button button-primary">Speichern</button>
|
||||
<a href="?module=devices&action=list" class="button">Abbrechen</a>
|
||||
<?php if ($isEdit): ?>
|
||||
<a href="#" class="button button-danger" onclick="confirmDelete(<?php echo $deviceId; ?>)">Löschen</a>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
|
||||
<label>
|
||||
Rack<br>
|
||||
<select name="rack_id">
|
||||
<!-- TODO: Racks laden -->
|
||||
</select>
|
||||
</label>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<br><br>
|
||||
<style>
|
||||
.device-edit {
|
||||
max-width: 800px;
|
||||
margin: 20px auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
<label>
|
||||
Position im Rack<br>
|
||||
<input type="number" name="rack_position" value="">
|
||||
</label>
|
||||
</fieldset>
|
||||
.edit-form {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
<!-- =========================
|
||||
Ports
|
||||
========================= -->
|
||||
.edit-form fieldset {
|
||||
margin: 20px 0;
|
||||
padding: 15px;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
<fieldset>
|
||||
<legend>Ports</legend>
|
||||
.edit-form legend {
|
||||
padding: 0 10px;
|
||||
font-weight: bold;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
<p class="hint">Ports werden vom Device-Type übernommen. Positionen können angepasst werden.</p>
|
||||
.form-group {
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
<div class="svg-editor-container">
|
||||
<svg
|
||||
id="device-svg"
|
||||
viewBox="0 0 800 400"
|
||||
width="100%"
|
||||
height="400"
|
||||
>
|
||||
<!-- TODO: SVG laden -->
|
||||
</svg>
|
||||
</div>
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
<!-- TODO: Port-Liste -->
|
||||
<div class="port-list">
|
||||
<!-- Ports mit Typ, Name, Modus, VLAN -->
|
||||
</div>
|
||||
</fieldset>
|
||||
.form-group input[type="text"],
|
||||
.form-group input[type="number"],
|
||||
.form-group select,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
<!-- =========================
|
||||
Aktionen
|
||||
========================= -->
|
||||
.form-group textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
<fieldset>
|
||||
<button type="submit">Speichern</button>
|
||||
<button type="button" onclick="history.back()">Abbrechen</button>
|
||||
<!-- TODO: Löschen, falls edit -->
|
||||
</fieldset>
|
||||
.form-group small {
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
</form>
|
||||
.required {
|
||||
color: red;
|
||||
}
|
||||
|
||||
<!-- =========================
|
||||
JS-Konfiguration
|
||||
========================= -->
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.button {
|
||||
padding: 10px 15px;
|
||||
background: #007bff;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
.button-primary {
|
||||
background: #28a745;
|
||||
}
|
||||
|
||||
.button-danger {
|
||||
background: #dc3545;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* SVG-Editor Konfiguration
|
||||
*/
|
||||
|
||||
// TODO: Device-ID setzen
|
||||
// window.DEVICE_ID = <?= (int)$deviceId ?>;
|
||||
|
||||
// TODO: Ports an JS übergeben
|
||||
// window.DEVICE_PORTS = <?= json_encode($ports) ?>;
|
||||
function confirmDelete(id) {
|
||||
if (confirm('Dieses Gerät wirklich löschen?')) {
|
||||
// TODO: AJAX-Delete implementieren
|
||||
alert('Löschen noch nicht implementiert');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* modules/devices/list.php
|
||||
* Vollständige Geräteübersicht
|
||||
* Vollständige Geräteübersicht mit Filter
|
||||
*/
|
||||
|
||||
// =========================
|
||||
// Filter / Suche einlesen
|
||||
// =========================
|
||||
|
||||
$search = trim($_GET['search'] ?? '');
|
||||
$typeId = (int)($_GET['type_id'] ?? 0);
|
||||
$locationId = (int)($_GET['location_id'] ?? 0);
|
||||
@@ -17,7 +16,6 @@ $rackId = (int)($_GET['rack_id'] ?? 0);
|
||||
// =========================
|
||||
// WHERE-Clause dynamisch bauen
|
||||
// =========================
|
||||
|
||||
$where = [];
|
||||
$types = '';
|
||||
$params = [];
|
||||
@@ -31,17 +29,11 @@ if ($search !== '') {
|
||||
}
|
||||
|
||||
if ($typeId > 0) {
|
||||
$where[] = "dt.id = ?";
|
||||
$where[] = "d.device_type_id = ?";
|
||||
$types .= "i";
|
||||
$params[] = $typeId;
|
||||
}
|
||||
|
||||
if ($locationId > 0) {
|
||||
$where[] = "l.id = ?";
|
||||
$types .= "i";
|
||||
$params[] = $locationId;
|
||||
}
|
||||
|
||||
if ($floorId > 0) {
|
||||
$where[] = "f.id = ?";
|
||||
$types .= "i";
|
||||
@@ -49,7 +41,7 @@ if ($floorId > 0) {
|
||||
}
|
||||
|
||||
if ($rackId > 0) {
|
||||
$where[] = "r.id = ?";
|
||||
$where[] = "d.rack_id = ?";
|
||||
$types .= "i";
|
||||
$params[] = $rackId;
|
||||
}
|
||||
@@ -57,9 +49,8 @@ if ($rackId > 0) {
|
||||
$whereSql = $where ? 'WHERE ' . implode(' AND ', $where) : '';
|
||||
|
||||
// =========================
|
||||
// Geräte laden (inkl. Status-Aggregate)
|
||||
// Geräte laden
|
||||
// =========================
|
||||
|
||||
$devices = $sql->get(
|
||||
"
|
||||
SELECT
|
||||
@@ -68,35 +59,16 @@ $devices = $sql->get(
|
||||
d.serial_number,
|
||||
d.rack_position_he,
|
||||
d.rack_height_he,
|
||||
|
||||
dt.name AS device_type,
|
||||
dt.image_path,
|
||||
dt.image_type,
|
||||
|
||||
l.name AS location_name,
|
||||
f.name AS floor_name,
|
||||
r.name AS rack_name,
|
||||
|
||||
COUNT(dp.id) AS total_ports,
|
||||
SUM(dp.status = 'active') AS active_ports,
|
||||
SUM(c.id IS NOT NULL) AS connected_ports
|
||||
|
||||
r.name AS rack_name
|
||||
FROM devices d
|
||||
JOIN device_types dt ON dt.id = d.device_type_id
|
||||
|
||||
LEFT JOIN racks r ON r.id = d.rack_id
|
||||
LEFT JOIN floors f ON f.id = r.floor_id
|
||||
LEFT JOIN buildings b ON b.id = f.building_id
|
||||
LEFT JOIN locations l ON l.id = b.location_id
|
||||
|
||||
LEFT JOIN device_ports dp ON dp.device_id = d.id
|
||||
LEFT JOIN connections c
|
||||
ON (c.port_a_type = 'device' AND c.port_a_id = dp.id)
|
||||
OR (c.port_b_type = 'device' AND c.port_b_id = dp.id)
|
||||
|
||||
$whereSql
|
||||
GROUP BY d.id
|
||||
ORDER BY l.name, f.level, r.name, d.rack_position_he, d.name
|
||||
ORDER BY f.name, r.name, d.rack_position_he, d.name
|
||||
",
|
||||
$types,
|
||||
$params
|
||||
@@ -105,138 +77,250 @@ $devices = $sql->get(
|
||||
// =========================
|
||||
// Filter-Daten laden
|
||||
// =========================
|
||||
|
||||
$deviceTypes = $sql->get("SELECT id, name FROM device_types ORDER BY name", "", []);
|
||||
$locations = $sql->get("SELECT id, name FROM locations ORDER BY name", "", []);
|
||||
$floors = $sql->get("SELECT id, name FROM floors ORDER BY level", "", []);
|
||||
$floors = $sql->get("SELECT id, name FROM floors ORDER BY name", "", []);
|
||||
$racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
|
||||
?>
|
||||
|
||||
<h2>Geräte</h2>
|
||||
<div class="devices-container">
|
||||
<h1>Geräte</h1>
|
||||
|
||||
<form method="get" class="toolbar">
|
||||
<input type="hidden" name="module" value="devices">
|
||||
<input type="hidden" name="action" value="list">
|
||||
<!-- =========================
|
||||
Filter-Toolbar
|
||||
========================= -->
|
||||
<form method="get" class="filter-form">
|
||||
<input type="hidden" name="module" value="devices">
|
||||
<input type="hidden" name="action" value="list">
|
||||
|
||||
<input type="text" name="search" placeholder="Suche…" value="<?= htmlspecialchars($search) ?>">
|
||||
<input type="text" name="search" placeholder="Suche nach Name oder Seriennummer…"
|
||||
value="<?php echo htmlspecialchars($search); ?>" class="search-input">
|
||||
|
||||
<select name="type_id">
|
||||
<option value="">Gerätetyp</option>
|
||||
<?php foreach ($deviceTypes as $t): ?>
|
||||
<option value="<?= $t['id'] ?>" <?= $t['id'] === $typeId ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($t['name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<select name="type_id">
|
||||
<option value="">- Alle Typen -</option>
|
||||
<?php foreach ($deviceTypes as $t): ?>
|
||||
<option value="<?php echo $t['id']; ?>" <?php echo $t['id'] === $typeId ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($t['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<select name="location_id">
|
||||
<option value="">Standort</option>
|
||||
<?php foreach ($locations as $l): ?>
|
||||
<option value="<?= $l['id'] ?>" <?= $l['id'] === $locationId ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($l['name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<select name="floor_id">
|
||||
<option value="">- Alle Stockwerke -</option>
|
||||
<?php foreach ($floors as $f): ?>
|
||||
<option value="<?php echo $f['id']; ?>" <?php echo $f['id'] === $floorId ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($f['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<select name="floor_id">
|
||||
<option value="">Floor</option>
|
||||
<?php foreach ($floors as $f): ?>
|
||||
<option value="<?= $f['id'] ?>" <?= $f['id'] === $floorId ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($f['name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<select name="rack_id">
|
||||
<option value="">- Alle Racks -</option>
|
||||
<?php foreach ($racks as $r): ?>
|
||||
<option value="<?php echo $r['id']; ?>" <?php echo $r['id'] === $rackId ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($r['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<select name="rack_id">
|
||||
<option value="">Rack</option>
|
||||
<?php foreach ($racks as $r): ?>
|
||||
<option value="<?= $r['id'] ?>" <?= $r['id'] === $rackId ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($r['name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit" class="button">Filter</button>
|
||||
|
||||
<button type="submit">Filtern</button>
|
||||
<a href="?module=devices&action=list" class="button">Reset</a>
|
||||
|
||||
<a href="/devices/edit" class="button">
|
||||
+ Neues Gerät
|
||||
</a>
|
||||
</form>
|
||||
<a href="?module=devices&action=edit" class="button button-primary" style="margin-left: auto;">
|
||||
+ Neues Gerät
|
||||
</a>
|
||||
</form>
|
||||
|
||||
<?php if ($devices): ?>
|
||||
<!-- =========================
|
||||
Geräte-Liste
|
||||
========================= -->
|
||||
<?php if (!empty($devices)): ?>
|
||||
<div class="device-stats">
|
||||
<p>Gefundene Geräte: <strong><?php echo count($devices); ?></strong></p>
|
||||
</div>
|
||||
|
||||
<table class="device-list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Vorschau</th>
|
||||
<th>Name</th>
|
||||
<th>Typ</th>
|
||||
<th>Standort</th>
|
||||
<th>Rack</th>
|
||||
<th>HE</th>
|
||||
<th>Ports</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<table class="device-list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Typ</th>
|
||||
<th>Stockwerk</th>
|
||||
<th>Rack</th>
|
||||
<th>Position (HE)</th>
|
||||
<th>Seriennummer</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($devices as $d): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<strong><?php echo htmlspecialchars($d['name']); ?></strong>
|
||||
</td>
|
||||
|
||||
<?php foreach ($devices as $d):
|
||||
$freePorts = max(0, $d['total_ports'] - $d['connected_ports']);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php if ($d['image_path']): ?>
|
||||
<img src="<?= htmlspecialchars($d['image_path']) ?>" class="thumb">
|
||||
<?php else: ?>
|
||||
—
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo htmlspecialchars($d['device_type']); ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<strong><?= htmlspecialchars($d['name']) ?></strong><br>
|
||||
<small><?= htmlspecialchars($d['serial_number'] ?? '') ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo htmlspecialchars($d['floor_name'] ?? '—'); ?>
|
||||
</td>
|
||||
|
||||
<td><?= htmlspecialchars($d['device_type']) ?></td>
|
||||
<td>
|
||||
<?php echo htmlspecialchars($d['rack_name'] ?? '—'); ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?= htmlspecialchars($d['location_name'] ?? '—') ?><br>
|
||||
<small><?= htmlspecialchars($d['floor_name'] ?? '') ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
if ($d['rack_position_he']) {
|
||||
echo $d['rack_position_he'];
|
||||
if ($d['rack_height_he']) {
|
||||
echo "–" . ($d['rack_position_he'] + $d['rack_height_he'] - 1);
|
||||
}
|
||||
} else {
|
||||
echo "—";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
<td><?= htmlspecialchars($d['rack_name'] ?? '—') ?></td>
|
||||
<td>
|
||||
<small><?php echo htmlspecialchars($d['serial_number'] ?? '—'); ?></small>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?= htmlspecialchars($d['rack_position_he'] ?? '—') ?>
|
||||
<?php if ($d['rack_height_he']): ?>
|
||||
– <?= $d['rack_position_he'] + $d['rack_height_he'] - 1 ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<a href="?module=devices&action=edit&id=<?php echo $d['id']; ?>" class="button button-small">Bearbeiten</a>
|
||||
<a href="#" class="button button-small button-danger" onclick="confirmDelete(<?php echo $d['id']; ?>)">Löschen</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<td>
|
||||
<?= (int)$d['connected_ports'] ?>/<?= (int)$d['total_ports'] ?>
|
||||
<br>
|
||||
<small><?= $freePorts ?> frei</small>
|
||||
</td>
|
||||
|
||||
<td class="actions">
|
||||
<a href="/devices/ports?id=<?= $d['id'] ?>">Ports</a>
|
||||
<a href="/devices/edit?id=<?= $d['id'] ?>">Bearbeiten</a>
|
||||
<a href="/devices/delete?id=<?= $d['id'] ?>"
|
||||
onclick="return confirm('Gerät wirklich löschen?')">
|
||||
Löschen
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<div class="empty-state">
|
||||
<p>Keine Geräte gefunden.</p>
|
||||
<?php else: ?>
|
||||
<div class="empty-state">
|
||||
<p>Keine Geräte gefunden.</p>
|
||||
<p>
|
||||
<a href="?module=devices&action=edit" class="button button-primary">
|
||||
Erstes Gerät anlegen
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
<style>
|
||||
.devices-container {
|
||||
padding: 20px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin: 20px 0;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-form input,
|
||||
.filter-form select {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
min-width: 250px;
|
||||
}
|
||||
|
||||
.device-stats {
|
||||
background: #f0f0f0;
|
||||
padding: 10px 15px;
|
||||
border-radius: 4px;
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
.device-list {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
.device-list th {
|
||||
background: #f5f5f5;
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 2px solid #ddd;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.device-list td {
|
||||
padding: 12px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.device-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 Gerät wirklich löschen?')) {
|
||||
// TODO: AJAX-Delete implementieren
|
||||
alert('Löschen noch nicht implementiert');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -5,216 +5,83 @@
|
||||
* Speichert / aktualisiert ein Gerät
|
||||
* - Basisdaten
|
||||
* - Rack-Zuordnung
|
||||
* - Ports (automatisch aus Device-Type oder manuell)
|
||||
*
|
||||
* Erwartet POST (form-data ODER JSON)
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
|
||||
// =========================
|
||||
// Request prüfen
|
||||
// =========================
|
||||
|
||||
// Nur POST
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'Invalid request method']);
|
||||
header('Location: ?module=devices&action=list');
|
||||
exit;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Daten einlesen (JSON oder POST)
|
||||
// Daten einlesen
|
||||
// =========================
|
||||
|
||||
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
|
||||
|
||||
if (str_contains($contentType, 'application/json')) {
|
||||
$data = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
} else {
|
||||
$data = $_POST;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Basisfelder
|
||||
// =========================
|
||||
|
||||
$deviceId = isset($data['id']) ? (int)$data['id'] : null;
|
||||
$name = trim($data['name'] ?? '');
|
||||
$comment = trim($data['comment'] ?? '');
|
||||
$deviceTypeId = (int)($data['device_type_id'] ?? 0);
|
||||
$rackId = isset($data['rack_id']) ? (int)$data['rack_id'] : null;
|
||||
$rackPositionHe = isset($data['rack_position_he']) ? (int)$data['rack_position_he'] : null;
|
||||
$rackHeightHe = isset($data['rack_height_he']) ? (int)$data['rack_height_he'] : null;
|
||||
$serialNumber = trim($data['serial_number'] ?? '');
|
||||
$portsData = $data['ports'] ?? null;
|
||||
$deviceId = (int)($_POST['id'] ?? 0);
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$deviceTypeId = (int)($_POST['device_type_id'] ?? 0);
|
||||
$rackId = (int)($_POST['rack_id'] ?? 0);
|
||||
$rackPositionHe = (int)($_POST['rack_position_he'] ?? 0);
|
||||
$rackHeightHe = (int)($_POST['rack_height_he'] ?? 1);
|
||||
$serialNumber = trim($_POST['serial_number'] ?? '');
|
||||
$comment = trim($_POST['comment'] ?? '');
|
||||
|
||||
// =========================
|
||||
// Validierung
|
||||
// =========================
|
||||
|
||||
$errors = [];
|
||||
|
||||
if ($name === '') {
|
||||
$errors[] = 'Name darf nicht leer sein';
|
||||
if (empty($name)) {
|
||||
$errors[] = "Name ist erforderlich";
|
||||
}
|
||||
|
||||
$deviceType = $sql->single(
|
||||
"SELECT * FROM device_types WHERE id = ?",
|
||||
"i",
|
||||
[$deviceTypeId]
|
||||
);
|
||||
|
||||
if (!$deviceType) {
|
||||
$errors[] = 'Ungültiger Gerätetyp';
|
||||
if ($deviceTypeId <= 0) {
|
||||
$errors[] = "Gerätetyp ist erforderlich";
|
||||
}
|
||||
|
||||
if ($rackId !== null) {
|
||||
$rack = $sql->single(
|
||||
"SELECT * FROM racks WHERE id = ?",
|
||||
"i",
|
||||
[$rackId]
|
||||
);
|
||||
|
||||
if (!$rack) {
|
||||
$errors[] = 'Ungültiges Rack';
|
||||
} elseif ($rackHeightHe !== null && $rackPositionHe !== null) {
|
||||
if ($rackPositionHe < 1 || ($rackPositionHe + $rackHeightHe - 1) > $rack['height_he']) {
|
||||
$errors[] = 'Gerät passt nicht ins Rack';
|
||||
}
|
||||
}
|
||||
if ($rackId <= 0) {
|
||||
$errors[] = "Rack ist erforderlich";
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'errors' => $errors
|
||||
]);
|
||||
if ($rackPositionHe <= 0) {
|
||||
$errors[] = "Rack-Position muss >= 1 sein";
|
||||
}
|
||||
|
||||
if ($rackHeightHe < 1) {
|
||||
$errors[] = "Höhe muss >= 1 sein";
|
||||
}
|
||||
|
||||
// Falls Fehler: zurück zum Edit-Formular
|
||||
if (!empty($errors)) {
|
||||
$_SESSION['error'] = implode(', ', $errors);
|
||||
$redirectUrl = $deviceId ? "?module=devices&action=edit&id=$deviceId" : "?module=devices&action=edit";
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Device speichern
|
||||
// In DB speichern
|
||||
// =========================
|
||||
|
||||
if ($deviceId) {
|
||||
|
||||
if ($deviceId > 0) {
|
||||
// UPDATE
|
||||
$sql->set(
|
||||
"
|
||||
UPDATE devices SET
|
||||
name = ?,
|
||||
comment = ?,
|
||||
device_type_id = ?,
|
||||
rack_id = ?,
|
||||
rack_position_he = ?,
|
||||
rack_height_he = ?,
|
||||
serial_number = ?
|
||||
WHERE id = ?
|
||||
",
|
||||
"ssiiii si",
|
||||
[
|
||||
$name,
|
||||
$comment,
|
||||
$deviceTypeId,
|
||||
$rackId,
|
||||
$rackPositionHe,
|
||||
$rackHeightHe,
|
||||
$serialNumber,
|
||||
$deviceId
|
||||
]
|
||||
"UPDATE devices SET name = ?, device_type_id = ?, rack_id = ?, rack_position_he = ?, rack_height_he = ?, serial_number = ?, comment = ? WHERE id = ?",
|
||||
"siiiissi",
|
||||
[$name, $deviceTypeId, $rackId, $rackPositionHe, $rackHeightHe, $serialNumber, $comment, $deviceId]
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
$deviceId = $sql->set(
|
||||
"
|
||||
INSERT INTO devices
|
||||
(name, comment, device_type_id, rack_id, rack_position_he, rack_height_he, serial_number)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?, ?, ?)
|
||||
",
|
||||
"ssiiiii",
|
||||
[
|
||||
$name,
|
||||
$comment,
|
||||
$deviceTypeId,
|
||||
$rackId,
|
||||
$rackPositionHe,
|
||||
$rackHeightHe,
|
||||
$serialNumber
|
||||
],
|
||||
true
|
||||
// INSERT
|
||||
$sql->set(
|
||||
"INSERT INTO devices (name, device_type_id, rack_id, rack_position_he, rack_height_he, serial_number, comment) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
"siiiiss",
|
||||
[$name, $deviceTypeId, $rackId, $rackPositionHe, $rackHeightHe, $serialNumber, $comment]
|
||||
);
|
||||
|
||||
// =========================
|
||||
// Ports vom Device-Type übernehmen (nur bei NEU)
|
||||
// =========================
|
||||
|
||||
$typePorts = $sql->get(
|
||||
"
|
||||
SELECT name, port_type_id
|
||||
FROM device_type_ports
|
||||
WHERE device_type_id = ?
|
||||
ORDER BY id
|
||||
",
|
||||
"i",
|
||||
[$deviceTypeId]
|
||||
);
|
||||
|
||||
foreach ($typePorts as $tp) {
|
||||
$sql->set(
|
||||
"
|
||||
INSERT INTO device_ports
|
||||
(device_id, name, port_type_id)
|
||||
VALUES
|
||||
(?, ?, ?)
|
||||
",
|
||||
"isi",
|
||||
[
|
||||
$deviceId,
|
||||
$tp['name'],
|
||||
$tp['port_type_id']
|
||||
]
|
||||
);
|
||||
}
|
||||
$deviceId = $sql->h->insert_id;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Ports aktualisieren (optional, z. B. VLAN / Mode)
|
||||
// =========================
|
||||
|
||||
if (is_array($portsData)) {
|
||||
foreach ($portsData as $portId => $port) {
|
||||
|
||||
$status = $port['status'] ?? 'active';
|
||||
$mode = $port['mode'] ?? null;
|
||||
$vlan = isset($port['vlan_config']) ? json_encode($port['vlan_config']) : null;
|
||||
|
||||
$sql->set(
|
||||
"
|
||||
UPDATE device_ports SET
|
||||
status = ?,
|
||||
mode = ?,
|
||||
vlan_config = ?
|
||||
WHERE id = ? AND device_id = ?
|
||||
",
|
||||
"sssii",
|
||||
[
|
||||
$status,
|
||||
$mode,
|
||||
$vlan,
|
||||
(int)$portId,
|
||||
$deviceId
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
$_SESSION['success'] = "Gerät gespeichert";
|
||||
|
||||
// =========================
|
||||
// Antwort
|
||||
// Redirect
|
||||
// =========================
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'ok',
|
||||
'id' => $deviceId
|
||||
]);
|
||||
header('Location: ?module=devices&action=list');
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user