Files
yogibook_aury_new/public/fetch_class_details.php
T

47 lines
1.5 KiB
PHP

<?php
// Buffer: scarta l'HTML degli include, risposta JSON pura
ob_start();
require_once('include/headscript.php');
/**
* Lezioni di un allievo nella scuola corrente (dettaglio di situationusers.php).
* POST: id_utente. Risposta: array di lezioni, oppure { error }.
*/
function jsonOut($payload, int $code = 200): void
{
if (ob_get_length() !== false) {
ob_end_clean();
}
http_response_code($code);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($payload, JSON_UNESCAPED_UNICODE);
exit;
}
if (!SchoolContext::isSchoolAdmin()) {
jsonOut(['error' => 'Accesso non autorizzato.'], 403);
}
$userId = (int) ($_POST['id_utente'] ?? 0);
if ($userId <= 0 || !SchoolScope::isMember($userId)) {
jsonOut([]);
}
try {
$pdo = DBHandlerSelect::getInstance()->getConnection();
$st = $pdo->prepare(
"SELECT bc.idbookingclass, bc.bookingstart, bc.status, bc.lostlesson, bc.prevbookingstart,
bc.idorder, ob.order_date_created, s.servicename, s.day, s.time
FROM bookingclass bc
LEFT JOIN orderbook ob ON bc.idorder = ob.idorderbook
LEFT JOIN service s ON bc.idservice = s.idservice
WHERE bc.iduser = ? AND bc.idschool = ? AND bc.status <> 'cancelled'
ORDER BY bc.bookingstart DESC"
);
$st->execute([$userId, $idschool]);
jsonOut($st->fetchAll());
} catch (Throwable $ex) {
error_log('fetch_class_details: ' . $ex->getMessage());
jsonOut(['error' => 'Errore nel caricamento.'], 500);
}