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

$id_wali = $_POST['id_wali'] ?? '';

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

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

if ($result) { 
    $data = array(); 
    while ($row = mysqli_fetch_assoc($result)) { 
        $data[] = [ 
            "id_laporan_wali"     => (int)$row['id_laporan_wali'], 
            "id_wali"             => (int)$row['id_wali'], 
            "tanggal"             => $row['tanggal'], 
            "kegiatan"            => $row['kegiatan'], 
            "hasil_tindak_lanjut" => $row['hasil_tindak_lanjut'], 
            "kesimpulan_saran"    => $row['kesimpulan_saran'], 
            "penutup"             => $row['penutup'], 
            "tipe"                => $row['tipe'],
            "foto1"               => $row['foto1'], // Tambahkan ini
            "foto2"               => $row['foto2'], // Tambahkan ini
            "foto3"               => $row['foto3']  // Tambahkan ini
        ]; 
    } 
    echo json_encode(["status" => true, "data" => $data]); 
} else { 
    echo json_encode(["status" => false, "message" => mysqli_error($koneksi)]); 
} 
?>