<?php
error_reporting(0);
header('Content-Type: text/html; charset=utf-8');
if($_GET["ne"]=="ulke"){
	$ID="s1"; $lname="Ülke Seç";
}elseif($_GET["ne"]=="il"){
	$ID="s1"; $lname="Şehir Seç";
}elseif($_GET["ne"]=="bolge"){
	$ID="s1"; $lname="Bölge Seç";
}elseif($_GET["ne"]=="ilce"){
	$ID="s2"; $lname="İlçe Seç";
}elseif($_GET["ne"]=="semt"){
	$ID="s3"; $lname="Semt Seç";
}
$result = file_get_contents(__DIR__.'/../jsons/locations.json');
$arrays = json_decode($result, true);
sort($arrays);
//Print_r($result);
echo "<option value=\"\">".$lname."</option>";
if($_GET["ne"]=="bolge"){
	$types = array();
	foreach($arrays as $array){
		if($array["ne"]=="il" and $array[$ID]==$_GET["ID"]){
			if (in_array($array["t3"], $types)){continue;}
			$types[] = $array['t3'];
			if($_GET["sID"]<>"" and ($array["t3"]==base64_decode($_GET["sID"]))){$slc="selected";}else{$slc="";}
			echo "<option value=\"".$array["t3"]."\" ID=\"".$array["id"]."\" S1=\"".$array["s1"]."\" S2=\"".$array["s2"]."\" S3=\"".$array["s3"]."\" ".$slc.">".$array["t3"]."</option>";
		}
	}
}else{
	foreach($arrays as $array){
		if($array["ne"]==$_GET["ne"] and $array[$ID]==$_GET["ID"]){
			if($_GET["sID"]<>"" and ($array["id"]==$_GET["sID"] or $array["t2"]==$_GET["sID"])){$slc="selected";}else{$slc="";}
			if($_GET["type"]=="name"){$type=$array["t1"];}else{$type=$array["id"];}
			echo "<option value=\"".$type."\" ID=\"".$array["id"]."\" S1=\"".$array["s1"]."\" S2=\"".$array["s2"]."\" S3=\"".$array["s3"]."\" ".$slc.">".$array["t1"]."</option>";
			//echo "".$array["t1"]." ".$array["id"]."\n";
		}
	}
}
?>