<div class="content-wrapper">

    <?php require('./layout/headerpage.php'); ?>

    <div class="container col-12 mb-4 pb-5">
        <div class="row">
            <div class="col-12">
                <div class="col-12">
                    <div class="card  mx-3">
                        <div class="timeline-header bg-primary py-2 pl-2">
                            <b class="text-light judul"><span class="bi bi-person-bounding-box"></span> Data User Siswa</b>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body my-4 mx-4">
                            <form action="" method="post">
                                <table id="example3" class="table table-bordered table-striped table-hover table-sm  mb-4">
                                    <thead>
                                        <tr>
                                            <th><input type="checkbox" class="small check_all"></th>
                                            <th>Edit</th>
                                            <th>NIS</th>
                                            <th>Nama Siswa</th>
                                            <th>L/P</th>
                                            <th>Kelas</th>
                                            <th>HP</th>
                                            <th>Email</th>
                                            <th>Username</th>
                                            <th>Status</th>

                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php
                                        $clsCrud = new crudData();
                                        $show = $clsCrud->showTable('user_siswa order by status asc, nama asc');
                                        while ($data = $show->fetch(PDO::FETCH_OBJ)) {

                                            $nis = $data->nis;
                                            $clsCrud = new crudData;

                                            //count tabel siswa
                                            $count = $clsCrud->countData($tb_siswa, " where nis='$nis'");
                                            if ($count > 0) {
                                                $kelas = $clsCrud->getValue($tb_siswa, " where nis='$nis'", 'jenjang') . "-" . $clsCrud->getValue($tb_siswa, " where nis='$nis'", 'paralel');
                                            } else {
                                                $kelas = "--";
                                            };

                                            $link = new linkpage;

                                            echo "
                                                    <tr>
                                                        <td width='5px'>
                                                            <input type='checkbox' class='d-inline small chk_boxes1' name='id_user[]' value='$data->id'> 
                                                        </td>
                                                        <td width='75px' align='center'>
                                                        <a " . $link->pageID($data->id, 'seting/userSiswa/user_edit') . " class='badge badge-primary  px-1 py-1 d-inline''> <i class='bi bi-pencil-square'></i> EDIT</a>
                                                        </td>
                                                        <td>$data->nis</td>
                                                        <td>$data->nama</td>
                                                        <td>$data->kelamin</td>
                                                        <td>$kelas</td>
                                                        <td>$data->hp</td>
                                                        <td>$data->email</td>
                                                       
                                                        <td>$data->username</td>
                                                        <td>$data->status</td>
                                                     
                                                        </tr>";
                                        };

                                        ?>

                                    </tbody>
                                </table>
                                <div class="div d-inline">
                                    <a <?php echo $link->page('seting/userSiswa/user_create'); ?> class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-person-plus"></i> TAMBAH</a>
                                    <a <?php echo $link->page('seting/userSiswa/user_create_multi'); ?> class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-person-plus"></i> TAMBAH KOLEKTIF</a>

                                    <button type="submit" name="submit" class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-trash"></i> HAPUS</button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--/. container-fluid -->
        </section>
        <!-- /.content -->
    </div>
</div>
<!-- /.content-wrapper -->
<script type="text/javascript">
    $(function() {
        $('.check_all').click(function() {
            $('.chk_boxes1').prop('checked', this.checked);
        });
    });
</script>

<?php
if (isset($_POST['submit'])) {
    foreach ($_POST['id_user'] as $id) {
        $user_admin = new crudData();
        $delete = $user_admin->deleteData('user_siswa', 'id', $id);
    };

    $direct = new toast();
    echo  $direct->redirect('toast', 'delete', 'seting/userSiswa/user_read');
} else {
    echo '';
}



?>