<?php define( '_BIGNIGHT_EXEC', 1 );?>
<?php session_start();?>

<?php require_once("helper.php"); ?>
<?php require_once("user.php"); ?>


<?php

	if(!isset($_GET["name"])) die("No event specified.");
	$username = str_replace("'","''",$_GET["name"]);
	
	if($user===NULL) die("Log in to subscribe.");
	
	global $DB;
	
	$result = $DB->qry("SELECT username FROM users WHERE username='{$username}';",3);
	if ($DB->numrows()===0){
		echo "Invalid user.";
	} else {					
		$subscribed = is_subscribed($username);
			
		if($subscribed){
			$DB->qry("DELETE FROM subscriptions WHERE host='{$username}' AND subscriber='{$user["username"]}';");
			echo "You have unsubscribed from this user's events.";
		} else {
			$DB->qry("INSERT INTO subscriptions (`subscriber`,`host`) VALUES ('{$user["username"]}','{$username}')");
			echo "You have subscribed to this user's event.";
		}
	}
	
	echo "|" . get_subscriptions($username);
?>