<?php
$set = $this->data->str;

if(empty($set->indDb)){
	$fil = array();
	$fil[] = $set->pk." = '".$_GET['nojnl']."'";
	if(!empty($set->where)){
		$fil[] = "(".$set->where.")";
	}
	$select = '*';
	if(!empty($set->select)){
		$select = $set->select;
	}
	$tmp = $this->em->getFindBy($set->data, $select, $fil, $set->sort);
}else{
	$tmp = $set->indDb;
}


$res = array();
$nom = 1;
foreach($tmp as $k => $r){
	$res[$nom] = $r;
	$nom++;
}

$det = array();
for($i = 1; $i <= $set->max; $i++){
	$n = '';
	if(!empty($res[$i])){
		$n = $res[$i];
	}
	$det[$i] = $n;
}
$idGrid = $set->grid;
?>
<table id="<?php echo $set->grid ?>">
	<thead>
		<tr>
			<?php if($set->autoNo == true){ ?>
				<th width="30">No</th>
			<?php } ?>
			<?php 
			foreach($set->attr as $k => $r){ 
				$type = "text";
				if(!empty($row['type'])){
					$type = $row['type'];
				}
				if(strtoupper($type) != strtoupper('hidden')){
			?>
				<th width="<?php echo $r['width'] ?>"><?php echo $r['label'] ?></th>
			<?php 
				}
			} 
			?>
		</tr>
	</thead>
	<tbody>
		<?php 
		$kode = new Kode;
		foreach($det as $no => $r){ ?>
			<tr>
				<?php if($set->autoNo == true){ ?>
					<td ><?php echo $no ?></td>
				<?php } ?>
				<?php 
				foreach($set->attr as $kye2 => $row){ 
					$k = $kye2+1;
					$idDet = $row['attr'];
					$baris = $no;
					$type = "text";
					if(!empty($row['type'])){
						$type = $row['type'];
					}
					if($row['mode'] == 'date' and !empty($r->$idDet)){
						$r->$idDet = date("d/m/Y", strtotime($r->$idDet));
					}
					if(strtoupper($type) == strtoupper('hidden')){
				?>
						<input type="hidden" row="<?php echo $no ?>" col="<?php echo $k ?>" class="text _det2View <?php echo $idGrid ?>_<?php echo $baris ?>_<?php echo $rows ?> <?php echo $row['class'] ?>" style="width:<?php echo ($row['width']) ?>px" name="<?php echo $idDet ?>[<?php echo $baris ?>]" id="<?php echo $idDet.'_'.$baris ?>" autocomplete="off" title="<?php echo $r->$idDet ?>" value="<?php echo $r->$idDet ?>" dec="<?php echo (int)$row['dec'] ?>" disabled _mode="cursor" <?php echo $tambah ?>>
				<?php 
				}else{ 
					$tambah = $kode->setAttrDetail($row, $baris);
					$after = $row['after'];
					$after = explode("(", $after);
					$after = trim(strtolower($after[0]));
					$_imgLod = false;
					if($after == 'load'){
						$_imgLod = true;
					}
					
					$baris = $no;
					$rows = $k;
				?>
					<td>
						<input type="text" row="<?php echo $rows ?>" col="<?php echo $baris ?>" class="text _detDiubleGrid _detTd _detTd_<?php echo $baris ?>_<?php echo $rows ?> <?php echo $row['class'] ?>" style="width:<?php echo ($row['width']) ?>px" name="<?php echo $idDet ?>[<?php echo $baris ?>]" id="<?php echo $idDet.'_'.$baris ?>" autocomplete="off" '+" title='<?php echo $r->$idDet ?>' value='<?php echo $r->$idDet ?>' "+' dec="<?php echo (int)$row['dec'] ?>" disabled _mode="cursor" <?php echo $tambah ?>>

					

						<!--
						<input type="text" row="<?php echo $no ?>" col="<?php echo $k ?>" class="text _det2View <?php echo $idGrid ?>_<?php echo $baris ?>_<?php echo $rows ?> <?php echo $row['class'] ?>" style="width:<?php echo ($row['width']) ?>px" name="<?php echo $idDet ?>[<?php echo $baris ?>]" id="<?php echo $idDet.'_'.$baris ?>" autocomplete="off" title="<?php echo $r->$idDet ?>" value="<?php echo $r->$idDet ?>" dec="<?php echo (int)$row['dec'] ?>" disabled _mode="cursor" <?php echo $tambah ?>>
						-->



						<?php if($_imgLod == true){ ?>
							<input row="<?php echo $k ?>" disabled col="<?php echo $no ?>" _idd="<?php echo $idDet.'_'.$no ?>" _nno="<?php echo $idDet.'_'.$no ?>" class="_imgCariD _imgCariDDouble _buttonLoadD" value="" _ttb="&pkBrowse=&get_def=&get_def=undefined" type="button">
						<?php } ?>
					</td>
				<?php 
				}
			} 
			?>
			</tr>
		<?php } ?>
	</tbody>
</table>

<script type="text/javascript">
$('#<?php echo $set->grid ?>').flexigrid({
	width: <?php echo $set->width ?>,
	height: <?php echo $set->height ?>,
	<?php if(!empty($set->label)){ ?>
	title: '<?php echo $set->label ?>',
	<?php } ?>
});
setDec();
_act = $('#_prosesAction').val();
if(_act === 'simpan' || _act === 'update'){
	$('._detDiubleGrid, ._imgCariDDouble').removeAttr("disabled");
}
</script>