<?php
include "../../layout/classModal.php";


$id = $_POST['rowid'];

$classsimakomRKAS = new simakom_rkas;
$kegiatan_id = $classsimakomRKAS->splitID($id); //ID
$tahun = $classsimakomRKAS->splitTahun($id); //Tahun
$tb_kegiatan = $classsimakomRKAS->getTabelbyID($id, 'simakom_kegiatan'); //Tabel Kegiatan


$cekID = new cekID();
$cekID->cek($tb_kegiatan, 'id', $kegiatan_id);

$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;

$rkas = new simakom_rkas();
$kegiatan_custome = $rkas->kodeCustome('simakom_ref_kegiatan', 'kegiatan', $kegiatan_old, 'kegiatan_custome');


?>
<div class="card-body">

    <form action='' method='post' role='form'>
        <?php $csrf->token();
        ?>
        <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="row ">
            <label class="col-sm-12 col-form-label">Pilih Kegiatan
            </label>
            <div class="col-md-12">
                <select name="kegiatan_new" class="form-control form-control-sm fontInput small select2" required>
                    <option value='<?php echo $data->kegiatan; ?>' class='form-control form-control-sm fontInput small'><?php echo $data->kegiatan . ' [' . $kegiatan_custome . '] : ' . $data->uraian; ?></option>
                    <?php
                    $opval = $form->optSelect('simakom_ref_kegiatan', "where kategori='$kategori' order by kegiatan asc");
                    while ($data_ref = $opval->fetch(PDO::FETCH_OBJ)) {
                        echo "<option value='$data_ref->kegiatan' class='form-control form-control-sm fontInput small'>$data_ref->kegiatan [$data_ref->kegiatan_custome] : $data_ref->uraian</option>";
                    };
                    ?>
                </select>
            </div>
        </div>
        <div class="mt-4">
            <div class="row">
                <div class="col-auto">
                    <div class='float-right'>
                        <button type='submit' class='btn btn-primary btn-xs' name='submitUpdateKegiatan'><i class='bi-save'></i> SIMPAN</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<?php
$select = new form();
$select->selectScript();

if (isset($_POST['submitUpdateKegiatan'])) {
    $csrf = $csrf->cekToken();
    $class = new simakom_rkas();
    $update = $class->updateRKASKegiatan($tb_kegiatan, $tb_komponen, $tb_akun, $tb_detail, $kegiatan_old, $tb_revisi);
} else {
    echo "";
};
