fixed multi school account

This commit is contained in:
2025-12-20 18:18:15 +01:00
parent 70d01f160e
commit 67cc0742ff
8 changed files with 1176 additions and 201 deletions
+223 -163
View File
@@ -5,44 +5,52 @@ if (!isset($iduserlogin)) header('Location: login.php');
$dbHandler = DBHandlerSelect::getInstance();
$pdo = $dbHandler->getConnection();
// Scuola corrente
$school_id = session('school_id');
if (!$school_id) die("Nessuna scuola selezionata");
// Dati utente
$stmt = $pdo->prepare("SELECT first_name FROM auth_users WHERE id = ?");
$stmt->execute([$iduserlogin]);
$user = $stmt->fetch();
// === LEZIONI FUTURE DELL'UTENTE (prenotate) ===
$stmt = $pdo->prepare("SELECT name, address_street, address_city, address_province FROM schools WHERE id = ?");
$stmt->execute([$school_id]);
$school = $stmt->fetch();
$currentMonth = $_GET['month'] ?? date('Y-m');
$monthDate = DateTime::createFromFormat('Y-m', $currentMonth) ?: new DateTime();
$prevMonth = (clone $monthDate)->modify('-1 month')->format('Y-m');
$nextMonth = (clone $monthDate)->modify('+1 month')->format('Y-m');
setlocale(LC_TIME, 'it_IT.UTF-8', 'Italian');
$monthName = ucfirst(utf8_encode(strftime('%B %Y', $monthDate->getTimestamp())));
$startOfMonth = $monthDate->format('Y-m-01');
$endOfMonth = (clone $monthDate)->modify('first day of next month')->format('Y-m-d');
$stmt = $pdo->prepare("
SELECT
sb.id as booking_id,
sb.booked_at,
sb.status,
cs.session_date,
cs.start_time,
cs.end_time,
cs.room_name,
c.name as class_name,
ct.level,
ct.day_of_week,
t.first_name as teacher_name,
o.id as order_id,
o.available_entries,
o.total_entries,
o.available_recoveries
FROM session_bookings sb
JOIN class_sessions cs ON sb.session_id = cs.id
JOIN class_types ct ON cs.class_type_id = ct.id
JOIN classes c ON ct.class_id = c.id
LEFT JOIN teachers t ON cs.teacher_id = t.id
JOIN orders o ON sb.order_id = o.id
WHERE sb.user_id = ?
AND cs.school_id = ?
AND cs.session_date >= CURDATE()
AND cs.session_date >= ?
AND cs.session_date < ?
ORDER BY cs.session_date ASC, cs.start_time ASC
");
$stmt->execute([$iduserlogin, $school_id]);
$stmt->execute([$iduserlogin, $school_id, $startOfMonth, $endOfMonth]);
$bookings = $stmt->fetchAll();
?>
@@ -52,51 +60,132 @@ $bookings = $stmt->fetchAll();
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Le mie lezioni - Yogiboook</title>
<title>Le mie lezioni</title>
<?php include('cssinclude.php'); ?>
<?php include('siteinfo.php'); ?>
<style>
:root {
--pastel-blue: #94bacc;
--pastel-green: #a3d9b1;
--pastel-pink: #f8bbd0;
.page-content {
background: #f9fff9;
padding-bottom: 3rem;
}
.month-header {
background: white;
padding: 0.9rem 1rem;
text-align: center;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.07);
position: sticky;
top: 0;
z-index: 10;
margin-bottom: 1.2rem;
}
.month-header h2 {
font-size: 1.45rem;
font-weight: 700;
margin: 0;
color: #1a1a1a;
}
.nav-arrow {
font-size: 1.7rem;
color: #10b981;
text-decoration: none;
}
.lesson-card {
background: white;
border-radius: 18px;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease;
border-left: 5px solid var(--pastel-blue);
margin: 1rem;
overflow: hidden;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.09);
border-left: 6px solid #86efac;
}
.lesson-card:hover {
transform: translateY(-8px);
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
.date-header {
background: #d1fae5;
color: #065f46;
padding: 1.4rem 1rem;
text-align: center;
}
.status-badge {
padding: 0.4em 1em;
border-radius: 50px;
font-size: 0.85rem;
.date-num {
font-size: 2.7rem;
font-weight: 800;
line-height: 1;
margin: 0;
}
.date-day {
font-size: 1.18rem;
font-weight: 600;
margin: 5px 0 0;
}
.btn-reschedule {
background: linear-gradient(45deg, #ff9a9e, #fad0c4);
.lesson-body {
padding: 1.4rem 1.3rem;
}
.lesson-title {
font-size: 1.38rem;
font-weight: 700;
color: #1a1a1a;
margin: 0 0 0.8rem;
}
.lesson-meta {
font-size: 0.98rem;
color: #444;
margin: 0.5rem 0;
display: flex;
align-items: center;
gap: 10px;
}
.lesson-meta i {
width: 20px;
color: #666;
font-size: 1.1rem;
}
.entries-badge {
display: inline-block;
background: #dbeafe;
color: #1e40af;
padding: 0.6rem 1rem;
border-radius: 12px;
font-weight: 600;
font-size: 0.92rem;
margin: 0.8rem 0;
}
.action-buttons {
margin-top: 1.2rem;
display: flex;
gap: 0.8rem;
flex-wrap: wrap;
}
.btn-custom {
flex: 1;
min-width: 130px;
padding: 0.85rem;
border-radius: 14px;
font-weight: 600;
font-size: 0.95rem;
text-align: center;
}
.btn-primary-custom {
background: #10b981;
color: white;
border: none;
color: white;
border-radius: 25px;
padding: 0.5rem 1.2rem;
font-size: 0.9rem;
}
.btn-cancel {
background: #e74c3c;
color: white;
border-radius: 25px;
padding: 0.5rem 1rem;
font-size: 0.85rem;
.btn-outline-custom {
background: transparent;
color: #10b981;
border: 2px solid #10b981;
}
</style>
</head>
@@ -107,96 +196,88 @@ $bookings = $stmt->fetchAll();
<?php include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content" style="background: linear-gradient(to bottom, #f8fdff, #f0f8ff);">
<div class="page-content">
<div class="container-fluid px-4 pt-4">
<div class="text-center mb-5">
<h1 class="display-5 fw-bold text-primary">
Le tue lezioni future
</h1>
<p class="lead text-muted">
<?php echo $user['first_name']; ?>, ecco tutte le lezioni che hai prenotato
</p>
<div class="month-header">
<div class="d-flex justify-content-between align-items-center">
<a href="?month=<?= $prevMonth ?>" class="nav-arrow"></a>
<h2><?= $monthName ?></h2>
<a href="?month=<?= $nextMonth ?>" class="nav-arrow"></a>
</div>
</div>
<div class="container-fluid px-0">
<?php if (empty($bookings)): ?>
<div class="text-center py-5">
<i class="bx bx-calendar-x bx-lg text-muted"></i>
<h4 class="text-muted mt-4">Nessuna lezione prenotata</h4>
<p class="text-muted">Quando acquisterai un carnet o un abbonamento, potrai prenotare qui le tue lezioni!</p>
<a href="products.php" class="btn btn-primary btn-lg mt-3">Vai ai corsi</a>
<div class="text-center py-5 px-3">
<i class="bx bx-calendar-x" style="font-size:4.5rem;color:#e0e0e0;"></i>
<h3 class="mt-4 text-secondary">Nessuna lezione prenotata</h3>
<p class="text-muted">Le tue lezioni appariranno qui</p>
<a href="products.php" class="btn btn-success btn-lg mt-3">Vedi i corsi</a>
</div>
<?php else: ?>
<div class="row g-4">
<?php foreach ($bookings as $b): ?>
<div class="col-lg-6 col-xl-4">
<div class="card lesson-card h-100">
<div class="card-body p-4">
<!-- Data e ora -->
<div class="d-flex justify-content-between align-items-start mb-3">
<div>
<h5 class="mb-1"><?php echo date('d', strtotime($b['session_date'])); ?></h5>
<p class="text-muted mb-0"><?php echo ucfirst(strftime('%B %Y', strtotime($b['session_date']))); ?></p>
</div>
<span class="status-badge <?php
echo $b['status'] == 'booked' ? 'bg-success' : ($b['status'] == 'cancelled' ? 'bg-danger' : 'bg-warning');
?>">
<?php echo $b['status'] == 'booked' ? 'Prenotata' : ($b['status'] == 'cancelled' ? 'Annullata' : 'In attesa'); ?>
</span>
</div>
<!-- Dettagli lezione -->
<h4 class="mb-2"><?php echo htmlspecialchars($b['class_name']); ?></h4>
<p class="text-primary mb-2">
<?php echo ucfirst($b['level'] ?? 'Tutti i livelli'); ?>
<?php if ($b['day_of_week']): ?> • <?php echo ucfirst($b['day_of_week']); ?><?php endif; ?>
</p>
<div class="mb-3">
<p class="mb-1">
<i class="bx bx-time"></i>
<?php echo date('H:i', strtotime($b['start_time'])); ?> - <?php echo date('H:i', strtotime($b['end_time'])); ?>
</p>
<?php if ($b['teacher_name']): ?>
<p class="mb-1">
<i class="bx bx-user"></i> Con <?php echo htmlspecialchars($b['teacher_name']); ?>
</p>
<?php endif; ?>
</div>
<!-- Ingressi rimanenti -->
<div class="alert alert-light border mb-3 py-2">
<small class="d-block">
<strong>Ingressi:</strong>
<span class="text-success"><?php echo $b['available_entries']; ?></span>/<?php echo $b['total_entries']; ?>
<?php if ($b['available_recoveries'] > 0): ?>
<strong>Recuperi:</strong> <?php echo $b['available_recoveries']; ?>
<?php endif; ?>
</small>
</div>
<!-- Pulsanti azione -->
<div class="d-flex gap-2">
<?php if ($b['status'] == 'booked' && strtotime($b['session_date']) > time() + 86400): // più di 24h prima
?>
<button class="btn btn-reschedule" onclick="reschedule(<?php echo $b['booking_id']; ?>)">
Riprogramma
</button>
<button class="btn btn-cancel btn-sm" onclick="cancelBooking(<?php echo $b['booking_id']; ?>)">
Annulla
</button>
<?php else: ?>
<button class="btn btn-secondary btn-sm" disabled>
Non modificabile
</button>
<?php endif; ?>
</div>
</div>
<?php foreach ($bookings as $b): ?>
<div class="lesson-card">
<div class="date-header">
<div class="date-num"><?= date('d', strtotime($b['session_date'])) ?></div>
<div class="date-day">
<?= ucfirst(utf8_encode(strftime('%A', strtotime($b['session_date'])))) ?>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="lesson-body">
<h3 class="lesson-title">
<?= htmlspecialchars($b['class_name']) ?>
<?php if ($b['level']): ?> <small style="color:#666;">- <?= ucfirst($b['level']) ?></small><?php endif; ?>
</h3>
<div class="lesson-meta">
<i class="bx bx-time"></i>
<?= date('H:i', strtotime($b['start_time'])) ?> - <?= date('H:i', strtotime($b['end_time'])) ?>
</div>
<div class="lesson-meta">
<i class="bx bx-home"></i>
<?= htmlspecialchars($school['name']) ?>
<?php if ($b['room_name']): ?> - <?= htmlspecialchars($b['room_name']) ?><?php endif; ?>
</div>
<div class="lesson-meta">
<i class="bx bx-map"></i>
<?= htmlspecialchars(trim($school['address_street'] . ', ' . $school['address_city'] . ' ' . $school['address_province'])) ?>
</div>
<?php if ($b['available_entries'] > 0 || $b['available_recoveries'] > 0): ?>
<div class="entries-badge">
<?php if ($b['available_entries'] > 0): ?>
Ingressi disponibili: <strong><?= $b['available_entries'] ?></strong>
<?php endif; ?>
<?php if ($b['available_recoveries'] > 0): ?>
<?= $b['available_entries'] > 0 ? ' • ' : '' ?>
Recuperi: <strong><?= $b['available_recoveries'] ?></strong>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($b['status'] == 'booked' && strtotime($b['session_date']) > time() + 86400): ?>
<div class="action-buttons">
<button class="btn-custom btn-primary-custom" onclick="reschedule(<?= $b['booking_id'] ?>)">
Riprogramma
</button>
<button class="btn-custom btn-outline-custom" onclick="cancelBooking(<?= $b['booking_id'] ?>)">
Cancella
</button>
</div>
<?php else: ?>
<div class="text-muted small mt-3">
Non modificabile (entro 24 ore)
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
@@ -205,52 +286,31 @@ $bookings = $stmt->fetchAll();
</div>
<?php include('jsinclude.php'); ?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
function reschedule(bookingId) {
Swal.fire({
title: 'Riprogrammare lezione?',
text: "Vuoi scegliere un nuovo orario per questa lezione?",
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Sì, riprogramma',
cancelButtonText: 'Annulla'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = 'reschedule.php?booking=' + bookingId;
}
});
}
function cancelBooking(bookingId) {
Swal.fire({
title: 'Annullare prenotazione?',
text: "L'ingresso ti verrà restituito come recupero",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#e74c3c',
confirmButtonText: 'Sì, annulla',
cancelButtonText: 'No, tienila'
}).then((result) => {
if (result.isConfirmed) {
fetch('cancel_booking.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'booking_id=' + bookingId
}).then(r => r.json()).then(data => {
if (data.success) {
Swal.fire('Annullata!', 'La lezione è stata annullata e hai ricevuto un recupero.', 'success')
.then(() => location.reload());
} else {
Swal.fire('Errore', data.message, 'error');
}
});
}
});
}
const reschedule = id => Swal.fire({
title: 'Riprogrammare?',
text: 'Scegli un nuovo orario',
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Sì',
cancelButtonText: 'No'
}).then(r => r.isConfirmed && (location = 'reschedule.php?booking=' + id));
const cancelBooking = id => Swal.fire({
title: 'Annullare prenotazione?',
text: 'Riceverai un recupero',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#ef4444',
confirmButtonText: 'Sì, annulla',
cancelButtonText: 'No'
}).then(r => r.isConfirmed && fetch('cancel_booking.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'booking_id=' + id
}).then(r => r.json()).then(d => d.success ? Swal.fire('Annullata!', 'Hai un recupero', 'success').then(() => location.reload()) : Swal.fire('Errore', d.message, 'error')));
</script>
</body>