<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-badge"></span> Data User Operator</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 width="40">Foto</th>
                                            <th>Nama User</th>
                                            <th>L/P</th>
                                            <th>Telpon</th>
                                            <th>Level</th>
                                            <th>Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php
                                        $user_admin = new crudData();
                                        $showUser = $user_admin->showTable('user');
                                        while ($data = $showUser->fetch(PDO::FETCH_OBJ)) {
                                            $link = new linkpage;

                                            $user_id_list = $data->id;

                                            if (file_exists($servroot . "/asset/dokumen/foto/" . $user_id_list . ".jpg") || file_exists("../../asset/dokumen/foto/" . $user_id_list . ".jpg")) {
                                                $user_foto = "<img src='../../asset/dokumen/foto/" . $user_id_list . ".jpg' width='45' height='45' class='img-circle user-image'/>";
                                            } elseif (file_exists($servroot . "/asset/dokumen/foto/" . $user_id_list . ".png") || file_exists("../../asset/dokumen/foto/" . $user_id_list . ".png")) {
                                                $user_foto = "<img src='../../asset/dokumen/foto/" . $user_id_list . ".png' width='45' height='45' class='img-circle user-image'/>";
                                            } elseif (file_exists($servroot . "/asset/dokumen/foto/" . $user_id_list . ".gif") || file_exists("../../asset/dokumen/foto/" . $user_id_list . ".gif")) {
                                                $user_foto = "<img src='../../asset/dokumen/foto/" . $user_id_list . ".gif' width='45' height='45' class='img-circle user-image'/>";
                                            } else {
                                                $user_foto = "<img src='../../asset/dokumen/foto/no_photo.png' width='45' height='45' class='img-circle user-image'/>";
                                            };


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

                                        ?>

                                    </tbody>
                                </table>
                                <div class="div d-inline">
                                    <a <?php echo $link->page('seting/userAdmin/user_create'); ?> class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-person-plus"></i> TAMBAH</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']) && isset($_POST['id_userad'])) {
    foreach ($_POST['id_userad'] as $id) {
        $user_admin = new crudData();
        $delete = $user_admin->deleteData('user', 'id_user', $id);
    };

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



?>