<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
$idmodule=$db->getidmodulenama($mod);
if(isset($_GET['id'])){
	$page->addPlugin("pilihpegawai");
	$page->addPlugin("upload");
	$page->addJs(BS_JS."reqcb.js");
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data SK Jabatan Struktural Pegawai Baru");
	$nama="";
	$nip="";
	$jeniskelamin="";
	$tangalsk="";
	$idpegawai-0;
	$nosk="";
	$idjabatan=0;
	$iddokumen=0;
	$keterangan="";
	$status=0;
	$namastatus="";
	$tanggalsk="";
	
	$namafile="PILIH FILE UNTUK UPLOAD DOKUMEN SK";
	$namabaru="";
	
	$editdata=1;
	
	$wh="";
	$datapush=array($_SESSION['profile']['level'],$_SESSION['profile']['level'],$id);
	
	$wh.="and t1.status in (select idstatus as status from tb_master_status_view where idmodule=?) ";
	array_push($datapush,$idmodule);
	
	if($id>0){
		$page->setJudul("Edit Data SK Jabatan Struktural Pegawai");
		$query="SELECT t1.`id`,
				t1.`tanggal_input`,
				t1.`tanggal_sk`,
				t1.tahun,
				t1.`tahun`,
				t1.`iduser`,
				t1.`nomor`,
				t1.`idpegawai`,
				t1.`idjabatan`,
				t1.`iddokumen`,
				t1.`keterangan`,
				t1.`status`,
				t2.`nama`,
				t2.nip,
				t1.`status`,
				t3.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,
				if(c1.nama_awal is null,'PILIH FILE UNTUK UPLOAD DOKUMEN SK',c1.nama_awal) as nama_awal,
				if(c1.nama_baru is null,'',c1.nama_baru) as nama_baru
		FROM tb_pegawai_skstruk as t1
		inner join tb_pegawai as t2 on t1.idpegawai=t2.id
		inner join tb_jenis_kelamin as t3 on t2.idjeniskelamin=t3.id
		inner join tb_master_status as a1 on t1.status=a1.id
		left join tb_master_status_level as b1 on t1.status=b1.idstatus and b1.mode=0 and b1.idlevel=?
		left join tb_master_status_level as b2 on t1.status=b2.idstatus and b2.mode=1 and b2.idlevel=?
		left join tb_dokumen as c1 on t1.iddokumen=c1.id
		WHERE t1.id=? ".$wh;
		$rs=$db->loadAssoc($query,$datapush);
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$nip=$rs['nip'];
			$jeniskelamin=$rs['jeniskelamin'];
			$idpegawai=$rs['idpegawai'];
			$namastatus=$rs['namastatus'];
			$idjabatan=$rs['idjabatan'];
			$status=$rs['status'];
			$nosk=$rs['nomor'];
			$iddokumen=$rs['iddokumen'];
			$keterangan=$rs['keterangan'];
			$tanggalsk=$db->sql_date($rs['tanggal_sk']);
			
			$namafile=$rs['nama_awal'];
			$namabaru=$rs['nama_baru'];
			$editdata=$rs['edit'];
		}
	}
	$datahasil=array(
		"id"=>$id,
		"idpegawai"=>$idpegawai,
		"idjabatan"=>$idjabatan,
		"iddokumen"=>$iddokumen,
		"editstatus"=>$editdata,
		"namafile"=>$namafile,
		"namabaru"=>$namabaru,
		"status"=>$status
	);
	$page->addLoad("skstruktural.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>DETAIL PEGAWAI</h3>
		
		<div class="group_form">
			<title>Nama Pegawai</title>
			<div class="col10">
				<input disabled="true" id="nama" value="<?php echo $nama;?>" />
				<?php
				if($editdata==1){
					?>
					<div style="margin-top: 8px">
						<span class="bthijau medium" onclick="skstruktural.pilihpegawai()">Pilih Pegawai</span>
					</div>
					<?php
				}
				?>
			</div>
		</div>
		<div class="group_form">
			<title>NIP</title>
			<div class="col10">
				<input disabled="true" id="nip" value="<?php echo $nip;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Jenis Kelamin</title>
			<div class="col10">
				<input id="jeniskelamin" value="<?php echo $jeniskelamin;?>" disabled="true" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>DATA SK</h3>
		
		<div class="group_form">
			<title>Tanggal SK</title>
			<div class="col10">
				<input style="width: 110px" <?php echo $disable;?> id="tanggalsk" value="<?php echo $tanggalsk;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Nomor SK</title>
			<div class="col10">
				<input id="nosk" <?php echo $disable;?> value="<?php echo $nosk;?>"/>
			</div>
		</div>
		<div class="group_form">
			<title>Jabatan Struktural</title>
			<div class="col10">
				<select id="sl_jabatan" <?php echo $disable;?> >
					<?php
					$query="select * from tb_master_jabatan where status=1";
					$rsjk=$db->loadAll($query);
					foreach ($rsjk as $obk) {
						?>
						<option value="<?php echo $obk['id'];?>"><?php echo $obk['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Keterangan</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>DOKUMEN SK</h3>
		<div id="grid_dokumensk"></div>
		<?php
		if($editdata==1){
			?>
			<div class="box_button_bawah">
				<span class="bthijau medium" onclick="skstruktural.uploaddokumen()">Upload Dokumen SK</span>
			</div>
			<?php
		}
		?>
		
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>STATUS</h3>
		
		<div class="group_form">
			<title>Status</title>
			<div class="col10">
				<?php
				if($editdata==1){
					?>
					<select id="sl_status" <?php echo $disable;?> >
						<?php
						$query="select * from tb_master_status where idkategori=5";
						$rsst=$db->loadAll($query);
						foreach ($rsst as $obk) {
							?>
							<option value="<?php echo $obk['id'];?>"><?php echo $obk['nama'];?></option>
							<?php
						}
						?>
					</select>
					<?php
				}else{
					?>
					<input disabled="true" value="<?php echo $namastatus;?>" />
					<?php
				}
				?>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_skstruktural" class="error"></div>
		<span class="btmerah btncancel" onclick="skstruktural.kembali()">Kembali</span>
		<?php
		if($editdata==1){
		?>
			&nbsp;&nbsp;<span onclick="skstruktural.simpan()" class="bthijau btnsave">Simpan</span>
		<?php			
		}
		?>
	</div>
	<div id="bteditdokumen" style="display:none;">
		<span class="#(#{editdata}==1)?'icon_del':''#" onclick="skstruktural.hapusdokumen(#{id},##{jumlah_tabel},##{baris_tabel})"></span>
	</div>
	<span id="btdokumensk" class="#(#{iddokumen}>0)?'dok_ya':''#" onclick="skstruktural.lihatdokumen(#{iddokumen})"></span>
	<div id="boxwin_uploaddokumen" style="display:none;">
		<div style="padding: 10px;">
			<div class="group_form">
				<title>Nama Dokumen</title>
				<div class="col10">
					<input id="namadokumen"/>
				</div>
			</div>
			<div class="group_form">
				<title>Upload Dokumen</title>
				<div class="col10">
					<div id="box_uploaddokumen"></div>
				</div>
			</div>
			<div class="group_form">
				<title>&nbsp;</title>
				<div class="col10">
					<div class="box_button_bawah">
						<div class="err" id="loader_uploaddokumen"></div>
						<span class="btmerah" onclick="skstruktural.batalupload()">BATAL</span>&nbsp;&nbsp;
						<span class="bthijau" onclick="skstruktural.simpanupload()">SIMPAN</span>
					</div>
				</div>
			</div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<?php
}else{
	$page->addLoad("skstruktural.load()");
	$page->setJudul("Master Data SK Jabatan Struktural Pegawai");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="skstruktural.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="skstruktural.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Pegawai" onkeypress="skstruktural.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="skstruktural.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="skstruktural.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_skstruktural"></div>
	<div id="loader_dataskstruktural" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="skstruktural.buat(0)" class="bthijau btninput">Input Data SK Jabatan Struktural</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="#(#{hapus}==1)?'icon_del':''#" onclick="skstruktural.hapus(#{id})"></span>
		<span class="#(#{edit}==1)?'icon_edit':'btlihat'#" onclick="skstruktural.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="btdetail" style="display: none;">
		<div><b>#{nama}</b></div>
		<div>#{jeniskelamin}</div>
		<div style="margin-top: 4px;">NIP <b>#{nip}</b></div>
	</div>
	<div id="btjumlahdokumensk" onclick="skstruktural.bukadokumensk(#{id},##{jumlah_tabel},##{baris_tabel},this)" style="display: none;" class="bthijau medium">#{jumlah_dokumen}</div>
	<span id="btdokumensk" class="#(#{iddokumen}>0)?'dok_ya':''#" onclick="skstruktural.lihatdokumen(#{iddokumen})"></span>
	
	<?php
}
?>
