api teacher lost
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_mark_lost.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Segna una prenotazione come persa o la ripristina (lostlesson Y/N).
|
||||
* Solo staff (Admin=1 / teacher=3).
|
||||
*
|
||||
* Posizione: public/api/api_teacher_mark_lost.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Body: booking_id=<int>&lost=<Y|N>
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$bookingId = isset($_POST['booking_id']) ? (int) $_POST['booking_id'] : 0;
|
||||
$lostRaw = isset($_POST['lost']) ? strtoupper(trim((string) $_POST['lost'])) : '';
|
||||
$lost = ($lostRaw === 'Y') ? 'Y' : 'N';
|
||||
|
||||
if ($bookingId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID prenotazione non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE bookingclass SET lostlesson = :lost WHERE idbookingclass = :id"
|
||||
);
|
||||
$stmt->execute([':lost' => $lost, ':id' => $bookingId]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'booking_id' => $bookingId,
|
||||
'lost' => $lost,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_mark_lost error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore aggiornamento']);
|
||||
}
|
||||
Reference in New Issue
Block a user