485 lines
20 KiB
PHP
485 lines
20 KiB
PHP
<?php
|
|
require_once('include/headscript.php');
|
|
|
|
/**
|
|
* Connessione unica PDO (singleton). $iduserlogin arriva dalla sessione
|
|
* autenticata via headscript.php. Lo forziamo comunque a intero.
|
|
*/
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
$iduserlogin = (int) $iduserlogin;
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* Helper per output sicuro in HTML (anti-XSS)
|
|
* ---------------------------------------------------------------------- */
|
|
function e($value): string
|
|
{
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* 1) Ordini dell'utente
|
|
* ---------------------------------------------------------------------- */
|
|
$sqlOrders = "SELECT o.idorderbook, o.order_id, o.idservice, o.order_date_created,
|
|
o.quantityclass, o.first_lesson_date, o.expireon,
|
|
o.maxreschedule, o.reprogrammed,
|
|
s.servicename, s.day, s.time
|
|
FROM orderbook o
|
|
LEFT JOIN service s ON o.idservice = s.idservice
|
|
WHERE o.iduser = :iduser
|
|
ORDER BY o.order_date_created DESC";
|
|
|
|
$stmtOrders = $pdo->prepare($sqlOrders);
|
|
$stmtOrders->execute([':iduser' => $iduserlogin]);
|
|
$orders = $stmtOrders->fetchAll();
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* 2) Tutte le lezioni degli ordini in UNA sola query (niente N+1)
|
|
* Poi le raggruppiamo per idorder in PHP.
|
|
* ---------------------------------------------------------------------- */
|
|
$lessonsByOrder = [];
|
|
$orderIds = array_filter(array_map(fn($o) => (int) $o['idorderbook'], $orders));
|
|
|
|
if (!empty($orderIds)) {
|
|
$placeholders = implode(',', array_fill(0, count($orderIds), '?'));
|
|
$sqlLessons = "SELECT bc.idbookingclass, bc.bookingstart, bc.status, bc.lostlesson,
|
|
bc.expirylesson, bc.idservice, bc.is_reprogrammed,
|
|
bc.idorder, s.servicename
|
|
FROM bookingclass bc
|
|
LEFT JOIN service s ON bc.idservice = s.idservice
|
|
WHERE bc.idorder IN ($placeholders)";
|
|
$stmtLessons = $pdo->prepare($sqlLessons);
|
|
$stmtLessons->execute(array_values($orderIds));
|
|
|
|
foreach ($stmtLessons->fetchAll() as $lesson) {
|
|
// Normalizziamo la data in formato ISO 8601 (come faceva date('c', ...))
|
|
if (!empty($lesson['bookingstart'])) {
|
|
$lesson['bookingstart'] = date('c', strtotime($lesson['bookingstart']));
|
|
}
|
|
$lessonsByOrder[(int) $lesson['idorder']][] = $lesson;
|
|
}
|
|
}
|
|
|
|
// Attacchiamo a ogni ordine il suo array di lezioni
|
|
foreach ($orders as &$order) {
|
|
$oid = (int) $order['idorderbook'];
|
|
$order['lessons'] = $lessonsByOrder[$oid] ?? [];
|
|
}
|
|
unset($order);
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>YogiBook - Prenotazioni YogaSoul</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" name="author" />
|
|
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
|
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
|
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
|
<link href="assets/css/app.min.css" id="app-style" 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@11"></script>
|
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
|
<script>
|
|
$(function() {
|
|
$("#expiryDate").datepicker({
|
|
dateFormat: "yy-mm-dd"
|
|
});
|
|
|
|
// ---- Funzione unica per costruire e mostrare il popup dettagli ordine ----
|
|
function showOrderDetails(data) {
|
|
var lessons = data.lessons || [];
|
|
var total = data.total;
|
|
var orderId = data.orderId;
|
|
var isExpired = data.isExpired === true;
|
|
var expireOn = data.expireOn;
|
|
|
|
var now = new Date();
|
|
|
|
var completed = lessons.filter(function(l) {
|
|
var lessonDate = new Date(l.bookingstart);
|
|
return (l.status === 'completed') ||
|
|
(l.status === 'booked' && lessonDate < now && l.lostlesson !== 'Y' && l.expirylesson !== 'Y');
|
|
}).length;
|
|
var lost = lessons.filter(function(l) {
|
|
return l.lostlesson === 'Y';
|
|
}).length;
|
|
var expired = lessons.filter(function(l) {
|
|
return l.expirylesson === 'Y';
|
|
}).length;
|
|
var booked = lessons.filter(function(l) {
|
|
var lessonDate = new Date(l.bookingstart);
|
|
return (l.status === 'booked' && lessonDate >= now && l.lostlesson !== 'Y' && l.expirylesson !== 'Y');
|
|
}).length;
|
|
var toSchedule = total - (booked + completed + lost + expired);
|
|
|
|
// Se l'ordine è scaduto, le "Da Programmare" diventano "Scadute"
|
|
if (isExpired) {
|
|
expired += toSchedule;
|
|
toSchedule = 0;
|
|
}
|
|
|
|
var expireOnFormatted = expireOn ? new Date(expireOn).toLocaleDateString('it-IT', {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: 'numeric'
|
|
}) : 'Non specificata';
|
|
|
|
var htmlContent = `
|
|
<h4 style="margin-bottom: 20px; color: #333; font-weight: 600;">
|
|
Dettagli Ordine #${orderId}
|
|
<span class="badge ${isExpired ? 'bg-danger' : 'bg-primary'}" style="margin-left: 10px; color: white;">
|
|
${isExpired ? 'Scaduto' : 'Attivo'}
|
|
</span>
|
|
</h4>
|
|
<div style="display: flex; justify-content: space-around; margin-bottom: 30px; gap: 10px;">
|
|
<div class="stat-box" style="background-color: #d1e7dd; border: 1px solid #a3cfbb;" title="Numero di lezioni acquistate per questo ordine">
|
|
<h5 style="margin: 0; color: #0f5132; font-size: 14px;">Totale</h5>
|
|
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #0f5132;">${total}</p>
|
|
</div>
|
|
<div class="stat-box" style="background-color: #d4edda; border: 1px solid #b1d4b6;" title="Lezioni già praticate">
|
|
<h5 style="margin: 0; color: #155724; font-size: 14px;">Praticate</h5>
|
|
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #155724;">${completed}</p>
|
|
</div>
|
|
<div class="stat-box" style="background-color: #f8d7da; border: 1px solid #f1aeb5;" title="Lezioni non praticate e non riprogrammate in tempo">
|
|
<h5 style="margin: 0; color: #721c24; font-size: 14px;">Perse</h5>
|
|
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #721c24;">${lost}</p>
|
|
</div>
|
|
<div class="stat-box" style="background-color: #fff3cd; border: 1px solid #ffecb5;" title="Lezioni non riprogrammate entro la data di scadenza dell'ordine">
|
|
<h5 style="margin: 0; color: #856404; font-size: 14px;">Scadute</h5>
|
|
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #856404;">${expired}</p>
|
|
</div>
|
|
<div class="stat-box" style="background-color: #e2d3f5; border: 1px solid #c3b2d6;" title="Lezioni da programmare entro la data di scadenza del tuo ordine (${expireOnFormatted})">
|
|
<h5 style="margin: 0; color: #4c2c92; font-size: 14px;">Da Programmare</h5>
|
|
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #4c2c92;">${toSchedule}</p>
|
|
</div>
|
|
</div>
|
|
<div style="background-color: #f8f9fa; padding: 15px; border-radius: 8px;">
|
|
<p style="margin: 0 0 15px 0; color: #333; font-size: 14px; font-weight: 500;">
|
|
Il tuo ordine scadrà il ${expireOnFormatted}
|
|
</p>
|
|
<table class="lesson-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Data e Ora</th>
|
|
<th>Lezione</th>
|
|
<th>Stato</th>
|
|
<th>Riprogrammata</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
if (lessons.length === 0) {
|
|
htmlContent += `
|
|
<tr>
|
|
<td colspan="4" style="text-align: center; padding: 10px; color: #666; font-size: 13px;">
|
|
Nessuna lezione trovata per questo ordine.
|
|
</td>
|
|
</tr>
|
|
`;
|
|
} else {
|
|
lessons.forEach(function(lesson, index) {
|
|
var lessonDate = new Date(lesson.bookingstart);
|
|
var statusText = lesson.status;
|
|
var badgeClass = 'bg-primary';
|
|
var badgeTextColor = '#fff';
|
|
if (lesson.status === 'completed') {
|
|
badgeClass = 'bg-success';
|
|
badgeTextColor = '#fff';
|
|
statusText = 'Completata';
|
|
} else if (lesson.lostlesson === 'Y') {
|
|
badgeClass = 'bg-danger';
|
|
badgeTextColor = '#fff';
|
|
statusText = 'Persa';
|
|
} else if (lesson.expirylesson === 'Y') {
|
|
badgeClass = 'bg-warning';
|
|
badgeTextColor = '#000';
|
|
statusText = 'Scaduta';
|
|
} else if (lesson.status === 'booked') {
|
|
if (lessonDate < now && lesson.lostlesson !== 'Y' && lesson.expirylesson !== 'Y') {
|
|
statusText = 'Completata';
|
|
badgeClass = 'bg-success';
|
|
badgeTextColor = '#fff';
|
|
} else {
|
|
statusText = 'Programmata';
|
|
}
|
|
}
|
|
var isReprogrammedText = lesson.is_reprogrammed === 'Y' ? 'Sì' : 'No';
|
|
|
|
htmlContent += `
|
|
<tr class="${index % 2 === 0 ? 'even-row' : 'odd-row'}">
|
|
<td style="padding: 8px; font-size: 13px;">${lessonDate.toLocaleString('it-IT', {
|
|
day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit'
|
|
})}</td>
|
|
<td style="padding: 8px; font-size: 13px;">${lesson.servicename ?? ''}</td>
|
|
<td style="padding: 8px;">
|
|
<span class="badge ${badgeClass}" style="color: ${badgeTextColor}; padding: 6px 10px; font-size: 12px; font-weight: 500;">${statusText}</span>
|
|
</td>
|
|
<td style="padding: 8px; font-size: 13px;">${isReprogrammedText}</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
}
|
|
|
|
htmlContent += `
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
`;
|
|
|
|
Swal.fire({
|
|
title: '',
|
|
html: htmlContent,
|
|
confirmButtonText: 'Chiudi',
|
|
width: '1000px',
|
|
customClass: {
|
|
popup: 'custom-modal'
|
|
}
|
|
});
|
|
}
|
|
|
|
// Estrae i dati dalla riga e chiama la funzione unica
|
|
function detailsFromRow(row) {
|
|
showOrderDetails({
|
|
lessons: row.data('lessons'),
|
|
total: row.data('total'),
|
|
orderId: row.data('order-id'),
|
|
isExpired: row.data('is-expired') === true,
|
|
expireOn: row.data('expireon')
|
|
});
|
|
}
|
|
|
|
// Click sulla riga
|
|
$('.order-row').click(function() {
|
|
detailsFromRow($(this));
|
|
});
|
|
|
|
// Click sul bottone "Dettagli" (senza propagare alla riga)
|
|
$('.details-btn').click(function(e) {
|
|
e.stopPropagation();
|
|
detailsFromRow($(this).closest('tr'));
|
|
});
|
|
});
|
|
|
|
function confirmDelete(id, deletePageUrl) {
|
|
Swal.fire({
|
|
title: "Sei sicuro?",
|
|
text: "Questa prenotazione verrà cancellata definitivamente! Ricordati poi di riprogrammare la tua lezione!",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#d33",
|
|
cancelButtonColor: "#3085d6",
|
|
confirmButtonText: "Sì, cancella!",
|
|
cancelButtonText: "Annulla"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
window.location.href = `deleteclass.php?id=${id}`;
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<style>
|
|
.order-row {
|
|
cursor: pointer;
|
|
}
|
|
|
|
.order-row:hover {
|
|
background-color: #f8f9fa !important;
|
|
}
|
|
|
|
.stat-box {
|
|
padding: 12px;
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
width: 18%;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
transition: transform 0.2s;
|
|
}
|
|
|
|
.stat-box:hover {
|
|
transform: translateY(-3px);
|
|
}
|
|
|
|
.custom-modal .swal2-content {
|
|
padding: 20px;
|
|
}
|
|
|
|
.custom-modal .lesson-table {
|
|
width: 100% !important;
|
|
border-collapse: collapse !important;
|
|
font-size: 13px !important;
|
|
color: #333 !important;
|
|
}
|
|
|
|
.custom-modal .lesson-table th {
|
|
background-color: #e9ecef !important;
|
|
padding: 10px !important;
|
|
text-align: left !important;
|
|
font-weight: 600 !important;
|
|
border-bottom: 2px solid #dee2e6 !important;
|
|
border-right: 1px solid #dee2e6 !important;
|
|
}
|
|
|
|
.custom-modal .lesson-table th:last-child {
|
|
border-right: none !important;
|
|
}
|
|
|
|
.custom-modal .lesson-table td {
|
|
padding: 8px !important;
|
|
line-height: 1.2 !important;
|
|
vertical-align: middle !important;
|
|
border-bottom: 1px solid #dee2e6 !important;
|
|
border-right: 1px solid #dee2e6 !important;
|
|
text-align: left !important;
|
|
}
|
|
|
|
.custom-modal .lesson-table td:last-child {
|
|
border-right: none !important;
|
|
}
|
|
|
|
.custom-modal .lesson-table .even-row {
|
|
background-color: #fff !important;
|
|
}
|
|
|
|
.custom-modal .lesson-table .odd-row {
|
|
background-color: #f8f9fa !important;
|
|
}
|
|
|
|
.custom-modal .lesson-table tr:hover {
|
|
background-color: #e9ecef !important;
|
|
}
|
|
|
|
.details-btn {
|
|
margin-left: 10px;
|
|
padding: 5px 10px;
|
|
font-size: 12px;
|
|
background-color: #007bff;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s;
|
|
}
|
|
|
|
.details-btn:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
</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">Prenotazione Classi</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'); ?>
|
|
<header class="ishorizontal-topbar">
|
|
<div class="navbar-header">
|
|
<div class="d-flex"></div>
|
|
</div>
|
|
<div class="topnav">
|
|
<div class="container-fluid">
|
|
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<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">
|
|
<h5>Benvenuta/o <?php echo e($firstname); ?></h5>
|
|
<p>Di seguito puoi visualizzare i tuoi ordini</p>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>N. Ordine</th>
|
|
<th>Data Ordine</th>
|
|
<th>Classe</th>
|
|
<th>Giorno/Ora</th>
|
|
<th>N. Ticket</th>
|
|
<th>Prima Lezione</th>
|
|
<th>Scadenza</th>
|
|
<th>Riprogr. Massime</th>
|
|
<th>Riprogrammate</th>
|
|
<th>Stato</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($orders as $document) {
|
|
$is_expired = strtotime($document['expireon']) < time();
|
|
?>
|
|
<tr class="order-row"
|
|
data-lessons='<?php echo e(json_encode($document['lessons'])); ?>'
|
|
data-total='<?php echo e($document['quantityclass']); ?>'
|
|
data-order-id='<?php echo e($document['idorderbook']); ?>'
|
|
data-is-expired='<?php echo $is_expired ? 'true' : 'false'; ?>'
|
|
data-expireon='<?php echo e($document['expireon']); ?>'>
|
|
<td><?php echo e($document['idorderbook']); ?></td>
|
|
<td><?php echo e(date('d-m-Y', strtotime($document['order_date_created']))); ?></td>
|
|
<td><?php echo e($document['servicename']); ?></td>
|
|
<td><?php echo e($document['day'] . ' ' . $document['time']); ?></td>
|
|
<td><?php echo e($document['quantityclass']); ?></td>
|
|
<td><?php echo e($document['first_lesson_date'] ? date('d-m-Y', strtotime($document['first_lesson_date'])) : '-'); ?></td>
|
|
<td style="<?php echo $is_expired ? 'color: #dc3545;' : ''; ?>">
|
|
<?php echo e(date('d-m-Y', strtotime($document['expireon']))); ?>
|
|
</td>
|
|
<td>
|
|
<span style="display: inline-block; padding: 4px 8px; font-size: 11px; font-weight: 500; color: #fff; background-color: #17a2b8; border-radius: 4px;">
|
|
<?php echo e($document['maxreschedule']); ?>
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span style="display: inline-block; padding: 4px 8px; font-size: 11px; font-weight: 500; color: #fff; background-color: <?php echo ($document['reprogrammed'] >= $document['maxreschedule']) ? '#dc3545' : '#28a745'; ?>; border-radius: 4px;">
|
|
<?php echo e($document['reprogrammed']); ?>
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span class="badge <?php echo $is_expired ? 'bg-danger' : 'bg-primary'; ?>">
|
|
<?php echo $is_expired ? 'Scaduto' : 'Attivo'; ?>
|
|
</span>
|
|
<button class="details-btn">Dettagli</button>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
</div>
|
|
<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>
|