<div class="row">
  <!-- begin col-8 -->
  <div class="col-lg-12">
      <!-- begin panel -->
      <form class="form-horizontal" method="post" name="" action="">
      <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">
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Waktu Pukul Mulai<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <div class="input-group bootstrap-timepicker">
                            <input value="<?php echo isset($edit) ? $edit['pukul_mulai'] : '' ?>" name="pukul_mulai" type="text" class="form-control timepicker" required>
                            <span class="input-group-addon"><i class="fa fa-clock"></i></span>
                        </div>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Waktu Pukul Selesai<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <div class="input-group bootstrap-timepicker">
                            <input value="<?php echo isset($edit) ? $edit['pukul_selesai'] : '' ?>" class="form-control timepicker" name="pukul_selesai" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-clock"></i></span>
                        </div>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Nomor Sampel</label>
                    <div class="col-md-7">
                        <input class="form-control" name="id_sampel" type="text" value="<?php echo $id_sampel; ?>" readonly>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Bentuk Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_bentuk_sampel" onchange="pilihJenis(this.value);" class="form-control default-select2" required>
                            <option></option>
                            <option <?php echo isset($edit) && strpos($edit['id_bentuk_sampel'], '1') !== false ? 'selected' : ''; ?> value="1">Cair</option>
                            <option <?php echo isset($edit) && strpos('2|3|4|', $edit['id_bentuk_sampel']) !== false ? 'selected' : ''; ?> value="Padat">Padat</option>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11" id="jenis_padat">
                    <label class="col-md-4 col-form-label"></label>
                    <div class="col-md-7">
                        <h5>Kondisi:</h5>
                    </div>
                    <label class="col-md-4 col-form-label control-label"></label>
                    <div class="col-md-7">
                        <?php $padat = explode('|', $edit['id_bentuk_sampel']); ?>
                        <select style="width: 100%;" name="bentuk_padat[]" class="form-control default-select2" multiple>
                            <option></option>
                            <?php foreach ($bentuk_sampel as $r) { ?>
                                <option <?php echo isset($edit) && in_array($r['id_jenis'], $padat) ? 'selected' : '' ?> value="<?php echo $r['id_jenis'] ?>"><?php echo $r['nama_jenis'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Jenis Penanganan Sampel Arsip<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_penanganan_arsip" class="form-control default-select2 id_penanganan_arsip" required>
                            <option></option>
                            <?php foreach ($penanganan_arsip as $r) { ?>
                            <?php if($r['nama_jenis'] === 'Cair') { ?>
                                <option <?php echo isset($edit) && $edit['id_penanganan_arsip'] === $r['id_jenis'] ? 'selected' : ''; ?> value="<?php echo $r['id_jenis'] ?>"><?php echo $r['nama_jenis'] ?></option>
                            <?php }else { ?>
                                <option <?php echo isset($edit) && $edit['id_penanganan_arsip'] === $r['id_jenis'] ? 'selected' : ''; ?> value="<?php echo $r['id_jenis'] ?>"><?php echo $r['nama_jenis'] ?></option>
                            <?php } ?>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Jenis Penggunaan Sampel Kerja<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_penanganan_kerja" onchange="onPenangananKerja(this.value);" class="form-control default-select2 id_penanganan_kerja" required>
                            <option></option>
                            <?php foreach ($penanganan_kerja as $r) { ?>
                                <option <?php echo isset($edit) && $edit['id_penanganan_kerja'] === $r['id_jenis'] ? 'selected' : ''; ?> value="<?php echo $r['id_jenis'] ?>"><?php echo $r['nama_jenis'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                
                <div class="form-group m-b-11 ket_penanganan_kerja">
                    <label class="col-md-4 col-form-label control-label"></label>
                    <div class="col-md-7">
                        <h5>Ket. Penggunaan Sampel Kerja</h5>
                        <?php $ket_penanganan_kerja = array('Uji Proksimat', 'Ca', 'P', 'MBM', 'Urea', 'Asam Amino'); ?>
                        <select style="width:100%" name="ket_penanganan_kerja" class="form-control default-select2">
                            <option></option>
                            <?php foreach ($ket_penanganan_kerja as $r) { ?>
                                <option <?php echo isset($edit) && $edit['ket_penanganan_kerja'] === $r ? 'selected' : ''; ?> value="<?php echo $r ?>"><?php echo $r ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>


                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Berat Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <input class="form-control berat_sampel" name="berat_sampel" <?php echo !empty($edit) ? "value='".$edit['berat_sampel']."'": ""; ?> type="text" placeholder="Masukkan Berat Sampel" required>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Satuan Berat<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select class="form-control satuan_sampel default-select2" name="satuan_sampel">
                            <option></option>
                            <option value='gram' <?php echo !empty($edit) && $edit['satuan_berat'] === 'gram' ? 'selected' : ''; ?>>gram</option>
                            <option value='mili liter' <?php echo !empty($edit) && $edit['satuan_berat'] === 'mili liter' ? 'selected' : ''; ?>>mili liter</option>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Kemasan<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <input class="form-control kemasan" name="kemasan" <?php echo !empty($edit) ? "value='".$edit['kemasan']."'": ""; ?> type="text" placeholder="Masukkan Kemasan" required>
                    </div>
                </div>


                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Grinder<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_jenis_grinder" class="form-control default-select2" required>
                            <option></option>
                            <?php foreach ($grinder as $r) { ?>
                                <option <?php echo isset($edit) && $edit['id_jenis_grinder'] === $r['id_jenis'] ? 'selected' : ''; ?> value="<?php echo $r['id_jenis'] ?>"><?php echo $r['nama_jenis'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Penyimpanan Sampel Kerja<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select class="form-control default-select2 id_sampel_kerja" name="id_sampel_kerja" required>
                            <option></option>
                            <?php foreach ($sampel_kerja as $r) { ?>
                                <option value="<?php echo $r['id_jenis']; ?>" <?php echo !empty($edit) && $edit['id_sampel_kerja'] === $r['id_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Penyimpanan Sampel Arsip<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select class="form-control default-select2 id_sampel_arsip" name="id_sampel_arsip" required>
                            <option></option>
                            <?php foreach ($sampel_arsip as $r) { ?>
                                <option value="<?php echo $r['id_jenis']; ?>" <?php echo !empty($edit) && $edit['id_sampel_arsip'] === $r['id_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>

                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Keterangan</label>
                    <div class="col-md-7">
                        <input class="form-control" name="keterangan" value="<?php echo isset($edit) ? $edit['keterangan'] : ''; ?>" type="text" placeholder="Masukkan keterangan">
                    </div>
                </div>

            </div>
        </div>
        <div class="panel panel-footer">
          <div class="col-sm-10">
            <div class="form-group m-b-11">
                <label class="col-md-4 col-form-label control-label"></label>
                <div class="col-md-7">
                    <button type="submit" class="btn btn-md btn-success">Simpan</button>
                    <button type="reset" class="btn btn-md btn-warning">Reset</button>
                    <a onclick="goBack();" class="btn btn-md btn-danger">Batal</a>
                </div>
            </div>
          </div>
        </div>
      </div>
      </form>
  </div>
</div>

<script type="text/javascript">
    <?php if(isset($edit) && '5' == $edit['id_penanganan_kerja']) { ?>
      $('.ket_penanganan_kerja').show();
    <?php }else { ?>
      $('.ket_penanganan_kerja').hide();
    <?php } ?>

    <?php if(isset($edit) && strpos('2|3|4|', $edit['id_bentuk_sampel']) !== false) { ?>
        $('#jenis_padat').show();
    <?php }else { ?>
        $('#jenis_padat').hide();
    <?php } ?>
    function pilihJenis(x){
        if(x === 'Padat'){
            $('#jenis_padat').show();
        }else{
            $('#jenis_padat').hide();
        }

        $.post( "<?php echo site_url('sampel/pengajuan/get_penanganan_sampel_arsip') ?>", { type: x}, function( data ) {
            $(".id_penanganan_arsip").html(data);
        });
    }

    function onPenangananKerja(x){
      if(x == '5'){
        $('.ket_penanganan_kerja').show();
      } else{
        $('.ket_penanganan_kerja').hide();
      }
    }

</script>
