defekter floorplan
This commit is contained in:
55
app/modules/locations/delete.php
Normal file
55
app/modules/locations/delete.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* app/modules/locations/delete.php
|
||||
*
|
||||
* Loescht einen Standort.
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$locationId = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
|
||||
|
||||
if ($locationId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Ungueltige Standort-ID'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$location = $sql->single(
|
||||
"SELECT id, name FROM locations WHERE id = ?",
|
||||
"i",
|
||||
[$locationId]
|
||||
);
|
||||
|
||||
if (!$location) {
|
||||
http_response_code(404);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Standort nicht gefunden'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$deleted = $sql->set(
|
||||
"DELETE FROM locations WHERE id = ?",
|
||||
"i",
|
||||
[$locationId]
|
||||
);
|
||||
|
||||
if ($deleted <= 0) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Standort konnte nicht geloescht werden'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Standort geloescht'
|
||||
]);
|
||||
exit;
|
||||
@@ -403,8 +403,23 @@ foreach ($floors as $floor) {
|
||||
<script>
|
||||
function confirmDelete(id) {
|
||||
if (confirm('Diesen Standort wirklich löschen?')) {
|
||||
// TODO: AJAX-Delete implementieren
|
||||
alert('Löschen noch nicht implementiert');
|
||||
fetch('?module=locations&action=delete&id=' + encodeURIComponent(id), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data && data.success) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
alert((data && data.message) ? data.message : 'Löschen fehlgeschlagen');
|
||||
})
|
||||
.catch(() => {
|
||||
alert('Löschen fehlgeschlagen');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,3 +435,4 @@ function confirmFloorDelete(id) {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user