192 lines
4.9 KiB
PHP
192 lines
4.9 KiB
PHP
<?php
|
|
/**
|
|
* app/modules/racks/edit.php
|
|
*/
|
|
|
|
$rackId = (int)($_GET['id'] ?? 0);
|
|
$rack = null;
|
|
|
|
if ($rackId > 0) {
|
|
$rack = $sql->single(
|
|
"SELECT * FROM racks WHERE id = ?",
|
|
"i",
|
|
[$rackId]
|
|
);
|
|
}
|
|
|
|
$isEdit = !empty($rack);
|
|
$pageTitle = $isEdit ? 'Rack bearbeiten: ' . htmlspecialchars((string)$rack['name']) : 'Neues Rack';
|
|
$floors = $sql->get("SELECT id, name FROM floors ORDER BY name", '', []);
|
|
?>
|
|
|
|
<div class="rack-edit">
|
|
<h1><?php echo $pageTitle; ?></h1>
|
|
|
|
<form method="post" action="?module=racks&action=save" class="edit-form">
|
|
<?php if ($isEdit): ?>
|
|
<input type="hidden" name="id" value="<?php echo (int)$rackId; ?>">
|
|
<?php endif; ?>
|
|
|
|
<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((string)($rack['name'] ?? '')); ?>" placeholder="z.B. Rack A1">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="comment">Beschreibung</label>
|
|
<textarea id="comment" name="comment" rows="3" placeholder="z.B. Standort, Besonderheiten"><?php echo htmlspecialchars((string)($rack['comment'] ?? '')); ?></textarea>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
<legend>Standort und Groesse</legend>
|
|
|
|
<div class="form-group">
|
|
<label for="floor_id">Stockwerk <span class="required">*</span></label>
|
|
<select id="floor_id" name="floor_id" required>
|
|
<option value="">- Waehlen -</option>
|
|
<?php foreach ($floors as $floor): ?>
|
|
<option value="<?php echo (int)$floor['id']; ?>" <?php echo ((int)($rack['floor_id'] ?? 0) === (int)$floor['id']) ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars((string)$floor['name']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="height_he">Hoehe in Hoeheneinheiten (HE) <span class="required">*</span></label>
|
|
<input type="number" id="height_he" name="height_he" required min="1" max="100" value="<?php echo (int)($rack['height_he'] ?? 42); ?>">
|
|
<small>Standard: 42 HE</small>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="form-actions">
|
|
<button type="submit" class="button button-primary">Speichern</button>
|
|
<a href="?module=racks&action=list" class="button">Abbrechen</a>
|
|
<?php if ($isEdit): ?>
|
|
<a href="#" class="button button-danger" onclick="return confirmDelete(<?php echo (int)$rackId; ?>)">Loeschen</a>
|
|
<?php endif; ?>
|
|
</fieldset>
|
|
</form>
|
|
</div>
|
|
|
|
<style>
|
|
.rack-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 Rack wirklich loeschen? Alle Geraete werden aus dem Rack entfernt.')) {
|
|
return false;
|
|
}
|
|
|
|
fetch('?module=racks&action=delete', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
|
body: 'id=' + encodeURIComponent(id)
|
|
})
|
|
.then((response) => response.json())
|
|
.then((data) => {
|
|
if (data && data.success) {
|
|
window.location.href = '?module=racks&action=list';
|
|
return;
|
|
}
|
|
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => alert('Loeschen fehlgeschlagen'));
|
|
|
|
return false;
|
|
}
|
|
</script>
|