317 lines
11 KiB
PHP
317 lines
11 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
if (!isset($iduserlogin)) header('Location: login.php');
|
|
|
|
$dbHandler = DBHandlerSelect::getInstance();
|
|
$pdo = $dbHandler->getConnection();
|
|
|
|
$school_id = $_SESSION['school_id'];
|
|
if (!$school_id) die("Nessuna scuola selezionata");
|
|
|
|
$stmt = $pdo->prepare("SELECT first_name FROM auth_users WHERE id = ?");
|
|
$stmt->execute([$iduserlogin]);
|
|
$user = $stmt->fetch();
|
|
|
|
$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.status,
|
|
cs.session_date,
|
|
cs.start_time,
|
|
cs.end_time,
|
|
cs.room_name,
|
|
c.name as class_name,
|
|
ct.level,
|
|
o.available_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
|
|
JOIN orders o ON sb.order_id = o.id
|
|
WHERE sb.user_id = ?
|
|
AND cs.school_id = ?
|
|
AND cs.session_date >= ?
|
|
AND cs.session_date < ?
|
|
ORDER BY cs.session_date ASC, cs.start_time ASC
|
|
");
|
|
$stmt->execute([$iduserlogin, $school_id, $startOfMonth, $endOfMonth]);
|
|
$bookings = $stmt->fetchAll();
|
|
?>
|
|
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Le mie lezioni</title>
|
|
<?php include('cssinclude.php'); ?>
|
|
<?php include('siteinfo.php'); ?>
|
|
<style>
|
|
.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;
|
|
margin: 1rem;
|
|
overflow: hidden;
|
|
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.09);
|
|
border-left: 6px solid #86efac;
|
|
}
|
|
|
|
.date-header {
|
|
background: #d1fae5;
|
|
color: #065f46;
|
|
padding: 1.4rem 1rem;
|
|
text-align: center;
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
.btn-outline-custom {
|
|
background: transparent;
|
|
color: #10b981;
|
|
border: 2px solid #10b981;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper">
|
|
<?php include('include/navbar.php'); ?>
|
|
<?php include('include/topbar.php'); ?>
|
|
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
|
|
<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 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: ?>
|
|
<?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>
|
|
|
|
<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>
|
|
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
|
|
<?php include('jsinclude.php'); ?>
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<script>
|
|
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>
|
|
|
|
</html>
|