<?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'])){
	$id=strip_tags(stripslashes($_GET['id']));
	$page->addPlugin("upload");
	$page->setJudul("Input Data Pegawai Baru");
	$nama="";
	$nip="";
	$alamat="";
	$idjeniskelamin=0;
	$idpropinsi=0;
	$idkota=0;
	$idgolongan=0;
	$idjabatanstruk=0;
	$idjabatanfung=0;
	$idpendidikan=0;
	$namasekolah="";
	$nohp="";
	$email="";
	$notelp="";
	$tempatlahir="";
	$tanggallahir="";
	$tanggalskawal="";
	$status=0;
	$statusasn=0;
	$namastatus="";
	
	$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 Pegawai");
		$query="SELECT t1.`id`,
				t1.`tanggal_input`,
				t1.`nama`,
				t1.nip,
				t1.`idpropinsi`,
				t1.`idkota`,
				t1.`alamat`,
				t1.tempatlahir,
				t1.tanggallahir,
				t1.`idjeniskelamin`,
				t1.`idgolongan`,
				t1.`idjabatanstruk`,
				t1.`idjabatanfung`,
				t1.`idpendidikan`,
				t1.`namasekolah`,
				t1.`jumlah_lampiran`,
				t1.`nohp`,
				t1.`email`,
				t1.`notelp`,
				t1.`tanggal_sk_gol`,
				t1.`tanggal_sk_awal` as tanggalskawal,
				t1.`statusasn`,
				t1.`status`,
				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_pegawai as t1
		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=?
		WHERE t1.id=? ".$wh;
		$rs=$db->loadAssoc($query,$datapush);
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$nip=$rs['nip'];
			$alamat=$rs['alamat'];
			$idjeniskelamin=$rs['idjeniskelamin'];
			$idpropinsi=$rs['idpropinsi'];
			$idkota=$rs['idkota'];
			$idgolongan=$rs['idgolongan'];
			$idjabatanstruk=$rs['idjabatanstruk'];
			$idjabatanfung=$rs['idjabatanfung'];
			$idpendidikan=$rs['idpendidikan'];
			$namasekolah=$rs['namasekolah'];
			$nohp=$rs['nohp'];
			$email=$rs['email'];
			$notelp=$rs['notelp'];
			$namastatus=$rs['namastatus'];
			$status=$rs['status'];
			$statusasn=$rs['statusasn'];
			$tempatlahir=$rs['tempatlahir'];
			$tanggallahir=$db->sql_date($rs['tanggallahir']);
			$tanggalskawal=$db->sql_date($rs['tanggalskawal']);
			$editdata=$rs['edit'];
		}
	}
	$datahasil=array(
		"id"=>$id,
		"idjeniskelamin"=>$idjeniskelamin,
		"idpropinsi"=>$idpropinsi,
		"idkota"=>$idkota,
		"idgolongan"=>$idgolongan,
		"idjabatanstruk"=>$idjabatanstruk,
		"idjabatanfung"=>$idjabatanfung,
		"idpendidikan"=>$idpendidikan,
		"statusasn"=>$statusasn,
		"status"=>$status,
		"editstatus"=>$editdata
	);
	$page->addLoad("masterpegawai.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 <?php echo $disable;?> id="nama" value="<?php echo $nama;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>NIP</title>
			<div class="col10">
				<input <?php echo $disable;?> id="nip" value="<?php echo $nip;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Jenis Kelamin</title>
			<div class="col10">
				<select <?php echo $disable;?> id="sl_jeniskelamin">
					<?php
					$query="select * from tb_jenis_kelamin where id>0";
					$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>Tempat Lahir</title>
			<div class="col10">
				<input id="tempatlahir" <?php echo $disable;?> value="<?php echo $tempatlahir;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Tanggal Lahir</title>
			<div class="col10">
				<input id="tanggallahir" <?php echo $disable;?> style="width: 110px;" value="<?php echo $tanggallahir;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Nomor HP</title>
			<div class="col10">
				<input id="nohp" <?php echo $disable;?> value="<?php echo $nohp;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Nomor NPWP</title>
			<div class="col10">
				<input id="notelp" <?php echo $disable;?> value="<?php echo $notelp;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Email</title>
			<div class="col10">
				<input id="email" <?php echo $disable;?> value="<?php echo $email;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>STATUS ASN</title>
			<div class="col10">
				<select id="sl_statusasn" <?php echo $disable;?> >
					<?php
					$query="select * from tb_master_statusasn where status=1 order by id asc";
					$rsjk=$db->loadAll($query);
					foreach ($rsjk as $obk) {
						?>
						<option value="<?php echo $obk['id'];?>"><?php echo $obk['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>ALAMAT PEGAWAI</h3>
		<div class="group_form">
			<title>Propinsi</title>
			<div class="col10">
				<select id="sl_propinsi" <?php echo $disable;?> onchange="masterpegawai.propch()">
					<?php
					$query="select * from tb_propinsi where status=1";
					$rsp=$db->loadAll($query);
					foreach ($rsp as $obp) {
						?>
						<option value="<?php echo $obp['id'];?>"><?php echo $obp['propinsi'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Kota/Kabupaten</title>
			<div class="col10">
				<select id="sl_kota" <?php echo $disable;?> ></select>
			</div>
		</div>
		<div class="group_form">
			<title>Alamat Pegawai</title>
			<div class="col10">
				<input id="alamat" <?php echo $disable;?> value="<?php echo $alamat;?>" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>DATA KEPEGAWAIAN</h3>
		<div class="group_form">
			<title>TMT PNS</title>
			<div class="col10">
				<input id="tanggalskawal" <?php echo $disable;?> style="width: 110px;" value="<?php echo $tanggalskawal;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Golongan</title>
			<div class="col10">
				<select id="sl_golongan" <?php echo $disable;?> >
					<option value="0">Tidak Ada</option>
					<?php
					$query="select * from tb_master_golongan where status=1";
					$rsjk=$db->loadAll($query);
					foreach ($rsjk as $obk) {
						?>
						<option value="<?php echo $obk['id'];?>"><?php echo $obk['kode']." ".$obk['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Jabatan Struktural</title>
			<div class="col10">
				<select id="sl_jabatanstr" <?php echo $disable;?> >
					<option value="0">Tidak Ada</option>
					<?php
					$query="select * from tb_master_jabatan where status=1";
					$rsjk=$db->loadAll($query);
					foreach ($rsjk as $obk) {
						$namaopt=$obk['nama'];
						$arrtab=explode("-", $obk['kode']);
						$jumlahtab=sizeof($arrtab)-2;
						$strtab="";
						if($jumlahtab>0){
							for($i=0;$i<$jumlahtab;$i++){
								$strtab=$strtab."- ";
							}
						}
						$namaopt=$strtab.$namaopt;
						?>
						<option value="<?php echo $obk['id'];?>"><?php echo $namaopt;?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Jabatan Fungsional</title>
			<div class="col10">
				<select id="sl_jabatanfu" <?php echo $disable;?> >
					<option value="0">Tidak Ada</option>
					<?php
					$query="select * from tb_master_jabatan_fungsional 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>Pendidikan Terakhir</title>
			<div class="col10">
				<select id="sl_pendidikan" <?php echo $disable;?> >
					<?php
					$query="select * from tb_master_pendidikan 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>Nama Sekolah</title>
			<div class="col10">
				<input id="namasekolah" <?php echo $disable;?>  value="<?php echo $namasekolah;?>" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>LAMPIRAN</h3>
		<div id="grid_lampiran"></div>
		<?php
		if($editdata==1){
			?>
			<div class="box_button_bawah">
				<span class="bthijau medium" onclick="masterpegawai.inputlampiran()">Input Lampiran Pegawai</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=1";
						$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_masterpegawai" class="error"></div>
		<span class="btmerah btncancel" onclick="masterpegawai.kembali()">Kembali</span>
		<?php
		if($editdata==1){
		?>
			&nbsp;&nbsp;<span onclick="masterpegawai.simpan()" class="bthijau btnsave">Simpan</span>
		<?php			
		}
		?>
	</div>
	<div id="box_lampiran" style="display:none;">
		<div style="padding: 10px;">
			<div class="group_form">
				<title>Nama Lampiran</title>
				<div class="col10">
					<input id="namalampiran"/>
				</div>
			</div>
			<div class="group_form">
				<title>&nbsp;</title>
				<div class="col10">
					<div class="box_button_bawah">
						<div class="err" id="loader_lampiran"></div>
						<span class="btmerah" onclick="masterpegawai.batallampiran()">BATAL</span>&nbsp;&nbsp;
						<span class="bthijau" onclick="masterpegawai.simpanlampiran()">SIMPAN</span>
					</div>
				</div>
			</div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<div id="bteditlampiran" style="display:none;">
		<span class="#(#{editstatus}==1)?'icon_del':''#" onclick="masterpegawai.hapuslampiran(##{jumlah_tabel},##{baris_tabel},this)"></span>
		<span class="#(#{editstatus}==1)?'icon_edit':''#" onclick="masterpegawai.editlampiran(##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<span id="btjumlahdokumen" style="display: none;" class="bthijau medium" onclick="masterpegawai.bukalampirandok(##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_dokumen}</span>
	<span id="btdokumen" class="#(#{iddokumen}>0)?'dok_ya':''#" onclick="masterpegawai.lihatdokumen(#{iddokumen})"></span>
	<div id="bteditdokumen" style="display:none;">
		<span class="#(#{editstatus}==1)?'icon_del':''#" onclick="masterpegawai.hapusdokumen(##{jumlah_tabel},##{baris_tabel},this)"></span>
	</div>
	<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="masterpegawai.batalupload()">BATAL</span>&nbsp;&nbsp;
						<span class="bthijau" onclick="masterpegawai.simpanupload()">SIMPAN</span>
					</div>
				</div>
			</div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<?php
}else{
	$page->addLoad("masterpegawai.load()");
	$page->setJudul("Master Data Pegawai");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="masterpegawai.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="masterpegawai.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Pegawai" onkeypress="masterpegawai.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="masterpegawai.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="masterpegawai.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_masterpegawai"></div>
	<div id="loader_datamasterpegawai" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="masterpegawai.buat(0)" class="bthijau btninput">Input Data Pegawai Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="#(#{hapus}==1)?'icon_del':''#" onclick="masterpegawai.hapus(#{id})"></span>
		<span class="#(#{edit}==1)?'icon_edit':'btlihat'#" onclick="masterpegawai.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> (<b>#{namastatusasn}</b>)</div>
		<div>#{jeniskelamin}</div>
		#('#{nip}'=='')?'':'<div>NIP <b>#{nip}</b></div>'#
		#('#{jabatanstruk}'=="")?'':'<div style="margin-top: 6px"><b>Jabatan Struktural</b></div><div>#{jabatanstruk}</div>'#
		#('#{jabatanfung}'=="")?'':'<div style="margin-top: 6px"><b>Jabatan Fungsional</b></div><div>#{jabatanfung}</div>'#
	</div>
	<span id="btjumlahlampiran" style="display: none;" class="bthijau medium" onclick="masterpegawai.lhatlampiran(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_lampiran}</span>
	<span id="btjumlahdokumen" style="display: none;" class="bthijau medium" onclick="masterpegawai.lihatdatadokumen(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{jumlah_dokumen}</span>
	<span id="btdokumen" class="#(#{iddokumen}>0)?'dok_ya':''#" onclick="masterpegawai.lihatdokumen(#{iddokumen})"></span>
	<?php
}
?>
