<?php
require '../db.php';
require '../functions.php';

header('Content-Type: application/json');
$checker = requireCheckerToken($pdo);

try {
    $stmt = $pdo->prepare("SELECT r.scandatetime, r.result, v.fullname
        FROM ridelog r LEFT JOIN villager v ON v.id = r.villagerid
        WHERE r.checkerid = ? AND r.isdeleted = 0
        ORDER BY r.scandatetime DESC LIMIT 50");
    $stmt->execute([$checker['id']]);
    jsonOut(true, '', $stmt->fetchAll());
} catch (Exception $e) {
    logDebug('[api_getridehistory] ' . $e->getMessage());
    jsonOut(false, 'Something went wrong. Please try again.');
}
