<?php 
	if (isset($_GET['id'])) { 
		$user = intval($_GET['id']); 
	} else { 
		die();
	}
	$login=false;
	$admin=false;
	$banned=false;
	session_start();
	if ($_SESSION['valid']) {
		$login=true;
		$myID = intval($_SESSION['id']);
	}else{
		echo '<link rel="stylesheet" href="style.css">';
		include 'header.php';
		echo('You are not logged.');
		die();
	}
	if ($myID==$user) {
		echo '<script>window.location="index.php?id='.$myID.'"</script>';
		die();
	}

	if($_SERVER['HTTP_REFERER']!="https://myspace.windows93.net/index.php?id=".$user&&$_SERVER['HTTP_REFERER']!="https://myspace.windows93.net/?id=".$user){die();}

	// me
	$json_source = file_get_contents('u/'.$myID.'/user.json');
	$json_data = json_decode($json_source, true);
	if ($json_data["ban"]) {
		echo 'you are banned';
		die();
	}

	if (in_array($user, $json_data["block"])) { 
		// unblock
		$where= array_search($user, $json_data["block"]);
		
		array_splice($json_data["block"], intval($where), 1);
		//unset($json_data["block"],[intval($where)-1]);  
		$json_dest = json_encode($json_data, JSON_PRETTY_PRINT);
		file_put_contents('u/'.$myID.'/user.json', $json_dest);

		echo '<script>window.location="index.php?id='.$user.'"</script>';

	}else{

		// block
		array_push($json_data['block'], intval($user));
		$json_dest = json_encode($json_data, JSON_PRETTY_PRINT);

		if ($user!=1) {
			file_put_contents('u/'.$myID.'/user.json', $json_dest);
		}

		echo '<script>window.location="index.php?id='.$user.'"</script>';
	}
?>