'Train number and date are required.']); exit; } // For demo purposes, we will return a mock response that includes a known station code. // In a real scenario, this would come from the RailApi call. $mockApiResponse = [ 'ResponseCode' => 200, 'TrainName' => 'SAMPARK KRANTI', 'TrainNo' => '12649', 'Position' => 'Arrived at KSR BENGALURU (SBC)', 'CurrentStation' => ['StationCode' => 'SBC', 'StationName' => 'KSR BENGALURU'], 'Route' => [ ['StationCode' => 'NDLS', 'StationName' => 'NEW DELHI', 'ScheduleArrival' => '20:00', 'ActualArrival' => '20:00', 'ScheduleDeparture' => '20:15', 'ActualDeparture' => '20:15', 'IsCurrentStation' => false], ['StationCode' => 'SBC', 'StationName' => 'KSR BENGALURU', 'ScheduleArrival' => '06:30', 'ActualArrival' => '06:30', 'ScheduleDeparture' => '-', 'ActualDeparture' => '-', 'IsCurrentStation' => true] ] ]; if ($mockApiResponse['ResponseCode'] == 200) { $currentStationCode = $mockApiResponse['CurrentStation']['StationCode']; try { $pdo = db(); $stmt = $pdo->prepare("SELECT latitude, longitude FROM stations WHERE station_code = ?"); $stmt->execute([$currentStationCode]); $coords = $stmt->fetch(PDO::FETCH_ASSOC); if ($coords) { $mockApiResponse['CurrentStation']['latitude'] = $coords['latitude']; $mockApiResponse['CurrentStation']['longitude'] = $coords['longitude']; } } catch (PDOException $e) { // Could not fetch coordinates, but we can still return the rest of the data. } } echo json_encode($mockApiResponse); ?>