<?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'])){
	$page->addJs(BS_JS."reqcb.js");
	$page->addPlugin(BS_JS."cetak");
	
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Detail Surat");
	$idpegawai=0;
	$iduser=0;
	$idkategori=0;
	$idjenissurat=0;
	$jenissurat="";
	$kategori="";
	$tanggal="";
	$namapegawai="&nbsp";
	$nippegawai="&nbsp";
	$jeniskelamin="nbsp";
	$jabatanpegawai="&nbsp";
	$golonganpegawai="&nbsp";
	
	$bg="";
	$warna="";
	$namastatus="";
	$idstatus=0;
	
	$namalib="";
	$namauser="&nbsp";
	$kelaminuser="&nbsp";
	$keterangan="&nbsp";
	$namadisposisi="&nbsp";
	$statusdisposisi=0;
	$inout=0;
	$idtemplate=0;
	if($id>0){
		$page->setJudul("Detail Surat");
		$datapusw=array($id);
		$query="SELECT t1.`id`,
				t1.`tanggal_input`,
				t1.`tanggal_surat`,
				t1.`idpegawai`,
				t1.`iduser`,
				t1.`idkategori`,
				t1.`idjenissurat`,
				t1.`datasurat`,
				t1.`iddisposisi`,
				t1.keterangan,
				t1.`status`,
				t1.statusdisposisi,
				t2.idtemplate,
				t2.lib,
				t2.nama as jenissurat,
				t2.in_out,
				if(p1.nama is null,'&nbsp',p1.nama) as namapegawai,
				if(p1.nip is null,'&nbsp',p1.nip) as nippegawai,
				if(p1.nama is null,'&nbsp',p1.nama) as namapegawai,
				if(p3.nama is null,'&nbsp',p3.nama) as jabatanpegawai,
				if(p4.nama is null,'&nbsp',p4.nama) as golonganpegawai,
				if(p2.nama is null,'&nbsp',p2.nama) as kelaminpegawai,
				if(p2.nama is null,'&nbsp',p1.nama) as namapegawai,
				if(u1.nama is null,'&nbsp',u1.nama) as namauser,
				if(u2.nama is null,'&nbsp',u2.nama) as kelaminuser,
				t3.nama as kategori,
				a1.nama as namastatus,
				a1.bg,a1.warna,
				if(t4.template is null,'',t4.template) as template,
				if(b1.nama is null,'',b1.nama) as namadisposisi
			FROM tb_suratbdk as t1 
			inner join tb_master_jenissurat as t2 on t1.idjenissurat=t2.id
			inner join tb_master_kategorisurat as t3 on t1.idkategori=t3.id
			left join tb_master_template_cetak as t4 on t2.idtemplate=t4.id
			inner join tb_master_status as a1 on t1.status=a1.id
			left join tb_suratbdk_disposisi as b1 on t1.iddisposisi=b1.id
			left join tb_pegawai as p1 on t1.idpegawai=p1.id
			left join tb_jenis_kelamin as p2 on p1.idjeniskelamin=p2.id
			left join tb_master_jabatan as p3 on p1.idjabatanstruk=p3.id
			left join tb_master_golongan as p4 on p1.idgolongan=p4.id
			left join tb_username as u1 on t1.iduser=u1.id
			left join tb_jenis_kelamin as u2 on u1.idjeniskelamin=u2.id
			WHERE t1.id=? 
			group by t1.id";
		$rs=$db->loadAssoc($query,$datapusw);
		
		if(isset($rs['id'])){
			$idpegawai=$rs['idpegawai'];
			$iduser=$rs['iduser'];
			$tanggal=$db->sql_date($rs['tanggal_surat']);
			$idkategori=$rs['idkategori'];
			$idjenissurat=$rs['idjenissurat'];
			$kategori=$rs['kategori'];
			$jenissurat=$rs['jenissurat'];
			$namapegawai=$rs['namapegawai'];
			$nippegawai=$rs['nippegawai'];
			$jeniskelamin=$rs['kelaminpegawai'];
			$jabatanpegawai=$rs['jabatanpegawai'];
			$golonganpegawai=$rs['golonganpegawai'];
			$keterangan=$rs['keterangan'];
			
			$namauser=$rs['namauser'];
			$kelaminuser=$rs['kelaminuser'];
			$bg=$rs['bg'];
			$warna=$rs['warna'];
			$namalib=$rs['lib'];
			$idstatus=$rs['status'];
			$statusdisposisi=$rs['statusdisposisi'];
			$namastatus=$rs['namastatus'];
			$namadisposisi=$rs['namadisposisi'];
			$inout=$rs['in_out'];
			$idtemplate=$rs['idtemplate'];
			
		}else{
			exit;
		}
	}else{
		exit;
	}
	$datahasil=array(
		"id"=>$id,
		"idkategori"=>$idkategori,
		"idpegawai"=>$idpegawai,
		"idstatus"=>$idstatus,
		"idjenissurat"=>$idjenissurat,
		"statusdisposisi"=>$statusdisposisi,
		"namalib"=>$namalib,
		"namastatus"=>$namastatus,
		"inout"=>$inout,
		"idtemplate"=>$idtemplate
	);
	$page->addLoad("monitoringsurat.edit(".json_encode($datahasil,true).")");
	
	?>
	<div class="box_main_konten">
		<h3>DATA SURAT</h3>
		<div class="group_form">
			<title>Tanggal Surat</title>
			<div class="col10">
				<div class="formdata"><?php echo $tanggal;?></div>
			</div>
		</div>
		<div class="group_form">
			<title>Kategori Surat</title>
			<div class="col10">
				<div class="formdata"><?php echo $kategori;?></div>
			</div>
		</div>
		<div class="group_form">
			<title>Jenis Surat</title>
			<div class="col10">
				<div id="frmjenissurat" class="formdata"><?php echo $jenissurat;?></div>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten" id="boxdatasurat" style="display: none;">
		
	</div>
	<div class="box_main_konten" id="boxuser" style="display: none;">
		<h3>DATA USER</h3>
		<div class="group_form">
			<title>Nama user</title>
			<div class="col10">
				<div class="formdata"><?php echo $namauser;?></div>
				
			</div>
		</div>
		
		<div class="group_form">
			<title>Jenis Kelamin</title>
			<div class="col10">
				<div class="formdata"><?php echo $kelaminuser;?></div>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>CATATAN SURAT</h3>
		<div id="grid_catatan"></div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>STATUS PENGAJUAN</h3>
		<div class="group_form">
			<title>Status Disposisi</title>
			<div class="col10">
				<div class="formdata"><?php echo $namadisposisi;?></div>
			</div>
		</div>
		<div class="group_form">
			<title>Status Surat</title>
			<div class="col10">
				<span id="boxnamastatus" style="padding:5px 10px;font-size: 120%;cursor: default;background: <?php echo $bg;?>" class="medium" onclick="monitoringsurat.setstatussurat()">
					<span id="namastatus" style="color: <?php echo $warna;?>"><?php echo $namastatus;?></span>
				</span>
			</div>
		</div>
		<div class="group_form">
			<title>Keterangan Status</title>
			<div class="col10">
				<div id="keterangansurat" class="formdata"><?php echo $keterangan;?></div>
			</div>
		</div>
	<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_monitoringsurat" class="error"></div>
		<span class="btmerah btncancel" onclick="monitoringsurat.kembali()">Kembali</span>
	</div>
	
	<?php
}else{
	$page->addLoad("monitoringsurat.katch()");
	$page->setJudul("Monitoring Surat");
	?>
	<div class="box_button_atas">
		<div class="box_main_konten">
			<h3>Filter Data</h3>
			<div class="group_form">
				<title>Kategori</title>
				<div class="col10">
					<select id="sl_kategori" onchange="monitoringsurat.katch()">
						<option value="0">Semua Kategori</option>
						<?php
						$query="select * from tb_master_kategorisurat where id>0";
						$rsk=$db->loadAll($query);
						foreach ($rsk as $obk) {
							?>
							<option value="<?php echo $obk['id'];?>"><?php echo $obk['nama'];?></option>
							<?php
						}
						?>
					</select>
				</div>
			</div>
			<div class="group_form" id="boxjenissurat" style="display: none;">
				<title>Jenis Surat</title>
				<div class="col10">
					<select id="sl_jenissurat" onchange="monitoringsurat.loade()"></select>
				</div>
			</div>
			<div class="group_form">
				<title>Baris dan Halaman</title>
				<div class="col10">
					<select id="jumlah_hal" style="width: 100px" onchange="monitoringsurat.loade()">
						<option value="30">30</option>
						<option value="50">50</option>
						<option value="100">100</option>
					</select> &nbsp;
					<select id="hal_ke" style="width: 100px" onchange="monitoringsurat.load()"><option value="1">1</option></select>
				</div>
			</div>
			<div class="group_form">
				<title>Filter Pencarian</title>
				<div class="col10">
					<input placeholder="Default: Jenis Surat" onkeypress="monitoringsurat.enter(event)" id="cari" class="in_cari" />
					<div style="margin-top: 10px;">
						<span id="btcari" class="btnone btncari" onclick="monitoringsurat.loade()">Cari</span>&nbsp;&nbsp;
						<span class="btnone btncanggih" onclick="monitoringsurat.caricanggih()">Cari Detail</span>
					</div>
				</div>
			</div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<div id="grid_monitoringsurat"></div>
	<div id="loader_datamonitoringsurat" class="error"></div>
	<div id="btedit" style="display:none;">
		<span class="btlihat" onclick="monitoringsurat.lihat(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<span id="btstatus" style="display: none;cursor: pointer;background: #{bg}" class="medium">
		<span style="color: #{warna}">#{namastatus}</span>
	</span>
	<div id="btdetailsurat" style="display: none;">
		<div>#{kategorisurat}</div>
		<div><b>#{jenissurat}</b></div>
	</div>
	<span id="btcatatan" onclick="monitoringsurat.lihatcatatan(#{id},##{jumlah_tabel},##{baris_tabel},this)" style="display: none" class="datajumlah">#{jumlah_catatan}</span>
	
	<?php
}
?>
