fixed cancellata
This commit is contained in:
@@ -117,6 +117,7 @@ if ($classTime->format('Y-m-d') === $currentTime->format('Y-m-d')) {
|
||||
$idOrder = $bk['idorder'] !== null ? (int) $bk['idorder'] : null;
|
||||
$ord = null;
|
||||
$incremented = 'N';
|
||||
$ticketLost = false;
|
||||
|
||||
try {
|
||||
$conn->begin_transaction();
|
||||
@@ -132,9 +133,11 @@ try {
|
||||
|
||||
if ($ord) {
|
||||
if ((int) $ord['reprogrammed'] >= (int) $ord['maxreschedule']) {
|
||||
throw new RuntimeException('limit');
|
||||
// Limite raggiunto: può cancellare (libera il posto) ma il ticket va perso
|
||||
$ticketLost = true;
|
||||
} else {
|
||||
$incremented = 'Y';
|
||||
}
|
||||
$incremented = 'Y';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +153,8 @@ try {
|
||||
FROM bookingclass
|
||||
WHERE idbookingclass = ? AND iduser = ?
|
||||
");
|
||||
$stmt->bind_param("isii", $userId, $incremented, $id, $userId);
|
||||
$storicoFlag = $ticketLost ? 'L' : $incremented;
|
||||
$stmt->bind_param("isii", $userId, $storicoFlag, $id, $userId);
|
||||
$stmt->execute();
|
||||
$copied = $stmt->affected_rows;
|
||||
$stmt->close();
|
||||
@@ -166,8 +170,14 @@ try {
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// Eliminazione della prenotazione
|
||||
$stmt = $conn->prepare("DELETE FROM bookingclass WHERE idbookingclass = ? AND iduser = ?");
|
||||
// Limite raggiunto: la prenotazione resta come persa (status 'lost'),
|
||||
// il posto in sala si libera ma il ticket non torna da programmare.
|
||||
// Altrimenti eliminazione normale: il ticket torna disponibile.
|
||||
if ($ticketLost) {
|
||||
$stmt = $conn->prepare("UPDATE bookingclass SET status = 'lost', lostlesson = 'Y' WHERE idbookingclass = ? AND iduser = ?");
|
||||
} else {
|
||||
$stmt = $conn->prepare("DELETE FROM bookingclass WHERE idbookingclass = ? AND iduser = ?");
|
||||
}
|
||||
$stmt->bind_param("ii", $id, $userId);
|
||||
$stmt->execute();
|
||||
$deleted = $stmt->affected_rows;
|
||||
@@ -245,7 +255,8 @@ try {
|
||||
$mail->Body = "
|
||||
<div style='font-family:Arial,sans-serif;font-size:14px;color:#222'>
|
||||
<p>Ciao " . htmlspecialchars($userName ?: 'Yogi') . ",</p>
|
||||
<p>La tua lezione è stata <b>cancellata</b>.</p>
|
||||
<p>La tua lezione è stata <b>cancellata</b>.</p>" . ($ticketLost ? "
|
||||
<p>Avendo già usato tutte le riprogrammazioni del pacchetto, questa lezione non potrà essere recuperata.</p>" : "") . "
|
||||
<p>
|
||||
<b>Lezione:</b> " . htmlspecialchars($className) . "<br>
|
||||
<b>Data/ora prevista:</b> " . htmlspecialchars($classDateTxt) . "<br>
|
||||
@@ -265,5 +276,5 @@ try {
|
||||
}
|
||||
|
||||
// Redirect
|
||||
header("Location: userpanel.php?deleted=1");
|
||||
header("Location: userpanel.php?deleted=" . ($ticketLost ? 'lost' : '1'));
|
||||
exit();
|
||||
|
||||
Reference in New Issue
Block a user