<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">Data User</h1>
    </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-primary">
            <div class="panel-heading">Data User</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">Username</th>
                                <th class="text-center">Level</th>
                                <th class="text-center">Sekolah</th>
                                <th class="text-center">Aksi</th>
                            </tr>
                        </thead>
                        <tbody>

<?php
if ($_SESSION['level'] == "admin_guru") {
    $sql = mysqli_query($koneksi, "SELECT * FROM user WHERE idu='{$_SESSION['idu']}'");
} else {
    $sql = mysqli_query($koneksi, "SELECT * FROM user WHERE idu <> '1'");
}

while ($rs = mysqli_fetch_assoc($sql)) {

    $sqla = mysqli_query(
        $koneksi,
        "SELECT * FROM sekolah WHERE id='{$rs['id']}'"
    );
    $rsa = mysqli_fetch_assoc($sqla);
?>
                            <tr>
                                <td><?= $rs['nama']; ?></td>
                                <td class="text-center"><?= $rs['level']; ?></td>
                                <td class="text-center"><?= $rsa['nama'] ?? '-'; ?></td>
                                <td class="text-center">

                                    <a href="media.php?module=input_user&act=edit_user&idu=<?= $rs['idu']; ?>"
                                       class="btn btn-info btn-sm">
                                        Edit
                                    </a>

<?php if ($_SESSION['level'] != "admin_guru") { ?>
                                    <a href="module/simpan.php?act=hapus_user&idu=<?= $rs['idu']; ?>"
                                       onclick="return confirm('Yakin ingin menghapus user ini?')"
                                       class="btn btn-danger btn-sm">
                                        Hapus
                                    </a>
<?php } ?>

                                </td>
                            </tr>
<?php } ?>

                        </tbody>
                    </table>
                </div>
            </div>

        </div>
    </div>
</div>
