<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
header("Content-type: application/json");
if(isset($_POST['ikdata'])){
	if (!isset($_SESSION)) session_start();	
	$db=pDatabase::getInstance();
	$datafungsi=[
		"getjadwalpelatihan"=>"getjadwalpelatihan",
		"getnarsum"=>"getnarsum",
		"getdokkonten"=>"getdokkonten"
	];

	$data=$_POST['ikdata'];
	$ex=false;
	if(isset($datafungsi[$data[0]])) $ex=$datafungsi[$data[0]]($data,$cl);
	echo $ex;
	
}else{
	echo false;
}


function getjadwalpelatihan($data){
	$db=pDatabase::getInstance();
	$query="select 
			*
		from db_singa.tb_master_pelatihan_jadwal
		where idpelatihan=? order by tanggal asc";
	$rs=$db->jsonData($query,array($data['idpelatihan']));
	return $rs;
}

function getnarsum($data){
	$db=pDatabase::getInstance();
	$query="select 
			t1.`id`,
			t1.`idpelatihan`,
			t1.`idpegawai`,
			t2.`nama`,
			t2.`nip`,
			t2.`alamat`,
			t3.nama as jeniskelamin,
			t4.nama as jabatan
		from db_singa.tb_master_pelatihan_narsum as t1
		inner join db_singa.tb_master_pegawai as t2 on t1.idpegawai=t2.id
		inner join db_singa.tb_jenis_kelamin as t3 on t2.idjeniskelamin=t3.id	
		inner join db_singa.tb_master_jabatan_pegawai as t4 on t2.idjabatan=t4.id
		where t1.idpelatihan=? ";
	$rs=$db->jsonData($query,array($data['idpelatihan']));
	return $rs;
}

function getdokkonten($data){
	$db=pDatabase::getInstance();
	$query="select 
			t1.`id`,
			t1.`idpelatihan`,
			t1.`iddokumen`,
			t1.`judul`,
			t1.`keterangan`
		from db_singa.tb_master_pelatihan_dokkonten as t1
		inner join db_singa.tb_dokumen as t2 on t1.iddokumen=t2.id
		where t1.idpelatihan=? ";
	$rs=$db->jsonData($query,array($data['idpelatihan']));
	return $rs;
}
?>