<?
include_once("inc/config.php");
include_once("inc/ftbbsdbclass.php");
include_once("inc/publicfun.php");
include_once("conn.php");
include_once("checkuser.php");
include_once("bbsuser.php");

$clubuser_id=intval(get_cookie('clubuser_id'));
$username=get_cookie('username');

$postuserid=intval($_GET["userid"]);
$sql="select clubuser_id,clubuser_name from {$tablepre}clubuser where clubuser_id='".$postuserid."'";
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$postuser=$row["clubuser_name"];

if ($postuser=="" || empty($postuser) || $username==""){
   echo "<script language='javascript'>";
   echo "alert('加为好友操作不成功！');history.go(-1);</script>";
   exit;
}
$sql="select * from {$tablepre}haoyou where userid='".$clubuser_id."' and haoyouname='".$postuser."'";
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs);
if ($numrows!=0){
   echo "<script language='javascript'>";
   echo "alert('你已经加入了该用户为好友！');history.go(-1);</script>";
   exit;
}
else{
   $strsql="insert into {$tablepre}haoyou (userid,haoyouname,groupname,addtime) values('$clubuser_id','$postuser','我的好友','$getnow')";
   mysql_query($strsql);
   $msg=$username."请求加为好友！";
   $smscontent=$username."请求加为好友！";
   $sql="insert into {$tablepre}sms(title,content,sender,accepter,bbssystem,indate) values('$msg','$smscontent','$username','$postuser',2,'$getnow')";
   mysql_query($sql);
   echo "<script language='javascript'>";
   echo "alert('加入成功,但必须等你的好友确认！');history.go(-1);</script>";
   exit;
}
$db->close(); 
?>