div TODOs
This commit is contained in:
35
app/modules/buildings/delete.php
Normal file
35
app/modules/buildings/delete.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* app/modules/buildings/delete.php
|
||||
*/
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'Methode nicht erlaubt']);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'ID fehlt']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$exists = $sql->single("SELECT id FROM buildings WHERE id = ?", "i", [$id]);
|
||||
if (!$exists) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['error' => 'Gebaeude nicht gefunden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $sql->set("DELETE FROM buildings WHERE id = ?", "i", [$id]);
|
||||
if ($rows === false) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Loeschen fehlgeschlagen']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['status' => 'ok', 'success' => true, 'rows' => $rows]);
|
||||
@@ -47,7 +47,7 @@ $selectedLocationId = $building['location_id'] ?? $prefillLocationId;
|
||||
<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($building['name'] ?? ''); ?>"
|
||||
value="<?php echo htmlspecialchars($building['name'] ?? '); ?>"
|
||||
placeholder="z.B. Gebäude A, Verwaltungsgebäude">
|
||||
</div>
|
||||
|
||||
@@ -57,7 +57,7 @@ $selectedLocationId = $building['location_id'] ?? $prefillLocationId;
|
||||
<option value="">- Wählen -</option>
|
||||
<?php foreach ($locations as $location): ?>
|
||||
<option value="<?php echo $location['id']; ?>"
|
||||
<?php echo ((int)$selectedLocationId === (int)$location['id']) ? 'selected' : ''; ?>>
|
||||
<?php echo ((int)$selectedLocationId === (int)$location['id']) ? 'selected' : '; ?>>
|
||||
<?php echo htmlspecialchars($location['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
@@ -67,7 +67,7 @@ $selectedLocationId = $building['location_id'] ?? $prefillLocationId;
|
||||
<div class="form-group">
|
||||
<label for="comment">Beschreibung</label>
|
||||
<textarea id="comment" name="comment" rows="3"
|
||||
placeholder="Adresse, Besonderheiten, etc."><?php echo htmlspecialchars($building['comment'] ?? ''); ?></textarea>
|
||||
placeholder="Adresse, Besonderheiten, etc."><?php echo htmlspecialchars($building['comment'] ?? '); ?></textarea>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
@@ -172,9 +172,25 @@ $selectedLocationId = $building['location_id'] ?? $prefillLocationId;
|
||||
|
||||
<script>
|
||||
function confirmDelete(id) {
|
||||
if (confirm('Dieses Gebäude wirklich löschen? Alle Stockwerke werden gelöscht.')) {
|
||||
// TODO: AJAX-Delete implementieren
|
||||
alert('Löschen noch nicht implementiert');
|
||||
if (confirm('Dieses Gebaeude wirklich loeschen? Alle Stockwerke werden geloescht.')) {
|
||||
fetch('?module=buildings&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.status === 'ok') {
|
||||
window.location.href = '?module=buildings&action=list';
|
||||
return;
|
||||
}
|
||||
alert((data && data.error) ? data.error : 'Loeschen fehlgeschlagen');
|
||||
})
|
||||
.catch(() => {
|
||||
alert('Loeschen fehlgeschlagen');
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -8,17 +8,17 @@
|
||||
// =========================
|
||||
// Filter einlesen
|
||||
// =========================
|
||||
$search = trim($_GET['search'] ?? '');
|
||||
$search = trim($_GET['search'] ?? ');
|
||||
$locationId = (int)($_GET['location_id'] ?? 0);
|
||||
|
||||
// =========================
|
||||
// WHERE-Clause bauen
|
||||
// =========================
|
||||
$where = [];
|
||||
$types = '';
|
||||
$types = ';
|
||||
$params = [];
|
||||
|
||||
if ($search !== '') {
|
||||
if ($search !== ') {
|
||||
$where[] = "b.name LIKE ? OR b.comment LIKE ?";
|
||||
$types .= "ss";
|
||||
$params[] = "%$search%";
|
||||
@@ -70,7 +70,7 @@ $locations = $sql->get("SELECT id, name FROM locations ORDER BY name", "", []);
|
||||
<option value="">- Alle Standorte -</option>
|
||||
<?php foreach ($locations as $loc): ?>
|
||||
<option value="<?php echo $loc['id']; ?>"
|
||||
<?php echo $loc['id'] === $locationId ? 'selected' : ''; ?>>
|
||||
<?php echo $loc['id'] === $locationId ? 'selected' : '; ?>>
|
||||
<?php echo htmlspecialchars($loc['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
@@ -112,7 +112,7 @@ $locations = $sql->get("SELECT id, name FROM locations ORDER BY name", "", []);
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<small><?php echo htmlspecialchars($building['comment'] ?? ''); ?></small>
|
||||
<small><?php echo htmlspecialchars($building['comment'] ?? '); ?></small>
|
||||
</td>
|
||||
|
||||
<td class="actions">
|
||||
@@ -241,9 +241,24 @@ $locations = $sql->get("SELECT id, name FROM locations ORDER BY name", "", []);
|
||||
|
||||
<script>
|
||||
function confirmDelete(id) {
|
||||
if (confirm('Dieses Gebäude wirklich löschen?')) {
|
||||
// TODO: AJAX-Delete implementieren
|
||||
alert('Löschen noch nicht implementiert');
|
||||
if (confirm('Dieses Gebaeude wirklich loeschen?')) {
|
||||
fetch('?module=buildings&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.status === 'ok') {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
alert((data && data.error) ? data.error : 'Loeschen fehlgeschlagen');
|
||||
})
|
||||
.catch(() => {
|
||||
alert('Loeschen fehlgeschlagen');
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user