<?php
include 'koneksi.php';

// Ambil data terakhir dari log_absen yang belum diproses
$result_log_absen = mysqli_query($conn, "SELECT * FROM log_absen WHERE processed = 0 ORDER BY timestamp DESC LIMIT 1");

if (mysqli_num_rows($result_log_absen) > 0) {
    $log = mysqli_fetch_assoc($result_log_absen);
    // Mengupdate status log_absen menjadi sudah diproses
    mysqli_query($conn, "UPDATE log_absen SET processed = 1 WHERE id = " . $log['id']);
    
    echo json_encode([
        'rfid' => $log['rfid']
    ]);
} else {
    echo json_encode([]);
}
?>
