115 lines
5.9 KiB
PHP
115 lines
5.9 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
require_once __DIR__ . '/class/mailer.php';
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
// Riusa la connessione già aperta da bkngstm.php
|
|
$conn = $bkngstm;
|
|
|
|
if (isset($_GET['idbookingclass'])) {
|
|
$idbookingclass = (int) $_GET['idbookingclass'];
|
|
|
|
// Recupera i dettagli della prenotazione per inviare la mail prima di cancellare il record
|
|
$query = "SELECT bookingclass.*, auth_users.*, service.*
|
|
FROM bookingclass
|
|
LEFT JOIN auth_users ON bookingclass.iduser = auth_users.id
|
|
LEFT JOIN service ON bookingclass.idservice = service.idservice
|
|
WHERE bookingclass.idbookingclass = $idbookingclass";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
if ($result) {
|
|
while ($row = $result->fetch_assoc()) {
|
|
$emailuser = $row['email'];
|
|
$firstname = $row['first_name'];
|
|
$newtime = $row['bookingstart'];
|
|
|
|
$newtimeformat = date("d-m-Y H:i", strtotime($newtime));
|
|
//mail to client
|
|
$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 $firstname , </span></strong></span></p>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Ci dispiace ma la tua richiesta di rirpogrammazione è stata rifiutata! </span></p>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Ecco la riprogrammazione rifiutata $newtimeformat</span></p>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Puoi collegarti al portale YogiBook come sotto riportato per programmare la tua lezione</span></p>
|
|
<br>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Per vedere e gestire le tue lezioni clicca qui: https://yogibook.yogasoul.it </span></p>
|
|
<br>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Se non ricordi la password o non hai sei mai entrata in Yogibbok, per prima cosa resettare la password cliccando di seguito</span></p>
|
|
<br>
|
|
<a href='https://yogibook.yogasoul.it/password/reset' 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;'>Reset Password</span></span>
|
|
</a>
|
|
<br>
|
|
<br>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Ci vediamo sul tappetino!</span></p>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Il Team Yogasoul</span></p>";
|
|
|
|
$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>";
|
|
|
|
|
|
$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';
|
|
|
|
|
|
include('mail/emailtemplate2.php');
|
|
// Email body content
|
|
|
|
//$trfnmbmail=$appformn.'r'.$revnumb;
|
|
$htmlContent = $mailmessage1;
|
|
|
|
|
|
$mail->From = $_ENV['MAIL_FROM_ADDRESS'];
|
|
$mail->FromName = $_ENV['MAIL_FROM_NAME'];
|
|
$mail->addAddress($emailuser); // Add a recipient
|
|
|
|
|
|
|
|
|
|
$mail->Subject = "YogiBook - Riprogrammazione rifiutata!";
|
|
$mail->Body = $htmlContent;
|
|
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
|
|
|
|
|
|
|
// Cancella comunque il record (il rifiuto va registrato a prescindere dalla mail)
|
|
$deleteQuery = "DELETE FROM bookingclass WHERE idbookingclass = ?";
|
|
$stmt = $conn->prepare($deleteQuery);
|
|
if ($stmt) {
|
|
$stmt->bind_param("i", $idbookingclass);
|
|
if (!$stmt->execute()) {
|
|
error_log("Errore cancellazione booking $idbookingclass: " . $stmt->error);
|
|
}
|
|
$stmt->close();
|
|
} else {
|
|
error_log("Errore preparazione delete booking: " . $conn->error);
|
|
}
|
|
|
|
// Prova a inviare la mail di rifiuto: se fallisce, logga ma non bloccare
|
|
try {
|
|
$mail->send();
|
|
} catch (Exception $e) {
|
|
error_log("Errore invio mail rifiuto (booking $idbookingclass): " . $mail->ErrorInfo);
|
|
}
|
|
|
|
// Reindirizza comunque
|
|
header("Location: pendingbookedclass.php");
|
|
exit();
|
|
}
|
|
} else {
|
|
echo "Errore durante l'esecuzione della query di recupero dei dettagli: " . $conn->error;
|
|
}
|
|
} else {
|
|
echo "Parametro 'idbookingclass' non trovato nella richiesta GET.";
|
|
}
|