fixed multi school account
This commit is contained in:
@@ -932,6 +932,7 @@ $daily_sessions = $stmt->fetchAll();
|
||||
<?php echo $class['status'] === 'active' ? 'Attivo' : 'Inattivo'; ?>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-warning" data-bs-toggle="modal" data-bs-target="#editClassModal"
|
||||
onclick='fillEditModal(<?php echo json_encode([
|
||||
@@ -981,6 +982,7 @@ $daily_sessions = $stmt->fetchAll();
|
||||
<th>Sala</th>
|
||||
<th>Insegnante</th>
|
||||
<th>Stato</th>
|
||||
<th>Prenotati</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -1117,20 +1119,43 @@ $daily_sessions = $stmt->fetchAll();
|
||||
}
|
||||
|
||||
// Recupera tutte le sessioni nell'intervallo
|
||||
// === NUOVA QUERY CON CONTEGGIO E LISTA PRENOTATI ===
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT cs.*,
|
||||
ct.level, ct.day_of_week, ct.start_time, ct.room_name, ct.teacher_id,
|
||||
c.name AS class_name, c.photo AS class_photo,
|
||||
ct.photo AS variation_photo,
|
||||
t.first_name AS teacher_first_name, t.last_name AS teacher_last_name
|
||||
FROM class_sessions cs
|
||||
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
|
||||
WHERE cs.session_date BETWEEN ? AND ?
|
||||
AND c.school_id = ?
|
||||
ORDER BY cs.session_date, cs.start_time
|
||||
");
|
||||
SELECT
|
||||
cs.*,
|
||||
ct.level, ct.day_of_week, ct.start_time AS ct_start_time, ct.room_name, ct.teacher_id,
|
||||
c.name AS class_name, c.photo AS class_photo,
|
||||
ct.photo AS variation_photo,
|
||||
t.first_name AS teacher_first_name, t.last_name AS teacher_last_name,
|
||||
|
||||
-- Contiamo gli studenti prenotati (solo booked, attended, rescheduled)
|
||||
(SELECT COUNT(*)
|
||||
FROM session_bookings sb
|
||||
WHERE sb.session_id = cs.id
|
||||
AND sb.status IN ('booked', 'attended', 'rescheduled')
|
||||
) AS booked_count,
|
||||
|
||||
-- Capacità massima (da class_sessions o da class_types se null)
|
||||
COALESCE(cs.max_capacity, ct.max_capacity, 0) AS effective_capacity,
|
||||
|
||||
-- Lista studenti prenotati (per il modale)
|
||||
(SELECT GROUP_CONCAT(
|
||||
CONCAT(au.first_name, ' ', au.last_name, '|', au.email, '|', COALESCE(au.phone, ''))
|
||||
SEPARATOR ';;;'
|
||||
)
|
||||
FROM session_bookings sb
|
||||
JOIN auth_users au ON sb.user_id = au.id
|
||||
WHERE sb.session_id = cs.id
|
||||
AND sb.status IN ('booked', 'attended', 'rescheduled')
|
||||
) AS booked_students
|
||||
FROM class_sessions cs
|
||||
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
|
||||
WHERE cs.session_date BETWEEN ? AND ?
|
||||
AND c.school_id = ?
|
||||
ORDER BY cs.session_date, cs.start_time
|
||||
");
|
||||
$stmt->execute([$start_date, $end_date, $school_id]);
|
||||
$range_sessions = $stmt->fetchAll();
|
||||
?>
|
||||
@@ -1158,6 +1183,7 @@ $daily_sessions = $stmt->fetchAll();
|
||||
<th>Sala</th>
|
||||
<th>Insegnante</th>
|
||||
<th>Stato</th>
|
||||
<th>Prenotati</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -1198,6 +1224,23 @@ $daily_sessions = $stmt->fetchAll();
|
||||
<?php echo $session['status'] === 'scheduled' ? 'Programmata' : ($session['status'] === 'completed' ? 'Completata' : 'Annullata'); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$booked = $session['booked_count'];
|
||||
$capacity = $session['effective_capacity'] > 0 ? $session['effective_capacity'] : '∞';
|
||||
$color = ($capacity !== '∞' && $booked >= $capacity) ? 'danger' : 'success';
|
||||
?>
|
||||
<button type="button" class="btn btn-sm btn-<?php echo $color; ?> position-relative"
|
||||
data-bs-toggle="modal" data-bs-target="#studentsModal-<?php echo $session['id']; ?>">
|
||||
<?php echo $booked; ?> / <?php echo $capacity; ?>
|
||||
<?php if ($booked > 0): ?>
|
||||
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-dark">
|
||||
<?php echo $booked; ?>
|
||||
<span class="visually-hidden">prenotati</span>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-warning" data-bs-toggle="modal" data-bs-target="#editSessionModal"
|
||||
onclick='fillEditSessionModal(<?php echo json_encode([
|
||||
@@ -1863,6 +1906,57 @@ $daily_sessions = $stmt->fetchAll();
|
||||
white-space: normal;
|
||||
}
|
||||
</style>
|
||||
<?php foreach ($range_sessions as $session): ?>
|
||||
<?php if ($session['booked_count'] > 0): ?>
|
||||
<div class="modal fade" id="studentsModal-<?php echo $session['id']; ?>" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-primary text-white">
|
||||
<h5 class="modal-title">
|
||||
Prenotati - <?php echo htmlspecialchars($session['class_name']); ?>
|
||||
<?php echo ucfirst($session['level']); ?>
|
||||
del <?php echo date('d/m/Y', strtotime($session['session_date'])); ?>
|
||||
ore <?php echo substr($session['start_time'], 0, 5); ?>
|
||||
</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Nome</th>
|
||||
<th>Email</th>
|
||||
<th>Telefono</th>
|
||||
<th>Stato</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$students = explode(';;;', $session['booked_students'] ?? '');
|
||||
foreach ($students as $s):
|
||||
if (empty(trim($s))) continue;
|
||||
list($name, $email, $phone) = explode('|', $s . '||');
|
||||
?>
|
||||
<tr>
|
||||
<td><strong><?php echo htmlspecialchars($name); ?></strong></td>
|
||||
<td><?php echo htmlspecialchars($email); ?></td>
|
||||
<td><?php echo htmlspecialchars($phone ?: '—'); ?></td>
|
||||
<td><span class="badge bg-success">Prenotato</span></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif;
|
||||
endforeach; ?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user