263 lines
13 KiB
PHP
263 lines
13 KiB
PHP
<?php
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
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');
|
|
|
|
// take idorder
|
|
if (isset($_GET['idorder'])) {
|
|
$idorder = $_GET['idorder'];
|
|
}
|
|
|
|
// 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 idorderbook = ?";
|
|
$stmt = $conn->prepare($select_query);
|
|
$stmt->bind_param("i", $idorder);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
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"];
|
|
$first_lesson_date = $row["first_lesson_date"];
|
|
|
|
echo "Elaborazione record con ID: $order_id, Service ID: $service_id\n";
|
|
|
|
$user_query = "SELECT id FROM auth_users WHERE email = ?";
|
|
$stmt_user = $conn->prepare($user_query);
|
|
$stmt_user->bind_param("s", $billing_email);
|
|
$stmt_user->execute();
|
|
$user_result = $stmt_user->get_result();
|
|
|
|
if ($user_result->num_rows > 0) {
|
|
$user_row = $user_result->fetch_assoc();
|
|
$user_id = $user_row["id"];
|
|
$update_query = "UPDATE orderbook SET iduser = ? WHERE idorderbook = ?";
|
|
$stmt_update = $conn->prepare($update_query);
|
|
$stmt_update->bind_param("ii", $user_id, $order_id);
|
|
$stmt_update->execute();
|
|
$stmt_update->close();
|
|
} else {
|
|
$password = "YogiBook159";
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
$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 (?, ?, ?, ?, 2, 'Active', ?, 'meditationb.png')";
|
|
$stmt_insert = $conn->prepare($insert_query);
|
|
$stmt_insert->bind_param("sssss", $billing_email, $hashed_password, $first_name, $last_name, $todaydate);
|
|
$stmt_insert->execute();
|
|
$new_user_id = $conn->insert_id;
|
|
$stmt_insert->close();
|
|
|
|
$update_query = "UPDATE orderbook SET iduser = ? WHERE idorderbook = ?";
|
|
$stmt_update = $conn->prepare($update_query);
|
|
$stmt_update->bind_param("ii", $new_user_id, $order_id);
|
|
$stmt_update->execute();
|
|
$stmt_update->close();
|
|
}
|
|
$stmt_user->close();
|
|
}
|
|
echo "Aggiornamento completato con successo.";
|
|
} else {
|
|
echo "Nessun record con status 'pending' trovato.";
|
|
}
|
|
$stmt->close();
|
|
|
|
// Recupera servischedule a partire da first_lesson_date
|
|
$service_schedule_query = "SELECT * FROM serviceschedule WHERE idservice = ? AND dateschedule >= ? ORDER BY dateschedule";
|
|
$stmt_schedule = $conn->prepare($service_schedule_query);
|
|
$stmt_schedule->bind_param("is", $service_id, $first_lesson_date);
|
|
$stmt_schedule->execute();
|
|
$service_schedule_result = $stmt_schedule->get_result();
|
|
|
|
if ($service_schedule_result->num_rows > 0) {
|
|
echo "Record per l'ordine ID: $order_id\n";
|
|
$inserted_count = 0;
|
|
|
|
while ($schedule_row = $service_schedule_result->fetch_assoc()) {
|
|
if ($inserted_count >= $quantity_class) {
|
|
break;
|
|
}
|
|
$date_schedule = $schedule_row["dateschedule"];
|
|
$selected_user_id = isset($new_user_id) ? $new_user_id : $user_id;
|
|
$idservice = $schedule_row["idservice"];
|
|
$idserviceschedule = $schedule_row["idserviceschedule"];
|
|
|
|
$querychk = "SELECT * FROM bookingclass WHERE iduser = ? AND idserviceschedule = ?";
|
|
$stmt_chk = $conn->prepare($querychk);
|
|
$stmt_chk->bind_param("ii", $selected_user_id, $idserviceschedule);
|
|
$stmt_chk->execute();
|
|
$result = $stmt_chk->get_result();
|
|
|
|
if ($result->num_rows == 0) {
|
|
$service_maxcapacity_query = "SELECT maxcapacity FROM service WHERE idservice = ?";
|
|
$stmt_maxcapacity = $conn->prepare($service_maxcapacity_query);
|
|
$stmt_maxcapacity->bind_param("i", $idservice);
|
|
$stmt_maxcapacity->execute();
|
|
$service_maxcapacity_result = $stmt_maxcapacity->get_result();
|
|
$row = $service_maxcapacity_result->fetch_assoc();
|
|
$maxcapacity = $row['maxcapacity'];
|
|
$stmt_maxcapacity->close();
|
|
|
|
$bookingclass_count_query = "SELECT COUNT(*) as total_records FROM bookingclass WHERE idserviceschedule = ?";
|
|
$stmt_count = $conn->prepare($bookingclass_count_query);
|
|
$stmt_count->bind_param("i", $idserviceschedule);
|
|
$stmt_count->execute();
|
|
$bookingclass_count_result = $stmt_count->get_result();
|
|
$rowcount = $bookingclass_count_result->fetch_assoc();
|
|
$total_records = $rowcount['total_records'];
|
|
$stmt_count->close();
|
|
|
|
if ($maxcapacity > $total_records) {
|
|
$insert_booking_query = "INSERT INTO bookingclass (idserviceschedule, idservice, iduser, bookingstart, idorder)
|
|
VALUES (?, ?, ?, ?, ?)";
|
|
$stmt_insert_booking = $conn->prepare($insert_booking_query);
|
|
$stmt_insert_booking->bind_param("iiisi", $idserviceschedule, $service_id, $selected_user_id, $date_schedule, $order_id);
|
|
if ($stmt_insert_booking->execute()) {
|
|
echo "Inserito record in bookingclass per l'ordine ID: $order_id\n";
|
|
$inserted_count++;
|
|
} else {
|
|
echo "Errore durante l'inserimento: " . $stmt_insert_booking->error . "\n";
|
|
}
|
|
$stmt_insert_booking->close();
|
|
} else {
|
|
echo "La capacità massima è stata raggiunta. Impossibile effettuare la prenotazione.\n";
|
|
}
|
|
}
|
|
$stmt_chk->close();
|
|
}
|
|
|
|
$update_order_status_query = "UPDATE orderbook SET status = 'booked' WHERE idorderbook = ?";
|
|
$stmt_status = $conn->prepare($update_order_status_query);
|
|
$stmt_status->bind_param("i", $order_id);
|
|
$stmt_status->execute();
|
|
$stmt_status->close();
|
|
echo "Aggiornato lo status a 'booked' per l'ordine ID: $order_id\n";
|
|
|
|
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 = 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';
|
|
include('mail/emailtemplate2.php');
|
|
$htmlContent = $mailmessage1;
|
|
$mail->From = 'info@yogasoul.it';
|
|
$mail->FromName = 'YogiBook [YogaSoul]';
|
|
$mail->addAddress($billing_email);
|
|
$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();
|
|
} else {
|
|
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();
|
|
|
|
// Recupera il numero di settimane da expiryparameter
|
|
$expiry_class_query = "SELECT quantityclass, first_lesson_date FROM orderbook WHERE idorderbook = ?";
|
|
$stmt_expiry = $conn->prepare($expiry_class_query);
|
|
$stmt_expiry->bind_param("i", $order_id);
|
|
$stmt_expiry->execute();
|
|
$expiry_class_result = $stmt_expiry->get_result();
|
|
|
|
if ($expiry_class_result && $expiry_class_result->num_rows > 0) {
|
|
$row = $expiry_class_result->fetch_assoc();
|
|
$quantity_class = $row['quantityclass'];
|
|
$first_lesson_date = $row['first_lesson_date'];
|
|
|
|
$expiry_weeks_query = "SELECT expiryweeks FROM expiryparameter WHERE quantityclass = ?";
|
|
$stmt_expiry_weeks = $conn->prepare($expiry_weeks_query);
|
|
$stmt_expiry_weeks->bind_param("i", $quantity_class);
|
|
$stmt_expiry_weeks->execute();
|
|
$expiry_weeks_result = $stmt_expiry_weeks->get_result();
|
|
|
|
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 basandosi su first_lesson_date
|
|
$update_expiry_query = "UPDATE orderbook SET expireon = DATE_ADD(first_lesson_date, INTERVAL ? WEEK) WHERE idorderbook = ?";
|
|
$stmt_update_expiry = $conn->prepare($update_expiry_query);
|
|
$stmt_update_expiry->bind_param("ii", $expiry_weeks, $order_id);
|
|
$stmt_update_expiry->execute();
|
|
$stmt_update_expiry->close();
|
|
|
|
echo "Aggiornata la colonna expireon per l'ordine ID: $order_id\n";
|
|
} else {
|
|
echo "Nessun record trovato in expiryparameter per quantityclass: $quantity_class\n";
|
|
}
|
|
$stmt_expiry_weeks->close();
|
|
} else {
|
|
echo "Nessun record trovato in orderbook per l'ordine ID: $order_id\n";
|
|
}
|
|
$stmt_expiry->close();
|
|
|
|
// Recupera il numero da expiryparameter per maxreschedule
|
|
$reschedule_number_query = "SELECT reschedulenumber FROM expiryparameter WHERE quantityclass = ?";
|
|
$stmt_reschedule = $conn->prepare($reschedule_number_query);
|
|
$stmt_reschedule->bind_param("i", $quantity_class);
|
|
$stmt_reschedule->execute();
|
|
$reschedule_number_result = $stmt_reschedule->get_result();
|
|
|
|
if ($reschedule_number_result && $reschedule_number_result->num_rows > 0) {
|
|
$reschedule_row = $reschedule_number_result->fetch_assoc();
|
|
$reschedule_number = $reschedule_row['reschedulenumber'];
|
|
|
|
$update_max_reschedule_query = "UPDATE orderbook SET maxreschedule = ? WHERE idorderbook = ?";
|
|
$stmt_max_reschedule = $conn->prepare($update_max_reschedule_query);
|
|
$stmt_max_reschedule->bind_param("ii", $reschedule_number, $order_id);
|
|
$stmt_max_reschedule->execute();
|
|
$stmt_max_reschedule->close();
|
|
|
|
echo "Aggiornata la colonna maxreschedule per l'ordine ID: $order_id\n";
|
|
header("Location: orderbooklist.php");
|
|
exit();
|
|
} else {
|
|
echo "Nessun record trovato in expiryparameter per quantityclass: $quantity_class\n";
|
|
}
|
|
$stmt_reschedule->close();
|
|
|
|
$conn->close();
|