<?php

require_once "conn.php";

$stmt = $conn->prepare("SELECT k.id, k.tanggal, COALESCE(p.pamong_nama, pend.nama) AS pamong, COALESCE(p.foto, pend.foto) AS foto, k.jam_masuk, k.jam_keluar, k.status_kehadiran 
                       FROM kehadiran_perangkat_desa k
                       LEFT JOIN tweb_desa_pamong p ON k.pamong_id = p.pamong_id
                       LEFT JOIN tweb_penduduk pend ON p.id_pend = pend.id;");

$stmt->execute();
$stmt->bind_result($id, $tanggal, $pamong, $foto, $masuk, $keluar, $status);

$kehadiran = array();

while($stmt->fetch()){
    $temp = array();
    $temp['id'] = $id;
    $temp['tanggal'] = $tanggal;
    $temp['pamong'] = $pamong;
    $temp['foto'] = $foto;
    $temp['jam masuk'] = $masuk;
    $temp['jam keluar'] = $keluar;
    $temp['status kehadiran'] = $status;

    array_push($kehadiran, $temp);
}

echo json_encode($kehadiran);
