<?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->addPlugin(BS_JS."cetak");
	$page->addJs(BS_JS."reqcb.js");
	$page->addPlugin("pilihpegawai");
	$page->addPlugin("pilihcatatan");
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data Surat Tugas Baru");
	$tugas="";
	$lokasi="";
	$keterangan="";
	$tanggalmulai="";
	$tanggalselesai="";
	$idpegawai=0;
	
	$namastatus="";
	$bg="";
	$warna="";
	
	$namalib="";
	$nomorsurat="";
	$editstatus=1;
	$statusdisposisi=0;
	$idsurat=0;
	$jenissurat="";
	$namalib="";
	
	if($id>0){
		$page->setJudul("Edit Data Surat Tugas");
		$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.`jumlah_pegawai`,
				t1.`tanggal_mulai`,
				t1.`tanggal_selesai`,
				t1.`tugas`,
				t1.lokasi,
				t1.`catatan_dasar`,
				t1.`catatan_menimbang`,
				t1.`catatan_surat`,
				t1.`tempat_tugas`,
				t1.`keterangan`,
				t2.`jumlah_catatan`,
				t2.`status`,
				t2.statusdisposisi,
				t2.nomor_panjang as nomorsurat,
				t3.lib,
				t3.nama as jenissurat,
				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_tugas as t1
			inner join tb_suratbdk as t2 on t1.idsurat=t2.id
			inner join tb_master_jenissurat as t3 on t2.idjenissurat=t3.id
			inner join tb_surat_tugas_pegawai as t4 on t1.id=t4.idsurattugas
			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'];
			$tugas=$rs['tugas'];
			$lokasi=$rs['lokasi'];
			if(isset($rs['tanggal_mulai'])) $tanggalmulai=$db->sql_date($rs['tanggal_mulai']);
			if(isset($rs['tanggal_selesai'])) $tanggalselesai=$db->sql_date($rs['tanggal_selesai']);
			$keterangan=$rs['keterangan'];
			
			$editstatus=$rs['edit'];
			$statusdisposisi=$rs['statusdisposisi'];
			$namastatus=$rs['namastatus'];
			$bg=$rs['bg'];
			$warna=$rs['warna'];
			$jenissurat=$rs['jenissurat'];
			$namalib=$rs['lib'];
		}else{
			exit;
		}
	}
	$datahasil=array(
		"id"=>$id,
		"editstatus"=>$editstatus,
		"statusdisposisi"=>$statusdisposisi,
		"idsurat"=>$idsurat,
		"jenissurat"=>$jenissurat,
		"lib"=>$namalib
	);
	$page->addLoad("surattugas.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 TUGAS</h3>
		<div class="group_form">
			<title>Tanggal Mulai Tugas</title>
			<div class="col10">
				<input style="width: 110px" id="tanggalmulai" <?php echo $disable;?> value="<?php echo $tanggalmulai;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Tanggal Selesai Tugas</title>
			<div class="col10">
				<input style="width: 110px" id="tanggalselesai" <?php echo $disable;?> value="<?php echo $tanggalselesai;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Nama Tugas</title>
			<div class="col10">
				<input id="tugas" <?php echo $disable;?> value="<?php echo $tugas;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Lokasi Tugas</title>
			<div class="col10">
				<input id="lokasi" <?php echo $disable;?> value="<?php echo $lokasi;?>" />
			</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>DATA PEGAWAI</h3>
		<div id="grid_pegawai"></div>
		<?php
		if($editstatus==1 && $statusdisposisi==0){
			?>
			<div style="margin-top: 15px;">
				<span onclick="surattugas.pilihpegawai()" class="bthijau medium">INPUT PEGAWAI</span>
			</div>
			<?php
		}
		?>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>MENIMBANG</h3>
		<div id="grid_menimbang"></div>
		<?php
		if($editstatus==1 && $statusdisposisi==0){
			?>
			<div style="margin-top: 15px;">
				<span onclick="surattugas.pilihmenimbang()" class="bthijau medium">INPUT MENIMBANG</span>
			</div>
			<?php
		}
		?>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>DASAR</h3>
		<div id="grid_dasar"></div>
		<?php
		if($editstatus==1 && $statusdisposisi==0){
			?>
			<div style="margin-top: 15px;">
				<span onclick="surattugas.pilihdasar()" class="bthijau medium">INPUT DASAR</span>
			</div>
			<?php
		}
		?>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>CATATAN TUGAS</h3>
		<div id="grid_catatantugas"></div>
		<?php
		if($editstatus==1 && $statusdisposisi==0){
			?>
			<div style="margin-top: 15px;">
				<span onclick="surattugas.pilihctttugas()" class="bthijau medium">INPUT CATATAN TUGAS</span>
			</div>
			<?php
		}
		?>
		<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_button_bawah">
		<div id="loader_surattugas" class="error"></div>
		<span class="btmerah btncancel" onclick="surattugas.kembali()">Kembali</span>&nbsp;&nbsp;
		<?php
		if($editstatus==1){
			?>
			<span onclick="surattugas.simpan(0)" class="btbiru btnsave">Simpan draft</span>&nbsp;&nbsp;
			<span onclick="surattugas.simpan(1)" class="bthijau btnsave">Submit Pengajuan</span>
			<?php
		}
		?>
	</div>
	<div id="bteditpegawai" style="display: none;">
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_del':''#" onclick="surattugas.hapuspegawai(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<div id="bteditmenimbang" style="display: none;">
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_del':''#" onclick="surattugas.hapusmenimbang(##{jumlah_tabel},##{baris_tabel},this)"></span>&nbsp;
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_edit':''#" onclick="surattugas.editmenimbang(##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<div id="bteditdasar" style="display: none;">
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_del':''#" onclick="surattugas.hapusdasar(##{jumlah_tabel},##{baris_tabel},this)"></span>&nbsp;
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_edit':''#" onclick="surattugas.editdasar(##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<div id="bteditctttugas" style="display: none;">
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_del':''#" onclick="surattugas.hapusctttugas(##{jumlah_tabel},##{baris_tabel},this)"></span>&nbsp;
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_edit':''#" onclick="surattugas.editctttugas(##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<div id="box_editcatatantgs" style="display:none;padding:10px">
		<div>
			<div id="boxeditcatatan"></div>
			<div class="box_button_bawah">
				<div class="err" id="loader_boxcatatansurat"></div>
				<span id="btbatalcatatan" class="btmerah">BATAL</span>&nbsp;&nbsp;
				<span id="btsimpancatatan" class="bthijau">SIMPAN</span>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<?php
}else{
	$page->addLoad("surattugas.load()");
	$page->setJudul("Data Surat Tugas");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="surattugas.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="surattugas.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Tugas" onkeypress="surattugas.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="surattugas.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="surattugas.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_surattugas"></div>
	<div id="loader_datasurattugas" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="surattugas.buat(0)" class="bthijau btninput">Buat Surat Tugas Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="#(#{hapus}==1)?'icon_del':''#" onclick="surattugas.hapus(#{id})"></span>
		<span class="#(#{edit}==1)?'icon_edit':'btlihat'#" onclick="surattugas.buat(#{id})"></span>
	</div>
	<span id="btstatus" style="display: none;cursor: pointer;background: #{bg}" class="medium">
		<span style="color: #{warna}">#{namastatus}</span>
	</span>
	<div id="btdetailtugas" style="display: none;">
		<div><b>#{tugas}</b></div>
		<div>Lokasi #{lokasi}</div>
	</div>
	<div id="btwaktu" style="display: none">
		<div>#{tanggal_mulai}</div>
		<div>s/d</div>
		<div>#{tanggal_selesai}</div>
	</div>
	<span id="btcatatan" onclick="surattugas.lihatcatatan(#{id},##{jumlah_tabel},##{baris_tabel},this)" style="display: none" class="datajumlah">#{jumlah_catatan}</span>
	<span id="btcetak" onclick="surattugas.initcetak(#{id},##{jumlah_tabel},##{baris_tabel},this)" class="#('#{status}'=='28' && '#{statusdisposisi}'=='1')?'btcetak':''#" style="display: none;"></span>
	<?php
}
?>
