<?php
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");

$userid=intval(get_cookie('clubuser_id'));
$username=get_cookie('username');
$postuser=ftbbs_request($_GET["postuser"]);
if (trim($_POST["haoyouname"])!=""){
   $haoyouname=ftbbs_request(trim($_POST["haoyouname"]));
   $gn=trim($_POST["gn"]);
   $str="select clubuser_name from {$tablepre}clubuser where clubuser_name='".$haoyouname."'";
   $rs=mysql_query($str);
   $myrow = mysql_fetch_array($rs);
   $numrows = mysql_num_rows($rs);
   if ($numrows!=0){
     $sql="select * from {$tablepre}haoyou where haoyouname='".$haoyouname. "' and userid=".$userid;
     $rs1=mysql_query($sql);
     $myrow1 = mysql_fetch_array($rs1);
     $numrows1 = mysql_num_rows($rs1);
	 if ($numrows1==0){
	    if ($gn=="创建新分组" || empty($gn) || $gn==""){
	       $groupname="我的好友";
		 }
	    else{
	       $groupname=$gn;
	    }
      $strsql="insert into {$tablepre}haoyou (userid,haoyouname,groupname,sign,addtime) values('$userid','$haoyouname','$groupname',0,'$getnow')";
	  mysql_query($strsql);
      $msg="(<font color=red>好友添加成功!</font>)";
      $msginfo=$username."请求加为好友！";
      $smscontent=$username."请求加为好友！";
      $sql="insert into {$tablepre}sms(title,content,sender,accepter,bbssystem,indate) values('".$msginfo."','".$smscontent."','".$username."','".$haoyouname."',2,'$getnow')";
      mysql_query($sql);
	 }
     else{
      $msg="(<font color=red>你已经添加了该用户为好友!</font>)";
     }
   }
   else{
    $msg="(<font color=red>你所添加的用户名不存在!</font>)";
   }
}
include_once("memberinfo.php");
?>
<html><head><meta http-equiv=content-type content="text/html; charset=utf-8">
<title>添加好友</title>
<link rel="stylesheet" type="text/css" href="<?=$cssfile?>">
</head>
<script language="javascript">
<!--
   function checkClick(obj){
    if(obj.checked){
 	  document.f.gn.disabled = false;
 	  document.f.gn.focus();
 	  document.f.gn.value="";
 	}else{
 	  document.f.gn.value="创建新分组";
 	  document.f.gn.disabled = true;	
     }
    }
	function f_submit(form)
	{
    if (form.haoyouname.value=="")
    	{
    	 alert("请填写好友的用户名！");
    	 form.haoyouname.focus();
    	 return false;
  	}
     return true;
	}
//-->
</script>
<body>
<center>
<?
include_once("usernav.php");
include_once("haoyouhead.php");
?>
<div class="stage">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="layout">
<tr>
<td width="22%" valign="top" class="c2t3">
<div id="mod_profile" class="mod" rel="drag">
<?
include_once("usercalog.php");
?>
</div>
</td>
<td width="78%" valign="top" class="c2t1">
<div id="m_blog" class="modbox"><br>
              <br>
              <br>
              <br>
              <table width="80%" border="0" align="center">
                <form name="f" method=post action="" onsubmit="return f_submit(this)">
                  <tr> 
                    <td height="30"><div align="center"></div></td>
                    <td height="30" class="f14"><strong>添加好友<?=$msg?></strong></td>
                  </tr>
                  <tr> 
                    <td width="27%" height="35" align="right">用户名：</td>
                    <td width="73%"> 
                      <input name="haoyouname" type="text" id="haoyouname" value="<?=$postuser?>"></td>
                  </tr>
                  <tr> 
                    <td height="35" align="right">选择分组：</td>
                    <td><input type="checkbox" name="xn" onclick="checkClick(this)">
					<input name="gn" type="text" disabled value="创建新分组" size="17"></td>
                  </tr>
                  <tr> 
                    <td height="40"></td>
                    <td><input type="submit" name="Submit" value="添加好友"></td>
                  </tr>
                </form>
              </table>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
            </div>
</td>
</tr></table>
</div>
</div>
<br><center>
<?
include_once("tail.php");
?>
  </center>
</center>
</body>
</html>