getConnection(); $idbookingclass = isset($_GET['idbookingclass']) ? (int) $_GET['idbookingclass'] : 0; $bk = null; $deleted = false; if ($idbookingclass > 0) { try { // Dati letti prima di eliminare (servono per l'email) $stmt = $pdo->prepare( "SELECT bc.status, bc.prevbookingstart, bc.bookingstart, u.first_name, u.email, s.servicename FROM bookingclass bc LEFT JOIN auth_users u ON u.id = bc.iduser LEFT JOIN service s ON s.idservice = bc.idservice WHERE bc.idbookingclass = :id" ); $stmt->execute([':id' => $idbookingclass]); $bk = $stmt->fetch(PDO::FETCH_ASSOC); if ($bk) { $stmt = $pdo->prepare("DELETE FROM bookingclass WHERE idbookingclass = :id"); $stmt->execute([':id' => $idbookingclass]); $deleted = ($stmt->rowCount() === 1); } } catch (Throwable $ex) { error_log('removebooking error (booking ' . $idbookingclass . '): ' . $ex->getMessage()); } } // ---- Email solo se è stata rifiutata una richiesta in attesa ---- if ($deleted && $bk['status'] === 'pending' && !empty($bk['email'])) { $nome = htmlspecialchars((string) $bk['first_name'], ENT_QUOTES, 'UTF-8'); $classe = htmlspecialchars((string) ($bk['servicename'] ?? ''), ENT_QUOTES, 'UTF-8'); $quando = date('d-m-Y H:i', strtotime($bk['bookingstart'])); if (!empty($bk['prevbookingstart'])) { $subject = 'YogiBook - Riprogrammazione rifiutata!'; $intro = 'Ci dispiace ma la tua richiesta di riprogrammazione è stata rifiutata!'; } else { $subject = 'YogiBook - Prenotazione rifiutata!'; $intro = 'Ci dispiace ma la tua richiesta di prenotazione è stata rifiutata!'; } $p = "

"; $pc = "

"; // Variabili usate da mail/emailtemplate2.php $messageedit = "

Ciao $nome ,

" . $p . $intro . $pc . $p . "Lezione richiesta: $classe del $quando" . $pc . $p . "Puoi collegarti al portale YogiBook come sotto riportato per programmare la tua lezione" . $pc . "
" . $p . "Per vedere e gestire le tue lezioni clicca qui: https://yogibook.yogasoul.it " . $pc . "
" . $p . "Ci vediamo sul tappetino!" . $pc . $p . "Il Team Yogasoul" . $pc; $buttonedit = " YogiBook - YogaSoul "; try { include('mail/emailtemplate2.php'); // crea $mailmessage1 $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = $_ENV['MAIL_HOST']; $mail->SMTPAuth = true; $mail->Username = $_ENV['MAIL_USERNAME']; $mail->Password = $_ENV['MAIL_PASSWORD']; $mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION']; $mail->Port = (int) $_ENV['MAIL_PORT']; $mail->CharSet = 'UTF-8'; $mail->From = $_ENV['MAIL_FROM_ADDRESS']; $mail->FromName = $_ENV['MAIL_FROM_NAME']; $mail->addAddress($bk['email']); $mail->isHTML(true); $mail->Subject = $subject; $mail->Body = $mailmessage1; $mail->AltBody = $intro . ' Lezione richiesta: ' . ($bk['servicename'] ?? '') . ' del ' . $quando; $mail->send(); } catch (Throwable $ex) { error_log('removebooking mail (booking ' . $idbookingclass . '): ' . $ex->getMessage()); } } header("Location: adminpanel.php"); exit;