<?php


function getActiveEvent() {
    global $conn;
    $result = $conn->query("SELECT * FROM dafdir_event WHERE status = 'aktif' LIMIT 1");
    return $result->fetch_assoc();
}

function getAllEvents() {
    global $conn;
    $result = $conn->query("SELECT * FROM dafdir_event ORDER BY tanggal_event DESC");
    $events = [];
    while ($row = $result->fetch_assoc()) {
        $events[] = $row;
    }
    return $events;
}

function getAttendanceByEvent($event_id) {
    global $conn;
    $result = $conn->query("SELECT * FROM dafdir_absensi WHERE id_event = $event_id ORDER BY waktu_isi DESC");
    $attendance = [];
    while ($row = $result->fetch_assoc()) {
        $attendance[] = $row;
    }
    return $attendance;
}
?>