<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-journal-text"></span> Daftar Kode Kegiatan</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>Kode</th>
                                            <th>Kode Custome</th>
                                            <th>Kegiatan</th>
                                            <th>Kategori</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $user_admin = new crudData();
                                        $showUser = $user_admin->showTableOrder('simakom_ref_kegiatan', 'kegiatan asc');
                                        while ($data = $showUser->fetch(PDO::FETCH_OBJ)) {
                                            $link = new linkpage;
                                            if ($data->kategori == "A") {
                                                $kategori = $data->kategori . " - Pendapatan";
                                            } elseif ($data->kategori == "B") {
                                                $kategori = $data->kategori . " - Belanja";
                                            } else {
                                                $kategori = "";
                                            };
                                            echo "
                                                    <tr>
                                                        <td width='5px'>
                                                            <input type='checkbox' class='d-inline small chk_boxes1' name='id_kegiatan[]' value='$data->no'> 
                                                        </td>
                                                        <td width='75px' align='center'>
                                                        <a " . $link->pageID($data->id, 'seting/kegiatan/kegiatan_edit') . " class='badge badge-primary  px-1 py-1 d-inline''> <i class='bi bi-pencil-square'></i> EDIT</a>
                                                        </td>
                                                        <td>$data->kegiatan</td>
                                                        <td>$data->kegiatan_custome</td>
                                                        <td>$data->uraian</td>
                                                        <td>$kategori</td>
                                                        </tr>";
                                        };
                                        ?>
                                    </tbody>
                                </table>
                                <div class="div d-inline">
                                    <a <?php echo $link->page('seting/kegiatan/kegiatan_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>
    </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_kegiatan'])) {
    foreach ($_POST['id_kegiatan'] as $id) {
        $user_admin = new crudData();
        $delete = $user_admin->deleteData('simakom_ref_kegiatan', 'no', $id);
    };

    $direct = new toast();
    echo  $direct->redirect('toast', 'delete', 'seting/kegiatan/kegiatan_read');
};
