yogiboook_new/public/userarea/ajax_client_bookings.php
2026-01-21 10:29:37 +01:00

118 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// ajax_client_bookings.php
// Non serve require_once se usi la stessa connessione del template principale
// Ma per sicurezza includi headscript.php (che contiene già DBHandler)
require_once('include/headscript.php'); // adatta il percorso se necessario
$dbHandler = DBHandlerSelect::getInstance();
$pdo = $dbHandler->getConnection();
// Poi il resto del codice...
$user_id = (int)($_POST['user_id'] ?? 0);
$school_id = (int)($_POST['school_id'] ?? 0);
if ($user_id <= 0 || $school_id <= 0) {
echo '<div class="alert alert-warning">Dati non validi.</div>';
exit;
}
$stmt = $pdo->prepare("
SELECT
cs.id AS session_id,
cs.session_date,
cs.start_time,
cs.end_time,
c.name AS class_name,
ct.level,
sb.status,
sb.booked_at,
o.id AS order_id,
o.order_number,
o.total_entries,
o.available_entries
FROM session_bookings sb
INNER JOIN class_sessions cs
ON sb.session_id = cs.id
AND cs.school_id = ?
INNER JOIN classes c
ON cs.class_id = c.id
AND c.school_id = ?
INNER JOIN class_types ct
ON cs.class_type_id = ct.id
AND ct.school_id = ?
LEFT JOIN orders o
ON sb.order_id = o.id
AND o.school_id = ?
WHERE sb.user_id = ?
ORDER BY cs.session_date DESC, cs.start_time DESC
LIMIT 100
");
$stmt->execute([
$school_id,
$school_id,
$school_id,
$school_id,
$user_id
]);
$bookings = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($bookings)) {
echo '<div class="alert alert-info">Nessuna prenotazione registrata per questo utente.</div>';
exit;
}
?>
<div class="table-responsive">
<table class="table table-sm table-bordered">
<thead class="table-light">
<tr>
<th>Data</th>
<th>Orario</th>
<th>Classe</th>
<th>Livello</th>
<th>Stato</th>
<th>Ordine</th>
<th>Data prenotazione</th>
</tr>
</thead>
<tbody>
<?php foreach ($bookings as $b):
$statoClass = match ($b['status']) {
'attended' => 'bg-success',
'missed' => 'bg-danger',
'booked' => (strtotime($b['session_date']) >= time()) ? 'bg-primary' : 'bg-secondary',
'cancelled' => 'bg-dark',
'rescheduled' => 'bg-info',
default => 'bg-secondary'
};
$statoText = match ($b['status']) {
'attended' => 'Frequentata',
'missed' => 'Persa',
'booked' => (strtotime($b['session_date']) >= time()) ? 'Prenotata' : 'Scaduta',
'cancelled' => 'Cancellata',
'rescheduled' => 'Riprog.',
default => $b['status']
};
?>
<tr>
<td><?= date('d/m/Y', strtotime($b['session_date'])) ?></td>
<td><?= substr($b['start_time'], 0, 5) ?> <?= substr($b['end_time'], 0, 5) ?></td>
<td><?= htmlspecialchars($b['class_name']) ?></td>
<td><?= ucfirst($b['level'] ?? '—') ?></td>
<td><span class="badge <?= $statoClass ?>"><?= $statoText ?></span></td>
<td>
<?php if ($b['order_id']): ?>
#<?= $b['order_number'] ?><br>
<small><?= $b['available_entries'] ?>/<?= $b['total_entries'] ?></small>
<?php else: ?>
<?php endif; ?>
</td>
<td><small><?= date('d/m/Y H:i', strtotime($b['booked_at'])) ?></small></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>