<?php

include('../global.php');

$id = Filter($_POST['accountId']);

$sql = mysql_query("SELECT block_newfriends FROM users WHERE id = '".$id."' LIMIT 1");
$row = mysql_fetch_assoc($sql);

if($row['block_newfriends'] !== "0"){
$error = 1;
$message = "Ce Beta &agrave; d&eacute;sactiv&eacute; les textamigos.";
}

$sql = mysql_query("SELECT * FROM messenger_friendships WHERE user_one_id = '".$id."' AND user_two_id = '".$my_id."'");
$rows = mysql_num_rows($sql);
if($rows <> 0){
$error = 1;
$message = "Cette personne est d&eacute;j&agrave; ton amis.";
}

$sql = mysql_query("SELECT * FROM messenger_friendships WHERE user_one_id = '".$my_id."' AND user_two_id = '".$id."'");
$rows = mysql_num_rows($sql);
if($rows <> 0){
$error = 1;
$message = "Cette personne est d&eacute;j&agrave; ton amis.";
}

$sql = mysql_query("SELECT * FROM messenger_requests WHERE from_id = '".$my_id."' AND to_id = '".$id."'");
$rows = mysql_num_rows($sql);
if($rows <> 0){
$error = 1;
$message = "Vous avez d&eacute;j&agrave; envoy&eacute; un textamigos &agrave; cette personne.";
}

$sql = mysql_query("SELECT * FROM messenger_requests WHERE to_id = '".$my_id."' AND from_id = '".$id."'");
$rows = mysql_num_rows($sql);
if($rows <> 0){
$error = 1;
$message = "Cette personne vous &agrave; d&eacute;j&agrave; envoy&eacute; un textamigos.";
}

if($id == $my_id){
$error = 1;
$message = "Vous ne pouvez pas vous demander en ami.";
}

if($error <> 1){
mysql_query("INSERT INTO messenger_requests (from_id,to_id) VALUES ('".$my_id."','".$id."')");

$message = "Textamigos envoy&eacute;.";
} ?>

<div id="avatar-habblet-dialog-body" class="topdialog-body"><ul>
	<li><?php echo $message; ?></li>
</ul>


<p>
<a href="#" class="new-button done"><b>Fermer</b><i></i></a>
</p></div>