<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=../inc/Limit_fun.asp -->
<%
DEF_BBS_HomeUrl = "../"
initDatabase
GBL_CHK_TempStr = ""
siteHead("   精华帖子")

Dim GoodID
Dim GBL_GoodFlag,ALL_FirstRootID,ALL_LastRootID,LMT_UserID
%>
<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 CheckIsCanDellSure = 1 Then
		If Request.Form("Form_GoodType") <> "1" Then 
			DisplayMakeGoodAnnounce
		Else
			MakeGoodAnnouncePrize
		End If
	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 CheckIsCanDellSure

	If GetBinarybit(GBL_CHK_UserLimit,6) = 1 Then
		Response.Write "错误,权限不足!<br>" & VbCrLf
		CheckIsCanDellSure = 0
		Exit Function
	End if
	GoodID = Left(Request("GoodID"),14)
	If isNumeric(GoodID) = 0 or inStr(GoodID,",") > 0 or GoodID = "" Then
		Response.Write "错误,请提供要精华的帖子的ID!<br>" & VbCrLf
		CheckIsCanDellSure = 0
		Exit Function
	End if

	GoodID = Fix(cCur(GoodID))
	Dim Rs,SQL
	SQL = "Select top 1 BoardID,ParentID,UserID,RootID,GoodFlag from LeadBBS_Announce where id=" & GoodID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Response.Write "错误,要精华的帖子ID不存在!<br>" & VbCrLf
		Rs.Close
		Set Rs = Nothing
		CheckIsCanDellSure = 0
		Exit Function
	End if

	GBL_Board_ID = Rs(0)
	LMT_UserID = cCur(Rs(2))
	GBL_GoodFlag = Rs(4)
	Rs.Close
	Set Rs = Nothing	

	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
		CheckIsCanDellSure = 0
		Set Rs = Nothing
	End If
	
	GBL_Board_MasterList = Temp(10,0)
	ALL_FirstRootID = Temp(33,0)
	ALL_LastRootID = Temp(34,0)
	If GetBinarybit(GBL_Board_BoardLimit,4) = 1 Then
		Response.Write "此版面不允许修改帖子."
		CheckIsCanDellSure = 0
		Exit Function
	End If
	
	CheckisBoardMaster
	If GBL_UserID >= 1 and (GBL_BoardMasterFlag >= 5 and GetBinarybit(GBL_CHK_UserLimit,6) = 0) Then
		CheckIsCanDellSure = 1
	Else
		CheckIsCanDellSure = 0
		Response.Write "错误,权限不足."
	End If
	If GBL_CHK_LastWriteTime < DEF_WriteEventSpace Then
		Response.Write "<b><font color=Red Class=RedFont>您的操作太频，请稍候再作提交!</font></b> <br>" & VbCrLf
		CheckIsCanDellSure = 0
		Exit Function
	End If

End Function

Function DisplayMakeGoodAnnounce

	If Request.Form("DeleteSureFlag")="dk9@dl9s92lw_SWxl" Then		
		Dim Rs,SQL
		Set Rs = Server.CreateObject("ADODB.RecordSet")
		SQL = "Select top 1 UserID,GoodFlag,BoardID,ParentID from LeadBBS_Announce where id=" & GoodID
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Response.Write "错误,要精华的帖子ID不存在!<br>" & VbCrLf
			Rs.Close
			Set Rs = Nothing
			Exit Function
		ElseIf cCur(Rs("ParentID")) <> 0 Then
			Response.Write "错误,精华的帖子必须是主题帖!<br>" & VbCrLf
			Rs.Close
			Set Rs = Nothing
			Exit Function
		End if
		
		Dim UserID,GoodFlag,BoardID
		UserID = Rs(0)
		GoodFlag = Rs(1)
		BoardID = Rs(2)
		If GoodFlag = 1 or GoodFlag = True Then
			Rs.Close
			Set Rs = Nothing
			Con.ExeCute("Update LeadBBS_Announce Set GoodFlag = 0 where id=" & GoodID)
			Con.ExeCute("Update LeadBBS_Topic Set GoodFlag = 0 where id=" & GoodID)
			GBL_DBNum = GBL_DBNum + 1
			If inStr(application(DEF_MasterCookies & "TopAncList"),"," & GoodID & ",") Then
				UpdateAnnounceApplicationInfo GoodID,12,0,0,0
			Else
				If inStr(application(DEF_MasterCookies & "TopAncList" & GBL_Board_BoardAssort),"," & GoodID & ",") Then UpdateAnnounceApplicationInfo GoodID,12,0,0,GBL_Board_BoardAssort
			End if
			
			Response.Write "此帖子已经是精华帖,现取消精华!<br>" & VbCrLf
			Con.ExeCute(" Update LeadBBS_User set Points=Points-" & DEF_BBS_MakeGoodAnnouncePoints & ",AnnounceGood=AnnounceGood-1 Where ID =" & UserID)
			GBL_DBNum = GBL_DBNum + 1
			'Con.ExeCute(" Update LeadBBS_Boards set GoodNum=GoodNum-1 Where BoardID =" & BoardID)
			UpdateBoardAnnounceNum Application(DEF_MasterCookies & "BoardInfo" & BoardID)(28,0),0,0,0,-1
			'UpdateBoardApplicationInfo BoardID,cCur(Application(DEF_MasterCookies & "BoardInfo" & BoardID)(13,0))-1,13
			'GBL_DBNum = GBL_DBNum + 1
		Else
			Rs.Close
			Set Rs = Nothing
			Con.ExeCute("Update LeadBBS_Announce Set GoodFlag = 1 where id=" & GoodID)
			Con.ExeCute("Update LeadBBS_Topic Set GoodFlag = 1 where id=" & GoodID)
			GBL_DBNum = GBL_DBNum + 1
			If inStr(application(DEF_MasterCookies & "TopAncList"),"," & GoodID & ",") Then
				UpdateAnnounceApplicationInfo GoodID,12,1,0,0
			Else
				If inStr(application(DEF_MasterCookies & "TopAncList" & GBL_Board_BoardAssort),"," & GoodID & ",") Then UpdateAnnounceApplicationInfo GoodID,12,1,0,GBL_Board_BoardAssort
			End If
			Response.Write "成功精华论坛帖子"
			Con.ExeCute(" Update LeadBBS_User set Points=Points+" & DEF_BBS_MakeGoodAnnouncePoints & ",AnnounceGood=AnnounceGood+1 Where ID =" & UserID)
			GBL_DBNum = GBL_DBNum + 1
			Con.ExeCute(" Update LeadBBS_Boards set GoodNum=GoodNum+1 Where BoardID =" & BoardID)
			UpdateBoardAnnounceNum Application(DEF_MasterCookies & "BoardInfo" & BoardID)(28,0),0,0,0,1
			'UpdateBoardApplicationInfo BoardID,cCur(Application(DEF_MasterCookies & "BoardInfo" & BoardID)(13,0))+1,13
			'GBL_DBNum = GBL_DBNum + 1
			Con.ExeCute("insert into LeadBBS_Log(LogType,LogTime,LogInfo,UserName,IP,BoardID) Values(102," & GetTimeValue(DEF_Now) & ",'成功精华 针对帖子：版面编号" & GBL_Board_ID & "帖子编号" & GoodID & " 作者编号:" & LMT_UserID & "．','" & Replace(Replace(htmlencode(Left(GBL_CHK_User,14)),"\","\\"),"'","''") & "','" & Replace(GBL_IPAddress,"'","''") & "'," & GBL_Board_ID & ")")
		End if
		If GoodID >= ALL_FirstRootID  Then UpdateBoardApplicationInfo GBL_board_ID,0,33
		If GoodID <= ALL_LastRootID  Then UpdateBoardApplicationInfo GBL_board_ID,0,34
		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
		Dim N
		%>
		<form id=DellClientForm name=DellClientForm action=MakeGood.asp method=post>
			<input type=hidden name=DeleteSureFlag value="dk9@dl9s92lw_SWxl">
			<input type=hidden name=GoodID value="<%=GoodID%>">
			<input type=hidden name=BoardID value="<%=GBL_Board_ID%>">
			<%
		If DEF_BBS_PrizeAnnouncePoints <> 0 Then%>
			<input class=fmchkbox type=radio name=Form_GoodType value=0 checked><span onclick="document.all.DellClientForm.Form_GoodType[0].checked=1;"><%
			If GBL_GoodFlag = 1 or GBL_GoodFlag = True Then%>取消<%
			End If%>精华编号为<font color=ff0000 class=RedFont><%=GoodID%></font>的帖子</span>
			<br><input class=fmchkbox type=radio name=Form_GoodType value=1><span onclick="document.all.DellClientForm.Form_GoodType[1].checked=1;">奖励或惩罚帖子作者</span>
			<select name=Form_AddPoints onchange="document.all.DellClientForm.Form_GoodType[1].checked=1;">
			<%
				For N = abs(DEF_BBS_PrizeAnnouncePoints) to 1 Step -1
					Response.Write "<option value=-" & N & ">减去" & DEF_PointsName & N & "</option>" & VbCrLf
				Next
				Response.Write "<option value=-" & N & " selected>无奖罚</option>" & VbCrLf
				For N = 1 to abs(DEF_BBS_PrizeAnnouncePoints)
					Response.Write "<option value=" & N & ">奖励" & DEF_PointsName & N & "</option>" & VbCrLf
				Next
			%>
			</select>[日志记录]
			<br><img src=../images/null.gif width=2 height=2><br><%
		Else%><b>确认要<%If GBL_GoodFlag = 1 or GBL_GoodFlag = True Then%>取消<%End If%>精华编号为<font color=ff0000 class=RedFont><%=GoodID%></font>的帖子吗？</b>
			<p><%
		End If%><input type=submit value=确定 class=fmbtn>
			<input type=button value=取消此操作 onclick="javascript:window.close();" class=fmbtn>
		</form>
		<%
	End If

End Function

Function UpdateBoardAnnounceNum(BoardList,TopicNum,AnnounceNum,TodayAnnounce,GoodNum)

	Dim SQL,N
	If BoardList = "" or (TopicNum = 0 and AnnounceNum = 0 and TodayAnnounce = 0 and GoodNum = 0) Then Exit Function
	SQL = "Update LeadBBS_Boards Set AnnounceNum=AnnounceNum+" & AnnounceNum & ",AnnounceNum_All=AnnounceNum_All+" & AnnounceNum
	If TopicNum <> 0 Then SQL = SQL & ",TopicNum=TopicNum+" & TopicNum
	If TopicNum <> 0 Then SQL = SQL & ",TopicNum_All=TopicNum_All+" & TopicNum
	If TodayAnnounce <> 0 Then  SQL = SQL & ",TodayAnnounce=TodayAnnounce+" & TodayAnnounce
	If TodayAnnounce <> 0 Then  SQL = SQL & ",TodayAnnounce_All=TodayAnnounce_All+" & TodayAnnounce
	If GoodNum <> 0 Then  SQL = SQL & ",GoodNum=GoodNum+" & GoodNum
	If GoodNum <> 0 Then  SQL = SQL & ",GoodNum_All=GoodNum_All+" & GoodNum
	SQL = SQL & " where BoardID in(" & BoardList & ")"
	Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	BoardList = Split(BoardList,",")
	SQL = Ubound(BoardList,1)
	Dim Temp
	For N = 0 To SQL
		Temp = Application(DEF_MasterCookies & "BoardInfo" & BoardList(N))
		If isArray(Temp) = False Then
			ReloadBoardInfo(BoardList(N))
			Temp = Application(DEF_MasterCookies & "BoardInfo" & BoardList(N))
		End If
		If isArray(Temp) = True Then
			If TopicNum <> 0 Then
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(5,0))+TopicNum,5
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(29,0))+TopicNum,29
			End If
			If AnnounceNum <> 0 Then
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(6,0))+AnnounceNum,6
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(30,0))+AnnounceNum,30
			End If
			If TodayAnnounce <> 0 Then
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(18,0))+TodayAnnounce,18
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(31,0))+TodayAnnounce,31
			End If
			If GoodNum <> 0 Then
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(13,0))+GoodNum,13
				UpdateBoardApplicationInfo BoardList(N),cCur(Temp(32,0))+GoodNum,32
			End If
		End If
	Next
	'28,T1.ParentBoardStr,29.TopicNum_All,30.AnnounceNum_All,31.TodayAnnounce_All,32.GoodNum_All

End Function

Sub UpdateAnnounceApplicationInfo(AncID,IndexN,Value,tp,tid)

	Dim GetDataTop,AllTopNum,N,Str
	If tid = 0 Then
		Str = ""
	Else
		Str = tid
	End if
	AllTopNum = -1
	GetDataTop = Application(DEF_MasterCookies & "TopAnc" & Str)
	If isArray(GetDataTop) = False Then
		'If GetDataTop <> "yes" Then ReloadTopAnnounceInfo(tid)
		Exit Sub
	Else
		AllTopNum = Ubound(GetDataTop,2)
	End If

	For N = 0 to AllTopNum
		If cCur(AncID) = cCur(GetDataTop(0,N)) Then
			If tp = 1 Then
				GetDataTop(IndexN,N) = cCur(GetDataTop(IndexN,N)) + Value
			Else
				GetDataTop(IndexN,N) = Value
			End If
			Application.Lock
			Application(DEF_MasterCookies & "TopAnc" & Str) = GetDataTop
			Application.UnLock
			Exit Sub
		End If
	Next

End Sub

Sub MakeGoodAnnouncePrize

	Dim Form_AddPoints,SavePoints
	Form_AddPoints = Request.Form("Form_AddPoints")
	If isNumeric(Form_AddPoints) = 0 then Form_AddPoints = 0
	Form_AddPoints = Fix(cCur(Form_AddPoints))
	If Form_AddPoints < 0-Abs(DEF_BBS_PrizeAnnouncePoints) or Form_AddPoints > Abs(DEF_BBS_PrizeAnnouncePoints) Then Form_AddPoints = 0
	If Form_AddPoints = 0 Then
		Response.Write "成功操作，但用户" & DEF_PointsName & "无任何改动．"
		Exit Sub
	End If
	
	If LMT_UserID = GBL_UserID Then
		Response.Write "不能为自己加分，用户" & DEF_PointsName & "无任何改动．"
		Exit Sub
	End If
	Dim Rs
	Set Rs = Con.ExeCute("Select top 1 SavePoints from LeadBBS_SiteInfo")
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		SavePoints = 0
	Else
		SavePoints = cCur(Rs(0))
	End If
	
	If SavePoints <= 0 Then
		Response.Write "论坛奖罚值已经不够用，操作失败．"
		Exit Sub
	End If

	Con.ExeCute("Update LeadBBS_User Set Points=Points+" & Form_AddPoints & " where ID=" & LMT_UserID)
	Con.ExeCute("Update LeadBBS_SiteInfo Set SavePoints=SavePoints-" & Abs(Form_AddPoints))
	Con.ExeCute("insert into LeadBBS_Log(LogType,LogTime,LogInfo,UserName,IP,BoardID) Values(105," & GetTimeValue(DEF_Now) & ",'针对帖子：版面编号" & GBL_Board_ID & "帖子编号" & GoodID & " 作者编号:" & LMT_UserID & " 奖罚数:" & Form_AddPoints & "．','" & Replace(Replace(htmlencode(Left(GBL_CHK_User,14)),"\","\\"),"'","''") & "','" & Replace(GBL_IPAddress,"'","''") & "'," & GBL_Board_ID & ")")
	GBL_DBNum = GBL_DBNum + 3
	Response.Write "成功完成对用户的奖罚，并已录入奖罚日志．" & VbCrLf

End Sub%>