274 lines
12 KiB
PHP
274 lines
12 KiB
PHP
<?php
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
?>
|
|
<?php
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
ini_set('display_errors', '1');
|
|
ini_set('display_startup_errors', '1');
|
|
error_reporting(E_ALL);
|
|
include('Connections/bkngstm.php');
|
|
//require_once('include/headscript.php'); ?>
|
|
<?php
|
|
// from email to ID auth_users
|
|
|
|
// Crea la connessione al database
|
|
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
|
|
// Verifica la connessione
|
|
if ($conn->connect_error) {
|
|
die("Connessione fallita: " . $conn->connect_error);
|
|
}
|
|
|
|
// Seleziona i record con status 'pending' dalla tabella orderbook
|
|
$select_query = "SELECT * FROM orderbook WHERE status = 'pending'";
|
|
$result = $conn->query($select_query);
|
|
|
|
if ($result->num_rows > 0) {
|
|
while ($row = $result->fetch_assoc()) {
|
|
$order_id = $row["idorderbook"];
|
|
$billing_email = $row["order_billing_email"];
|
|
$first_name = $row["first_name"];
|
|
$last_name = $row["last_name"];
|
|
$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);
|
|
|
|
if ($user_result->num_rows > 0) {
|
|
$user_row = $user_result->fetch_assoc();
|
|
$user_id = $user_row["id"];
|
|
|
|
$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
|
|
$password = "YogiBook159"; // La password casuale
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
// Inserisci un nuovo utente in auth_users
|
|
$todaydate = date('Y-m-d H:i:s');
|
|
$insert_query = "INSERT INTO auth_users (email, password, first_name, last_name, role_id, status, created_at, avatar)
|
|
VALUES ('$billing_email', '$hashed_password', '$first_name', '$last_name', 2, 'Active', '$todaydate', 'meditationb.png')";
|
|
$conn->query($insert_query);
|
|
|
|
// Ottieni l'ID appena inserito
|
|
$new_user_id = $conn->insert_id;
|
|
|
|
// Aggiorna l'ID utente nell'ordine
|
|
$update_query = "UPDATE orderbook SET iduser = '$new_user_id' WHERE idorderbook = '$order_id'";
|
|
$conn->query($update_query);
|
|
}
|
|
}
|
|
echo "Aggiornamento completato con successo.";
|
|
} else {
|
|
echo "Nessun record con status 'pending' trovato.";
|
|
}
|
|
|
|
|
|
|
|
//recupera servischedule
|
|
|
|
// Seleziona i primi "n" record dalla tabella serviceschedule successivi al momento attuale
|
|
$current_datetime = date("Y-m-d H:i:s");
|
|
$service_schedule_query = "SELECT * FROM serviceschedule WHERE idservice = '$service_id' AND dateschedule >= '$current_datetime' ORDER BY dateschedule";
|
|
$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
|
|
|
|
|
|
while ($schedule_row = $service_schedule_result->fetch_assoc()) {
|
|
|
|
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"];
|
|
|
|
//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) {
|
|
|
|
|
|
//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'];
|
|
|
|
|
|
|
|
$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'];
|
|
|
|
// Ora hai il numero totale di record con l'idserviceschedule specificato
|
|
} else {
|
|
$total_records='0';
|
|
}
|
|
|
|
// 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";
|
|
}
|
|
} else {
|
|
echo "La capacità massima è stata raggiunta. Impossibile effettuare la prenotazione.\n";
|
|
}
|
|
|
|
}}
|
|
//brackets of while
|
|
}
|
|
|
|
// Aggiorna lo status a 'booked' nella tabella orderbook
|
|
$update_order_status_query = "UPDATE orderbook SET status = 'booked' WHERE idorderbook = '$order_id'";
|
|
$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=" <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 $name , </span></strong></span></p>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Le prenotazioni relative al tuo ultimo ordine n. $ordern sono state inserite con successo!</span></p>
|
|
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Puoi vederle e riprogrammarle dall'indirizzo https://yogibook.yogasoul.it </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 per prima cosa resettare la password cliccando di seguito</span></p>
|
|
<br>
|
|
<a href='https://yogibook.yogasoul.it/public/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 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';
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
$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 {
|
|
echo "Nessun record di schedule futuro trovato per l'ordine ID: $order_id\n";
|
|
}
|
|
|
|
|
|
// 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);
|
|
|
|
if ($expiry_class_result && $expiry_class_result->num_rows > 0) {
|
|
$row = $expiry_class_result->fetch_assoc();
|
|
$quantity_class = $row['quantityclass'];
|
|
|
|
$expiry_weeks_query = "SELECT expiryweeks FROM expiryparameter WHERE quantityclass = '$quantity_class'";
|
|
$expiry_weeks_result = $conn->query($expiry_weeks_query);
|
|
|
|
if ($expiry_weeks_result && $expiry_weeks_result->num_rows > 0) {
|
|
$expiry_row = $expiry_weeks_result->fetch_assoc();
|
|
$expiry_weeks = $expiry_row['expiryweeks'];
|
|
|
|
// Aggiorna la colonna expireon in orderbook
|
|
$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";
|
|
} else {
|
|
echo "Nessun record trovato in expiryparameter per quantityclass: $quantity_class\n";
|
|
}
|
|
} else {
|
|
echo "Nessun record trovato in orderbook per l'ordine ID: $order_id\n";
|
|
}
|
|
|
|
// Recupera il numero da expiryparameter per maxreschedule
|
|
$reschedule_number_query = "SELECT reschedulenumber FROM expiryparameter WHERE quantityclass = '$quantity_class'";
|
|
$reschedule_number_result = $conn->query($reschedule_number_query);
|
|
|
|
if ($reschedule_number_result && $reschedule_number_result->num_rows > 0) {
|
|
$reschedule_row = $reschedule_number_result->fetch_assoc();
|
|
$reschedule_number = $reschedule_row['reschedulenumber'];
|
|
|
|
// Aggiorna la colonna maxreschedule in orderbook
|
|
$update_max_reschedule_query = "UPDATE orderbook SET maxreschedule = '$reschedule_number' WHERE idorderbook = '$order_id'";
|
|
$conn->query($update_max_reschedule_query);
|
|
|
|
echo "Aggiornata la colonna maxreschedule per l'ordine ID: $order_id\n";
|
|
} else {
|
|
echo "Nessun record trovato in expiryparameter per quantityclass: $quantity_class\n";
|
|
}
|
|
|
|
// Chiudi la connessione al database
|
|
$conn->close();
|
|
?>
|