38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
// Buffer: scarta l'HTML degli include, risposta JSON pura
|
|
ob_start();
|
|
require_once('include/headscript.php');
|
|
|
|
/**
|
|
* Rimozione di una prenotazione da parte dello staff (da situationusers.php).
|
|
* POST: id = idbookingclass. Risposta: { success, message }
|
|
*/
|
|
function jsonOut(array $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::isStaff()) {
|
|
jsonOut(['success' => false, 'message' => 'Accesso non autorizzato.'], 403);
|
|
}
|
|
|
|
$id = (int) ($_POST['id'] ?? 0);
|
|
if (!SchoolScope::belongs('bookingclass', $id)) {
|
|
jsonOut(['success' => false, 'message' => 'Prenotazione non trovata.'], 404);
|
|
}
|
|
|
|
try {
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
$pdo->prepare("DELETE FROM bookingclass WHERE idbookingclass = ? AND idschool = ?")->execute([$id, $idschool]);
|
|
jsonOut(['success' => true]);
|
|
} catch (Throwable $ex) {
|
|
error_log('deleteclass: ' . $ex->getMessage());
|
|
jsonOut(['success' => false, 'message' => 'Errore durante la rimozione.'], 500);
|
|
}
|