<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
if(isset($_GET['id'])){
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Template Baru");
	$nama="";
	$kode="";
	$template="";
	$idkategori=0;
	if($id>0){
		$page->setJudul("Edit Template");
		$query="SELECT * FROM tb_master_template_cetak 
			WHERE id=?";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$kode=$rs['kode'];
			$template=$rs['template'];
			$idkategori=$rs['idkategori'];
		}
	}
	$hasil=array("id"=>$id,"idkategori"=>$idkategori);
	$page->addLoad("mastertemplatecetak.edit(".json_encode($hasil,true).")");
	?>
	<div class="box_main_konten">
		<h3>Nama Template</h3>
		<div class="group_form">
			<title>Kode</title>
			<div class="col10"><input id="kode" value="<?php echo $kode;?>" />
				
			</div>
		</div>
		<div class="group_form">
			<title>Kategori Template</title>
			<div class="col10">
				<select id="sl_kategori">
					<?php
					$query="select * from tb_master_template_kategori where id>0";
					$rs=$db->loadAll($query);
					foreach ($rs as $obj) {
						?>
						<option value="<?php echo $obj['id'];?>"><?php echo $obj['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Nama Template</title>
			<div class="col10"><input id="nama" value="<?php echo $nama;?>" />
				
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>Template</h3>
		<div>
			<textarea id="template" style="height: 500px;width: 100%;box-sizing: border-box;"><?php echo $template;?></textarea>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_mastertemplatecetak" class="error"></div>
		<span class="btmerah btncancel" onclick="mastertemplatecetak.kembali()">Kembali</span>&nbsp;&nbsp;
		<span onclick="mastertemplatecetak.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	<?php
}else{
	$page->addLoad("mastertemplatecetak.load()");
	$page->setJudul("Master Template");
	?>
	<div class="box_button_atas">
		Baris: <select id="jumlah_hal" class="slkecil" onchange="mastertemplatecetak.loade()">
			<option value="30">30</option>
			<option value="50">50</option>
			<option value="100">100</option>
		</select> &nbsp;
		Hal: <select id="hal_ke" class="slkecil" onchange="mastertemplatecetak.load()"><option value="1">1</option></select>
		Kategori: <select id="sl_kategori_template" onchange="mastertemplatecetak.loade()">
			<option value="0">Semua Kategori</option>
			<?php
			$query="select * from tb_master_template_kategori where id>0";
			$rs=$db->loadAll($query);
			foreach ($rs as $obj) {
				?>
				<option value="<?php echo $obj['id'];?>"><?php echo $obj['nama'];?></option>
				<?php
			}
			?>
		</select>&nbsp;&nbsp;
		&nbsp;<input placeholder="Default: Nama Template" onkeypress="mastertemplatecetak.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="mastertemplatecetak.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="mastertemplatecetak.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_mastertemplatecetak"></div>
	<div class="box_button_bawah">
		<span onclick="mastertemplatecetak.buat(0)" class="bthijau btninput">Input Template Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="mastertemplatecetak.hapus(#{id})"></span>
		<span class="icon_edit" onclick="mastertemplatecetak.buat(#{id})"></span>
	</div>
	<div id="btdetailtpl" style="display: none;">
		<div><b>#{nama}</b></div>
		<div>Kode <b>#{kode}</b></div>
		<div style="margin-top: 8px;">Kategori</div>
		<div><b>#{kategori}</b></div>
	</div>
	<span id="btstatus" class="#(#{status}==1)?'mini_ok':'mini_dis'#" style="display:none;" onclick="mastertemplatecetak.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<?php
}
?>
