<?php
header('Content-Type: application/json');
include '../koneksi.php'; // Titik dua kali artinya naik satu folder ke atas

$id_anak = $_POST['id_anak'] ?? $_GET['id_anak'] ?? '';

if (empty($id_anak)) {
    echo json_encode(["status" => false, "message" => "ID Anak tidak ditemukan"]);
    exit;
}

$sql = "SELECT * FROM laporan_harian WHERE id_anak = '$id_anak' ORDER BY tanggal DESC";
$result = mysqli_query($koneksi, $sql);

$data_list = array();
if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        $data_list[] = [
            "id_laporan"        => (int)$row['id_laporan'],
            "id_anak"           => (int)$row['id_anak'],
            "tanggal"           => $row['tanggal'],
            "kegiatan"          => $row['kegiatan'],
            "catatan_kesehatan" => $row['catatan_kesehatan'],
            "keterangan"        => $row['keterangan'],
            "foto_laporan"      => $row['foto_laporan']
        ];
    }
}

echo json_encode(["status" => true, "data" => $data_list]);
?>