<?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("upload");
	$page->addJs(BS_JS."reqcb.js");
	
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data Pengajuan PKL Baru");
	$nomor="";
	$nomorpengajuan="";
	$namasekolah="";
	$alamatsekolah="";
	
	$keperluan="";
	$keterangan="";
	$tanggalsurat="";
	
	$idpropinsi=0;
	$idkota=0;
	
	$statusdisposisi=0;
	$jenissurat="";
	$namalib="";
	$status=0;
	$editstatus=1;
	$idsurat=0;
	
	if($id>0){
		$page->setJudul("Edit Data Pengajuan PKL");
		
		$whp="";
		$datapushp=array($_SESSION['profile']['level'],$_SESSION['profile']['level'],$id);
		if($_SESSION['profile']['level']<=10){
			$whp.="and t1.iduser=? ";
			array_push($datapushp,$_SESSION['profile']['id']);
		}
		
		$query="SELECT t1.`id`,
				t1.`tanggal_update`,
				t1.`tanggal_surat`,
				t1.`iduser`,
				t1.`idsurat`,
				t1.`nomor`,
				t1.nomor_surat_pengajuan,
				t1.`nama_sekolah`,
				t1.idpropinsi,
				t1.idkota,
				t1.`alamat_sekolah`,
				t1.`jumlah_peserta`,
				t1.`jumlah_dokumen`,
				t1.`keterangan`,
				t1.`status_balasan`,
				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_pengajuan_pkl 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_master_status as a1 on t2.status=a1.id
			inner join tb_master_jenissurat as t8 on t2.idjenissurat=t8.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'])){
			$nomor=$rs['nomor'];
			$nomorpengajuan=$rs['nomor_surat_pengajuan'];
			
			$namasekolah=$rs['nama_sekolah'];
			$alamatsekolah=$rs['alamat_sekolah'];
			$tanggalsurat=$db->d_date($rs['tanggal_surat']);
			
			$keterangan=$rs['keterangan'];
			$editstatus=$rs['edit'];
			$idsurat=$rs['idsurat'];
			$idpropinsi=$rs['idpropinsi'];
			$idkota=$rs['idkota'];
			
			$statusdisposisi=$rs['statusdisposisi'];
			$jenissurat=$rs['jenissurat'];
			$status=$rs['status'];
			$namalib=$rs['lib'];
		}else{
			exit;
		}
	}
	$datahasil=array(
		"id"=>$id,
		"idsurat"=>$idsurat,
		"jenissurat"=>$jenissurat,
		"status"=>$status,
		"statusdisposisi"=>$statusdisposisi,
		"idpropinsi"=>$idpropinsi,
		"idkota"=>$idkota,
		"lib"=>$namalib,
		"editstatus"=>$editstatus
	);
	$page->addLoad("epengajuanpkl.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 PKL</h3>
		
		<div class="group_form" id="boxtanggalsurat" style="display: none;">
			<title>Tanggal Surat</title>
			<div class="col10">
				<input id="tanggalsurat" style="width: 110px;" disabled="true" value="<?php echo $tanggalsurat;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Nomor Surat Pengajuan</title>
			<div class="col10">
				<input id="nomorsuratpengajuan" <?php echo $disable;?> value="<?php echo $nomorpengajuan;?>" />
			</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 class="group_form">
			<title>Propinsi</title>
			<div class="col10">
				<select id="sl_propinsi" <?php echo $disable;?> onchange="epengajuanpkl.propch(0)">
					<option value="0">Pilih Propinsi</option>
					<?php
					$query="select * from tb_propinsi where status=1";
					$rsprop=$db->loadAll($query);
					foreach ($rsprop 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;?>>
					<option value="0">Pilih Kota</option>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Alamat Sekolah</title>
			<div class="col10">
				<input id="alamatsekolah" <?php echo $disable;?> value="<?php echo $alamatsekolah;?>" />
			</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 PESERTA</h3>
		<div id="grid_peserta"></div>
		<?php
		if($editstatus==1){
			?>
			<div class="box_button_bawah" style="margin-top: 10px;">
				<span onclick="epengajuanpkl.inputpeserta()" class="bthijau medium">Input Peserta</span>&nbsp;&nbsp;
			</div>
			<?php
		}
		?>
	</div>
	<div class="box_main_konten">
		<h3>DOKUMEN SURAT</h3>
		<div id="grid_dokumen"></div>
		<?php
		if($editstatus==1){
			?>
			<div class="box_button_bawah" style="margin-top: 10px;">
				<span onclick="epengajuanpkl.inputdokumen()" class="bthijau medium">Upload Dokumen</span>&nbsp;&nbsp;
			</div>
			<?php
		}
		?>
	</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_epengajuanpkl" class="error"></div>
		<span class="btmerah btncancel" onclick="epengajuanpkl.kembali()">Kembali</span>&nbsp;&nbsp;
		<span id="btcetaksurat" style="display: none;" class="btbiru btnsave">Cetak Surat</span>&nbsp;&nbsp;
			
		<?php
		if($editstatus==1){
			?>
			<span onclick="epengajuanpkl.simpan(0)" class="btbiru btnsave">Simpan draft</span>&nbsp;&nbsp;
			<span onclick="epengajuanpkl.simpan(1)" class="bthijau btnsave">Submit Pengajuan</span>
			<?php
		}
		?>
	</div>
	<div id="bteditpeserta" style="display: none;">
		<span class="#('#{editstatus}'=='1')?'icon_del':''#" onclick="epengajuanpkl.hapuspeserta(##{jumlah_tabel},##{baris_tabel},this)"></span>&nbsp;
	</div>
	<div id="bteditdokumen" style="display: none;">
		<span class="#('#{edit}'=='1' && '#{statusdisposisi}'=='0')?'icon_del':''#" onclick="epengajuanpkl.hapusdokumen(##{jumlah_tabel},##{baris_tabel},this)"></span>&nbsp;
	</div>
	<span id="btdokumen" class="dok_ya" onclick="epengajuanpkl.lihatdokumen(#{iddokumen})" style="display: none;"></span>
	<div id="box_peserta" style="display: none">
		<div>
			<div class="group_form">
				<title>Nama Peserta</title>
				<div class="col10">
					<input id="namapeserta" />
				</div>
			</div>
			<div class="group_form">
				<title>NIM/NIS</title>
				<div class="col10">
					<input id="nopelajar" />
				</div>
			</div>
			<div class="group_form">
				<title>Alamat</title>
				<div class="col10">
					<input id="alamat" />
				</div>
			</div>
			<div class="group_form">
				<title>&nbsp;</title>
				<div class="col10">
					<div class="box_button_bawah">
						<div id="loader_peserta" class="error"></div>
						<div>
							<span onclick="epengajuanpkl.batalsimpanpeserta()" class="btbiru btnsave">Batal</span>&nbsp;&nbsp;
							<span onclick="epengajuanpkl.simpanpeserta()" class="bthijau btnsave">Simpan</span>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="box_upload_dok" style="display: none">
		<div>
			<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="upload_dokumen"></div>
				</div>
			</div>
			<div class="group_form">
				<title>&nbsp;</title>
				<div class="col10">
					<div class="box_button_bawah">
						<div id="loader_upload" class="error"></div>
						<div>
							<span onclick="epengajuanpkl.bataluploaddokumen()" class="btbiru btnsave">Batal</span>&nbsp;&nbsp;
							<span onclick="epengajuanpkl.simpandokumen()" class="bthijau btnsave">Simpan</span>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<?php
}else{
	$page->addLoad("epengajuanpkl.load()");
	$page->setJudul("Data Pengajuan PKL");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="epengajuanpkl.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="epengajuanpkl.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Sekolah" onkeypress="epengajuanpkl.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="epengajuanpkl.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="epengajuanpkl.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_epengajuanpkl"></div>
	<div id="loader_dataepengajuanpkl" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="epengajuanpkl.buat(0)" class="bthijau btninput">Buat Pengajuan PKL Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="#(#{hapus}==1)?'icon_del':''#" onclick="epengajuanpkl.hapus(#{id})"></span>
		<span class="#(#{edit}==1)?'icon_edit':'btlihat'#" onclick="epengajuanpkl.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="btdetailsekolah" style="display: none;">
		<div><b>#{nama_sekolah}</b></div>
		<div>#{alamat_sekolah}</div>
	</div>
	<span id="btpeserta" style="display: none" onclick="epengajuanpkl.bukapeserta(#{id},##{jumlah_tabel},##{baris_tabel},this)" class="bthijau medium">#{jumlah_peserta}</span>
	<span id="btcatatan" onclick="epengajuanpkl.lihatcatatan(#{id},##{jumlah_tabel},##{baris_tabel},this)" style="display: none" class="datajumlah">#{jumlah_catatan}</span>
	<span id="btcetak" onclick="epengajuanpkl.initcetak(#{id},##{jumlah_tabel},##{baris_tabel},this)" class="#(('#{status}'=='68' || '#{status}'=='69') && '#{statusdisposisi}'=='1')?'btcetak':''#" style="display: none;"></span>
	<?php
}
?>
