<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header"><strong>Jadwal Belajar</strong></h3>
    </div>
</div>

<?php
$id_siswa = $_SESSION['idu']; 
$sql_user = mysqli_query($koneksi, "SELECT idk FROM siswa WHERE ids = '$id_siswa'");
$r_user   = mysqli_fetch_array($sql_user);
$klss     = isset($r_user['idk']) ? $r_user['idk'] : 0; 

$sql_kelas = mysqli_query($koneksi, "SELECT * FROM kelas WHERE idk='$klss'");
$kelas = mysqli_fetch_array($sql_kelas);
?>

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-primary">
            <div class="panel-heading">
                Jadwal Belajar Kelas <?php echo isset($kelas['nama']) ? htmlspecialchars($kelas['nama']) : "-"; ?>
            </div>

            <ul class="nav nav-tabs">
                <li><a href="media.php?module=siswa_senin">Senin</a></li>
                <li><a href="media.php?module=siswa_selasa">Selasa</a></li>
                <li><a href="media.php?module=siswa_rabu">Rabu</a></li>
                <li><a href="media.php?module=siswa_kamis">Kamis</a></li>
                <li class="active"><a href="media.php?module=siswa_jumat">Jum'at</a></li>
            </ul>

            <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">Hari</th>
                                <th class="text-center">Jam</th>
                                <th class="text-center">Guru Pengajar</th>
                                <th class="text-center">Mata Pelajaran</th>
                                <th class="text-center">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
<?php
$no = 1;
// Filter Hari Jumat (idh=5)
$sql = mysqli_query($koneksi, "SELECT j.idj, h.hari, g.nama as nama_guru, m.nama_mp, j.jam_mulai, j.jam_selesai
    FROM jadwal j 
    JOIN hari h ON j.idh=h.idh 
    JOIN guru g ON j.idg=g.idg 
    JOIN mata_pelajaran m ON j.idm=m.idm
    WHERE j.idh=5 AND j.idk='$klss' 
    ORDER BY j.jam_mulai ASC");

if (mysqli_num_rows($sql) > 0) {
    while ($row = mysqli_fetch_array($sql)) { ?>
                            <tr>
                                <td class="text-center"><?php echo $no++; ?></td>
                                <td class="text-center"><?php echo htmlspecialchars($row['hari']); ?></td>
                                <td class="text-center"><?php echo $row['jam_mulai']." - ".$row['jam_selesai']; ?></td>
                                <td><?php echo htmlspecialchars($row['nama_guru']); ?></td>
                                <td><?php echo htmlspecialchars($row['nama_mp']); ?></td>
                                <td class="text-center">
                                    <a href="media.php?module=rekap_s&idj=<?php echo $row['idj']; ?>" class="btn btn-primary btn-sm">
                                        <i class="fa fa-book"></i> Data Absen
                                    </a>
                                </td>
                            </tr>
<?php } 
} else {
    echo "<tr><td colspan='6' class='text-center'>Jadwal hari Jumat belum tersedia.</td></tr>";
} ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>