36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
require_once '../includes/auth.php';
|
|
require_once '../includes/db.php';
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$vehicle_id = isset($_GET['vehicle_id']) ? intval($_GET['vehicle_id']) : 0;
|
|
|
|
if ($vehicle_id === 0) {
|
|
echo json_encode(['success' => false, 'message' => 'Invalid vehicle ID']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
SELECT vi.*, d.first_name, d.last_name
|
|
FROM vehicle_inspections vi
|
|
LEFT JOIN drivers d ON vi.inspector_cid COLLATE utf8mb4_unicode_ci = d.hr_cid COLLATE utf8mb4_unicode_ci
|
|
WHERE vi.vehicle_id = ?
|
|
ORDER BY vi.inspection_date DESC, vi.inspection_time DESC
|
|
LIMIT 50
|
|
");
|
|
$stmt->execute([$vehicle_id]);
|
|
$history = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Decode JSON items for each record
|
|
foreach ($history as &$record) {
|
|
$record['items'] = json_decode($record['items_json'], true);
|
|
unset($record['items_json']);
|
|
}
|
|
|
|
echo json_encode(['success' => true, 'data' => $history]);
|
|
} catch (PDOException $e) {
|
|
echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
|
|
}
|