<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=../inc/Limit_fun.asp -->
<%
DEF_BBS_HomeUrl = "../"
Const LMT_MaxCollectAnnounce = 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 CheckIsCanCollSure = 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
SiteBottom_Spend

Function CheckIsCanCollSure

	Dim CollectID
	CollectID = Left(Request("CollectID"),14)
	If isNumeric(CollectID) = 0 or inStr(CollectID,",") > 0 or CollectID = "" Then
		Response.Write "错误,要收藏的主题不存在!<br>" & VbCrLf
		CheckIsCanCollSure = 0
		Exit Function
	End if
	If GBL_CHK_LastWriteTime < DEF_WriteEventSpace Then
		Response.Write "<b><font color=Red Class=RedFont>您的操作太频，请稍候再作提交!</font></b> <br>" & VbCrLf
		CheckIsCanCollSure = 0
		Exit Function
	End If

	CollectID = cCur(CollectID)
	Dim Rs,SQL
	SQL = "Select top 1 BoardID,ParentID,UserID,RootID from LeadBBS_Announce where id=" & CollectID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Response.Write "错误,要收藏的主题不存在!<br>" & VbCrLf
		Rs.Close
		Set Rs = Nothing
		CheckIsCanCollSure = 0
		Exit Function
	End if

	Dim ParentID
	GBL_Board_ID = cCur(Rs("BoardID"))
	ParentID = cCur(Rs("ParentID"))
	Rs.Close
	Set Rs = Nothing
	
	If ParentID > 0 Then
		Response.Write "错误,收藏的帖子必须是主题帖!<br>" & VbCrLf
		CheckIsCanCollSure = 0
		Exit Function
	End If

	Dim Temp
	Temp = Application(DEF_MasterCookies & "BoardInfo" & GBL_Board_ID)
	If isArray(Temp) = False Then
		ReloadBoardInfo(GBL_Board_ID)
		Temp = Application(DEF_MasterCookies & "BoardInfo" & GBL_Board_ID)
	End If
	If isArray(Temp) = False Then
		Response.Write "社区发生错误，请联系管理员!<br>" & VbCrLf
		CheckIsCanCollSure = 0
		Set Rs = Nothing
	End If
	GBL_Board_MasterList = Temp(10,0)

	CheckisBoardMaster
	CheckAccessLimit
	If GBL_CHK_TempStr <> "" or GetBinarybit(GBL_CHK_UserLimit,1) = 1 Then
		Response.Write "您的权限不足.<br>" & VbCrLf
		CheckIsCanCollSure = 0
		Exit Function
	End If
	CheckIsCanCollSure = 1

End Function


Function DisplayCollectAnnounce

	Dim CollectID
	CollectID = Left(Request("CollectID"),14)
	If isNumeric(CollectID) = 0 or inStr(CollectID,",") > 0 or CollectID = "" Then
		Response.Write "错误,要收藏的主题不存在!<br>" & VbCrLf
		Exit Function
	End if
	If Request.Form("DeleteSureFlag")="dk9@dl9s92lw_SWxl" Then
		
		CollectID = cCur(CollectID)
		Dim Rs,SQL
		SQL = "Select count(*) from LeadBBS_CollectAnc 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_MaxCollectAnnounce Then
			Response.Write "错误,您收藏帖数已经超过" & LMT_MaxCollectAnnounce & "帖，不能再收藏!<br>" & VbCrLf
			Exit Function
		End if
		
		SQL = "Select top 1 ID from LeadBBS_CollectAnc where AnnounceID=" & CollectID & " and UserID=" & GBL_UserID
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Not Rs.Eof Then
			Response.Write "您已经收藏过此帖!<br>" & VbCrLf
			Rs.Close
			Set Rs = Nothing
			Exit Function
		End If
		Rs.Close
		Set Rs = Nothing

		Response.Write "成功收藏社区帖子"
		Con.ExeCute(" insert into LeadBBS_CollectAnc(AnnounceID,UserID) Values(" & CollectID & "," & 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)
			GBL_DBNum = GBL_DBNum + 1
			UpdateSessionValue 13,GetTimeValue(DEF_Now),0
		End If
	Else
		%>
		<form name=DellClientForm action=CollectAnnounce.asp method=post>
			<input type=hidden name=DeleteSureFlag value="dk9@dl9s92lw_SWxl">
			<input type=hidden name=CollectID value="<%=CollectID%>">
			<input type=hidden name=BoardID value="<%=GBL_Board_ID%>">
			<b>确认要收藏编号为<font color=ff0000 class=RedFont><%=CollectID%></font>的帖子吗？</b>
			<p><input type=submit value=确定 class=fmbtn>
			<input type=button value=取消此操作 onclick="javascript:window.close();" class=fmbtn>
		</form>
		<%
	End If

End Function%>