<?php
/*=====================================================================+
|| # HaddoCMS based HoloCMS - Website and Content Management System
|+=====================================================================+
|| # Copyright © 2008 Meth0d. All rights reserved.
|| # http://www.meth0d.org
|+===================================================+
|| # HoloCMS is provided "as is" and comes without
|| # warrenty of any kind. HoloCMS is free software!
|+=====================================================================+
|| # HaddoCMS v2.0 by Raikas77
|| # www.sciax2.it/forum/development/haddocms-v2-build-2100-a-535753.html
|+=====================================================================*/

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

$allow_guests = false;


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



$sql = mysql_query("SELECT * FROM messenger_friendships WHERE sender = '".$id."' AND receiver = '".$my_id."'");
$rows = mysql_num_rows($sql);

if($rows <> 0){
$error = 1;
$message = "Questa persona e gia tua amica.";
}

$sql = mysql_query("SELECT * FROM messenger_friendships WHERE sender = '".$my_id."' AND receiver = '".$id."'");
$rows = mysql_num_rows($sql);
if($rows <> 0){
$error = 1;
$message = "Questa persona e gia tua amica.";
}

$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 = "Hai gią una richiesta di amicizia in sospeso.";
}

$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 = "Hai gią una richiesta di amicizia in sospeso.";
}

if($id == $my_id){
$error = 1;
$message = "Non puoi chiedere a te stesso di essere tuo amico!";
}

if($error <> 1){
$sql = mysql_query("SELECT MAX(id) FROM messenger_requests WHERE to_id = '".$id."'");
$requestid = mysql_result($sql, 0);
$requestid = $requestid + 1;

mysql_query("INSERT INTO messenger_requests (from_id,to_id,id) VALUES ('".$my_id."','".$id."','".$requestid."')");

$message = "Richiesta inviata correttamente.";
} ?>

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


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