<?php
	
	if ($_GET['send'] == 'ok' && mysql_result(mysql_query("SELECT COUNT(`id`) FROM `friends` WHERE `user_id` = '".$id."' AND `friend_id` = '".$user_id."' LIMIT 1"),0) == false)
	{
		$arr_user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."' LIMIT 1"));
		if ($arr_user['ban'] == 1) go(URL.'/?id='.$arr_user['id']);
		
			// Приймаємо дружбу по зустрічній заявці
		if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `notifications` WHERE `for_id` = '".$user_id."' AND `from_id` = '".$id."' AND `mod` = 'friends' AND `type` = 'new_friend' LIMIT 1"),0) == true) go(URL.'/friends/z_in.php?ok='.$id);
		// Або надсилаємо заявку
		else if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `notifications` WHERE `for_id` = '".$id."' AND `from_id` = '".$user_id."' AND `mod` = 'friends' AND `type` = 'new_friend' LIMIT 1"),0) == false)
		{
			if (mysql_query("INSERT INTO `notifications` SET
			`for_id` = '".$id."',
			`from_id` = '".$user_id."',
			`sex` = '".$user['sex']."',
			`mod` = 'friends',
			`type` = 'new_friend',
			`refid` = '".$user_id."',
			`time` = '".time()."',
			`new` = 1
			") == true)
			{
				mysql_query("UPDATE `users` SET `notifications` = 1, notifications_friends=notifications_friends+1 WHERE `id` = '".$id."'");
			}
		}

		go(URL.'/?id='.$id);
	}

?>