Files
yogibook_aury_new/public/notificationmail.php
T
2026-09-04 10:03:38 +02:00

203 lines
7.2 KiB
PHP

<?php
header('Content-Type: text/html; charset=utf-8');
include('Connections/bkngstm.php');
require_once __DIR__ . '/class/mailer.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$conn = $bkngstm;
?>
<?php
// teacher notification
// Calcola la data del giorno successivo
$today = date('Y-m-d');
$nextDay = date('Y-m-d', strtotime($today . ' + 1 day'));
// Query SQL per recuperare gli eventi
$sql = "SELECT serviceschedule.dateschedule, serviceschedule.dateschedule, service.servicename, serviceschedule.idserviceschedule, service.maxcapacity
FROM serviceschedule
LEFT JOIN service ON serviceschedule.idservice = service.idservice
WHERE DATE(serviceschedule.dateschedule) = '$nextDay'
ORDER BY serviceschedule.dateschedule";
$result = $conn->query($sql);
//send email to teacher
//mail to client
$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 sent
$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 Aurora , </span></strong></span></p>
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Di seguito riepilogo delle tue lezioni di domani $nextDay</span></p>";
if ($result->num_rows > 0) {
// Ci sono record, inizializza la variabile $buttonedit
$buttonedit = "";
while ($row = $result->fetch_assoc()) {
$date = date('d-M-Y H:i', strtotime($row["dateschedule"]));
$buttonedit .= "<strong>Classe: " . $row["servicename"] . ", Data: " . $date . "</strong><br>";
// Query per recuperare i partecipanti alla classe
$idserviceschedule = $row["idserviceschedule"];
$participantQuery = "SELECT auth_users.first_name, auth_users.last_name
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) {
// Ci sono partecipanti, aggiungi i nomi e cognomi a $buttonedit
$buttonedit .= "<table>";
while ($participantRow = $participantResult->fetch_assoc()) {
$buttonedit .= "<tr>";
$buttonedit .= "<td>" . $participantRow["first_name"] . "</td>";
$buttonedit .= "<td>" . $participantRow["last_name"] . "</td>";
$buttonedit .= "</tr>";
}
$buttonedit .= "</table>";
// Conta il numero di partecipanti
$numPartecipanti = $participantResult->num_rows;
// Aggiungi l'ultima riga con il numero di posti e maxcapacity
$buttonedit .= "<em>Partecipanti: $numPartecipanti / " . $row["maxcapacity"] . "</em><br><br>";
} 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 = $_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.";
}
// Connessione $bkngstm condivisa: non la chiudiamo qui
?>
<?php
// email notification to users
$conn = $bkngstm;
// Calcolo della data successiva
$today = date("Y-m-d");
$nextDay = date('Y-m-d', strtotime($today . ' + 1 day'));
// Query SQL
$sql = "SELECT s.servicename,
DATE_FORMAT(ss.dateschedule, '%d-%m-%Y %H:%i') AS formatted_date,
au.first_name,
au.email
FROM serviceschedule ss
LEFT JOIN service s ON ss.idservice = s.idservice
LEFT JOIN bookingclass bc ON ss.idserviceschedule = bc.idserviceschedule
LEFT JOIN auth_users au ON bc.iduser = au.id
WHERE DATE(ss.dateschedule) = '$nextDay'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Stampa dei risultati
while ($row = $result->fetch_assoc()) {
$servicename = $row["servicename"];
$formatted_date = $row["formatted_date"];
$first_name = $row["first_name"];
$email = $row["email"];
//send email to users
//mail to client
$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';
$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 $first_name , </span></strong></span></p>
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Eccoti un promemoria per ricordarti la tua prossima lezione di '$servicename' del $formatted_date .</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>";
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($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();
echo "Nome evento: " . $servicename . "<br>";
echo "Data e ora: " . $formatted_date . "<br>";
echo "Nome allievo: " . $first_name . "<br>";
echo "Email: " . $email . "<br><br>";
}
} else {
echo "Nessun risultato trovato.";
}
?>