<?php 
    if(empty($edit)){
        $edit = null;
    }
?>
<div class="row">
<!-- begin col-8 -->
<div class="col-lg-12">
    <!-- begin panel -->
    <div class="panel panel-grey">
        <div class="panel-heading">
            <div class="panel-heading-btn">
                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-remove"><i class="fa fa-times"></i></a>
            </div>
            <a onclick="goBack()" class="btn btn-primary m-b-5"><span class="fa fa-arrow-left"></span> Kembali</a>
            <hr>
        </div>
        <div class="panel-body">
            <div class="col-sm-10">
                <form class="form-horizontal" method="post" action="<?= $url; ?>" enctype="multipart/form-data">
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">Nama personil</label>
                    <div class="col-md-6">
                        <input class="form-control" name="nama" value="<?php echo (!is_null($edit)?$edit['nama'] : '') ?>" type="text" placeholder="Masukkan nama personil">
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">Jabatan</label>
                    <div class="col-md-6">
                        <select name="id_jabatan[]" onchange="klik_jabatan(this.value);" class="form-control select2" multiple>
                        <option></option>
                        <?php foreach($role_jabatan as $j) { ?>
                            <option <?= multi_selected($edit, 'id_jabatan', $j['id']); ?> ><?php echo $j['nama']; ?></option>
                        <?php } ?>
                        </select>

                        <input style="margin-top:5px;" class="form-control jabatan_lainnya" name="jabatan_lainnya" value="<?php echo (!is_null($edit)?$edit['jabatan_lainnya'] : '') ?>" type="text" placeholder="Masukkan jabatan lainnya">
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">NIP</label>
                    <div class="col-md-6">
                        <input class="form-control" name="nip" value="<?php echo (!is_null($edit)?$edit['nip'] : '') ?>" type="text" placeholder="Masukkan NIP">
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">NIPTK</label>
                    <div class="col-md-6">
                        <input class="form-control" name="niptk" value="<?php echo (!is_null($edit)?$edit['niptk'] : '') ?>" type="text" placeholder="Masukkan NIPTK">
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">Alamat</label>
                    <div class="col-md-6">
                        <input class="form-control" name="alamat" value="<?php echo (!is_null($edit)?$edit['alamat'] : '') ?>" type="text" placeholder="Masukkan alamat">
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">Nomor Telepon</label>
                    <div class="col-md-6">
                        <input class="form-control" name="no_telp" value="<?php echo (!is_null($edit)?$edit['no_telp'] : '') ?>" type="text" placeholder="Masukkan nomor telepon">
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">Email</label>
                    <div class="col-md-6">
                        <input class="form-control" name="email" value="<?php echo (!is_null($edit)?$edit['email'] : '') ?>" type="text" placeholder="Masukkan email">
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label">Foto</label>
                    <div class="col-md-6">
                        <input class="form-control" type="file" accept="image/jpeg" name="file_foto">
                        <?php if(!is_null($edit)) : ?>
                            <input type='hidden' name='file_foto_lama' value='<?= $edit["file_foto"]; ?>'>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="form-group m-b-11">
                    <label class="col-md-2 col-form-label control-label"></label>
                    <div class="col-md-6">
                        <button type="submit" class="btn btn-md btn-success">Simpan</button>
                        <button type="reset" class="btn btn-md btn-warning">Reset</button>
                        <a href="<?= base_url('data_personil'); ?>" class="btn btn-md btn-danger">Batal</a>
                    </div>
                </div>

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

<script>
    <?php if(!is_null($edit) && strpos($edit['id_jabatan'], '8|') != false) { ?>
    $('.jabatan_lainnya').show();
    <?php } else{ ?>
    $('.jabatan_lainnya').hide();
    <?php } ?>
    function goBack() {
        window.history.back();
    }

    function klik_jabatan(x){
    console.log(x);
    if(x == 8){
        $('.jabatan_lainnya').show();
    }else{
        $('.jabatan_lainnya').hide();
    }
    }
</script>
