<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=../inc/Limit_fun.asp -->
<%
DEF_BBS_HomeUrl = "../"
Const LMT_MaxFriendNum = 200 '最多好友数
initDatabase
GBL_CHK_TempStr = ""
siteHead("   添加好友")
%>
<script language=javascript>
	window.moveTo(window.screen.width/2-225,window.screen.height/2-18);
</script>
<%
UpdateOnlineUserAtInfo GBL_board_ID,"添加好友"

If GBL_CHK_Flag=1 Then
	If CheckIsCanAddFriendSure = 1 Then
		DisplayCollectAnnounce
	End If
Else
	If Request("submitflag")="" Then
		Response.Write "<br><b>请先登录</b>"
	Else
		Response.Write "<br><p align=left><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font>"
	End If
	Response.Write "</p>"
End If

closeDataBase

Function CheckIsCanAddFriendSure

	If GetBinarybit(GBL_CHK_UserLimit,1) = 1 Then
		Response.Write "您的权限不足，非正式会员无此功能.<br>" & VbCrLf
		CheckIsCanAddFriendSure = 0
		Exit Function
	End If

	If GBL_CHK_LastWriteTime < DEF_WriteEventSpace Then
		Response.Write "<b><font color=Red Class=RedFont>您的操作太频，请稍候再作提交!</font></b> <br>" & VbCrLf
		CheckIsCanAddFriendSure = 0
		Exit Function
	End If
	CheckIsCanAddFriendSure = 1

End Function


Function DisplayCollectAnnounce

	Dim FriendName,FriendID
	FriendName = Left(Request("FriendName"),20)
	If Request.Form("AddSureFlag")="yes" and FriendName <> "" Then
		Dim Rs,SQL
		SQL = "Select count(*) from LeadBBS_FriendUser where UserID=" & GBL_UserID
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			SQL = 0
		Else
			SQL = Rs(0)
			If IsNull(SQL) Then SQL = 0
			SQL = cCur(SQL)
		End If
		Rs.Close
		Set Rs = Nothing

		If SQL > LMT_MaxFriendNum Then
			Response.Write "<b>错误,好友数已经超过" & LMT_MaxFriendNum & "人，不能再添加!</b><br>" & VbCrLf
			Set Rs = Nothing
			Exit Function
		End if

		SQL = "Select top 1 ID,UserName from LeadBBS_User where UserName='" & Replace(FriendName,"'","''") & "'"
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Response.Write "<b>" & htmlencode(FriendName) & "未找到，请确定用户名是否正确!</b><br>" & VbCrLf
			Rs.Close
			Set Rs = Nothing
			Exit Function
		End If
		FriendID = cCur(Rs(0))
		FriendName = Rs(1)
		Rs.Close
		Set Rs = Nothing
		
		SQL = "Select top 1 ID from LeadBBS_FriendUser where FriendUserID=" & FriendID & " and UserID=" & GBL_UserID
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Not Rs.Eof Then
			Response.Write "<b>" & htmlencode(FriendName) & "已经是您的好友，不用再添加!</b><br>" & VbCrLf
			Rs.Close
			Set Rs = Nothing
			Exit Function
		End If
		Rs.Close
		Set Rs = Nothing

		Response.Write "<b>成功添加" & htmlencode(FriendName) & "到好友列表!</b>"
		Con.ExeCute(" insert into LeadBBS_FriendUser(FriendUserID,UserID) Values(" & FriendID & "," & GBL_UserID & ")")
		GBL_DBNum = GBL_DBNum + 1
		Set Rs = Nothing
		If CheckSupervisorUserName = 0 Then
			Con.ExeCute("Update LeadBBS_User Set LastWriteTime=" & GetTimeValue(DEF_Now) & " where ID=" & GBL_UserID)
			UpdateSessionValue 13,GetTimeValue(DEF_Now),0
			GBL_DBNum = GBL_DBNum + 1
		End If
	Else
		%>
		<form name=DellClientForm action=AddFriend.asp method=post>
			<input type=hidden name=AddSureFlag value="yes">
			<input type=hidden name=BoardID value="<%=GBL_Board_ID%>">
			<b>请输入好友的名字:</b>
			<input type=input name=FriendName value="<%=FriendName%>">
			<p><input type=submit value=确定 class=fmbtn>
			<input type=button value=取消此操作 onclick="javascript:window.close();" class=fmbtn>
		</form>
		<%
	End If

End Function%>