177 lines
4.1 KiB
PHP
177 lines
4.1 KiB
PHP
<?php
|
|
/**
|
|
* app/modules/locations/edit.php
|
|
*
|
|
* Standort anlegen/bearbeiten
|
|
*/
|
|
|
|
// =========================
|
|
// Kontext bestimmen
|
|
// =========================
|
|
$locationId = (int)($_GET['id'] ?? 0);
|
|
$location = null;
|
|
|
|
if ($locationId > 0) {
|
|
$location = $sql->single(
|
|
"SELECT * FROM locations WHERE id = ?",
|
|
"i",
|
|
[$locationId]
|
|
);
|
|
}
|
|
|
|
$isEdit = !empty($location);
|
|
$pageTitle = $isEdit ? "Standort bearbeiten: " . htmlspecialchars($location['name']) : "Neuer Standort";
|
|
|
|
?>
|
|
|
|
<div class="location-edit">
|
|
<h1><?php echo $pageTitle; ?></h1>
|
|
|
|
<form method="post" action="?module=locations&action=save" class="edit-form">
|
|
|
|
<?php if ($isEdit): ?>
|
|
<input type="hidden" name="id" value="<?php echo $locationId; ?>">
|
|
<?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($location['name'] ?? '); ?>"
|
|
placeholder="z.B. Hauptgebäude, Campus A, Außenstelle Berlin">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="comment">Beschreibung</label>
|
|
<textarea id="comment" name="comment" rows="3"
|
|
placeholder="Adresse, Kontaktinformationen, Besonderheiten"><?php echo htmlspecialchars($location['comment'] ?? '); ?></textarea>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<!-- =========================
|
|
Aktionen
|
|
========================= -->
|
|
<fieldset class="form-actions">
|
|
<button type="submit" class="button button-primary">Speichern</button>
|
|
<a href="?module=locations&action=list" class="button">Abbrechen</a>
|
|
<?php if ($isEdit): ?>
|
|
<a href="#" class="button button-danger" onclick="confirmDelete(<?php echo $locationId; ?>)">Löschen</a>
|
|
<?php endif; ?>
|
|
</fieldset>
|
|
|
|
</form>
|
|
</div>
|
|
|
|
<style>
|
|
.location-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 textarea {
|
|
width: 100%;
|
|
padding: 8px 12px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
font-family: inherit;
|
|
}
|
|
|
|
.form-group textarea {
|
|
resize: vertical;
|
|
}
|
|
|
|
.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('Diesen Standort wirklich loeschen? Alle Gebaeude werden geloescht.')) {
|
|
fetch('?module=locations&action=delete', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
|
body: 'id=' + encodeURIComponent(id)
|
|
})
|
|
.then((res) => res.json())
|
|
.then((data) => {
|
|
if (data && data.success) {
|
|
window.location.href = '?module=locations&action=list';
|
|
return;
|
|
}
|
|
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => {
|
|
alert('Loeschen fehlgeschlagen');
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
|