<form class="form-horizontal" method="post" id="formUjiSampel">
<div class="row">
    <div class="col-lg-12">
      <!-- begin panel -->
      <div class="panel panel-grey">
          <div class="panel-heading">
           <a href="#" 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 id="form_sampel" class="">
                <input type="hidden" name="id_uji" <?php echo !empty($edit) ? "value='".$edit['id_uji']."'": ""; ?>>
                <input type="hidden" name="id_sampel_hidden" <?php echo !empty($editSampel) && empty($add_history) ? "value='".$editSampel['id_sampel']."'": ""; ?>>
                <input type="hidden" name="id_disposisi_hidden" <?php echo !empty($editSampel) ? "value='".$editSampel['id_disposisi']."'": ""; ?>>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Asal Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control asal_sampel" name="asal_sampel" <?php echo !empty($editSampel) ? "value='".$editSampel['asal_sampel']."'": "value='".$edit['instansi_umum']."'"; ?> type="text" placeholder="Asal Sampel" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Klasifikasi<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select class="form-control default-select2 klasifikasi" onchange="pilihJenisSampel(this.value,1)" name="klasifikasi" required>
                            <option></option>
                            <?php foreach ($klasifikasi as $r) { ?>
                                <option value="<?php echo $r['id_jenis']; ?>" <?php echo !empty($editSampel) && $editSampel['klasifikasi'] === $r['nama_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Golongan Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select class="form-control default-select2 id_keterangan" onchange="pilihJenisSampel(this.value,2)" name="id_keterangan" required>
                            <option></option>
                            <?php foreach ($gol_sampel as $r) { ?>
                                <option value="<?php echo $r['id_jenis']; ?>" <?php echo !empty($editSampel) && $editSampel['id_keterangan'] === $r['id_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Jenis Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select class="form-control default-select2 id_jenis_sampel" name="id_jenis_sampel" required>
                            <option></option>
                            <?php foreach ($jenis_sampel as $r) { ?>
                                <option value="<?php echo $r['id_jenis']; ?>" <?php echo !empty($editSampel) && $editSampel['id_jenis_sampel'] === $r['id_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']. (isset($r['kode_jenis']) ? '['.$r['kode_jenis'].']' : ''); ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label"></label>
                    <div class="col-md-6">
                        <input class="form-control merek_dagang" name="merek_dagang" <?php echo !empty($editSampel) ? "value='".$editSampel['merek_dagang']."'": ""; ?> type="text" placeholder="Masukkan merek dagang">
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Kualitas<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select class="form-control default-select2 kualitas" name="kualitas" required>
                            <option></option>
                            <option value="Baik" <?php echo !empty($editSampel) && $editSampel['kualitas'] === 'Baik' ? 'selected' : ''; ?>>Baik</option>
                            <option value="Tidak Baik" <?php echo !empty($editSampel) && $editSampel['kualitas'] === 'Tidak Baik' ? 'selected' : ''; ?>>Tidak Baik</option>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Bentuk/Jenis<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control bentuk_jenis" name="bentuk_jenis" <?php echo !empty($editSampel) ? "value='".$editSampel['bentuk_jenis']."'": ""; ?> type="text" placeholder="Bentuk/Jenis" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Jenis Pengujian<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select name="jenis_pengujian[]" id="jenis_pengujian" onchange="setproksimat()" class="form-control  default-select2 jenis_pengujian" multiple="" required>
                            <option></option>
                            <option value="1|2|3|4|5">Proksimat</option>
                            <?php foreach ($jenis_pengujian as $r) { ?>
                                <option value="<?php echo $r['id_jenis']; ?>" <?php echo !empty($editSampel) && strpos($editSampel['jenis_pengujian'], $r['id_jenis'].'|') !== FALSE ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis'] ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Label Pakan<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control label_pakan" name="label_pakan" <?php echo !empty($editSampel) ? "value='".$editSampel['label_pakan']."'": ""; ?> type="text" placeholder="Label Pakan" required>
                    </div>
                </div>
                <?php if($edit['jenis_layanan'] == 'Aktif') { ?>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Petugas Pengambil Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control petugas_pengambil_sampel" name="petugas_pengambil_sampel" <?php echo !empty($editSampel) ? "value='".$editSampel['petugas_pengambil_sampel']."'": ""; ?> type="text" placeholder="Petugas Pengambil Sampel" required>
                    </div>
                </div>
              <?php }else{ ?>
                  <input type="hidden" name="petugas_pengambil_sampel">
              <?php } ?>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Penanganan Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select class="form-control default-select2 id_penanganan_sampel" name="id_penanganan_sampel" required>
                            <option></option>
                            <?php foreach ($penanganan_sampel as $r) { ?>
                                <option value="<?php echo $r['id_jenis']; ?>" <?php echo !empty($editSampel) && $editSampel['id_penanganan_sampel'] === $r['id_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Berat Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control berat_sampel" name="berat_sampel" <?php echo !empty($editSampel) ? "value='".$editSampel['berat_sampel']."'": ""; ?> type="text" placeholder="Masukkan Berat Sampel" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Satuan Berat<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <select class="form-control satuan_sampel default-select2" name="satuan_sampel">
                            <option></option>
                            <option value='gram' <?php echo !empty($editSampel) && $editSampel['satuan_berat'] === 'gram' ? 'selected' : ''; ?>>gram</option>
                            <option value='mili liter' <?php echo !empty($editSampel) && $editSampel['satuan_berat'] === 'mili liter' ? 'selected' : ''; ?>>mili liter</option>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Kemasan<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <input class="form-control kemasan" name="kemasan" <?php echo !empty($editSampel) ? "value='".$editSampel['kemasan']."'": ""; ?> type="text" placeholder="Masukkan Kemasan" required>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Penyimpanan Sampel Kerja<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <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($editSampel) && $editSampel['id_sampel_kerja'] === $r['id_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-12">
                    <label class="col-md-3 col-form-label control-label">Penyimpanan Sampel Arsip<span class="text-danger">*</span></label>
                    <div class="col-md-6">
                        <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($editSampel) && $editSampel['id_sampel_arsip'] === $r['id_jenis'] ? 'selected' : ''; ?>>
                                    <?php echo $r['nama_jenis']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
         </div>
         <div class="panel-footer">
           <div class="form-group m-b-12">
               <label class="col-md-3 col-form-label control-label"></label>
               <div class="col-md-6">
                   <button type='submit' class='btn btn-success m-b-5' style='margin-right: 5px;'>Simpan</button>
                   <a href="#" onclick="goBack()" class="btn btn-danger m-b-5">Batal</a>
               </div>
           </div>
         </div>
      </div>
  </div>
</div>
</form>

<script>
    function pilihJenisSampel(x, type) {
        var idKlasifikasi = $(".klasifikasi").val();
        var idGolSampel = $(".id_keterangan").val();

        if(idKlasifikasi !== '' && idGolSampel !== '') {
            $.post( "<?php echo site_url('sampel/pendaftaran/get_jenis_sampel') ?>", { id_klasifikasi: idKlasifikasi, id_gol_sampel: idGolSampel}, function( data ) {
                $(".id_jenis_sampel").html(data);
            });
        }
    }

    function setproksimat(){
      var x = $('#jenis_pengujian').val();

      //console.log(x.indexOf("1|2|3|4|5"));
      //if(x.indexOf("1|2|3|4|5") == 0){
      //  console.log(x);
      //  $.post( "<?php echo site_url('sampel/pendaftaran/get_jenis_pengujian') ?>", { id_pengujian:x}, function( data ) {
      //      $("#jenis_pengujian").html(data);
      //  });
      //}else{
      //  $.post( "<?php echo site_url('sampel/pendaftaran/get_jenis_pengujian') ?>", { id_pengujian:'kosong'}, function( data ) {
      //      $("#jenis_pengujian").html(data);
      //  });
      //}
    }
</script>
