<?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=[
		"gettahunikm"=>"gettahunikm",
		"getbulanikm"=>"getbulanikm",
		"getkategoriik"=>"getkategoriik",
		"gettahunikc"=>"gettahunikc"
	];


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

function gettahunikm($data){
	$db=pDatabase::getInstance();
	
	$query="select tahun from db_singa.tb_indeks_kepuasan group by tahun order by tahun desc";
	$rs=$db->jsonData($query);
	return $rs;
}

function getbulanikm($data){
	$db=pDatabase::getInstance();
	
	$query="select 
			t1.idbulan,
			t2.nama as bulan 
		from db_singa.tb_indeks_kepuasan as t1
		inner join db_singa.tb_bulan as t2 on t1.idbulan=t2.id
		where t1.tahun=?
		group by t1.idbulan order by t1.idbulan desc";
	$rs=$db->jsonData($query,array($data['tahun']));
	return $rs;
}

function getkategoriik($data){
	$db=pDatabase::getInstance();
	$query="select 
			t1.id,
			t1.nama  
		from db_singa.tb_indeks_kepuasan_custom_kategori as t1
		where t1.status=1 order by t1.id asc";
	$rs=$db->jsonData($query);
	return $rs;
}

function gettahunikc($data){
	$db=pDatabase::getInstance();
	
	$query="select tahun from db_singa.tb_indeks_kepuasan_custom 
		where idkategori=?
		group by tahun order by tahun desc";
	$rs=$db->jsonData($query,array($data['kategori']));
	return $rs;
}
?>