<!--#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
room_id=cschat.room_id

ID=cint(request.querystring("ID"))
if request("answer")="yes" then
  answer=true
else
  answer=false
end if

errstr=""
Set Conn=Server.CreateObject("ADODB.Connection")
conn.open Application( ConstStr & "_connstr")
set rs=conn.execute("select * from friendrq where towho='"&myname&"' and ID="&ID)
if rs.eof or rs.bof then
  errstr="没有找到好友申请的记录，加入好友失败！"
else
  username=trim(rs("who"))
  if username=myname then
    errstr="你不能成为你自己的好友！"
  else
    set rs=conn.execute("SELECT friends FROM user WHERE username='" & username & "'")
    if rs.eof or rs.bof then
      errstr=username&"还没有被注册呢！"
    else
      usernamefriends=" "&trim(rs("friends"))&" "&myname&" "
      if len(usernamefriends)>250 then
        errstr=username&"的好友名单已经满了！不允许在添加新的好友！"
      else
        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
            if answer then
              conn.execute("update user set friends='"&usernamefriends&"' where username='"&username&"'")
              conn.execute("update user set friends='"&mynamefriends&"' where username='"&myname&"'")
              errstr="你和"&username&"正式成为好友！恭喜！<\script>parent.addfriend(\'"&username&"\')</\script>"
              callmess="你好！很高兴能和你成为好友！"
            else
              errstr="你拒绝了"&username&"的好友申请！"
              callmess="对不起！我现在还不能和你成为好友！"
            end if
            conn.execute("insert into calls (who,towho,callmess,calltime,read) values ('"&myname&"','"&username&"','"&callmess&"','"&now()&"',false)")
            if instr(Application( ConstStr & "_user_list"),"<$"&username&"$>")<>0 then
    says = Application(ConstStr & "_says")
    current = Application(ConstStr & "_current")
              cschat.newsay username,username,1,-2,"<\script>window.open(\'getcall.asp\',\'\',\'width=550,height=300,scrollbars=1\');</\script>","#","#",-5,says,current
    Application(ConstStr & "_says") = says
    Application(ConstStr & "_current") = current
            end if
          end if
        end if
      end if
    end if
  end if
end if
conn.execute("delete from friendrq where towho='"&myname&"' and ID="&ID)
response.write "<META content='text/html; charset=gb2312' http-equiv=content-type><meta HTTP-EQUIV='Pragma' CONTENT='no-cache'><SCRIPT>parent.addsay(-1,'【系统】"&errstr&"','','"&myname&"',0,'990066','',-2,'"&time()&"');</script>"
set cschat=nothing
application.unlock
rs.close
set rs=nothing
conn.close
set conn=nothing%>