<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(isset($_POST['ikdata'])){
if (!isset($_SESSION)) session_start();
$db=pDatabase::getInstance();


header("Content-type: application/json");
	$data=$_POST['ikdata'];
	$fungsi = strip_tags(stripslashes($data[0]));
	$ex=$fungsi($data);
	if($ex){
		echo $ex;
	}else{
		echo false;
	}
}else{
	echo false;
}

function getlayout($data){
	$db=pDatabase::getInstance();
	$query="select t1.id,t1.nama,t2.nama_baru from tb_printlayout as t1
		inner join tb_dokumen as t2 on t1.idkonten=t2.id
		where t1.jenis=? and t1.status=1";
	$rs=$db->jsonData($query,array($data[1]));
	return $rs;
}
function getSampletr($data){
	$db=pDatabase::getInstance();
	$query="select t1.id,t2.merk,t2.kemasan,t1.noglobal,t1.nourut,YEAR(t3.tanggal) as tahun,t4.kodecontoh
			from tb_transaksi_sample as t1
		inner join tb_transaksi_jenis as t2 on t1.idjenis=t2.id
		inner join tb_transaksi as t3 on t1.idtransaksi=t3.id
		inner join tb_kodecontoh as t4 on t2.idkodecontoh=t4.id
		where t1.idtransaksi=?";
	$rs=$db->jsonData($query,array($data[2]));
	return $rs;
}

function getdatatampilan($data){
	$db=pDatabase::getInstance();
	$query="select t1.id,t1.nama,t2.nama_baru from tb_printlayout as t1
		inner join tb_dokumen as t2 on t1.idkonten=t2.id
		where t1.jenis=? and t1.status=1";
	$rst=$db->loadAll($query,array($data[1]));
	
	$query="select t1.id,t2.merk,t2.kemasan,t1.noglobal,t1.nourut,YEAR(t3.tanggal) as tahun,t4.kodecontoh
			from tb_transaksi_sample as t1
		inner join tb_transaksi_jenis as t2 on t1.idjenis=t2.id
		inner join tb_transaksi as t3 on t1.idtransaksi=t3.id
		inner join tb_kodecontoh as t4 on t2.idkodecontoh=t4.id
		where t1.idtransaksi=?";
	$rsj=$db->loadAll($query,array($data[2]));
	return json_encode(array("layout"=>$rst,"sample"=>$rsj));
}
?>