652 lines
25 KiB
PHP

<?php require_once('include/headscript.php'); ?>
<?php
// optionquery
$optionquery = new WA_MySQLi_RS("optionquery", $bkngstm, 0);
$optionquery->setQuery("SELECT * FROM option");
$optionquery->execute();
?>
<?php
// Verifica se è stato inviato un modulo
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_FILES["fileToUpload"]) && $_FILES["fileToUpload"]["error"] === UPLOAD_ERR_OK) {
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione al database fallita: " . $conn->connect_error);
}
$iduserlogin = $_POST["iduserlogin"];
$conn->close();
}
}
?>
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione al database fallita: " . $conn->connect_error);
}
// Query per selezionare i dati filtrati per iduser
$query = "SELECT o.*, s.servicename, s.day, s.time
FROM orderbook o
LEFT JOIN service s ON o.idservice = s.idservice
WHERE o.iduser = '$iduserlogin'";
$result = $conn->query($query);
$documents = array();
while ($row = $result->fetch_assoc()) {
// Get lesson details for each order
$order_id = $row['order_id'];
$lesson_query = "SELECT bc.bookingstart, bc.status, bc.lostlesson, bc.expirylesson, s.servicename
FROM bookingclass bc
LEFT JOIN service s ON bc.idservice = s.idservice
WHERE bc.idorder = '$order_id'";
$lesson_result = $conn->query($lesson_query);
$lessons = array();
while ($lesson_row = $lesson_result->fetch_assoc()) {
$lessons[] = $lesson_row;
}
$row['lessons'] = $lessons;
$documents[] = $row;
}
?>
<!doctype html>
<html lang="en">
<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@10"></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"
});
// Handle order click for popup
$('.order-row').click(function() {
var lessons = $(this).data('lessons');
var total = $(this).data('total');
var orderId = $(this).data('order-id');
var isExpired = $(this).data('is-expired');
// Calcolo delle date
var now = new Date();
// Calcolo dei conteggi
var completed = lessons.filter(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(l => l.lostlesson === 'Y').length;
var expired = lessons.filter(l => l.expirylesson === 'Y').length;
var booked = lessons.filter(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);
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;">
<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;">
<h5 style="margin: 0; color: #155724; font-size: 14px;">Fatte</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;">
<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;">
<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;">
<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;">
<table class="lesson-table">
<thead>
<tr>
<th>Data e Ora</th>
<th>Lezione</th>
<th>Stato</th>
</tr>
</thead>
<tbody>
`;
if (lessons.length === 0) {
htmlContent += `
<tr>
<td colspan="3" 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';
}
}
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>
</tr>
`;
});
}
htmlContent += `
</tbody>
</table>
</div>
`;
Swal.fire({
title: '',
html: htmlContent,
confirmButtonText: 'Chiudi',
width: '1000px',
customClass: {
popup: 'custom-modal'
}
});
});
// Handle details button click
$('.details-btn').click(function(e) {
e.stopPropagation(); // Prevent row click event
var row = $(this).closest('tr');
var lessons = row.data('lessons');
var total = row.data('total');
var orderId = row.data('order-id');
var isExpired = row.data('is-expired');
// Calcolo delle date
var now = new Date();
// Calcolo dei conteggi
var completed = lessons.filter(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(l => l.lostlesson === 'Y').length;
var expired = lessons.filter(l => l.expirylesson === 'Y').length;
var booked = lessons.filter(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);
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;">
<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;">
<h5 style="margin: 0; color: #155724; font-size: 14px;">Fatte</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;">
<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;">
<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;">
<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;">
<table class="lesson-table">
<thead>
<tr>
<th>Data e Ora</th>
<th>Lezione</th>
<th>Stato</th>
</tr>
</thead>
<tbody>
`;
if (lessons.length === 0) {
htmlContent += `
<tr>
<td colspan="3" 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';
}
}
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>
</tr>
`;
});
}
htmlContent += `
</tbody>
</table>
</div>
`;
Swal.fire({
title: '',
html: htmlContent,
confirmButtonText: 'Chiudi',
width: '1000px',
customClass: {
popup: 'custom-modal'
}
});
});
});
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>
.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: #ff4d4f;
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: #e6f3ff;
}
.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;
}
}
.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 $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>Stato</th>
</tr>
</thead>
<tbody>
<?php foreach ($documents as $document) {
$is_expired = strtotime($document['expireon']) < time();
?>
<tr class="order-row"
data-lessons='<?php echo json_encode($document['lessons']); ?>'
data-total='<?php echo $document['quantityclass']; ?>'
data-order-id='<?php echo $document['order_id']; ?>'
data-is-expired='<?php echo $is_expired ? 'true' : 'false'; ?>'>
<td><?php echo $document['order_id']; ?></td>
<td><?php echo date('d-m-Y', strtotime($document['order_date_created'])); ?></td>
<td><?php echo $document['servicename']; ?></td>
<td><?php echo $document['day'] . ' ' . $document['time']; ?></td>
<td><?php echo $document['quantityclass']; ?></td>
<td><?php echo $document['first_lesson_date'] ? date('d-m-Y', strtotime($document['first_lesson_date'])) : '-'; ?></td>
<td><?php echo date('d-m-Y', strtotime($document['expireon'])); ?></td>
<td>
<span class="badge <?php echo $is_expired ? 'bg-danger' : 'bg-primary'; ?>">
<?php echo $is_expired ? 'Scaduto' : 'Attivo'; ?>
</span>
<button class="details-btn" data-order-id="<?php echo $document['order_id']; ?>" data-lessons='<?php echo json_encode($document['lessons']); ?>' data-total='<?php echo $document['quantityclass']; ?>' data-is-expired='<?php echo $is_expired ? 'true' : 'false'; ?>'>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>
<?php $conn->close(); ?>