<?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=[
		"setStatus"=>"setStatus"
	];


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

function arrayRecursiveDiff($aArray1, $aArray2) { 
    $aReturn = array(); 

    foreach ($aArray1 as $mKey => $mValue) { 
        if (array_key_exists($mKey, $aArray2)) { 
            if (is_array($mValue)) { 
                $aRecursiveDiff = arrayRecursiveDiff($mValue, $aArray2[$mKey]); 
                if (count($aRecursiveDiff)) { $aReturn[$mKey] = $aRecursiveDiff; } 
            } else { 
                if ($mValue != $aArray2[$mKey]) { 
                    $aReturn[$mKey] = $mValue; 
                } 
            } 
        } else { 
            $aReturn[$mKey] = $mValue; 
        } 
    } 

    return $aReturn; 
}

function setStatus($data){
	
	if($data[2]==1){
		if(isset($_SESSION['menu_sub'])){
			if(!in_array($data[1], $_SESSION['menu_sub'])){
				array_push($_SESSION['menu_sub'],$data[1]);
			}
		}else{
			$_SESSION['menu_sub']=array();
			array_push($_SESSION['menu_sub'],$data[1]);
		}
	}else{
		$datases=$data[1];
		for($i=0;$i<sizeof($_SESSION['menu_sub']);$i++){
			if(isset($_SESSION['menu_sub'][$i]) && (json_encode($datases,true)==json_encode($_SESSION['menu_sub'][$i],true))){
				unset($_SESSION['menu_sub'][$i]);
			}
		}
	}
	
	return true;
}
?>