<?php
include '../../config/conn.php';
include '../../config/rupiah.php';
$date = date('Y-m-d');

header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Data Santri Rumah tahfidz .xls");



//sorting data per Kelas
if (!isset($_GET['kelas']) or $_GET['kelas'] == 0) {
    $kelas = "";
} else {
    $kelas = "AND jenis_rt=$_GET[kelas]";
}

//sorting data per angkatan
if (!isset($_GET['angkatan']) or $_GET['angkatan'] == 0) {
    $angkatan = "";
} else {
    $angkatan = "AND YEAR(tanggal_masuk)=$_GET[angkatan]";
}


?>

<table id="datatable" border="1" class="table table-striped table-bordered">
    <thead>
        <tr>
            <td colspan="10" align="center" style="font-size: x-large;">DATA SANTRI RUMAH TAHFIDZ</td>
        </tr>
    </thead>
    <thead>
        <tr>
            <th width="50">No</th>
            <th>ID santri</th>
            <!--<th>No Rekening</th>-->
            <th>Nama</th>
            <th>Alamat</th>
            <th>Tempat Lahir</th>
            <th>Tanggal lahir</th>
            <th>NIK</th>
            <th>No. KK</th>
            <th>Nama Ayah</th>
            <th>Nama Ibu</th>
            <th>Kelas</th>
            <th>Tanggal Masuk</th>

        </tr>
    </thead>
    <tbody>
        <?php
        $no = 0;
        $query = mysqli_query($conn, "SELECT * FROM santri_rt WHERE id_santri != '' $kelas $angkatan ORDER BY nama");
        while ($row = mysqli_fetch_array($query)) {
            $no++;
        ?>
            <tr>
                <td><?php echo $no; ?></td>
                <td><?php echo $row['id_santri']; ?></td>
                <!--<td><?php //echo $row['no_rekening'];
                        ?></td>-->
                <td><?php echo $row['nama']; ?></td>
                <td><?php echo $row['alamat']; ?></td>
                <td><?php echo $row['tempat_lahir']; ?></td>
                <td><?php echo $row['tanggal_lahir']; ?></td>
                <td><?php echo "'" . $row['nik_santri']; ?></td>
                <td><?php echo "'" . $row['no_kk']; ?></td>
                <td><?php echo $row['nama_ayah']; ?></td>
                <td><?php echo $row['nama_ibu']; ?></td>
                <td><?php $kueri  = mysqli_query($conn, "SELECT * FROM jenis_rt WHERE id='$row[jenis_rt]' order by id asc");
                    while ($data = mysqli_fetch_array($kueri)) {
                        echo "$data[nama_jenis]";
                    } ?></td>
                <td><?php echo $row['tanggal_masuk']; ?></td>

            </tr>
        <?php } ?>
    </tbody>
</table>