diff --git a/public/acceptbookingclass.php b/public/acceptbookingclass.php index 35e4ea9..489652a 100644 --- a/public/acceptbookingclass.php +++ b/public/acceptbookingclass.php @@ -1,17 +1,18 @@ - Ciao $firstname ,

@@ -65,20 +64,21 @@ if (isset($_GET['idbookingclass'])) { $mail = new PHPMailer(true); - $mail->isSMTP(); // Set mailer to use SMTP - $mail->Host = 'mail.yogasoul.it'; // Specify main and backup server - $mail->SMTPAuth = true; // Enable SMTP authentication - $mail->Username = 'info@yogasoul.it'; // SMTP username - $mail->Password = '!Testolina88'; // SMTP password - $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted - $mail->Port = '587'; + $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']; // ssl + $mail->Port = (int) $_ENV['MAIL_PORT']; // 465 + $mail->CharSet = 'UTF-8'; include('mail/emailtemplate2.php'); // Email body content $htmlContent = $mailmessage1; - $mail->From = 'info@yogasoul.it'; - $mail->FromName = 'YogiBook [YogaSoul]'; + $mail->From = $_ENV['MAIL_FROM_ADDRESS']; + $mail->FromName = $_ENV['MAIL_FROM_NAME']; $mail->addAddress($emailuser); // Add a recipient $mail->Subject = "YogiBook - Lezione riprogrammata con successo!"; @@ -104,7 +104,3 @@ if (isset($_GET['idbookingclass'])) { } else { echo "Parametro 'idbookingclass' non trovato nella richiesta GET."; } - -// Chiudi la connessione al database -$conn->close(); -?> \ No newline at end of file diff --git a/public/bookandgo.php b/public/bookandgo.php index 06a1cb3..6ef04b6 100644 --- a/public/bookandgo.php +++ b/public/bookandgo.php @@ -1,33 +1,23 @@ connect_error) { - die("Connessione al database fallita: " . $conn->connect_error); -} +// Riusa la connessione già aperta da bkngstm.php +$conn = $bkngstm; // Recupera dateschedule e servicename $query = "SELECT serviceschedule.dateschedule, service.servicename @@ -45,7 +35,6 @@ if ($resultnew->num_rows > 0) { $servicename = $rownew['servicename'] ?? 'N/D'; } else { $stmt->close(); - $conn->close(); die("Errore: Nessun orario trovato per idserviceschedule = $idnewbooking."); } $stmt->close(); @@ -53,6 +42,19 @@ $stmt->close(); // Formatta la data per l'email $newtimeformat = date("d-m-Y H:i", strtotime($newtime)); +// Recupera nome ed email dell'utente per la mail +$firstname = ''; +$emailuser = ''; +$stmtUser = $conn->prepare("SELECT first_name, email FROM auth_users WHERE id = ?"); +$stmtUser->bind_param("i", $iduser); +$stmtUser->execute(); +$resUser = $stmtUser->get_result(); +if ($rowUser = $resUser->fetch_assoc()) { + $firstname = $rowUser['first_name'] ?? ''; + $emailuser = $rowUser['email'] ?? ''; +} +$stmtUser->close(); + // Inserisce la nuova prenotazione in bookingclass $insertQuery = "INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status) VALUES (?, ?, '0', '0', ?, ?, ?, 'pending')"; @@ -60,7 +62,6 @@ $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(); @@ -75,8 +76,13 @@ $stmt->bind_param("ii", $iduser, $idorder); $stmt->execute(); $stmt->close(); -// Chiudi la connessione al database -$conn->close(); +// Connessione $bkngstm gestita globalmente: non la chiudiamo qui + +// Se non abbiamo un'email valida, salta l'invio ma completa comunque il flusso +if ($emailuser === '') { + header("Location: userpanel.php?reprogram=Y"); + exit(); +} // Configura il contenuto dell'email $messageedit = " @@ -141,23 +147,24 @@ include('mail/emailtemplate2.php'); $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->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->setFrom('info@yogasoul.it', 'YogiBook [YogaSoul]'); + $mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']); $mail->addAddress($emailuser); $mail->Subject = "Proposta di riprogrammazione!"; - $mail->Body = $mailmessage1; + $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); + // La prenotazione è già salvata: logghiamo l'errore mail ma non blocchiamo l'utente + error_log("Errore invio mail riprogrammazione (iduser $iduser): " . $mail->ErrorInfo); } // Esegui il reindirizzamento diff --git a/public/cancella-prenotazione.php b/public/cancella-prenotazione.php index 390e563..9261c96 100644 --- a/public/cancella-prenotazione.php +++ b/public/cancella-prenotazione.php @@ -1,20 +1,13 @@ connect_error) { - die("Connessione al database fallita: " . $conn->connect_error); -} - +// Riusa la connessione già aperta da bkngstm.php +$conn = $bkngstm; // Inizializza log $logFile = 'cancella_prenotazione_log.txt'; $logMessage = "Esecuzione cancellazione: " . date('Y-m-d H:i:s') . "\n"; @@ -47,7 +40,7 @@ if (!$idbookingclass) { // Verifica validità: token corrisponde, lezione futura $query = "SELECT bc.*, ob.expireon, au.email, au.first_name, s.servicename FROM bookingclass bc - LEFT JOIN orderbook ob ON bc.idorder = ob.order_id + LEFT JOIN orderbook ob ON bc.idorder = ob.idorderbook LEFT JOIN auth_users au ON bc.iduser = au.id LEFT JOIN service s ON bc.idservice = s.idservice WHERE bc.idbookingclass = ? @@ -176,19 +169,15 @@ if (isset($_GET['action']) && $_GET['action'] === 'cancel') { YogiBook - YogaSoul "; - require_once 'phpmailer/src/Exception.php'; - require_once 'phpmailer/src/PHPMailer.php'; - require_once 'phpmailer/src/SMTP.php'; - $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->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']; if (!file_exists('mail/emailtemplate2.php')) { throw new Exception("File emailtemplate2.php non trovato."); @@ -201,8 +190,8 @@ if (isset($_GET['action']) && $_GET['action'] === 'cancel') { $htmlContent = str_replace('{message}', $messagecancel, $mailmessage1); - $mail->From = 'info@yogasoul.it'; - $mail->FromName = 'YogiBook [YogaSoul]'; + $mail->From = $_ENV['MAIL_FROM_ADDRESS']; + $mail->FromName = $_ENV['MAIL_FROM_NAME']; $mail->addAddress($emailuser); $mail->Subject = "YogiBook - Lezione cancellata con successo!"; $mail->Body = $htmlContent; @@ -314,5 +303,5 @@ file_put_contents($logFile, $logMessage, FILE_APPEND); close(); -$conn->close(); +// Connessione $bkngstm gestita globalmente: non la chiudiamo qui ?> \ No newline at end of file diff --git a/public/class/mailer.php b/public/class/mailer.php index 6f86010..e15050f 100644 --- a/public/class/mailer.php +++ b/public/class/mailer.php @@ -1,14 +1,10 @@ load(); - -error_log("✅ Variabili .env caricate: " . print_r($_ENV, true)); diff --git a/public/delete_lesson.php b/public/delete_lesson.php index 278077f..49973f3 100644 --- a/public/delete_lesson.php +++ b/public/delete_lesson.php @@ -30,10 +30,7 @@ $userId = (int)$iduserlogin; /*********************** * DB ***********************/ -$conn = new mysqli($servername, $username, $password, $dbname); -if ($conn->connect_error) { - die("Connessione fallita: " . $conn->connect_error); -} +$conn = $bkngstm; /*********************** * 1) USER INFO (auth_users) @@ -69,7 +66,6 @@ $bk = $res->fetch_assoc(); $stmt->close(); if (!$bk) { - $conn->close(); header("Location: userpanel.php?deleted=0&err=notfound"); exit(); } @@ -89,12 +85,11 @@ $stmt->bind_param("ii", $id, $userId); if (!$stmt->execute()) { $err = $stmt->error; $stmt->close(); - $conn->close(); die("Errore durante la cancellazione del record: " . htmlspecialchars($err)); } $stmt->close(); -$conn->close(); +// Connessione $bkngstm gestita globalmente: non la chiudiamo qui /*********************** * 4) EMAIL (TO utente + CC info@yogasoul.it) diff --git a/public/emailsend.php b/public/emailsend.php index efe05e0..b410e3b 100644 --- a/public/emailsend.php +++ b/public/emailsend.php @@ -1,51 +1,36 @@ 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->isHTML(true); -$mail->isSMTP(); // Set mailer to use SMTP -$mail->Host = 'mail.yogasoul.it'; // Specify main and backup server -$mail->SMTPAuth = true; // Enable SMTP authentication -$mail->Username = 'info@yogasoul.it'; // SMTP username -$mail->Password = '!Testolina88'; // SMTP password -$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted -$mail->Port = '587'; - + include('mail/emailtemplate2.php'); + $htmlContent = $mailmessage1; -include('mail/emailtemplate2.php'); -// Email body content + $mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']); + $mail->addAddress('info@claudiosironi.com'); -//$trfnmbmail=$appformn.'r'.$revnumb; -$htmlContent = $mailmessage1; - - -$mail->From = 'info@yogasoul.it'; -$mail->FromName = 'YogiBook [YogaSoul]'; -$mail->addAddress('info@claudiosironi.com'); // Add a recipient - - - - -$mail->Subject = 'Comunicazione YogiBook'; -$mail->Body = $htmlContent; -$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + $mail->Subject = 'Comunicazione YogiBook'; + $mail->Body = $htmlContent; + $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); - // echo 'Message has been sent'; - -?> \ No newline at end of file + echo 'Message has been sent'; +} catch (Exception $e) { + error_log("Errore invio mail (emailsend): " . $mail->ErrorInfo); + echo 'Invio non riuscito'; +} diff --git a/public/mail/emailtemplate2.php b/public/mail/emailtemplate2.php index f29c9b2..44b3f85 100644 --- a/public/mail/emailtemplate2.php +++ b/public/mail/emailtemplate2.php @@ -1,4 +1,4 @@ - + - +
@@ -157,7 +157,7 @@ table, td { color: #000000; } #u_body a { color: #0000ee; text-decoration: under
- + @@ -120,7 +120,7 @@ table, td { color: #000000; } #u_body a { color: #0000ee; text-decoration: under
- Logo + Logo
- - - - - - - - - @@ -272,7 +252,7 @@ $messageedit - border + border @@ -320,7 +300,7 @@ $messageedit
- Instagram + Instagram
@@ -330,7 +310,7 @@ $messageedit
- Facebook + Facebook
@@ -372,10 +352,9 @@ $messageedit
-

Queste mail ti sono inviate solo come promemoria
delle lezioni da te acquistate su Yogasoul.it

-

Puoi comunque decidere di cancellarti cliccando qui.

-

 

-

© 2023 YogaSoul  All Rights Reserved.
www.yogasoul.it - info@yogasoul.it

+

Questa è una email di servizio relativa alle lezioni acquistate su Yogasoul.it e alla gestione delle tue prenotazioni.

+

+

© 2023 YogaSoul All Rights Reserved.
www.yogasoul.it - info@yogasoul.it

@@ -396,49 +375,6 @@ $messageedit -
-
-
- - - -
-
-
- - - - - - - -
- - - - - -
- - border - -
- -
- -
-
-
- - -
-
-
- - - - -
@@ -489,4 +425,4 @@ $messageedit -"; ?> +"; diff --git a/public/notificationmail.php b/public/notificationmail.php index 8cf32e1..9ea8fc6 100644 --- a/public/notificationmail.php +++ b/public/notificationmail.php @@ -1,14 +1,12 @@ - query($sql); - //send email to teacher - - require 'phpmailer/src/Exception.php'; -require 'phpmailer/src/PHPMailer.php'; -require 'phpmailer/src/SMTP.php'; +//send email to teacher - - //mail to client +//mail to client $mail = new PHPMailer(true); -$mail->isSMTP(); // Set mailer to use SMTP -$mail->Host = 'mail.yogasoul.it'; // Specify main and backup server -$mail->SMTPAuth = true; // Enable SMTP authentication -$mail->Username = 'info@yogasoul.it'; // SMTP username -$mail->Password = '!Testolina88'; // SMTP password -$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted -$mail->Port = '587'; - +$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 sent +//mail sent -$messageedit="

Ciao Aurora ,

+$messageedit = "

Ciao Aurora ,

Di seguito riepilogo delle tue lezioni di domani $nextDay

"; if ($result->num_rows > 0) { // Ci sono record, inizializza la variabile $buttonedit @@ -65,7 +58,7 @@ if ($result->num_rows > 0) { FROM bookingclass LEFT JOIN auth_users ON bookingclass.iduser = auth_users.id WHERE bookingclass.idserviceschedule = '$idserviceschedule'"; - + $participantResult = $conn->query($participantQuery); if ($participantResult->num_rows > 0) { @@ -78,40 +71,37 @@ if ($result->num_rows > 0) { $buttonedit .= ""; } $buttonedit .= ""; - + // Conta il numero di partecipanti $numPartecipanti = $participantResult->num_rows; - + // Aggiungi l'ultima riga con il numero di posti e maxcapacity - $buttonedit .= "Partecipanti: $numPartecipanti / " . $row["maxcapacity"] . "

"; - - - + $buttonedit .= "Partecipanti: $numPartecipanti / " . $row["maxcapacity"] . "

"; } else { // Nessun partecipante trovato $buttonedit .= "Nessun partecipante per questa classe."; } } - - include('mail/emailtemplate2.php'); -// Email body content -//$trfnmbmail=$appformn.'r'.$revnumb; -$htmlContent = $mailmessage1; - - -$mail->From = 'info@yogasoul.it'; -$mail->FromName = 'YogiBook [YogaSoul]'; -$mail->addAddress('info@yogasoul.it'); // Add a recipient - + include('mail/emailtemplate2.php'); + // Email body content - + //$trfnmbmail=$appformn.'r'.$revnumb; + $htmlContent = $mailmessage1; -$mail->Subject = "YogiBook - Lezioni di domani $nextDay"; -$mail->Body = $htmlContent; -$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; -$mail->send(); + $mail->From = $_ENV['MAIL_FROM_ADDRESS']; + $mail->FromName = $_ENV['MAIL_FROM_NAME']; + $mail->addAddress('info@yogasoul.it'); // riepilogo alla teacher + + + + + $mail->Subject = "YogiBook - Lezioni di domani $nextDay"; + $mail->Body = $htmlContent; + $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + + $mail->send(); } else { // Nessun record trovato $buttonedit = "Non ci sono record per il giorno successivo."; @@ -119,14 +109,13 @@ $mail->send(); - -// Chiudi la connessione al database -$conn->close(); + +// Connessione $bkngstm condivisa: non la chiudiamo qui ?> query($sql); if ($result->num_rows > 0) { // Stampa dei risultati while ($row = $result->fetch_assoc()) { - $servicename = $row["servicename"]; + $servicename = $row["servicename"]; $formatted_date = $row["formatted_date"]; $first_name = $row["first_name"]; $email = $row["email"]; - //send email to users - + //send email to users - //mail to client -$mail = new PHPMailer(true); + //mail to client -$mail->isSMTP(); // Set mailer to use SMTP -$mail->Host = 'premium60.web-hosting.com'; // Specify main and backup server -$mail->SMTPAuth = true; // Enable SMTP authentication -$mail->Username = 'info@yogasoul.it'; // SMTP username -$mail->Password = '!Testolina88'; // SMTP password -$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted -$mail->Port = '587'; - + $mail = new PHPMailer(true); -$messageedit="

Ciao $first_name ,

+ $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'; + + + $messageedit = "

Ciao $first_name ,

Eccoti un promemoria per ricordarti la tua prossima lezione di '$servicename' del $formatted_date .

"; -$buttonedit=" + $buttonedit = " YogiBook - YogaSoul "; - include('mail/emailtemplate2.php'); -// Email body content + include('mail/emailtemplate2.php'); + // Email body content -//$trfnmbmail=$appformn.'r'.$revnumb; -$htmlContent = $mailmessage1; - - -$mail->From = 'info@yogasoul.it'; -$mail->FromName = 'YogiBook [YogaSoul]'; -$mail->addAddress($email); // Add a recipient - + //$trfnmbmail=$appformn.'r'.$revnumb; + $htmlContent = $mailmessage1; - -$mail->Subject = "YogiBook - Promemoria lezione di domani $nextDay"; -$mail->Body = $htmlContent; -$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + $mail->From = $_ENV['MAIL_FROM_ADDRESS']; + $mail->FromName = $_ENV['MAIL_FROM_NAME']; + $mail->addAddress($email); // promemoria all'utente + + + + + $mail->Subject = "YogiBook - Promemoria lezione di domani $nextDay"; + $mail->Body = $htmlContent; + $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + + $mail->send(); -$mail->send(); - echo "Nome evento: " . $servicename . "
"; echo "Data e ora: " . $formatted_date . "
"; echo "Nome allievo: " . $first_name . "
"; @@ -207,7 +197,6 @@ $mail->send(); echo "Nessun risultato trovato."; } -$conn->close(); ?> diff --git a/public/orderpropagate.php b/public/orderpropagate.php index 6696ea5..290b101 100644 --- a/public/orderpropagate.php +++ b/public/orderpropagate.php @@ -1,25 +1,13 @@ - -connect_error) { - die("Connessione fallita: " . $conn->connect_error); -} +// Riusa la connessione già aperta da bkngstm.php +$conn = $bkngstm; // Seleziona i record con status 'pending' dalla tabella orderbook $select_query = "SELECT * FROM orderbook WHERE status = 'pending'"; @@ -34,9 +22,9 @@ if ($result->num_rows > 0) { $service_id = $row["idservice"]; $quantity_class = $row["quantityclass"]; $ordern = $row["order_id"]; - + echo "Elaborazione record con ID: $order_id, Service ID: $service_id\n"; - + $user_query = "SELECT id FROM auth_users WHERE email = '$billing_email'"; $user_result = $conn->query($user_query); @@ -47,7 +35,7 @@ if ($result->num_rows > 0) { $update_query = "UPDATE orderbook SET iduser = '$user_id' WHERE idorderbook = '$order_id'"; $conn->query($update_query); } else { - // Genera una password casuale e crea l'hash + // Genera una password casuale e crea l'hash $password = "YogiBook159"; // La password casuale $hashed_password = password_hash($password, PASSWORD_DEFAULT); // Inserisci un nuovo utente in auth_users @@ -80,73 +68,73 @@ $service_schedule_result = $conn->query($service_schedule_query); if ($service_schedule_result->num_rows > 0) { echo "Record per l'ordine ID: $order_id\n"; - - $inserted_count = 0; // Numero di inserimenti effettuati con successo - + + $inserted_count = 0; // Numero di inserimenti effettuati con successo + while ($schedule_row = $service_schedule_result->fetch_assoc()) { - - if ($inserted_count >= $quantity_class) { - break; // Se il numero di inserimenti riusciti è sufficiente, esci dal ciclo + + if ($inserted_count >= $quantity_class) { + break; // Se il numero di inserimenti riusciti è sufficiente, esci dal ciclo } - + $date_schedule = $schedule_row["dateschedule"]; $selected_user_id = isset($new_user_id) ? $new_user_id : $user_id; - + $idservice = $schedule_row["idservice"]; -//recover number of booking -$idserviceschedule = $schedule_row["idserviceschedule"]; + //recover number of booking + $idserviceschedule = $schedule_row["idserviceschedule"]; -//check if already booked -$querychk = "SELECT * FROM bookingclass WHERE iduser = '$user_id' AND idserviceschedule = '$idserviceschedule'"; -$result = mysqli_query($conn, $querychk); + //check if already booked + $querychk = "SELECT * FROM bookingclass WHERE iduser = '$user_id' AND idserviceschedule = '$idserviceschedule'"; + $result = mysqli_query($conn, $querychk); -if ($result) { - // Verifica se esiste almeno una riga nella query - if (mysqli_num_rows($result) == 0) { + if ($result) { + // Verifica se esiste almeno una riga nella query + if (mysqli_num_rows($result) == 0) { -//recover maxcapacity -$service_maxcapacity_query = "SELECT maxcapacity FROM service WHERE idservice = '$idservice'"; -$service_maxcapacity_result = $conn->query($service_maxcapacity_query); + //recover maxcapacity + $service_maxcapacity_query = "SELECT maxcapacity FROM service WHERE idservice = '$idservice'"; + $service_maxcapacity_result = $conn->query($service_maxcapacity_query); - $row = $service_maxcapacity_result->fetch_assoc(); - $maxcapacity = $row['maxcapacity']; - + $row = $service_maxcapacity_result->fetch_assoc(); + $maxcapacity = $row['maxcapacity']; -$bookingclass_count_query = "SELECT COUNT(*) as total_records FROM bookingclass WHERE idserviceschedule = '$idserviceschedule'"; -$bookingclass_count_result = $conn->query($bookingclass_count_query); -if ($bookingclass_count_result) { - $rowcount= $bookingclass_count_result->fetch_assoc(); - $total_records = $rowcount['total_records']; + $bookingclass_count_query = "SELECT COUNT(*) as total_records FROM bookingclass WHERE idserviceschedule = '$idserviceschedule'"; + $bookingclass_count_result = $conn->query($bookingclass_count_query); - // Ora hai il numero totale di record con l'idserviceschedule specificato -} else { - $total_records='0'; -} + if ($bookingclass_count_result) { + $rowcount = $bookingclass_count_result->fetch_assoc(); + $total_records = $rowcount['total_records']; -// Check if maxcapacity is greater than total_records before inserting - if ($maxcapacity > $total_records) { + // Ora hai il numero totale di record con l'idserviceschedule specificato + } else { + $total_records = '0'; + } - // Inserisci il nuovo record in bookingclass - $insert_booking_query = "INSERT INTO bookingclass (idserviceschedule, idservice, iduser, bookingstart,idorder) + // Check if maxcapacity is greater than total_records before inserting + if ($maxcapacity > $total_records) { + + // Inserisci il nuovo record in bookingclass + $insert_booking_query = "INSERT INTO bookingclass (idserviceschedule, idservice, iduser, bookingstart,idorder) VALUES ('{$schedule_row['idserviceschedule']}', '$service_id', '$selected_user_id', '$date_schedule', '$order_id')"; - if ($conn->query($insert_booking_query)) { - echo "Inserito record in bookingclass per l'ordine ID: $order_id\n"; - $inserted_count++; - } else { - echo "Errore durante l'inserimento: " . $conn->error . "\n"; + if ($conn->query($insert_booking_query)) { + echo "Inserito record in bookingclass per l'ordine ID: $order_id\n"; + $inserted_count++; + } else { + echo "Errore durante l'inserimento: " . $conn->error . "\n"; + } + } else { + echo "La capacità massima è stata raggiunta. Impossibile effettuare la prenotazione.\n"; + } } - } else { - echo "La capacità massima è stata raggiunta. Impossibile effettuare la prenotazione.\n"; } - - }} - //brackets of while + //brackets of while } // Aggiorna lo status a 'booked' nella tabella orderbook @@ -154,15 +142,12 @@ if ($bookingclass_count_result) { $conn->query($update_order_status_query); echo "Aggiornato lo status a 'booked' per l'ordine ID: $order_id\n"; - - //send email to user - - require 'phpmailer/src/Exception.php'; -require 'phpmailer/src/PHPMailer.php'; -require 'phpmailer/src/SMTP.php'; -$name=$first_name; -$messageedit="

Ciao $name ,

+ //send email to user + + $name = $first_name; + + $messageedit = "

Ciao $name ,

Le prenotazioni relative al tuo ultimo ordine n. $ordern sono state inserite con successo!

Puoi vederle e riprogrammarle dall'indirizzo https://yogibook.yogasoul.it


@@ -176,47 +161,49 @@ $messageedit="

Ci vediamo sul tappetino!

Il Team Yogasoul

"; -$buttonedit=" + $buttonedit = " YogiBook - YogaSoul "; //mail to client -$mail = new PHPMailer(true); + $mail = new PHPMailer(true); -$mail->isSMTP(); // Set mailer to use SMTP -$mail->Host = 'mail.yogasoul.it'; // Specify main and backup server -$mail->SMTPAuth = true; // Enable SMTP authentication -$mail->Username = 'info@yogasoul.it'; // SMTP username -$mail->Password = '!Testolina88'; // SMTP password -$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted -$mail->Port = '587'; - + $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 = 'info@yogasoul.it'; -$mail->FromName = 'YogiBook [YogaSoul]'; -$mail->addAddress($billing_email); // Add a recipient - + 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($billing_email); // Add a recipient + + + + + $mail->Subject = "YogiBook - Prenotazioni effettuate per il tuo ordine $ordern"; + $mail->Body = $htmlContent; + $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + + try { + $mail->send(); + } catch (Exception $e) { + error_log("Errore invio mail ordine $order_id: " . $mail->ErrorInfo); + } -$mail->Subject = "YogiBook - Prenotazioni effettuate per il tuo ordine $ordern"; -$mail->Body = $htmlContent; -$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; - $mail->send(); - - //mail sent - - // ... (il resto del codice come prima) } else { @@ -224,7 +211,7 @@ $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; } - // Recupera il numero di settimane da expiryparameter +// Recupera il numero di settimane da expiryparameter $expiry_class_query = "SELECT quantityclass FROM orderbook WHERE idorderbook = '$order_id'"; $expiry_class_result = $conn->query($expiry_class_query); @@ -243,7 +230,7 @@ if ($expiry_class_result && $expiry_class_result->num_rows > 0) { $update_expiry_query = "UPDATE orderbook SET expireon = DATE_ADD(order_date_created, INTERVAL $expiry_weeks WEEK) WHERE idorderbook = '$order_id'"; $conn->query($update_expiry_query); - echo "Aggiornata la colonna expireon per l'ordine ID: $order_id\n"; + echo "Aggiornata la colonna expireon per l'ordine ID: $order_id\n"; } else { echo "Nessun record trovato in expiryparameter per quantityclass: $quantity_class\n"; } @@ -268,6 +255,4 @@ if ($reschedule_number_result && $reschedule_number_result->num_rows > 0) { echo "Nessun record trovato in expiryparameter per quantityclass: $quantity_class\n"; } -// Chiudi la connessione al database -$conn->close(); -?> +// Connessione $bkngstm gestita globalmente: non la chiudiamo qui diff --git a/public/promemoria-cron.php b/public/promemoria-cron.php index b3c1540..1491701 100644 --- a/public/promemoria-cron.php +++ b/public/promemoria-cron.php @@ -1,24 +1,12 @@ connect_error) { - die("Connessione al database fallita: " . $conn->connect_error); -} +// Riusa la connessione già aperta da bkngstm.php +$conn = $bkngstm; // Inizializza contatore e log $emailCount = 0; @@ -127,12 +115,13 @@ while ($row = $result->fetch_assoc()) { $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->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'; if (!file_exists('mail/emailtemplate2.php')) { throw new Exception("File emailtemplate2.php non trovato."); @@ -145,8 +134,8 @@ while ($row = $result->fetch_assoc()) { $htmlContent = str_replace('{message}', $message, $mailmessage1); - $mail->From = 'info@yogasoul.it'; - $mail->FromName = 'YogiBook [YogaSoul]'; + $mail->From = $_ENV['MAIL_FROM_ADDRESS']; + $mail->FromName = $_ENV['MAIL_FROM_NAME']; $mail->addAddress($emailuser); $mail->Subject = "YogiBook - Promemoria lezione!"; $mail->Body = $htmlContent; @@ -178,4 +167,4 @@ if (!empty($errors)) { } echo "Dettagli nel file di log: $logFile\n"; -$conn->close(); +// Connessione $bkngstm gestita globalmente: non la chiudiamo qui diff --git a/public/propagatesingleorder.php b/public/propagatesingleorder.php index ca2df42..67d1cbd 100644 --- a/public/propagatesingleorder.php +++ b/public/propagatesingleorder.php @@ -1,26 +1,18 @@ connect_error) { - die("Connessione fallita: " . $conn->connect_error); -} +// Riusa la connessione già aperta da bkngstm.php +$conn = $bkngstm; // Seleziona i record con status 'pending' dalla tabella orderbook $select_query = "SELECT * FROM orderbook WHERE idorderbook = ?"; @@ -227,9 +219,6 @@ if ($is_openflexy || $service_schedule_result->num_rows > 0) { $stmt_reschedule->close(); // Invia la mail (modificata per includere la scadenza) - require 'phpmailer/src/Exception.php'; - require 'phpmailer/src/PHPMailer.php'; - require 'phpmailer/src/SMTP.php'; $name = $first_name; $messageedit = "

Ciao $name ,

Le prenotazioni relative al tuo ultimo ordine n. $ordern sono state inserite con successo!

@@ -250,16 +239,17 @@ if ($is_openflexy || $service_schedule_result->num_rows > 0) { "; $mail = new PHPMailer(true); $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->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'); $htmlContent = $mailmessage1; // Assumo che $mailmessage1 sia il template; se devi integrare $messageedit qui, dimmelo - $mail->From = 'info@yogasoul.it'; - $mail->FromName = 'YogiBook [YogaSoul]'; + $mail->From = $_ENV['MAIL_FROM_ADDRESS']; + $mail->FromName = $_ENV['MAIL_FROM_NAME']; $mail->addAddress($billing_email); $mail->Subject = "YogiBook - Prenotazioni effettuate per il tuo ordine $ordern"; $mail->Body = str_replace(['{messageedit}', '{buttonedit}'], [$messageedit, $buttonedit], $htmlContent); // Se il template ha placeholders, altrimenti usa direttamente $messageedit come Body @@ -277,5 +267,3 @@ if ($is_openflexy || $service_schedule_result->num_rows > 0) { echo "Nessun record di schedule futuro trovato per l'ordine ID: $order_id a partire dalla data della prima lezione: $first_lesson_date\n"; } $stmt_schedule->close(); - -$conn->close(); diff --git a/public/rebookandgo.php b/public/rebookandgo.php index dce0cb0..0c63374 100644 --- a/public/rebookandgo.php +++ b/public/rebookandgo.php @@ -1,65 +1,96 @@ -query($selectQuery); - - $sqlnewbook = "SELECT dateschedule FROM serviceschedule WHERE idserviceschedule = $idnewbooking"; -$resultnew = $conn->query($sqlnewbook); +if ($idpreviousbooking === 0 || $idnewbooking === 0 || $iduser === 0 || $idservicenew === 0) { + die("Errore: Parametri mancanti."); +} - // Estrai il risultato e memorizzalo in $newtime - $rownew = $resultnew->fetch_assoc(); - $newtime = $rownew["dateschedule"]; +// Riusa la connessione già aperta da bkngstm.php +$conn = $bkngstm; - if ($result && $result->num_rows > 0) { - $row = $result->fetch_assoc(); - $prevBookingStart = $row['bookingstart']; - $idPrevServiceSchedule = $row['idserviceschedule']; - $globalidorder = $row['idorder']; +// Nuovo orario della lezione scelta +$stmt = $conn->prepare("SELECT dateschedule FROM serviceschedule WHERE idserviceschedule = ?"); +$stmt->bind_param("i", $idnewbooking); +$stmt->execute(); +$resultnew = $stmt->get_result(); +$rownew = $resultnew->fetch_assoc(); +$newtime = $rownew['dateschedule'] ?? null; +$stmt->close(); - // Effettua la cancellazione del record nella tabella bookingclass - $deleteQuery = "DELETE FROM bookingclass WHERE idbookingclass = $idpreviousbooking"; - $conn->query($deleteQuery); +if (!$newtime) { + die("Errore: orario della nuova lezione non trovato."); +} - // Effettua l'inserimento del nuovo record nella tabella bookingclass - $insertQuery = "INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status) - VALUES ($idnewbooking, $iduser, '$prevBookingStart', $idPrevServiceSchedule, $idservicenew, $globalidorder, '$newtime', 'pending')"; - $conn->query($insertQuery); +// Dati della prenotazione precedente +$stmt = $conn->prepare("SELECT bookingstart, idserviceschedule, idorder FROM bookingclass WHERE idbookingclass = ?"); +$stmt->bind_param("i", $idpreviousbooking); +$stmt->execute(); +$result = $stmt->get_result(); - // Aggiorna la tabella orderbook -echo $globalidorder; -echo 'ciao'; +if ($result->num_rows === 0) { + $stmt->close(); + die("Errore: prenotazione precedente non trovata."); +} - $updateQuery = "UPDATE orderbook SET reprogrammed = reprogrammed + 1 WHERE idorderbook = $globalidorder"; - $conn->query($updateQuery); -echo "Query di aggiornamento: " . $updateQuery; - // Chiudi la connessione al database - $conn->close(); - - - $newtimeformat = date("d-m-Y H:i", strtotime($newtime)); - require 'phpmailer/src/Exception.php'; -require 'phpmailer/src/PHPMailer.php'; -require 'phpmailer/src/SMTP.php'; - //mail to client -$messageedit="

Ciao $firstname ,

+$row = $result->fetch_assoc(); +$prevBookingStart = $row['bookingstart']; +$idPrevServiceSchedule = (int) $row['idserviceschedule']; +$globalidorder = (int) $row['idorder']; +$stmt->close(); + +// Cancella la prenotazione precedente +$stmt = $conn->prepare("DELETE FROM bookingclass WHERE idbookingclass = ?"); +$stmt->bind_param("i", $idpreviousbooking); +$stmt->execute(); +$stmt->close(); + +// Inserisci la nuova prenotazione (pending) +$stmt = $conn->prepare( + "INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status) + VALUES (?, ?, ?, ?, ?, ?, ?, 'pending')" +); +$stmt->bind_param("iisiiss", $idnewbooking, $iduser, $prevBookingStart, $idPrevServiceSchedule, $idservicenew, $globalidorder, $newtime); +$stmt->execute(); +$stmt->close(); + +// Incrementa il contatore riprogrammazioni sull'ordine +$stmt = $conn->prepare("UPDATE orderbook SET reprogrammed = reprogrammed + 1 WHERE idorderbook = ?"); +$stmt->bind_param("i", $globalidorder); +$stmt->execute(); +$stmt->close(); + +// Recupera nome ed email dell'utente per la mail +$firstname = ''; +$emailuser = ''; +$stmtUser = $conn->prepare("SELECT first_name, email FROM auth_users WHERE id = ?"); +$stmtUser->bind_param("i", $iduser); +$stmtUser->execute(); +$resUser = $stmtUser->get_result(); +if ($rowUser = $resUser->fetch_assoc()) { + $firstname = $rowUser['first_name'] ?? ''; + $emailuser = $rowUser['email'] ?? ''; +} +$stmtUser->close(); + +$newtimeformat = date("d-m-Y H:i", strtotime($newtime)); + +// Se manca l'email, completa comunque il flusso senza inviare +if ($emailuser === '') { + header("Location: userpanel.php?reprogram=Y"); + exit(); +} + +// Contenuto mail +$messageedit = "

Ciao $firstname ,

Hai inviato una richiesta di riprogrammazione della tua lezione

Ecco il dettaglio della riprogrammazione $newtimeformat

La tua richiesta è in fase di accettazione! Verrai avvisata se la riprogrammazione è stata accettata

@@ -76,49 +107,36 @@ $messageedit="

Ci vediamo sul tappetino!

Il Team Yogasoul

"; -$buttonedit=" +$buttonedit = " YogiBook - YogaSoul - "; - - -$mail = new PHPMailer(true); - -$mail->isSMTP(); // Set mailer to use SMTP -$mail->Host = 'mail.yogasoul.it'; // Specify main and backup server -$mail->SMTPAuth = true; // Enable SMTP authentication -$mail->Username = 'info@yogasoul.it'; // SMTP username -$mail->Password = '!Testolina88'; // SMTP password -$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted -$mail->Port = '587'; - + "; include('mail/emailtemplate2.php'); -// Email body content +$htmlContent = $mailmessage1; -//$trfnmbmail=$appformn.'r'.$revnumb; -$htmlContent = $mailmessage1; - - -$mail->From = 'info@yogasoul.it'; -$mail->FromName = 'YogiBook [YogaSoul]'; -$mail->addAddress($emailuser); // Add a recipient - +$mail = new PHPMailer(true); +try { + $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->isHTML(true); - + $mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']); + $mail->addAddress($emailuser); -$mail->Subject = "Proposta di riprogrammazione!"; -$mail->Body = $htmlContent; -$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + $mail->Subject = "Proposta di riprogrammazione!"; + $mail->Body = $htmlContent; + $mail->AltBody = 'Hai inviato una richiesta di riprogrammazione. La tua richiesta è in fase di accettazione.'; $mail->send(); - - //mail sent - - - +} catch (Exception $e) { + error_log("Errore invio mail riprogrammazione (iduser $iduser): " . $mail->ErrorInfo); +} - // Esegui il reindirizzamento - header("Location: userpanel.php?reprogram=Y"); - exit(); - } -?> \ No newline at end of file +header("Location: userpanel.php?reprogram=Y"); +exit(); diff --git a/public/rejectbookingclass.php b/public/rejectbookingclass.php index a0aea5b..187cb00 100644 --- a/public/rejectbookingclass.php +++ b/public/rejectbookingclass.php @@ -1,15 +1,15 @@ - - fetch_assoc()) { $emailuser = $row['email']; $firstname = $row['first_name']; - $newtime = $row['bookingstart']; + $newtime = $row['bookingstart']; - $newtimeformat = date("d-m-Y H:i", strtotime($newtime)); - require 'phpmailer/src/Exception.php'; -require 'phpmailer/src/PHPMailer.php'; -require 'phpmailer/src/SMTP.php'; - //mail to client -$messageedit="

Ciao $firstname ,

+ $newtimeformat = date("d-m-Y H:i", strtotime($newtime)); + //mail to client + $messageedit = "

Ciao $firstname ,

Ci dispiace ma la tua richiesta di rirpogrammazione è stata rifiutata!

Ecco la riprogrammazione rifiutata $newtimeformat

Puoi collegarti al portale YogiBook come sotto riportato per programmare la tua lezione

@@ -48,63 +45,66 @@ $messageedit="

Ci vediamo sul tappetino!

Il Team Yogasoul

"; -$buttonedit=" + $buttonedit = " YogiBook - YogaSoul - "; + "; -$mail = new PHPMailer(true); + $mail = new PHPMailer(true); -$mail->isSMTP(); // Set mailer to use SMTP -$mail->Host = 'mail.yogasoul.it'; // Specify main and backup server -$mail->SMTPAuth = true; // Enable SMTP authentication -$mail->Username = 'info@yogasoul.it'; // SMTP username -$mail->Password = '!Testolina88'; // SMTP password -$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted -$mail->Port = '587'; - + $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 = 'info@yogasoul.it'; -$mail->FromName = 'YogiBook [YogaSoul]'; -$mail->addAddress($emailuser); // Add a recipient - + include('mail/emailtemplate2.php'); + // Email body content - + //$trfnmbmail=$appformn.'r'.$revnumb; + $htmlContent = $mailmessage1; -$mail->Subject = "YogiBook - Riprogrammazione rifiutata!"; -$mail->Body = $htmlContent; -$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + + $mail->From = $_ENV['MAIL_FROM_ADDRESS']; + $mail->FromName = $_ENV['MAIL_FROM_NAME']; + $mail->addAddress($emailuser); // Add a recipient - if ($mail->send()) { - // Mail inviata con successo, ora cancella il record - $deleteQuery = "DELETE FROM bookingclass WHERE idbookingclass = ?"; - $stmt = $conn->prepare($deleteQuery); - if ($stmt) { - $stmt->bind_param("i", $idbookingclass); - if ($stmt->execute()) { - // Reindirizza alla pagina "pendingbookedclass.php" dopo la cancellazione - header("Location: pendingbookedclass.php"); - exit(); - } else { - echo "Errore durante l'esecuzione della query di cancellazione: " . $stmt->error; - } - $stmt->close(); - } else { - echo "Errore nella preparazione della query di cancellazione: " . $conn->error; + $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 { - echo "Errore nell'invio della mail: " . $mail->ErrorInfo; + 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; @@ -112,14 +112,3 @@ $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; } else { echo "Parametro 'idbookingclass' non trovato nella richiesta GET."; } - -$conn->close(); -?> - - - - - - - - diff --git a/public/send_email.php b/public/send_email.php index 906a519..accb177 100644 --- a/public/send_email.php +++ b/public/send_email.php @@ -10,7 +10,8 @@ use PHPMailer\PHPMailer\Exception; header('Content-Type: application/json'); // Funzione per generare il template HTML dell'email -function generateEmailTemplate($message) { +function generateEmailTemplate($message) +{ return << @@ -108,12 +109,12 @@ try { throw new Exception('Dati mancanti.'); } -// Prepara tutti gli indirizzi email ricevuti -$to = array_column($recipients, 'email'); + // Prepara tutti gli indirizzi email ricevuti + $to = array_column($recipients, 'email'); -if (empty($to)) { - throw new Exception('Nessun destinatario valido trovato.'); -} + if (empty($to)) { + throw new Exception('Nessun destinatario valido trovato.'); + } // Sostituisci i newline con
per l'HTML @@ -130,23 +131,10 @@ if (empty($to)) { $mail->Username = $_ENV['MAIL_USERNAME']; $mail->Password = $_ENV['MAIL_PASSWORD']; $mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION']; - $mail->Port = $_ENV['MAIL_PORT']; + $mail->Port = (int) $_ENV['MAIL_PORT']; $mail->Timeout = 5; // Timeout di 5 secondi $mail->SMTPKeepAlive = false; // Disabilita la connessione persistente - // Abilita debug SMTP per diagnosticare problemi - $mail->SMTPDebug = 2; // 2 = Mostra messaggi di debug dettagliati - $mail->Debugoutput = function($str, $level) { - error_log("PHPMailer Debug [$level]: $str"); - }; - - // Debug: verifica i valori SMTP - error_log('SMTP Host: ' . $mail->Host); - error_log('SMTP Username: ' . $mail->Username); - error_log('SMTP Password: ' . $mail->Password); - error_log('SMTP Secure: ' . $mail->SMTPSecure); - error_log('SMTP Port: ' . $mail->Port); - // Mittente $mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']); @@ -169,4 +157,4 @@ if (empty($to)) { // Log dell'errore completo error_log('Errore in send_email.php: ' . $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine()); echo json_encode(['success' => false, 'message' => "Errore nell'invio dell'email: " . $e->getMessage()]); -} \ No newline at end of file +} diff --git a/public/userpanel.php b/public/userpanel.php index 6463217..1ec6bc1 100644 --- a/public/userpanel.php +++ b/public/userpanel.php @@ -526,7 +526,7 @@ $italianMonths = [