<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
$page->addPlugin(BS_JS."cetak");

if(isset($_GET['id'])){
	$page->addPlugin("pilihpegawai");
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data Pengajuan Cuti Baru");
	$nama="";
	$nip="";
	$jeniskelamin="";
	$jabatan="";
	$golongan="";
	$pegawai=$_SESSION['profile']['pegawai'];
	$idpegawai=0;
	
	$idjeniscuti=0;
	$keperluan="";
	$waktu="";
	$idkodewaktu=0;
	$alamatcuti="";
	$telpcuti="";
	$keterangan="";
	$masakerja="";
	$tanggalmulai="";
	$tanggalselesai="";
	
	$statusdisposisi=0;
	$jenissurat="";
	$namalib="";
	$status=0;
	$editdata=1;
	$idsurat=0;
	if($_SESSION['profile']['pegawai']==1){
		$query="select t1.id,t1.nama,t1.nip,
			if(t2.nama is null,'Tidak ada',t2.nama) as jabatanstruk,
			if(t3.nama is null,'Tidak ada',t3.nama) as golongan,
			t4.nama as jeniskelamin
		from tb_pegawai as t1
		left join tb_master_jabatan as t2 on t1.idjabatanstruk=t2.id
		left join tb_master_golongan as t3 on t1.idgolongan=t3.id
		inner join tb_jenis_kelamin as t4 on t1.idjeniskelamin=t4.id
		where t1.id=? ";
		$rspeg=$db->loadAssoc($query,array($_SESSION['profile']['idpegawai']));
		if(!isset($rspeg)){
			exit("Tidak diijinkan");
		}
		$nama=$rspeg['nama'];
		$idpegawai=$rspeg['id'];
		$nip=$rspeg['nip'];
		$jabatan=$rspeg['jabatanstruk'];
		$golongan=$rspeg['golongan'];
		$jeniskelamin=$rspeg['jeniskelamin'];
	}
	if($id>0){
		$page->setJudul("Edit Data Pengajuan Cuti");
		
		$whp="";
		$datapushp=array($_SESSION['profile']['level'],$_SESSION['profile']['level'],$id);
		if($_SESSION['profile']['pegawai']==1){
			$whp.="and t1.idpegawai=? ";
			array_push($datapushp,$_SESSION['profile']['idpegawai']);
		}
		
		$query="SELECT t1.`id`,
				t1.`tanggal_input`,
				t1.`tanggal_surat`,
				t1.`idsurat`,
				t1.`idpegawai`,
				t1.`idjeniscuti`,
				t1.`waktu`,
				t1.`idkodewaktu`,
				t1.tanggal_mulai,
				t1.tanggal_selesai,
				t1.`keperluan`,
				t1.alamat_cuti,
				t1.telp_cuti,
				t1.masa_kerja,
				t1.`keterangan`,
				t1.`jumlah_catatan`,
				t7.`status`,
				t7.statusdisposisi,
				t8.lib,
				t8.nama as jenissurat,
				t2.nama as namapegawai,
				t2.nip as nip,
				if(t4.nama is null,'Tidak ada',t4.nama) as jabatanstruk,
				if(t5.nama is null,'Tidak ada',t5.nama) as golongan,
				t6.nama as jeniskelamin,
				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_cuti_pegawai as t1
			inner join tb_pegawai as t2 on t1.idpegawai=t2.id
			inner join tb_master_jeniscuti as t3 on t1.idjeniscuti=t3.id 
			left join tb_master_jabatan as t4 on t2.idjabatanstruk=t4.id
			left join tb_master_golongan as t5 on t2.idgolongan=t5.id
			inner join tb_jenis_kelamin as t6 on t2.idjeniskelamin=t6.id
			inner join tb_suratbdk as t7 on t1.idsurat=t7.id
			inner join tb_master_status as a1 on t7.status=a1.id
			inner join tb_master_jenissurat as t8 on t7.idjenissurat=t8.id
			left join tb_master_status_level as b1 on t7.status=b1.idstatus and b1.mode=0 and b1.idlevel=?
			left join tb_master_status_level as b2 on t7.status=b2.idstatus and b2.mode=1 and b2.idlevel=?
			WHERE t1.id=? ".$whp;
		$rs=$db->loadAssoc($query,$datapushp);
		if(isset($rs['id'])){
			$nama=$rs['namapegawai'];
			$idpegawai=$rs['idpegawai'];
			$nip=$rs['nip'];
			$jabatan=$rs['jabatanstruk'];
			$golongan=$rs['golongan'];
			$jeniskelamin=$rs['jeniskelamin'];
			
			$idjeniscuti=$rs['idjeniscuti'];
			$idkodewaktu=$rs['idkodewaktu'];
			$keperluan=$rs['keperluan'];
			$waktu=$rs['waktu'];
			$alamatcuti=$rs['alamat_cuti'];
			$telpcuti=$rs['telp_cuti'];
			$keterangan=$rs['keterangan'];
			$editdata=$rs['edit'];
			$idsurat=$rs['idsurat'];
			$masakerja=$rs['masa_kerja'];
			if(isset($rs['tanggal_mulai'])) $tanggalmulai=$db->sql_date($rs['tanggal_mulai']);
			if(isset($rs['tanggal_selesai'])) $tanggalselesai=$db->sql_date($rs['tanggal_selesai']);
		
			$statusdisposisi=$rs['statusdisposisi'];
			$jenissurat=$rs['jenissurat'];
			$status=$rs['status'];
			$namalib=$rs['lib'];
		}else{
			exit;
		}
	}
	$datahasil=array(
		"id"=>$id,
		"idpegawai"=>$idpegawai,
		"idjeniscuti"=>$idjeniscuti,
		"idkodewaktu"=>$idkodewaktu,
		"idsurat"=>$idsurat,
		"jenissurat"=>$jenissurat,
		"status"=>$status,
		"statusdisposisi"=>$statusdisposisi,
		"lib"=>$namalib,
	);
	$page->addLoad("epengajuancuti.edit(".json_encode($datahasil,true).")");
	
	$disable="disabled='true'";
	$display="style='display:none;'";
	$classdis="class='input_dis'";
	if($editdata==1){
		$disable="";
		$display="";
		$classdis="";
	}
	
	?>
	<div class="box_main_konten">
		<h3>DATA PEGAWAI</h3>
		<div class="group_form">
			<title>Nama Pegawai</title>
			<div class="col10">
				<input id="nama" disabled="true" value="<?php echo $nama;?>" />
				<?php
				if($pegawai==0 && $editdata==1){
					?>
					<div style="margin-top: 8px;">
						<span class="bthijau medium" onclick="epengajuancuti.pilihpegawai()">Pilih Pegawai</span>
					</div>
					<?php
				}
				?>
			</div>
		</div>
		<div class="group_form">
			<title>NIP</title>
			<div class="col10">
				<input id="nip" disabled="true" value="<?php echo $nip;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Jenis Kelamin</title>
			<div class="col10">
				<input id="jeniskelamin" disabled="true" value="<?php echo $jeniskelamin;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Jabatan</title>
			<div class="col10">
				<input id="jabatan" disabled="true" value="<?php echo $jabatan;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Golongan</title>
			<div class="col10">
				<input id="golongan" disabled="true" value="<?php echo $golongan;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Masa Kerja</title>
			<div class="col10">
				<div id="loader_masakerja"></div>
				<input id="masakerja" disabled="true" value="<?php echo $masakerja;?>" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>DATA CUTI</h3>
		<div class="group_form">
			<title>Jenis Cuti Yang Diambil</title>
			<div class="col10">
				<select <?php echo $disable;?> id="sl_jeniscuti">
					<?php
					$query="select * from tb_master_jeniscuti where status=1";
					$rsjenis=$db->loadAll($query);
					foreach ($rsjenis as $obj) {
						?>
						<option value="<?php echo $obj['id'];?>"><?php echo $obj['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Keperluan</title>
			<div class="col10">
				<input id="keperluan" <?php echo $disable;?> value="<?php echo $keperluan;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Lama Waktu Cuti</title>
			<div class="col10">
				<input id="waktu" <?php echo $disable;?> style="width: 100" value="<?php echo $waktu;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Satuan Waktu</title>
			<div class="col10">
				<select id="sl_kodewaktu" <?php echo $disable;?> >
					<?php
					$query="select * from tb_kodewaktu where id>0";
					$rsjenis=$db->loadAll($query);
					foreach ($rsjenis as $obj) {
						?>
						<option value="<?php echo $obj['id'];?>"><?php echo $obj['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Tanggal Mulai Cuti</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 Cuti</title>
			<div class="col10">
				<input style="width: 110px" id="tanggalselesai" <?php echo $disable;?> value="<?php echo $tanggalselesai;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Alamat Selama Cuti</title>
			<div class="col10">
				<input id="alamatcuti" <?php echo $disable;?> value="<?php echo $alamatcuti;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>No telp Selama Cuti</title>
			<div class="col10">
				<input id="telpcuti" <?php echo $disable;?> value="<?php echo $telpcuti;?>" />
			</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 SURAT</h3>
		<div id="grid_catatan"></div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_epengajuancuti" class="error"></div>
		<span class="btmerah btncancel" onclick="epengajuancuti.kembali()">Kembali</span>&nbsp;&nbsp;
		<span id="btcetaksurat" style="display: none;" class="btbiru btnsave">Cetak Surat</span>&nbsp;&nbsp;
			
		<?php
		if($editdata==1){
			?>
			<span onclick="epengajuancuti.simpan(0)" class="btbiru btnsave">Simpan draft</span>&nbsp;&nbsp;
			<span onclick="epengajuancuti.simpan(1)" class="bthijau btnsave">Submit Pengajuan</span>
			<?php
		}
		?>
	</div>
	<?php
}else{
	$page->addLoad("epengajuancuti.load()");
	$page->setJudul("Data Pengajuan Cuti");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="epengajuancuti.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="epengajuancuti.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Jenis Cuti" onkeypress="epengajuancuti.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="epengajuancuti.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="epengajuancuti.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_epengajuancuti"></div>
	<div id="loader_dataepengajuancuti" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="epengajuancuti.buat(0)" class="bthijau btninput">Buat Pengajuan Cuti Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="#(#{hapus}==1)?'icon_del':''#" onclick="epengajuancuti.hapus(#{id})"></span>
		<span class="#(#{edit}==1)?'icon_edit':'btlihat'#" onclick="epengajuancuti.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="btdetailpegawai" style="display: none;">
		<div><b>#{namapegawai}</b></div>
		<div>#('#{nip}'=='')?'':'NIP. #{nip}'#</div>
	</div>
	<div id="btlamacuti" style="display: none">
		<div>#{waktu} #{kodewaktu}</div>
	</div>
	<span id="btcatatan" onclick="epengajuancuti.lihatcatatan(#{id},##{jumlah_tabel},##{baris_tabel},this)" style="display: none" class="datajumlah">#{jumlah_catatan}</span>
	<span id="btcetak" onclick="epengajuancuti.initcetak(#{id},##{jumlah_tabel},##{baris_tabel},this)" class="#('#{status}'=='28' && '#{statusdisposisi}'=='1')?'btcetak':''#" style="display: none;"></span>
	<?php
}
?>
