<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header"><strong>Riwayat Absensi Saya</strong></h3>
    </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-primary">
            <div class="panel-heading">Daftar Kehadiran Siswa</div>
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                        <thead>
                            <tr>
                                <th class="text-center">No</th>
                                <th class="text-center">Tanggal</th>
                                <th class="text-center">Mata Pelajaran</th>
                                <th class="text-center">Keterangan</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php
                        $no = 1;
                        $id_siswa = $_SESSION['idu']; // ID siswa dari session login
                        
                        $sql = mysqli_query($koneksi, "SELECT * FROM absen 
                               JOIN jadwal ON absen.idj = jadwal.idj
                               JOIN mata_pelajaran ON jadwal.idm = mata_pelajaran.idm
                               WHERE absen.ids = '$id_siswa' 
                               ORDER BY absen.tgl DESC");

                        while($r = mysqli_fetch_array($sql)){
                            $label = ($r['ket'] == 'H') ? 'success' : (($r['ket'] == 'A') ? 'danger' : 'warning');
                            $status = ($r['ket'] == 'H') ? 'Hadir' : (($r['ket'] == 'A') ? 'Alpa' : (($r['ket'] == 'I') ? 'Izin' : 'Sakit'));
                        ?>
                            <tr>
                                <td class="text-center"><?php echo $no++; ?></td>
                                <td class="text-center"><?php echo $r['tgl']; ?></td>
                                <td><?php echo $r['nama_mp']; ?></td>
                                <td class="text-center">
                                    <span class="label label-<?php echo $label; ?>"><?php echo $status; ?></span>
                                </td>
                            </tr>
                        <?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>