<?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("pilihcatatan");
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data Surat Balasan Baru");
	$sifat="";
	$lampiran="";
	$halsurat="";
	$kepada="";
	$ditempat="";
	$keterangan="";
	
	$namastatus="";
	$bg="";
	$warna="";
	
	$nomorsurat="";
	$editstatus=1;
	$statusdisposisi=0;
	$idsurat=0;
	
	if($id>0){
		$page->setJudul("Edit Data Surat Balasan");
		$whp="";
		$datapushp=array($_SESSION['profile']['level'],$_SESSION['profile']['level'],$id);
		if($_SESSION['profile']['pegawai']==1){
			$whp.="and t4.idpegawai=? ";
			array_push($datapushp,$_SESSION['profile']['idpegawai']);
		}
		
		$query="SELECT t1.`id`,
				t1.`tanggal_input`,
				t1.`tanggal_surat`,
				t1.`nomor`,
				t1.`nomor_panjang`,
				t1.`idsurat`,
				t1.`iduser`,
				t1.`sifat`,
				t1.lampiran,
				t1.hal,
				t1.kepada,
				t1.ditempat,
				t1.`catatan_balasan`,
				t1.`keterangan`,
				t2.`jumlah_catatan`,
				t2.`status`,
				t2.statusdisposisi,
				a1.nama as namastatus,
				a1.bg,a1.warna,
				if(b1.id is null,0,1) as edit,
				if(b2.id is null,0,1) as hapus
			FROM tb_surat_balasan as t1
			inner join tb_suratbdk as t2 on t1.idsurat=t2.id
			inner join tb_master_status as a1 on t2.status=a1.id
			left join tb_master_status_level as b1 on t2.status=b1.idstatus and b1.mode=0 and b1.idlevel=?
			left join tb_master_status_level as b2 on t2.status=b2.idstatus and b2.mode=1 and b2.idlevel=?
			WHERE t1.id=? ".$whp;
		$rs=$db->loadAssoc($query,$datapushp);
		if(isset($rs['id'])){
			$idsurat=$rs['idsurat'];
			$sifat=$rs['sifat'];
			$lampiran=$rs['lampiran'];
			$halsurat=$rs['hal'];
			$kepada=$rs['kepada'];
			$ditempat=$rs['ditempat'];
			$keterangan=$rs['keterangan'];
			
			$editstatus=$rs['edit'];
			$statusdisposisi=$rs['statusdisposisi'];
			$namastatus=$rs['namastatus'];
			$bg=$rs['bg'];
			$warna=$rs['warna'];
		}else{
			exit;
		}
	}
	$datahasil=array(
		"id"=>$id,
		"editstatus"=>$editstatus,
		"statusdisposisi"=>$statusdisposisi,
		"idsurat"=>$idsurat
	);
	$page->addLoad("suratbalasan.edit(".json_encode($datahasil,true).")");
	
	$disable="disabled='true'";
	$display="style='display:none;'";
	$classdis="class='input_dis'";
	if($editstatus==1){
		$disable="";
		$display="";
		$classdis="";
	}
	
	?>
	<div class="box_main_konten">
		<h3>DATA SURAT BALASAN</h3>
		<div class="group_form">
			<title>Nomor Surat</title>
			<div class="col10">
				<input id="nomorsurat" <?php echo $disable;?> value="<?php echo $nomorsurat;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Sifat Surat</title>
			<div class="col10">
				<input id="sifat" <?php echo $disable;?> value="<?php echo $sifat;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Lampiran Surat</title>
			<div class="col10">
				<input id="lampiran" <?php echo $disable;?> value="<?php echo $lampiran;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Hal Surat</title>
			<div class="col10">
				<input id="halsurat" <?php echo $disable;?> value="<?php echo $halsurat;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Kepada Surat</title>
			<div class="col10">
				<input id="kepada" <?php echo $disable;?> value="<?php echo $kepada;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Di</title>
			<div class="col10">
				<input id="ditempat" <?php echo $disable;?> value="<?php echo $ditempat;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Keterangan tambahan (jika ada)</title>
			<div class="col10">
				<input id="keterangan" <?php echo $disable;?> value="<?php echo $keterangan;?>" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>CATATAN BALASAN</h3>
		<div id="grid_catatanbalasan"></div>
		<?php
		if($editstatus==1 && $statusdisposisi==0){
			?>
			<div style="margin-top: 15px;">
				<span onclick="surattbalasan.pilihcttbalasan()" class="bthijau medium">INPUT CATATAN BALASAN</span>
			</div>
			<?php
		}
		?>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>CATATAN</h3>
		<div id="grid_catatan"></div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_suratbalasan" class="error"></div>
		<span class="btmerah btncancel" onclick="suratbalasan.kembali()">Kembali</span>&nbsp;&nbsp;
		<?php
		if($editstatus==1){
			?>
			<span onclick="suratbalasan.simpan(0)" class="btbiru btnsave">Simpan draft</span>&nbsp;&nbsp;
			<span onclick="suratbalasan.simpan(1)" class="bthijau btnsave">Submit Pengajuan</span>
			<?php
		}
		?>
	</div>
	<div id="bteditcttbalasan" style="display: none;">
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_del':''#" onclick="suratbalasan.hapuscttbalasan(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<?php
}else{
	$page->addLoad("suratbalasan.load()");
	$page->setJudul("Data Surat Balasan");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="suratbalasan.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="suratbalasan.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama balasan" onkeypress="suratbalasan.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="suratbalasan.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="suratbalasan.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_suratbalasan"></div>
	<div id="loader_datasuratbalasan" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="suratbalasan.buat(0)" class="bthijau btninput">Buat Surat Balasan Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="#(#{hapus}==1)?'icon_del':''#" onclick="suratbalasan.hapus(#{id})"></span>
		<span class="#(#{edit}==1)?'icon_edit':'btlihat'#" onclick="suratbalasan.buat(#{id})"></span>
	</div>
	<span id="btstatus" style="display: none;cursor: pointer;background: #{bg}" class="medium">
		<span style="color: #{warna}">#{namastatus}</span>
	</span>
	<span id="btcatatan" onclick="suratbalasan.lihatcatatan(#{id},##{jumlah_tabel},##{baris_tabel},this)" style="display: none" class="datajumlah">#{jumlah_catatan}</span>
	<span id="btcetak" onclick="suratbalasan.initcetak(#{id},##{jumlah_tabel},##{baris_tabel},this)" class="#('#{status}'=='28' && '#{statusdisposisi}'=='1')?'btcetak':''#" style="display: none;"></span>
	<?php
}
?>
