<?php



$kegiatan_id = $id_page;

$cekID = new cekID();
$cekID->cek($tb_kegiatan, 'id', $kegiatan_id);
$classsimakomRKAS = new simakom_rkas;
$class = new crudData();
$form = new form();
$edit = $class->editData($tb_kegiatan, 'id', $kegiatan_id);
$data = $edit->fetch(PDO::FETCH_OBJ);
$kategori = $data->kategori;
$kegiatan_old = $data->kegiatan;
$kegiatan_uraian = $data->uraian;
$uraian_kategori = $classsimakomRKAS->uraianRKAS('simakom_ref_kategori', 'kategori', $kategori, 'uraian');
$rkas = new simakom_rkas();
$kegiatan_custome = $rkas->kodeCustome('simakom_ref_kegiatan', 'kegiatan', $kegiatan_old, 'kegiatan_custome');
?>
<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-pencil"></span> Edit Kegiatan</b>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body my-4 mx-4">
                            <form action="" method="post">
                                <input type="text" name="kategori" value="<?php echo $data->kategori;
                                                                            ?>" hidden>
                                <input type="text" name="kegiatan_old" value="<?php echo $data->kegiatan;
                                                                                ?>" hidden>
                                <input type="text" name="kegiatan_id" value="<?php echo $kegiatan_id;
                                                                                ?>" hidden>
                                <input type="text" name="submitUpdate" value="<?php echo $kegiatan_id;
                                                                                ?>" hidden>

                                <div class="info-box-content">
                                    <dl class="row">
                                        <dt class="col-sm-3 pt-0">KATEGORI</dt>
                                        <dd class="col-sm-9  pt-0"><b>: <?php echo $kategori . ' - ' . $uraian_kategori; ?></b></dd>
                                        <dt class="col-sm-3">KEGIATAN</dt>
                                        <dd class="col-sm-9"><b>: <?php echo $kegiatan_old . ' - ' . $kegiatan_uraian; ?></b></dd>


                                    </dl>
                                </div>
                                <div class="div d-inline">
                                    <button type="submit" name="submitUpdateKegiatan" class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-pencil-plus"></i> UBAH KEGIATAN <?php echo $kegiatan_old; ?></button>
                                </div>
                                <?php
                                $class = new simakom_search();
                                $showList = $class->search_input();
                                ?>

                                <table id="searchtable" class="table table-bordered table-striped table-sm mb-4 mt-2">
                                    <thead>
                                        <tr>

                                            <th width="50" align="center" class="text-center">Pilih</th>
                                            <th width="110">Kode Kegiatan</th>
                                            <th width="">Uraian</th>
                                            <th width="250">Kategori</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $crud = new crudData();
                                        $showUser = $crud->showTableOrder("simakom_ref_kegiatan where kategori='$kategori'", 'kegiatan asc');
                                        $no = 0;
                                        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 = "";
                                            };
                                            $no++;
                                            echo "
                                                    <tr>
                                                        <td width='5px'  align='center'>
                                                            <input type='radio' class='' name='kegiatan_new' value='$data->kegiatan' > 
                                                        </td>
                                                      
                                                        <td for='customRadio$data->no'>$data->kegiatan</td>
                                                    
                                                        <td>$data->uraian</td>
                                                        <td>$kategori</td>
                                                        
                                                        </tr>";
                                        };; ?>
                                    </tbody>
                                </table>

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

<?php

if (isset($_POST['submitUpdateKegiatan'])) {

    $class = new simakom_rkas();
    $update = $class->updateRKASKegiatan($tb_kegiatan, $tb_komponen, $tb_akun, $tb_detail, $kegiatan_old, $tb_revisi);
} else {
    echo "";
};
