<?php
header('Content-Type: text/html; charset=utf-8');
$path="../../";
include("../../map.php");
$data = json_decode($_POST["data"], true);
//print_r($data);
$_SESSION["t7"] = $_POST["t7"];
if($_GET["durum"]==""){
	foreach($data as $key=>$value){
			echo "ID => ".$value["id"].", S2==>0<br>";
			$sql = mysqli_query($conn, "update genel set s1='".$key."',s2='0' where ne='menu' and id=".$value["id"]."");
		foreach($data[$key]["children"] as $key1=>$value1){
			echo "ID2 => ".$value1["id"].", S2==>".$value["id"]."<br>";
			$sql = mysqli_query($conn, "update genel set s1='".$key1."',s2='".$value["id"]."' where ne='menu' and id=".$value1["id"]."");
			foreach($data[$key]["children"][$key1]["children"] as $key2=>$value2){
				echo "ID3 => ".$value2["id"].", S2==>".$value1["id"]."<br>";
				$sql = mysqli_query($conn, "update genel set s1='".$key2."',s2='".$value1["id"]."' where ne='menu' and id=".$value2["id"]."");
				foreach($data[$key]["children"][$key2]["children"][$key2]["children"] as $key3=>$value3){
					echo "ID4 => ".$value3["id"].", S2==>".$value2["id"]."<br>";
					$sql = mysqli_query($conn, "update genel set s1='".$key3."',s2='".$value2["id"]."' where ne='menu' and id=".$value3["id"]."");
					foreach($data[$key]["children"][$key3]["children"][$key3]["children"][$key3]["children"] as $key4=>$value4){
						echo "ID5 => ".$value4["id"].", S2==>".$value3["id"]."<br>";
						$sql = mysqli_query($conn, "update genel set s1='".$key4."',s2='".$value3["id"]."' where ne='menu' and id=".$value4["id"]."");
					}
				}
			}
		}
	}
}elseif($_GET["durum"]=="kaydet"){
	$iarr = array();
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			$iarr = $iarr + array(trim($key) => trim($value));
		}
	}
	$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
	$larr = array();
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="l"){
			$larr = $larr + array(trim($key) => trim($value));
		}
	}
	$rjsl = json_encode($larr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
		$s3s = explode(',',$_POST["s3"]);
	if($_GET["id"]<>""){
		$Sql = mysqli_query($conn, "update genel set n1='".addslashes(stripslashes($rjsl))."', n2='".addslashes(stripslashes($_POST["n2"]))."', n17='".addslashes(stripslashes($rjsi))."', t2='".$s3s[1]."', t3='".$_POST["t3"]."', t4='".$_POST["t4"]."', t5='".$_POST["t5"]."', t6='".$_POST["t6"]."', t7='".$_POST["t7"]."', t8='".$_POST["t8"]."', n5='".$_POST["n5"]."', s3='".$s3s[0]."', s4='".$_POST["s4"]."', s19='".$_POST["s19"]."' where id=".$_GET["id"]."");	
	}else{
		$sql = $conn->query("insert into genel (ne,n1,n2,n17,t2,t3,t4,t6,t7,t8,n5,s4,s2,s3,s19,ts1) values ('menu', '".addslashes(stripslashes($rjsl))."', '".addslashes(stripslashes($_POST["n2"]))."', '".addslashes(stripslashes($rjsi))."', '".$s3s[1]."', '".$_POST["t3"]."', '".$_POST["t4"]."', '".$_POST["t6"]."', '".$_POST["t7"]."', '".$_POST["t8"]."', '".$_POST["n5"]."', '".$_POST["s4"]."', '0', '".$s3s[0]."', '".$_POST["s19"]."', now())");
	}
	echo "url:?ne=ayarlar&islem=menu";
}elseif($_GET["durum"]=="clear"){
	$sql=mysqli_query($conn, "select * from genel where ne='menu'"); while($rs=mysqli_fetch_assoc($sql)){
		$Sql = mysqli_query($conn, "update genel set s2='0' where id=".$rs["id"]."");
	}
	echo "url:?ne=ayarlar&islem=menu";
}elseif($_GET["durum"]=="sil"){
	$Rs = mysqli_query($conn, "delete from genel where ne='menu' and id=".$_GET["id"]);
	echo "url:?ne=ayarlar&islem=menu";
}
?>