<!--#include file="inc_const.asp"-->
<%response.expires=0
Response.CacheControl = "Private"
application.lock

set cschat=server.createobject("ffcschat.cssbchat")

my_level=cschat.getLevel(Session,Application(ConstStr & "_user_list"),Application(ConstStr & "_room_list"))

if my_level=0 then
  set cschat=nothing
  application.unlock
  response.end
end if

myname=cschat.myname
username=request("suser")
errstr=""
if lcase(username)=lcase(myname) then
  errstr="你不能成为你自己的好友！"
else
  Set Conn=Server.CreateObject("ADODB.Connection")
  conn.open Application(ConstStr & "_connstr")
  set rs=conn.execute("SELECT username FROM user WHERE username='" & username & "'")
  if rs.eof or rs.bof then
    errstr=username&"还没有被注册呢！"
  else
    username=rs("username")
    set rs=conn.execute("SELECT friends FROM user WHERE username='" & myname & "'")
    if instr(" "&rs("friends")&" "," "&username&" ")<>0 then
       errstr=username&"已经在你的好友名单里面了！"
    else
      mynamefriends=" "&trim(rs("friends"))&" "&username&" "
      if len(mynamefriends)>250 then
        errstr="你的好友名单已经满了！不允许在添加新的好友！"
      else
        set rs=conn.execute("select who from friendrq where who='"&myname&"' and towho='"&username&"'")
        if not (rs.eof or rs.bof) then
          errstr="你已经发出好友申请了！正在等待对方回复！"
        else
          EXflag=false
          if instr(Application(ConstStr & "_user_list"),"<$"&username&"$>")<>0 then EXflag=true
          conn.execute("insert into friendrq (who,towho,sub_time) values ('"&myname&"','"&username&"','"&now()&"')")
          set rs2=conn.execute("select * from friendrq where who='"&myname&"' and towho='"&username&"'")
          errstr="你向"&username&"发出好友申请！正在等待对方回复！<\script>parent.addfriend(\'"&username&"\')</\script>"
          if EXflag then
            says = Application(ConstStr & "_says")
            current = Application(ConstStr & "_current")
            cschat.newsay username,username,1,-2,"【系统】"&myname&"向你发出好友申请，你是[<a onclick=\'parent.input.document.forms[0].saystemp.focus()\' href=\'agreefriend.asp?ID="&rs2("ID")&"&answer=yes\' target=newsay>同意</a>]还是[<a onclick=\'parent.input.document.forms[0].saystemp.focus()\' href=\'agreefriend.asp?ID="&rs2("ID")&"&answer=no\' target=newsay>不同意</a>]？<br>","#000000","#000000",-5,says,current
            Application(ConstStr & "_says") = says
            Application(ConstStr & "_current") = current
          end if
        end if
      end if
    end if
  end if
  rs.close
  set rs=nothing
  conn.close
  set conn=nothing
end if
set cschat=nothing
application.unlock
%>
<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'><meta content='text/html;charset=gb2312' http-equiv='content-type'><SCRIPT>parent.addsay(-1,'【系统】<%=errstr%>','','<%=myname%>',0,'green','',-2,'<%=time()%>');</script>
