<?php


$cekID = new cekID();
$jmldata = $cekID->cek($tabungan_siswa, 'id', $id_page);

$clasCrud = new crudData();
$qry = $clasCrud->editData($tabungan_siswa, 'id', $id_page);
$data = $qry->fetch(PDO::FETCH_OBJ);

?>
<style>
    .fontInput {
        font-size: 11px;
        font-family: arial;
    }
</style>
<!-- Content Wrapper. Contains page content -->
<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 Nasabah</b>
                        </div>
                        <div class="row col-md-12">
                            <div class="col-md-10">
                                <div class="card-body mt-4 px-1 mx-2">

                                    <div class="row">
                                        <div class="col-12 col-sm-6 col-md-12">
                                            <div class="info-box mb-3">


                                                <div class="info-box-content">
                                                    <div class="relative mb-0 pb-4">
                                                        <input name="judul" value="EDIT NASABAH" style="background-color: gainsboro;" class="form-control-sm col-sm-3 fontInput small bg-default mt-3 text-center" disabled>
                                                    </div>

                                                    <div class="col-sm-12 invoice-col pt-0">
                                                        <form action="" method="post">

                                                            <?php $csrf->token(); ?>
                                                            <input type="text" name="id" value="<?php echo $data->id; ?>" class="form-control form-control-sm fontInput" hidden>
                                                            <input type="text" name="nis" value="<?php echo $data->nis; ?>" class="form-control form-control-sm fontInput" hidden>
                                                            <div class="row">
                                                                <label for="exampleEmail" class="col-sm-3 col-form-label">Nama Nasabah </label>
                                                                <div class="col-sm-7">
                                                                    <input type="text" name="nama" value="<?php echo $data->nama; ?>" class="form-control form-control-sm fontInput" placeholder="Nama Nasabah">
                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <label for="exampleEmail" class="col-sm-3 col-form-label">NIS Nasabah </label>
                                                                <div class="col-sm-7">
                                                                    <input type="text" name="nis2" value="<?php echo $data->nis; ?>" class="form-control form-control-sm fontInput" placeholder="NIS Nasabah" disabled>
                                                                </div>
                                                            </div>
                                                            <div class="row">

                                                                <label class="col-sm-3 col-form-label">No. Rekening </label>
                                                                <div class="col-md-7">
                                                                    <input type="text" style="text-align:left" value="<?php echo $data->rekening; ?>" oninput="this.value=this.value.replace(/[aA-zZ.]/g,'').replace(/(\..*)./g,'$1');" class="form-control form-control-sm fontInput small" name="rekening" required>

                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <label class="col-sm-3 col-form-label">Jenis Kelamin</label>
                                                                <div class="col-md-7">
                                                                    <select name="kelamin" class="form-control form-control-sm fontInput small" required>
                                                                        <option value="<?php echo $data->kelamin; ?>">
                                                                            <?php if ($data->kelamin == 'L') {
                                                                                echo "Laki-laki";
                                                                            } else {
                                                                                echo "Perempuan";
                                                                            }; ?></option>
                                                                        <option value="L">Laki-laki</option>
                                                                        <option value="P">Perempuan</option>
                                                                    </select>
                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <label for="nis" class="col-sm-3 col-form-label">Saldo Awal / Tahun Lalu</label>
                                                                <div class="col-sm-7">
                                                                    <input type="text" class="form-control form-control-sm fontInput" value="<?php echo $data->saldo; ?>" placeholder="Salado Awal/Tahun Lalu" name="saldo">

                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <label class="col-sm-3 col-form-label">Status Nasabah</label>
                                                                <div class="col-md-7">
                                                                    <select name="status" class="form-control form-control-sm fontInput small" required>
                                                                        <option value="<?php echo $data->status; ?>"><?php echo $data->status; ?></option>
                                                                        <option>Aktif</option>
                                                                        <option>Non Aktif</option>

                                                                    </select>
                                                                </div>
                                                            </div>
                                                            <div class="row mt-4">
                                                                <div class="col-auto">
                                                                    <a <?php echo $link->page('nasabah/nasabah_read'); ?> class="btn btn-primary btn-xs float-right mx-2"><i class="bi-arrow-left-circle"></i> Cancel</a>
                                                                    <button type="submit" class="btn btn-primary btn-xs float-right" name="submit"><i class="bi-save"></i> Simpan</button>
                                                                </div>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>

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

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php


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


    $clsCrud = new crudData;
    $clstime = new time;
    $waktu = $clstime->getTime();
    $user = $clsCrud->getValue('user', " where username='$username'", 'id');


    $id = htmlspecialchars($_POST['id']);
    $nama = htmlspecialchars($_POST['nama']);
    $nis = htmlspecialchars($_POST['nis']);
    $rekening = htmlspecialchars($_POST['rekening']);
    $kelamin = htmlspecialchars($_POST['kelamin']);
    $status = htmlspecialchars($_POST['status']);
    $saldo = htmlspecialchars(trim($_POST['saldo']));



    $dataarray = [
        'nama' => $nama,
        'nis' => $nis,
        'rekening' => $rekening,
        'kelamin' => $kelamin,
        'saldo' => $saldo,
        'status' => $status,
        'id' => $id,
        'created_at' => $waktu,
        'updated_at' => $waktu,
        'created_by' => $user
    ];
    $update = $clsCrud->updateData($tabungan_siswa, $dataarray, ['id', ' = ', $id_page]);

    $direct = new toast();
    echo  $direct->redirect('toast', 'update', 'nasabah/nasabah_read');
} else {
    echo 'Error';
}

?>