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

$id_kegiatan = $_POST['rowid'];
$classsimakomRKAS = new simakom_rkas;
$kegiatan = $classsimakomRKAS->splitID($id_kegiatan);
$tb_kegiatan = $classsimakomRKAS->getTabelbyID($id_kegiatan, 'simakom_kegiatan');
$tb_komponen = $classsimakomRKAS->getTabelbyID($id_kegiatan, 'simakom_komponen');
$tb_revisi = $classsimakomRKAS->getTabelbyID($id_kegiatan, 'simakom_revisi');


//$db = database::getInstance();
//$show = $db->runQuery("SELECT * FROM   {$tb_kegiatan}  WHERE kegiatan = $kegiatan");
//$view = $show->fetch(PDO::FETCH_OBJ);
//$kategori_kode = $view->kategori;
//$kegiatan_kode = $view->kegiatan;

$clasCrud = new crudData;
$kategori_kode = $clasCrud->getValue($tb_kegiatan, " where kegiatan='$kegiatan'", 'kategori');
$kegiatan_kode = $clasCrud->getValue($tb_kegiatan, " where kegiatan='$kegiatan'", 'kegiatan');

$class = new simakom_rkas();
$uraian_kategori = $class->uraianRKAS('simakom_ref_kategori', 'kategori', $kategori_kode, 'uraian');
$uraian_kegiatan = $class->uraianRKAS($tb_kegiatan, 'kegiatan', $kegiatan_kode, 'uraian');


?>
<div class="card-body">
    <form action='' method='post' role='form'>
        <?php $csrf->token();
        ?>
        <input type="text" name="kegiatan" value="<?php echo $kegiatan;
                                                    ?>" hidden>
        <input type="text" name="submitKomp" value="<?php echo $kegiatan;
                                                    ?>" 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_kode . ' - ' . $uraian_kategori; ?></b></dd>
                <dt class="col-sm-3">KEGIATAN</dt>
                <dd class="col-sm-9"><b>: <?php echo $kegiatan_kode . ' - ' . $uraian_kegiatan; ?></b></dd>

            </dl>
        </div>
        <div class="row ">
            <label class="col-sm-12 col-form-label">Tambah Komponen</label>
            <div class="col-md-2">
                <input type="text" name="komponen" class="form-control form-control-sm fontInput" value="" minlength="1" maxlength="3" placeholder="Kode" required>
            </div>
            <div class="col-md-10">
                <input type="text" name="uraian" class="form-control form-control-sm  fontInput" value="" minlength="3" placeholder="Uraian Komponen" required>
            </div>
            <p class="footnote pl-2 mt-2 small"><i>Komponen adalah Kodifikasi berupa Huruf/Abjad, terdiri 1 - 3 digit. Misal : A, B, AA, ABC</i></p>
        </div>
        <div class="mt-3">
            <div class="row">
                <div class="col-auto">
                    <div class='float-right'>
                        <button type='submit' class='btn btn-primary btn-xs' name='submitKomponen'><i class='bi-save'></i> SIMPAN</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

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

if (isset($_POST['submitKomponen'])) {
    $csrf = $csrf->cekToken();
    $class = new simakom_rkas();
    $save = $class->insertRKASKomponen($tahun, $tb_kegiatan, $tb_komponen, $tb_revisi);
} else {
    echo "";
};
