Files
yogibook_aury_new/public/rebook-from-cancel.php
T

484 lines
21 KiB
PHP

<?php
// Abilita visualizzazione errori PHP (solo per debug)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Includi headscript.php
require_once('include/headscript.php');
// Connessione al database
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione al database fallita: " . $conn->connect_error);
}
// Inizializza log
$logFile = 'rebook_from_cancel_log.txt';
$logMessage = "Esecuzione riprogrammazione: " . date('Y-m-d H:i:s') . "\n";
// Recupera parametri GET
if (!isset($_GET['idbookingclass']) || !isset($_GET['token'])) {
$logMessage .= "Parametri mancanti: idbookingclass o token\n";
file_put_contents($logFile, $logMessage, FILE_APPEND);
echo "<h1>Riprogrammazione non possibile</h1>";
echo "<p>Parametri mancanti.</p>";
echo "<a href='https://yogibook.yogasoul.it'>Torna al portale</a>";
$conn->close();
exit;
}
$idbookingclass = filter_var($_GET['idbookingclass'], FILTER_VALIDATE_INT);
$token = $_GET['token'];
if (!$idbookingclass) {
$logMessage .= "Errore: idbookingclass non valido: " . $_GET['idbookingclass'] . "\n";
file_put_contents($logFile, $logMessage, FILE_APPEND);
echo "<h1>Riprogrammazione non possibile</h1>";
echo "<p>Parametro idbookingclass non valido.</p>";
echo "<a href='https://yogibook.yogasoul.it'>Torna al portale</a>";
$conn->close();
exit;
}
// Verifica validità della prenotazione
$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 auth_users au ON bc.iduser = au.id
LEFT JOIN service s ON bc.idservice = s.idservice
WHERE bc.idbookingclass = ?
AND bc.cancellation_token = ?
AND bc.status = 'booked'
AND bc.bookingstart > NOW()";
$stmt = $conn->prepare($query);
if (!$stmt) {
$logMessage .= "Errore preparazione query per ID $idbookingclass: " . $conn->error . "\n";
file_put_contents($logFile, $logMessage, FILE_APPEND);
echo "<h1>Riprogrammazione non possibile</h1>";
echo "<p>Errore nella preparazione della query.</p>";
echo "<a href='https://yogibook.yogasoul.it'>Torna al portale</a>";
$conn->close();
exit;
}
$stmt->bind_param("is", $idbookingclass, $token);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
$logMessage .= "Tentativo di riprogrammazione fallito per ID $idbookingclass: link non valido o lezione non prenotata\n";
file_put_contents($logFile, $logMessage, FILE_APPEND);
echo "<h1>Riprogrammazione non possibile</h1>";
echo "<p>Il link non è valido o la lezione non è prenotata.</p>";
echo "<a href='https://yogibook.yogasoul.it'>Torna al portale</a>";
$stmt->close();
$conn->close();
exit;
}
$row = $result->fetch_assoc();
$bookingstart = $row['bookingstart'];
$newtimeformat = date("d-m-Y H:i", strtotime($bookingstart));
$expireon = $row['expireon'] ? date("d-m-Y", strtotime($row['expireon'])) : "sconosciuta";
$emailuser = $row['email'];
$firstname = $row['first_name'] ?? 'Utente';
$servicename = $row['servicename'] ?? 'Sconosciuta';
$iduser = $row['iduser'];
$idserviceordered = $row['idservice'];
$idorder = $row['idorder'];
// Verifica il limite di cancellazione/riprogrammazione
$lessonTime = new DateTime($bookingstart);
$hour = (int)$lessonTime->format('H');
$minute = (int)$lessonTime->format('i');
$isBefore1700 = ($hour < 17) || ($hour === 17 && $minute === 0);
$currentTime = new DateTime();
$lessonDate = $lessonTime->format('Y-m-d');
if ($isBefore1700) {
$deadline = new DateTime("$lessonDate 00:01:00");
} else {
$deadline = new DateTime("$lessonDate 12:00:00");
}
if ($currentTime > $deadline) {
$logMessage .= "Tentativo di riprogrammazione fallito per ID $idbookingclass: orario oltre il limite (" . $deadline->format('Y-m-d H:i:s') . ")\n";
file_put_contents($logFile, $logMessage, FILE_APPEND);
echo "<h1>Riprogrammazione non possibile</h1>";
echo "<p>Non è possibile riprogrammare la lezione dopo le " . ($isBefore1700 ? "00:01" : "12:00") . " del giorno della lezione.</p>";
echo "<a href='https://yogibook.yogasoul.it'>Torna al portale</a>";
$stmt->close();
$conn->close();
exit;
}
// Recupera la data di scadenza dell'ordine
$expiryDate = new DateTime($row['expireon']);
// Query sulla tabella associateclass
$sql = "SELECT idassociateservice FROM associateclass WHERE idmainservice = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $idserviceordered);
$stmt->execute();
$result = $stmt->get_result();
$idassociateservices = array();
array_push($idassociateservices, $idserviceordered);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$idassociateservices[] = $row['idassociateservice'];
}
}
$stmt->close();
// Verifica se è stata specificata una richiesta per cambiare il mese
if (isset($_GET['prev_month'])) {
$currentMonthStart = $_GET['prev_month'] . '-01';
} elseif (isset($_GET['next_month'])) {
$currentMonthStart = $_GET['next_month'] . '-01';
} else {
$currentMonthStart = date("Y-m-01");
}
$currentMonthEnd = date("Y-m-t", strtotime($currentMonthStart));
// Aggiungi filtro per la data di scadenza
$expiryCondition = '';
if ($expiryDate) {
$expiryCondition = "AND serviceschedule.dateschedule <= '{$expiryDate->format('Y-m-d 23:59:59')}'";
}
// Query per le lezioni disponibili
$placeholders = implode(',', array_fill(0, count($idassociateservices), '?'));
$query = "SELECT ss.*, s.servicename, s.colorclass, s.maxcapacity
FROM serviceschedule ss
LEFT JOIN service s ON ss.idservice = s.idservice
WHERE ss.dateschedule BETWEEN ? AND DATE_ADD(?, INTERVAL 1 DAY)
$expiryCondition
AND ss.idservice IN ($placeholders)
ORDER BY ss.dateschedule";
$stmt = $conn->prepare($query);
$types = 'ss' . str_repeat('i', count($idassociateservices));
$params = array_merge([$currentMonthStart, $currentMonthEnd], $idassociateservices);
$stmt->bind_param($types, ...$params);
$stmt->execute();
$bookedclass = $stmt->get_result();
// Mappa dei mesi in italiano
$italianMonths = [
"January" => "Gennaio",
"February" => "Febbraio",
"March" => "Marzo",
"April" => "Aprile",
"May" => "Maggio",
"June" => "Giugno",
"July" => "Luglio",
"August" => "Agosto",
"September" => "Settembre",
"October" => "Ottobre",
"November" => "Novembre",
"December" => "Dicembre"
];
$logMessage .= "Caricata pagina di riprogrammazione per ID $idbookingclass, mese: $currentMonthStart\n";
file_put_contents($logFile, $logMessage, FILE_APPEND);
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8" />
<title>YogiBook - Riprogramma Lezione</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="YogiBook - Prenotazione facile YogaSOul" name="description" />
<meta content="Advanced Creative Solutions" author />
<link rel="shortcut icon" href="assets/images/favicon.ico">
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
<link href="assets/css/app.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<style>
.custom-card {
margin: 10px auto;
display: flex;
width: 90%;
max-width: 700px;
background-color: white;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
cursor: pointer;
transition: transform 0.2s;
}
.custom-card:hover {
transform: translateY(-5px);
}
.custom-date-box {
flex: 1;
background-color: red;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0;
font-size: 60px;
font-weight: bold;
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
}
.custom-day {
line-height: 1;
}
.custom-month {
font-size: 28px;
}
.custom-event-details {
flex: 2;
display: flex;
flex-direction: column;
padding: 10px 20px;
background-color: lightblue;
}
.custom-heading {
margin-top: 0;
font-size: 24px;
}
.custom-paragraph {
margin-bottom: 5px;
}
.custom-actions {
display: none;
flex-direction: row;
justify-content: space-between;
margin-top: 10px;
}
.custom-card.expanded .custom-actions {
display: flex;
}
.custom-action-button {
background-color: #f0f0f0;
border: none;
padding: 8px 12px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
.custom-action-button:hover {
background-color: #e0e0e0;
}
@media (max-width: 768px) {
.custom-card {
flex-direction: column;
}
.custom-date-box,
.custom-event-details {
width: 100%;
border-radius: 0;
}
.custom-event-time {
font-size: 24px;
}
}
.month-navigation {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
.month-nav-button {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
}
.current-month {
font-size: 24px;
margin: 0 20px;
}
.booking-details {
margin-top: 10px;
border-top: 1px solid #ccc;
padding-top: 10px;
}
.booking-button {
background-color: #1ebf73;
color: #fff;
border: none;
padding: 8px 12px;
border-radius: 4px;
cursor: pointer;
}
.booking-button:hover {
background-color: #17a663;
}
</style>
</head>
<body>
<div id="layout-wrapper">
<header id="page-topbar" class="isvertical-topbar">
<div class="navbar-header">
<div class="d-flex">
<?php include('include/logoarea.php'); ?>
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
<i class="bx bx-menu align-middle"></i>
</button>
<div class="page-title-box align-self-center d-none d-md-block">
<h4 class="page-title mb-0">Riprogramma la tua lezione</h4>
</div>
</div>
<div class="d-flex">
<?php include('include/languageselection.php'); ?>
<?php include('include/profiletopbar.php'); ?>
</div>
</div>
</header>
<?php include('include/sidebar.php'); ?>
<div class="main-content">
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<h3>Riprogrammazione Lezione</h3>
<p>Lezione attuale: <?php echo htmlspecialchars($servicename); ?> del <?php echo htmlspecialchars($newtimeformat); ?></p>
<p>Scadenza abbonamento: <?php echo htmlspecialchars($expireon); ?></p>
</div>
</div>
</div>
</div>
<div class="month-navigation">
<a href="?idbookingclass=<?php echo $idbookingclass; ?>&token=<?php echo urlencode($token); ?>&prev_month=<?php echo date('Y-m', strtotime('-1 month', strtotime($currentMonthStart))); ?>" class="arrow-link">
<i class="fas fa-chevron-left fa-2x"></i>
</a>
<h2><?php echo $italianMonths[date("F", strtotime($currentMonthStart))] . ' ' . date("Y", strtotime($currentMonthStart)); ?></h2>
<a href="?idbookingclass=<?php echo $idbookingclass; ?>&token=<?php echo urlencode($token); ?>&next_month=<?php echo date('Y-m', strtotime('+1 month', strtotime($currentMonthStart))); ?>" class="arrow-link">
<i class="fas fa-chevron-right fa-2x"></i>
</a>
</div>
<?php if ($bookedclass->num_rows == 0): ?>
<p>Classi non presenti per questo mese o oltre la data di scadenza.</p>
<a href="https://yogibook.yogasoul.it" class="btn btn-primary">Torna al portale</a>
<?php else: ?>
<?php while ($row = $bookedclass->fetch_assoc()): ?>
<?php
$dateschedule = $row['dateschedule'];
$dateObj = new DateTime($dateschedule);
$dayInItalian = $dateObj->format("d");
$monthInItalian = $italianMonths[$dateObj->format("F")];
$newDateFormat = $dateObj->format("d-m-Y H:i");
$eventId = $row['idserviceschedule'];
$bookingQuery = "SELECT iduser FROM bookingclass WHERE idserviceschedule = ? AND status='booked'";
$stmtBooking = $conn->prepare($bookingQuery);
$stmtBooking->bind_param("i", $eventId);
$stmtBooking->execute();
$bookingResult = $stmtBooking->get_result();
$countPersons = $bookingResult->num_rows;
$stmtBooking->close();
$maxcapacity = $row['maxcapacity'];
$freeplace = $maxcapacity - $countPersons;
$idcheckservice = $row['idserviceschedule'];
$query = "SELECT * FROM bookingclass WHERE idserviceschedule = ? AND iduser = ?";
$stmtCheck = $conn->prepare($query);
$stmtCheck->bind_param("ii", $idcheckservice, $iduser);
$stmtCheck->execute();
$resultcheck = $stmtCheck->get_result();
$alreadybooked = $resultcheck->num_rows > 0 ? 'Y' : 'N';
$stmtCheck->close();
?>
<div class="custom-card" onclick="toggleCard(this)">
<?php if ($alreadybooked == 'Y'): ?>
<div class="custom-date-box" style="background-color:#FF6609">
<?php elseif ($freeplace > 0): ?>
<div class="custom-date-box" style="background-color:#1ebf73">
<?php else: ?>
<div class="custom-date-box" style="background-color:#9C9C9C">
<?php endif; ?>
<div class="custom-day"><?php echo $dayInItalian; ?></div>
<div class="custom-month"><?php echo $monthInItalian; ?></div>
</div>
<?php if ($alreadybooked == 'Y'): ?>
<div class="custom-event-details" style="background-color:#FFAC7A">
<?php elseif ($freeplace > 0): ?>
<div class="custom-event-details" style="background-color:<?php echo htmlspecialchars($row['colorclass']); ?>">
<?php else: ?>
<div class="custom-event-details" style="background-color:#CDCDCD">
<?php endif; ?>
<h2 class="custom-heading"><?php echo htmlspecialchars($row['servicename']); ?> - <?php echo $countPersons; ?>/<?php echo $maxcapacity; ?></h2>
<p class="custom-paragraph">Quando: <?php echo $newDateFormat; ?></p>
<p class="custom-paragraph">Luogo: via Valassina 62/B Seregno - Sala Contesto Yoga</p>
<div class="booking-details">
<?php if ($alreadybooked == 'Y'): ?>
<button class="booking-button"><i class="fa fa-check"></i> Sei già prenotata/o</button>
<?php elseif ($freeplace > 0): ?>
<a href="rebookandgo.php?idpreviousbooking=<?php echo $idbookingclass; ?>&idservicenew=<?php echo $row['idservice']; ?>&idnewbooking=<?php echo $row['idserviceschedule']; ?>&iduser=<?php echo $iduser; ?>">
<button class="booking-button"><i class="fas fa-arrow-circle-right"></i> Riprogramma Classe</button>
</a>
<?php else: ?>
<button class="booking-button"><i class="fa fa-stop"></i> Classe Piena</button>
<?php endif; ?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<div class="month-navigation">
<a href="?idbookingclass=<?php echo $idbookingclass; ?>&token=<?php echo urlencode($token); ?>&prev_month=<?php echo date('Y-m', strtotime('-1 month', strtotime($currentMonthStart))); ?>" class="arrow-link">
<i class="fas fa-chevron-left fa-2x"></i>
</a>
<h2><?php echo $italianMonths[date("F", strtotime($currentMonthStart))] . ' ' . date("Y", strtotime($currentMonthStart)); ?></h2>
<a href="?idbookingclass=<?php echo $idbookingclass; ?>&token=<?php echo urlencode($token); ?>&next_month=<?php echo date('Y-m', strtotime('+1 month', strtotime($currentMonthStart))); ?>" class="arrow-link">
<i class="fas fa-chevron-right fa-2x"></i>
</a>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
</div>
<script>
function toggleCard(card) {
card.classList.toggle("expanded");
}
</script>
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
<script src="assets/libs/simplebar/simplebar.min.js"></script>
<script src="assets/libs/eva-icons/eva.min.js"></script>
<script src="assets/js/app.js"></script>
</body>
</html>
<?php
$stmt->close();
$conn->close();
?>