<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
$page->addPlugin("pilihtemplate");
if(isset($_GET['id'])){
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data Jenis Surat Baru");
	$nama="";
	$iddata=1;
	$idparrent=0;
	$idkategori=0;
	$libsurat="";
	$kodesurat="";
	$inout=0;
	$qr="select max(id) as maxid from tb_master_jenissurat where id>0";
	$rsj=$db->loadAssoc($qr);
	if(isset($rsj['maxid'])) $iddata=$rsj['maxid']+1;
	
	if($id>0){
		$page->setJudul("Edit Data Jenis Surat");
		$query="SELECT * FROM tb_master_jenissurat 
			WHERE id=?";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$iddata=$rs['id'];
			$idparrent=$rs['idparrent'];
			$idkategori=$rs['idkategori'];
			$libsurat=$rs['lib'];
			$kodesurat=$rs['kodesurat'];
			$inout=$rs['in_out'];
		}
	}
	$datahasil=array(
		"id"=>$id,
		"idparrent"=>$idparrent,
		"idkategori"=>$idkategori,
		"inout"=>$inout
	);
	$page->addLoad("masterjenissurat.edit(".json_encode($datahasil,true).")");
	
	?>
	<div class="box_main_konten">
		<h3>DATA JENIS SURAT</h3>
		<div class="group_form">
			<title>ID</title>
			<div class="col10">
				<input id="iddata" value="<?php echo $iddata;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Kode Surat</title>
			<div class="col10">
				<input id="kodesurat" value="<?php echo $kodesurat;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Kategori Surat</title>
			<div class="col10">
				<select id="sl_kategori">
					<?php
					$query="select * from tb_master_kategorisurat where id>0";
					$rskat=$db->loadAll($query);
					foreach ($rskat as $obk) {
						?>
						<option value="<?php echo $obk['id'];?>"><?php echo $obk['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Nama Jenis Surat</title>
			<div class="col10">
				<input id="nama" value="<?php echo $nama;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Masuk/Keluar</title>
			<div class="col10">
				<select id="sl_inout">
					<option value="0">None</option>
					<option value="1">Masuk</option>
					<option value="2">Keluar</option>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Library</title>
			<div class="col10">
				<input id="libsurat" value="<?php echo $libsurat;?>" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_masterjenissurat" class="error"></div>
		<span class="btmerah btncancel" onclick="masterjenissurat.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="masterjenissurat.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	<?php
}else{
	$page->addLoad("masterjenissurat.load()");
	$page->setJudul("Data Master Jenis Surat");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="masterjenissurat.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="masterjenissurat.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Jenis Surat" onkeypress="masterjenissurat.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="masterjenissurat.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="masterjenissurat.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_masterjenissurat"></div>
	<div id="loader_datamasterjenissurat" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="masterjenissurat.buat(0)" class="bthijau btninput">Buat Data Jenis Surat Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="masterjenissurat.hapus(#{id})"></span>
		<span class="icon_edit" onclick="masterjenissurat.buat(#{id})"></span>
	</div>
	<span id="btstatus" class="#(#{status}==1)?'mini_ok':'mini_dis'#" style="display:none;" onclick="masterjenissurat.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<span id="bttemplate" class="#(#{idtemplate}==0)?'dok_tidak':'dok_ya'#" style="display:none;" onclick="masterjenissurat.bukatemplate(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<span id="btjumlahsub" class="bthijau medium" style="display:none;" onclick="masterjenissurat.bukasub(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_sub}</span>
	<div id="bteditsub" style="display:none;">
		<span class="icon_del" onclick="masterjenissurat.hapussub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
		<span class="icon_edit" onclick="masterjenissurat.editsub(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<div id="box_subjenissurat" style="display:none;padding:10px">
		<div style="padding: 10px;">
			<div class="group_form">
				<title>ID Sub Jenis Surat</title>
				<div class="col10">
					<input id="idsub" />
				</div>
			</div>
			<div class="group_form">
				<title>Nama Sub Jenis Surat</title>
				<div class="col10">
					<input id="namasub" />
				</div>
			</div>
			
			<div class="group_form">
				<title>&nbsp;</title>
				<div class="col10">
					<div class="box_button_bawah">
						<div class="err" id="loader_sub"></div>
						<span class="btmerah" onclick="masterjenissurat.batalsub()">BATAL</span>&nbsp;&nbsp;
						<span class="bthijau" onclick="masterjenissurat.inputsub()">SIMPAN</span>
					</div>
				</div>
			</div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<span id="btinout" style="display:none;">#('#{in_out}'=='0')?'':(('#{in_out}'=='1')?'Masuk':(('#{in_out}'=='2')?'Keluar':''))#</span>
	
	<div id="bthapustpl" style="display: none;">
		<span class="icon_del" onclick="masterjenissurat.hapustpl(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
		<span class="icon_edit" onclick="masterjenissurat.edittpl(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<?php
}
?>
