yogibook_aury_new/public/bookandgo.php
2025-10-15 20:59:49 +02:00

166 lines
6.2 KiB
PHP

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once('include/headscript.php');
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
// Abilita il reporting degli errori per il debug
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Recupera i parametri GET
$idorder = isset($_GET['idorder']) ? (int)$_GET['idorder'] : 0;
$idnewbooking = isset($_GET['idnewbooking']) ? (int)$_GET['idnewbooking'] : 0;
$iduser = isset($_GET['iduser']) ? (int)$_GET['iduser'] : 0;
$idservicenew = isset($_GET['idservicenew']) ? (int)$_GET['idservicenew'] : 0;
// Valida i parametri richiesti
if ($idorder === 0 || $idnewbooking === 0 || $iduser === 0 || $idservicenew === 0) {
die("Errore: Parametri mancanti.");
}
// Crea la connessione al database
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione al database fallita: " . $conn->connect_error);
}
// Recupera dateschedule e servicename
$query = "SELECT serviceschedule.dateschedule, service.servicename
FROM serviceschedule
LEFT JOIN service ON service.idservice = ?
WHERE serviceschedule.idserviceschedule = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $idservicenew, $idnewbooking);
$stmt->execute();
$resultnew = $stmt->get_result();
if ($resultnew->num_rows > 0) {
$rownew = $resultnew->fetch_assoc();
$newtime = $rownew['dateschedule'];
$servicename = $rownew['servicename'] ?? 'N/D';
} else {
$stmt->close();
$conn->close();
die("Errore: Nessun orario trovato per idserviceschedule = $idnewbooking.");
}
$stmt->close();
// Formatta la data per l'email
$newtimeformat = date("d-m-Y H:i", strtotime($newtime));
// Inserisce la nuova prenotazione in bookingclass
$insertQuery = "INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status)
VALUES (?, ?, '0', '0', ?, ?, ?, 'pending')";
$stmt = $conn->prepare($insertQuery);
$stmt->bind_param("iiiis", $idnewbooking, $iduser, $idservicenew, $idorder, $newtime);
if (!$stmt->execute()) {
$stmt->close();
$conn->close();
die("Errore durante l'inserimento della nuova prenotazione: " . $conn->error);
}
$stmt->close();
// Aggiorna una prenotazione cancellata a pending (se esiste)
$updateQuery = "UPDATE bookingclass
SET status = 'pending'
WHERE iduser = ? AND idorder = ? AND status = 'cancelled'
LIMIT 1";
$stmt = $conn->prepare($updateQuery);
$stmt->bind_param("ii", $iduser, $idorder);
$stmt->execute();
$stmt->close();
// Chiudi la connessione al database
$conn->close();
// Configura il contenuto dell'email
$messageedit = "
<p style='font-size: 14px; line-height: 190%;'>
<span style='font-size: 18px; line-height: 34.2px;'>
<strong>Ciao $firstname,</strong>
</span>
</p>
<p style='font-size: 14px; line-height: 190%;'>
<span style='font-size: 16px; line-height: 30.4px;'>
Hai inviato una richiesta di riprogrammazione della tua lezione per il servizio <strong>$servicename</strong>.
</span>
</p>
<p style='font-size: 14px; line-height: 190%;'>
<span style='font-size: 16px; line-height: 30.4px;'>
Ecco il dettaglio della riprogrammazione: $newtimeformat
</span>
</p>
<p style='font-size: 14px; line-height: 190%;'>
<span style='font-size: 16px; line-height: 30.4px;'>
La tua richiesta è in fase di accettazione! Verrai avvisata/o se la riprogrammazione è stata accettata.
</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:
<a href='https://yogibook.yogasoul.it'>YogiBook</a>
</span>
</p>
<br>
<p style='font-size: 14px; line-height: 190%;'>
<span style='font-size: 16px; line-height: 30.4px;'>
Per il primo accesso devi prima resettare la password cliccando qui:
</span>
</p>
<br>
<a href='https://yogibook.yogasoul.it/public/password/reset' target='_blank' style='box-sizing: border-box; display: inline-block; text-decoration: none; text-align: center; color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px; width: auto; max-width: 100%; font-size: 14px;'>
<span style='display: block; padding: 10px 20px; line-height: 120%;'>Reset Password</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; text-align: center; color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px; width: auto; max-width: 100%; font-size: 14px;'>
<span style='display: block; padding: 10px 20px; line-height: 120%;'>YogiBook - YogaSoul</span>
</a>";
// Integra $messageedit in $mailmessage1
include('mail/emailtemplate2.php');
// Configura l'email
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'mail.yogasoul.it';
$mail->SMTPAuth = true;
$mail->Username = 'info@yogasoul.it';
$mail->Password = '!Testolina88';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('info@yogasoul.it', 'YogiBook [YogaSoul]');
$mail->addAddress($emailuser);
$mail->Subject = "Proposta di riprogrammazione!";
$mail->Body = $mailmessage1;
$mail->AltBody = 'Hai inviato una richiesta di riprogrammazione della tua lezione per il servizio ' . $servicename . ' il ' . $newtimeformat . '. La tua richiesta è in fase di accettazione.';
$mail->send();
} catch (Exception $e) {
die("Errore durante l'invio dell'email: " . $mail->ErrorInfo);
}
// Esegui il reindirizzamento
header("Location: userpanel.php?reprogram=Y");
exit();