| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/clients/client1/seaside.pacim.de/web/ |
Upload File : |
<?php die(); ?><!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Invoice ID Löschen</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<div class="container mt-5">
<h2 class="text-center">Invoice ID Löschen</h2>
<form id="invoiceForm" method="post" onsubmit="return confirm('Datensätze wirklich löschen?');" class="border p-4 bg-light">
<div class="form-group">
<label for="invoice_id">Gebe die Invoice ID ein:</label>
<input type="text" class="form-control" id="invoice_id" name="invoice_id" placeholder="z.B. 12345" required>
</div>
<button type="submit" class="btn btn-danger">
Datensätze Löschen
</button>
</form>
<div id="message" class="mt-3"></div>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty(trim($_POST['invoice_id']))) {
require_once 'includes/config.inc.php';
$invoice_id = trim($_POST['invoice_id']);
$db = new MysqliDb(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
$db->startTransaction();
try {
/*
* Erst Kunden-IDs sichern,
* bevor pacim_booking gelöscht wird.
*/
$customerIds = $db
->where('booking_invoice', $invoice_id)
->getValue('pacim_booking', 'booking_customer', null);
if (!is_array($customerIds)) {
$customerIds = array();
}
$customerIds = array_filter(array_unique($customerIds));
/*
* Rechnung löschen
*/
$db->where('invoice_id', $invoice_id)
->delete('pacim_invoice');
/*
* Rechnungspositionen löschen
*/
$db->where('invoice_id', $invoice_id)
->delete('pacim_invoice_pos');
/*
* Buchungen löschen
*/
$db->where('booking_invoice', $invoice_id)
->delete('pacim_booking');
/*
* Zahlungen löschen
*/
$db->where('payment_invoice', $invoice_id)
->delete('pacim_payments');
/*
* Kunden löschen,
* aber nur wenn diese nach dem Löschen
* keine weiteren Buchungen mehr haben.
*/
foreach ($customerIds as $customerId) {
$remainingBookings = $db
->where('booking_customer', $customerId)
->getValue('pacim_booking', 'COUNT(*)');
if ((int)$remainingBookings === 0) {
$db->where('customer_id', $customerId)
->delete('pacim_customer');
}
}
$db->commit();
echo "<script>
$(document).ready(function() {
$('#message').html('<div class=\"alert alert-success\">Datensätze inklusive nicht mehr verwendeter Kunden erfolgreich gelöscht.</div>');
});
</script>";
} catch (Exception $e) {
$db->rollback();
$errorMessage = htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
echo "<script>
$(document).ready(function() {
$('#message').html('<div class=\"alert alert-danger\">Fehler beim Löschen: " . $errorMessage . "</div>');
});
</script>";
}
}
?>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>