Files
netwatch/app/modules/devices/edit.php
Troy Grunt 88ff04aa01 löschen
2026-02-11 21:59:13 +01:00

242 lines
7.1 KiB
PHP

<?php
/**
* app/modules/devices/edit.php
*
* Konkretes Gerät anlegen / bearbeiten
* - Name, Seriennummer
* - Gerätetyp wählen
* - Standort (Rack, HE-Position)
*/
// =========================
// Kontext bestimmen
// =========================
$deviceId = (int)($_GET['id'] ?? 0);
$device = null;
if ($deviceId > 0) {
$device = $sql->single(
"SELECT d.* FROM devices d WHERE d.id = ?",
"i",
[$deviceId]
);
}
$isEdit = !empty($device);
$pageTitle = $isEdit ? "Gerät bearbeiten: " . htmlspecialchars($device['name']) : "Neues Gerät";
// =========================
// 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", "", []);
?>
<div class="device-edit">
<h1><?php echo $pageTitle; ?></h1>
<form method="post" action="?module=devices&action=save" class="edit-form">
<?php if ($isEdit): ?>
<input type="hidden" name="id" value="<?php echo $deviceId; ?>">
<?php endif; ?>
<!-- =========================
Basisdaten
========================= -->
<fieldset>
<legend>Allgemein</legend>
<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>
<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>
<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>
<div class="form-group">
<label for="web_config_url">Webconfig-URL</label>
<input type="url" id="web_config_url" name="web_config_url"
value="<?php echo htmlspecialchars($device['web_config_url'] ?? ''); ?>"
placeholder="https://switch.example.local">
<small>Optionaler Link zur Weboberfläche des Geräts (öffnet in neuem Tab).</small>
</div>
<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>
<!-- =========================
Standort im Rack
========================= -->
<fieldset>
<legend>Standort</legend>
<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>
<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>
<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>
<!-- =========================
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>
</form>
</div>
<style>
.device-edit {
max-width: 800px;
margin: 20px auto;
padding: 20px;
}
.edit-form {
background: white;
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;
font-size: 1.1em;
}
.form-group {
margin: 15px 0;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.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;
}
.form-group textarea {
resize: vertical;
}
.form-group small {
display: block;
margin-top: 5px;
color: #666;
}
.required {
color: red;
}
.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>
function confirmDelete(id) {
if (confirm('Dieses Gerät wirklich löschen?')) {
window.location.href = '?module=devices&action=delete&id=' + encodeURIComponent(id);
}
}
</script>