105 lines
4.6 KiB
PHP
105 lines
4.6 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
require_once __DIR__ . '/class/mailer.php';
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
/**
|
|
* Pannello Classi: cestino. Elimina una prenotazione (confermata, in attesa o in coda).
|
|
* Se era una richiesta in attesa (pending), cioè un rifiuto, avvisa l'allieva
|
|
* via email come rejectbookingclass.php. Per confermate e coda: nessuna email.
|
|
*/
|
|
$pdo = DBHandlerSelect::getInstance()->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 = "<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>";
|
|
$pc = "</span></p>";
|
|
|
|
// Variabili usate da mail/emailtemplate2.php
|
|
$messageedit = "<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 18px; line-height: 34.2px;'><strong><span style='line-height: 34.2px; font-size: 18px;'> Ciao $nome , </span></strong></span></p>"
|
|
. $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
|
|
. "<br>"
|
|
. $p . "Per vedere e gestire le tue lezioni clicca qui: https://yogibook.yogasoul.it " . $pc
|
|
. "<br>"
|
|
. $p . "Ci vediamo sul tappetino!" . $pc
|
|
. $p . "Il Team Yogasoul" . $pc;
|
|
|
|
$buttonedit = "<a href='https://yogibook.yogasoul.it/' target='_blank' class='v-button v-font-size' style='box-sizing: border-box;display: inline-block;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;font-size: 14px;'>
|
|
<span style='display:block;padding:10px 20px;line-height:120%;'><span style='line-height: 16.8px;'>YogiBook - YogaSoul</span></span>
|
|
</a>";
|
|
|
|
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;
|