<style type="text/css">
	.width-td{width: 100px;}
	.myselect-container {
	position:relative;
	height:10px;
	width:100px;
	/*for contain our absoulte select tag */
	}
	.myselect-container select {
		position:absolute;
		/*for put our list on other tag */
	}
</style>

<style type="text/css">
.table > thead > tr > th {
	vertical-align: middle;
	text-align: center;
}
.table > tbody > tr > td {
	vertical-align: middle;
	text-align: center;
}
</style>

<?php 
	$jam_mulai = get_str_jam($data[0]['mulai_uji']); 
	$menit_mulai = get_str_menit($data[0]['mulai_uji']);
	$jam_selesai = get_str_jam($data[0]['selesai_uji']); 
	$menit_selesai = get_str_menit($data[0]['selesai_uji']);

  	$jam = date('H'); $menit = date('i');
	$jam_mulai = ($jam_mulai != '') ? $jam_mulai : $jam;
	$menit_mulai = ($menit_mulai != '') ? $menit_mulai : $menit;
	$jam_selesai = ($jam_selesai != '') ? $jam_selesai : $jam;
	$menit_selesai = ($menit_selesai != '') ? $menit_selesai :$menit;
?>

<h4>Nomor Batch: <?= $nomor_batch; ?></h4>
<div class="row">
	<!-- begin col-8 -->
	<div class="col-sm-12">
		<!-- begin panel -->
		<div class="panel panel-grey">
			<?php 
				if(!empty($is_edit)){
					$url_form = base_url()."update_batch_uji/$jenis_uji/$nomor_batch/$kontrol_sampel";
					$url_back = base_url()."batch_sampel_list/$jenis_uji/$nomor_batch/$kontrol_sampel";
					$url_back_deret = base_url()."batch_sampel_list/$jenis_uji/$nomor_batch/$kontrol_sampel";
				}else {
					$url_form = base_url().'save_batch_uji/'.$jenis_uji;
					$url_back = base_url().'sampel_uji/'.$jenis_uji;
					$url_back_deret = "#";
				}
			?>
			<form method="post" id="form_edit" action="<?= $url_form; ?>"">
				<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>
					<?php if(in_array($jenis_uji, ['fosfor', 'ca', 'ur', 'af'])) : ?>
						<a href="<?= $url_back_deret; ?>" class="btn btn-primary">Kembali</a>
					<?php else : ?>
						<a class="btn btn-primary" href="<?= $url_back; ?>">Kembali</a>
					<?php endif; ?>
					<button type="button" onclick="save_analis();" class="btn btn-warning">Simpan</button>
					<hr>
					<table class="table">
                        <tr>
                            <?php
                                $default_nomor_bagian = '';
                                if($jenis_uji == 'ca'){
                                    $default_nomor_bagian = 'FM. 7.4-32';
                                }
                                if($jenis_uji == 'ur'){
                                    $default_nomor_bagian = 'FM. 7.4-31';
                                }
                                if($jenis_uji == 'fosfor'){
                                    $default_nomor_bagian = 'FM. 7.4-13';
                                }
                                if($jenis_uji == 'af'){
                                    $default_nomor_bagian = 'FM. 7.4-29';
                                }
                                if($jenis_uji == 'kalsium'){
                                    $default_nomor_bagian = 'FM. 7.4-12';
                                }

                                // TAMBAHAN TERBARU
                                if($jenis_uji == 'air'){
                                    $default_nomor_bagian = 'FM. 7.4-7';
                                }
                                if($jenis_uji == 'abu'){
                                    $default_nomor_bagian = 'FM. 7.4-8';
                                }
                                if($jenis_uji == 'andf'){
                                    $default_nomor_bagian = 'FM. 7.4-30';
                                }
                                if($jenis_uji == 'pkd'){
                                    $default_nomor_bagian = 'FM. 7.4-32';
                                }
                                if($jenis_uji == 'lemak_kasar'){
                                    $default_nomor_bagian = 'FM. 7.4-10';
                                }
                                if($jenis_uji == 'serat_kasar'){
                                    $default_nomor_bagian = 'FM. 7.4-11';
                                }
                                if($jenis_uji == 'protein_kasar'){
                                    $default_nomor_bagian = 'FM. 7.4-9';
                                }
                            ?>
							<th>Nomor Bagian</th>
							<td>:</td>
							<th><input class="" style="width:200px;" name='nomor_bagian[]' value="<?= $default_nomor_bagian; ?>"></th>

							<th>Halaman</th>
                            <td>:</td>
							<th><input class="" style="width:200px;" name='halaman[]' value="<?= ($data[0]['halaman'] ? $data[0]['halaman'] : '1 dari 1') ?>"></th>

							<th style="width:100px;"></th>
						</tr>
						<tr>
							<th>Terbitan/Revisi</th>
							<td>:</td>
							<th>
                                <?php 
                                    $terbitan = '1/0';
                                    if(!in_array($jenis_uji,['ur', 'ca'])){
                                        $terbitan = '1/1';
                                    }
                                ?>
                                <input class="" style="width:200px;" name='terbitan_revisi_ke[]' value="<?= ($data[0]['terbitan_revisi_ke'] ? $data[0]['terbitan_revisi_ke'] : $terbitan); ?>">
                            </th>
                            
                            <?php if(in_array($jenis_uji, ['ca', 'ur'])) : ?>
                                <input type='hidden' name='tanggal_revisi[]' value='0'>
                                <th>Tanggal Revisi</th>
							    <td>:</td>
                                <td class='text-left'>-</td>
                            <?php else : ?>
							<th>Tanggal Revisi</th>
							<td>:</td>
							<th>
								<?= toi_date_input('tanggal_revisi[]', ($data[0]['tanggal_revisi']) ? $data[0]['tanggal_revisi'] : '2019-10-14', false, 200); ?>
							</th>
                            <?php endif; ?>

							<th style="width:100px;"></th>
						</tr>
						<tr>
							<th>Tanggal Terbitan</th>
							<td>:</td>
							<th>
                                <?php 
                                    $tgl_terbitan = '2019-12-02';
                                    if(!in_array($jenis_uji,['ur', 'ca'])){
                                        $tgl_terbitan = '2019-01-02';
                                    }
                                    if(in_array($jenis_uji,['pkd'])){
                                        $tgl_terbitan = '2019-09-02';
                                    }
                                ?>
								<?= toi_date_input('tanggal_terbitan[]', ($data[0]['tanggal_terbitan']) ? $data[0]['tanggal_terbitan'] : $tgl_terbitan, false, 200); ?>
							</th>
							<th></th> <th></th> <th></th>
							<th style="width:100px;"></th>
						</tr>
						<tr>
							<th>Tanggal Mulai Pengujian</th>
							<td>:</td>
							<td>
								<?= toi_date_input('mulai_uji[]', $data[0]['mulai_uji'], false, 200); ?>
							</td>

							<th>Suhu (ᵒC)</th>
							<td>:</td>
							<th><input class="" style="width:200px;" name='suhu[]' value="<?= $data[0]['suhu'] ?>"></th>

							<th></th>
						</tr>
						<tr>
							<th>Pukul Mulai Pengujian</th>
							<td>:</td>
							<td class="input-group">
								<?= toi_time_input('waktu_mulai[]', $data[0]['mulai_uji'], false, 200); ?>
							</td>
							<th>RH (%)</th>
							<td>:</td>
							<th><input class="" style="width:200px;" name='rh[]' value="<?= $data[0]['rh'] ?>"></th>

							<th></th>
						</tr>

                        <tr>
							<th>Tanggal Selesai Pengujian</th>
							<td>:</td>
							<td>
								<?= toi_date_input('selesai_uji[]', $data[0]['selesai_uji'], false, 200); ?>
							</td>

                            <th>Metode Uji</th>
                            <th>:</th>
                            <td>
                                <?php
                                    $default_metode_uji = '';
                                    if($jenis_uji == 'ca'){
                                        $default_metode_uji = 'AOAC 2012 Bab 4 Butir 4.8.02 Metode 968.08';
                                    }
                                    if($jenis_uji == 'ur'){
                                        $default_metode_uji = 'AOAC 2019 Bab 4 Butir 4.3.02 Metode 967.07';
                                    }
                                    if($jenis_uji == 'fosfor'){
                                        $default_metode_uji = 'AOAC 2019 Bab 4 Butir 4.8.14 Metode 965.17';
                                    }
                                    if($jenis_uji == 'af'){
                                        $default_metode_uji = 'Agra Quant Total Aflatoxin Test Kit';
                                    }
                                    if($jenis_uji == 'kalsium'){
                                        $default_metode_uji = 'AOAC 2012 Bab 4 Butir 4.8.03 Metode 927.02';
                                    }

                                    // TAMBAHAN TERBARU
                                    if($jenis_uji == 'air'){
                                        $default_metode_uji = 'AOAC 2019 Bab 4 Butir 4.1.06 Metode 930.15';
                                    }
                                    if($jenis_uji == 'abu'){
                                        $default_metode_uji = 'AOAC 2019 Bab 4 Butir 4.1.10 Metode 942.05';
                                    }
                                    if($jenis_uji == 'andf'){
                                        $default_metode_uji = 'AOAC 2012 Bab 4 Butir 4.6.04 Metode 2002.04';
                                    }
                                    if($jenis_uji == 'pkd'){
                                        $default_metode_uji = 'AOAC 2019 Bab 4 Butir 4.2.08 Metode 990.03';
                                    }
                                    if($jenis_uji == 'lemak_kasar'){
                                        $default_metode_uji = 'AOAC 2019 Bab 4 Butir 4.5.06 Metode 2003.6';
                                    }
                                    if($jenis_uji == 'serat_kasar'){
                                        $default_metode_uji = 'SNI-01-2891-1992 Butir 11';
                                    }
                                    if($jenis_uji == 'protein_kasar'){
                                        $default_metode_uji = 'AOAC 2019 Bab 4 Butir 4.2.11 Metode 2001.11';
                                    }
                                ?>
                                <textarea class="" style="width: 200px; float: left;" name="metode_uji[]"><?= $data[0]['metode_uji'] ? $data[0]['metode_uji'] : $default_metode_uji; ?>
                                </textarea>
                            </td>
                            <th></th>
						</tr>
						
						<tr>
							<th>Pukul Selesai Pengujian</th>
							<td>:</td>
							<td class="input-group">
								<?= toi_time_input('waktu_selesai[]', $data[0]['selesai_uji'], false, 200); ?>
							</td>
							
							<?php if(!in_array($jenis_uji, ['fosfor', 'ca', 'af', 'ur', 'kalsium', 'lemak_kasar', 'protein_kasar', 'andf', 'serat_kasar'])) : ?>
								<th>Alat Uji</th>
								<td>:</td>
								<th>
									<?php 
										$alat = ($data[0]['alat_uji']) ? json_decode($data[0]['alat_uji']) : [];
									?>
									<select style="width:200px;" class="select2 alat_uji" <?= ($jenis_uji == 'air') ? "onchange='pilih_vochdoos(this.value);'" : "";?> name="alat_uji[0][]" multiple>
										<option value="" readonly>Pilih salah satu</option>
										<?php foreach($alat_uji as $au) {?>
											<option <?= (in_array($au['id'], $alat)) ? 'selected' : '';?> value="<?php echo $au['id'] ?>"><?php echo $au['nama_alat']; ?></option>
										<?php } ?>
									</select>
								</th>
								<th></th>
							<?php else: ?>
                                <td></td><td></td><td></td><td></td>
                            <?php endif; ?>
						</tr>
                        <tr>
                            <?php $nama_analis = $this->m_analis->get_nama_analis($this->session->userdata('id_user')); ?>
                            <th>Nama Analis</th>
							<td>:</td>
							<th><input class="" style="width:200px;" name='nama_analis[]' value="<?= ($data[0]['nama_analis']) ? $data[0]['nama_analis'] : $nama_analis; ?>"></th>

							<th></th>
							<td></td>
							<th></th>

							<th></th>
						<tr>
							<td colspan="7"></td>
						</tr>
					</table>
	            </div>

				<div class="panel panel-body table-responsive">
					<?php if(empty($is_edit)) : ?>
						<button class="btn btn-primary" type="button" onclick="add_kontrol_sampel();">
							Tambah Kontrol Sampel
						</button>
						<label><input type="radio" id="t1" name="letak[]" value="t1_">Sebelum</label>
						<label><input type="radio" id="t3" name="letak[]" value="t3_">Sesudah</label>
						<select id="letak_id" name="letak_id[]">
							<option disable>Pilih sampel</option>
							<?php foreach($data as $d) : ?>
								<?php if(!is_null($d['nomor_sampel'])) : ?>
									<option value="<?= $d['id']; ?>"><?= $d['nomor_sampel']; ?></option>
								<?php endif; ?>
							<?php endforeach; ?>
						</select>
						<hr>
					<?php endif; ?>