getConnection(); $id = (int) ($_GET['idbookingclass'] ?? 0); $token = preg_replace('/[^a-zA-Z0-9\-]/', '', (string) ($_GET['token'] ?? '')); $st = $pdo->prepare( "SELECT idbookingclass, idschool, iduser FROM bookingclass WHERE idbookingclass = ? AND cancellation_token = ? AND status = 'booked'" ); $st->execute([$id, $token]); $bk = ($id > 0 && $token !== '') ? $st->fetch() : null; if (!$bk || (int) $bk['iduser'] !== (int) $iduserlogin) { header('Location: userpanel.php?bookerror=order'); exit; } // La lezione può essere di un'altra scuola dell'utente: passa a quella if ((int) $bk['idschool'] !== $idschool) { SchoolContext::switchTo((int) $bk['idschool']); } header('Location: bookingpanel.php?id=' . (int) $bk['idbookingclass']); exit;