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

<div class="row">
    <div class="col-lg-12">
        <div style="margin-bottom: 20px;">
            <a href="media.php?module=input_guru&act=input" class="btn btn-primary">
                <i class="fa fa-plus"></i> Tambah Guru
            </a>
        </div>

        <div class="panel panel-primary">
            <div class="panel-heading">
                Data Guru
            </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">NIP</th>
                                <th class="text-center">Nama</th>
                                <th class="text-center">JK</th>
                                <th class="text-center">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
<?php
// Menggunakan variabel koneksi yang konsisten
$koneksi_aktif = isset($db) ? $db : $koneksi;
$sql = mysqli_query($koneksi_aktif, "SELECT * FROM guru");

while ($rs = mysqli_fetch_array($sql)) :
?>
                            <tr class="odd gradeX">
                                <td class="text-center"><?= htmlspecialchars($rs['nip']); ?></td>
                                <td><?= htmlspecialchars($rs['nama']); ?></td>
                                <td class="text-center"><?= $rs['jk']; ?></td>
                                <td class="text-center">
                                    <a href="media.php?module=detail_guru&idg=<?= $rs['idg']; ?>" class="btn btn-warning btn-sm">
                                        <i class="fa fa-search"></i> Detail
                                    </a>
                                    <a href="media.php?module=input_guru&act=edit_guru&idg=<?= $rs['idg']; ?>" class="btn btn-info btn-sm">
                                        <i class="fa fa-edit"></i> Edit
                                    </a>
                                    <a href="module/simpan.php?act=hapus_guru&idg=<?= $rs['idg']; ?>" 
                                       class="btn btn-danger btn-sm" 
                                       onclick="return confirm('Yakin ingin menghapus data ini?');">
                                        <i class="fa fa-trash"></i> Hapus
                                    </a>
                                </td>
                            </tr>
<?php endwhile; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function() {
        if (!$.fn.DataTable.isDataTable('#dataTables-example')) {
            $('#dataTables-example').dataTable({
                "bPaginate": true,
                "bLengthChange": true,
                "bFilter": true,
                "bSort": true,
                "bInfo": true,
                "bAutoWidth": false
            });
        }
    });
</script>