203 lines
7.7 KiB
PHP
203 lines
7.7 KiB
PHP
<?php
|
|
require_once('include/headscript.php');
|
|
require_once('class/SchoolMail.php');
|
|
|
|
/**
|
|
* Gestione lezione dal link dell'email di promemoria.
|
|
* GET: idbookingclass, token [+ action=cancel per confermare la cancellazione]
|
|
* Il token identifica la prenotazione; la scuola è quella della lezione
|
|
* (non quella selezionata in sessione).
|
|
*/
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
|
|
function e($v): string
|
|
{
|
|
return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
$id = (int) ($_GET['idbookingclass'] ?? 0);
|
|
$token = preg_replace('/[^a-zA-Z0-9\-]/', '', (string) ($_GET['token'] ?? ''));
|
|
|
|
$bk = null;
|
|
if ($id > 0 && $token !== '') {
|
|
$st = $pdo->prepare(
|
|
"SELECT bc.idbookingclass, bc.idschool, bc.iduser, bc.status,
|
|
ss.dateschedule, s.servicename, ob.expireon,
|
|
au.email, au.first_name
|
|
FROM bookingclass bc
|
|
JOIN serviceschedule ss ON ss.idserviceschedule = bc.idserviceschedule
|
|
LEFT JOIN service s ON s.idservice = bc.idservice
|
|
LEFT JOIN orderbook ob ON ob.idorderbook = bc.idorder
|
|
LEFT JOIN auth_users au ON au.id = bc.iduser
|
|
WHERE bc.idbookingclass = ? AND bc.cancellation_token = ?"
|
|
);
|
|
$st->execute([$id, $token]);
|
|
$bk = $st->fetch() ?: null;
|
|
}
|
|
|
|
$school = null;
|
|
if ($bk) {
|
|
$st = $pdo->prepare("SELECT * FROM schools WHERE idschool = ?");
|
|
$st->execute([(int) $bk['idschool']]);
|
|
$school = $st->fetch() ?: null;
|
|
}
|
|
|
|
$state = 'ask'; // ask | done | invalid | toolate
|
|
$message = '';
|
|
|
|
if (!$bk || !$school || $bk['status'] !== 'booked') {
|
|
$state = 'invalid';
|
|
} elseif (!BookingRules::canCancel($bk['dateschedule'])) {
|
|
$state = 'toolate';
|
|
} elseif (($_GET['action'] ?? '') === 'cancel') {
|
|
$upd = $pdo->prepare(
|
|
"UPDATE bookingclass SET status = 'cancelled'
|
|
WHERE idbookingclass = ? AND cancellation_token = ? AND status = 'booked'"
|
|
);
|
|
$upd->execute([$id, $token]);
|
|
|
|
if ($upd->rowCount() > 0) {
|
|
$lines = [
|
|
'La tua lezione <strong>' . e($bk['servicename'] ?: 'Lezione') . '</strong> del <strong>'
|
|
. date('d-m-Y H:i', strtotime($bk['dateschedule'])) . '</strong> è stata cancellata.',
|
|
];
|
|
if (!empty($bk['expireon'])) {
|
|
$lines[] = 'Ricordati di riprenotarla entro la scadenza del tuo pacchetto: <strong>' . date('d-m-Y', strtotime($bk['expireon'])) . '</strong>.';
|
|
}
|
|
SchoolMail::toStudent((string) $bk['email'], (string) $bk['first_name'], 'Lezione cancellata', $lines, '', $school, true);
|
|
}
|
|
$state = 'done';
|
|
}
|
|
|
|
$when = $bk ? date('d-m-Y H:i', strtotime($bk['dateschedule'])) : '';
|
|
$expiry = ($bk && !empty($bk['expireon'])) ? date('d-m-Y', strtotime($bk['expireon'])) : null;
|
|
$schName = $school['name'] ?? 'YogiBook';
|
|
$baseQs = 'idbookingclass=' . $id . '&token=' . urlencode($token);
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title><?php echo e($schName); ?> - Gestione lezione</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
|
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<style>
|
|
body {
|
|
background: #f5f6f8;
|
|
font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
|
|
}
|
|
|
|
.box {
|
|
max-width: 520px;
|
|
margin: 60px auto;
|
|
background: #fff;
|
|
border-radius: 16px;
|
|
box-shadow: 0 6px 26px rgba(0, 0, 0, .08);
|
|
padding: 32px 28px;
|
|
text-align: center;
|
|
}
|
|
|
|
.box h1 {
|
|
font-size: 22px;
|
|
font-weight: 700;
|
|
color: #1f2937;
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.school {
|
|
color: #9ca3af;
|
|
font-size: 13px;
|
|
text-transform: uppercase;
|
|
letter-spacing: .05em;
|
|
margin-bottom: 18px;
|
|
}
|
|
|
|
.lesson {
|
|
background: #f8fafc;
|
|
border-radius: 12px;
|
|
padding: 14px;
|
|
margin: 18px 0;
|
|
}
|
|
|
|
.lesson strong {
|
|
display: block;
|
|
font-size: 17px;
|
|
color: #1f2937;
|
|
}
|
|
|
|
.icon {
|
|
font-size: 40px;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.btn {
|
|
border-radius: 10px;
|
|
padding: 10px 20px;
|
|
font-weight: 600;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="box">
|
|
<div class="school"><?php echo e($schName); ?></div>
|
|
|
|
<?php if ($state === 'invalid') : ?>
|
|
<div class="icon" style="color:#e67e22;"><i class="fas fa-link-slash"></i></div>
|
|
<h1>Link non valido</h1>
|
|
<p class="text-muted">Il link non è valido oppure la lezione è già stata cancellata o spostata.</p>
|
|
|
|
<?php elseif ($state === 'toolate') : ?>
|
|
<div class="icon" style="color:#c0392b;"><i class="fas fa-clock"></i></div>
|
|
<h1>Cancellazione non più possibile</h1>
|
|
<div class="lesson"><strong><?php echo e($bk['servicename']); ?></strong><?php echo e($when); ?></div>
|
|
<p class="text-muted">Il termine per cancellare o spostare questa lezione è scaduto.</p>
|
|
|
|
<?php elseif ($state === 'done') : ?>
|
|
<div class="icon" style="color:#1ebf73;"><i class="fas fa-circle-check"></i></div>
|
|
<h1>Lezione cancellata</h1>
|
|
<div class="lesson"><strong><?php echo e($bk['servicename']); ?></strong><?php echo e($when); ?></div>
|
|
<?php if ($expiry) : ?>
|
|
<p>Ricordati di riprenotarla entro il <strong><?php echo e($expiry); ?></strong>.</p>
|
|
<?php endif; ?>
|
|
|
|
<?php else : ?>
|
|
<div class="icon" style="color:#2980b9;"><i class="fas fa-calendar-day"></i></div>
|
|
<h1>Cosa vuoi fare con questa lezione?</h1>
|
|
<div class="lesson"><strong><?php echo e($bk['servicename']); ?></strong><?php echo e($when); ?></div>
|
|
<?php if ($expiry) : ?>
|
|
<p class="text-muted" style="font-size:14px;">Pacchetto valido fino al <?php echo e($expiry); ?></p>
|
|
<?php endif; ?>
|
|
<div class="d-flex gap-2 justify-content-center flex-wrap mt-3">
|
|
<a href="rebook-from-cancel.php?<?php echo e($baseQs); ?>" class="btn btn-primary"><i class="fas fa-calendar-alt me-1"></i> Sposta la lezione</a>
|
|
<button type="button" class="btn btn-outline-danger" id="btn-cancel"><i class="fas fa-trash me-1"></i> Cancella la lezione</button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="mt-4"><a href="userpanel.php"><i class="fas fa-arrow-left me-1"></i> Vai alle tue lezioni</a></div>
|
|
</div>
|
|
|
|
<?php if ($state === 'ask') : ?>
|
|
<script>
|
|
document.getElementById('btn-cancel').addEventListener('click', function() {
|
|
Swal.fire({
|
|
title: 'Cancellare la lezione?',
|
|
html: <?php echo json_encode($expiry ? 'Ricordati di riprenotarla entro il <strong>' . $expiry . '</strong>.' : 'Potrai riprenotarla dal tuo pannello.'); ?>,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#d33',
|
|
confirmButtonText: 'Sì, cancella',
|
|
cancelButtonText: 'Annulla'
|
|
}).then(function(r) {
|
|
if (r.isConfirmed) window.location.replace('cancella-prenotazione.php?<?php echo $baseQs; ?>&action=cancel');
|
|
});
|
|
});
|
|
</script>
|
|
<?php endif; ?>
|
|
</body>
|
|
|
|
</html>
|