feat: complete package 2 delete flows and package 3 port management
This commit is contained in:
@@ -2,30 +2,48 @@
|
||||
/**
|
||||
* app/modules/floor_infrastructure/delete.php
|
||||
*
|
||||
* Loescht Patchpanels oder Wandbuchsen.
|
||||
* Loescht Patchpanels oder Wandbuchsen (AJAX-POST bevorzugt).
|
||||
*/
|
||||
|
||||
$type = strtolower(trim((string)($_GET['type'] ?? '')));
|
||||
$id = (int)($_GET['id'] ?? 0);
|
||||
$isPost = ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST';
|
||||
$type = strtolower(trim((string)($_POST['type'] ?? $_GET['type'] ?? '')));
|
||||
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
|
||||
|
||||
if ($id <= 0 || !in_array($type, ['patchpanel', 'outlet'], true)) {
|
||||
if ($isPost) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Ungueltige Anfrage']);
|
||||
exit;
|
||||
}
|
||||
header('Location: ?module=floor_infrastructure&action=list');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($type === 'patchpanel') {
|
||||
$sql->set(
|
||||
$rows = $sql->set(
|
||||
"DELETE FROM floor_patchpanels WHERE id = ?",
|
||||
"i",
|
||||
[$id]
|
||||
);
|
||||
} else {
|
||||
$sql->set(
|
||||
$rows = $sql->set(
|
||||
"DELETE FROM network_outlets WHERE id = ?",
|
||||
"i",
|
||||
[$id]
|
||||
);
|
||||
}
|
||||
|
||||
if ($isPost) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
if ($rows > 0) {
|
||||
echo json_encode(['success' => true, 'message' => 'Infrastrukturobjekt geloescht']);
|
||||
} else {
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'message' => 'Infrastrukturobjekt nicht gefunden oder bereits geloescht']);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Location: ?module=floor_infrastructure&action=list');
|
||||
exit;
|
||||
|
||||
@@ -180,7 +180,14 @@ if ($editorFloor) {
|
||||
<td><?php echo (int)$panel['port_count']; ?></td>
|
||||
<td class="actions">
|
||||
<a href="?module=floor_infrastructure&action=edit&type=patchpanel&id=<?php echo (int)$panel['id']; ?>" class="button button-small">Bearbeiten</a>
|
||||
<a href="?module=floor_infrastructure&action=delete&type=patchpanel&id=<?php echo (int)$panel['id']; ?>" class="button button-small button-danger" onclick="return confirm('Patchpanel wirklich loeschen?');">Loeschen</a>
|
||||
<button
|
||||
type="button"
|
||||
class="button button-small button-danger js-floor-infra-delete"
|
||||
data-delete-id="<?php echo (int)$panel['id']; ?>"
|
||||
data-delete-type="patchpanel"
|
||||
data-delete-label="<?php echo htmlspecialchars((string)$panel['name'], ENT_QUOTES, 'UTF-8'); ?>">
|
||||
Loeschen
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -226,7 +233,14 @@ if ($editorFloor) {
|
||||
<td><?php echo htmlspecialchars((string)($outlet['comment'] ?? '')); ?></td>
|
||||
<td class="actions">
|
||||
<a href="?module=floor_infrastructure&action=edit&type=outlet&id=<?php echo (int)$outlet['id']; ?>" class="button button-small">Bearbeiten</a>
|
||||
<a href="?module=floor_infrastructure&action=delete&type=outlet&id=<?php echo (int)$outlet['id']; ?>" class="button button-small button-danger" onclick="return confirm('Wandbuchse wirklich loeschen?');">Loeschen</a>
|
||||
<button
|
||||
type="button"
|
||||
class="button button-small button-danger js-floor-infra-delete"
|
||||
data-delete-id="<?php echo (int)$outlet['id']; ?>"
|
||||
data-delete-type="outlet"
|
||||
data-delete-label="<?php echo htmlspecialchars((string)$outlet['name'], ENT_QUOTES, 'UTF-8'); ?>">
|
||||
Loeschen
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -237,3 +251,38 @@ if ($editorFloor) {
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('.js-floor-infra-delete').forEach((button) => {
|
||||
button.addEventListener('click', () => {
|
||||
const id = Number(button.dataset.deleteId || '0');
|
||||
const type = (button.dataset.deleteType || '').trim();
|
||||
const label = button.dataset.deleteLabel || 'Objekt';
|
||||
if (id <= 0 || (type !== 'patchpanel' && type !== 'outlet')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entityLabel = type === 'patchpanel' ? 'Patchpanel' : 'Wandbuchse';
|
||||
if (!confirm(entityLabel + ' "' + label + '" wirklich loeschen?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('?module=floor_infrastructure&action=delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
||||
body: 'id=' + encodeURIComponent(id) + '&type=' + encodeURIComponent(type)
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data && data.success) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
||||
})
|
||||
.catch(() => alert('Loeschen fehlgeschlagen'));
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user