<!-- #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 GoodAssort
%>
<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 CheckIsCanRepairSure = 1 Then
		DisplayRepairAnnounce
	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 CheckIsCanRepairSure

	Dim RepairID
	RepairID = Left(Request("RepairID"),14)
	If isNumeric(RepairID) = 0 or inStr(RepairID,",") > 0 or RepairID = "" Then
		Response.Write "错误,请提供要修复的帖子的ID!<br>" & VbCrLf
		CheckIsCanRepairSure = 0
		Exit Function
	End if

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

	RepairID = cCur(RepairID)
	Dim Rs,SQL
	SQL = "Select top 1 BoardID,0,UserID,RootID,GoodAssort from LeadBBS_Topic where id=" & RepairID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Response.Write "错误,要修复的帖子ID不存在!<br>" & VbCrLf
		Rs.Close
		Set Rs = Nothing
		CheckIsCanRepairSure = 0
		Exit Function
	End if

	GBL_Board_ID = cCur(Rs("BoardID"))
	GoodAssort = cCur(Rs("GoodAssort"))
	Rs.Close
	Set Rs = Nothing
	
	SQL = "Select top 1 MasterList from LeadBBS_Boards where BoardID=" & GBL_Board_ID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		GBL_Board_MasterList = Rs(0)
	Else
		Response.Write "错误B,社区发生错误,请联系管理员!<br>" & VbCrLf
		Rs.Close
		Set Rs = Nothing
		CheckIsCanRepairSure = 0
		Exit Function
	End if
	Rs.Close
	Set Rs = Nothing
	
	CheckisBoardMaster
	If GBL_UserID >= 1 and (GBL_BoardMasterFlag >= 5 and GetBinarybit(GBL_CHK_UserLimit,4) = 0) Then
		CheckIsCanRepairSure = 1
	Else
		CheckIsCanRepairSure = 0
		Response.Write "错误,权限不足."
	End If

End Function


Function DisplayRepairAnnounce

	Dim RepairID
	RepairID = Left(Request("RepairID"),14)
	If isNumeric(RepairID) = 0 or inStr(RepairID,",") > 0 or RepairID = "" Then
		Response.Write "错误,请提供要修复的帖子的ID!<br>" & VbCrLf
		Exit Function
	End if
	If Request.Form("submitFlag")="dk9@dl9s92lw_SWxl" Then
		RepairID = cCur(RepairID)
		RepairAnnounce(RepairID)
		Response.Write "成功修复社区帖子，请按ESC键退出。"
	Else
		%>
		<form name=DellClientForm action=RepairAnnounce.asp method=post>
			<input type=hidden name=submitFlag value="dk9@dl9s92lw_SWxl">
			<input type=hidden name=RepairID value="<%=RepairID%>">
			<input type=hidden name=BoardID value="<%=GBL_Board_ID%>">
			<b>确认要修复编号为<font color=ff0000 class=RedFont><%=RepairID%></font>的帖子吗？</b>
			<%DisplayEType%>
			<p><input type=submit value=确定 class=fmbtn>
			<input type=button value=取消此操作 onclick="javascript:window.close();" class=fmbtn>
		</form>
		<%
	End If

End Function

Function DisplayEType

	Dim TArray,N,Num
	TArray = Application(DEF_MasterCookies & "BoardInfo" & GBL_Board_ID & "_TI")
	If isArray(TArray) = False Then Exit Function
	Num = Ubound(TArray,2)
	%>
	<br>修改所属专题区 <select name="GoodAssort">
		<option class=TBBG9 value=0>===选择专题区===</option>
	<%
	For N = 0 To Num
		If GoodAssort = cCur(TArray(0,N)) Then
			Response.Write "		<option class=TBBG9 value=" & TArray(0,N) & " selected>" & TArray(1,N) & "</a>" & VbCrLf
		Else
			Response.Write "		<option class=TBBG9 value=" & TArray(0,N) & ">" & TArray(1,N) & "</a>" & VbCrLf
		End If
	Next%>
	</Select>
	<%

End Function

Function RepairAnnounce(ID)

	Dim Rs,SQL,RootID,ParentID,BoardID,RootIDBak
	SQL = "Select top 1 RootID,0,BoardID,ID from LeadBBS_Topic where ID=" & ID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Rs.Close
		Set Rs = Nothing
		Exit function
	Else
		RootID = cCur(Rs(0))
		ParentID = cCur(Rs(1))
		BoardID = cCur(Rs(2))
		RootIDBak = cCur(Rs(3))
		Rs.Close
		Set Rs = Nothing
	End If
	
	If ParentID <> 0 Then Exit Function

	Dim GoodAssort_Old
	GoodAssort_Old = GoodAssort
	GoodAssort = Left(Request.Form("GoodAssort"),14)
	If isNumeric(GoodAssort) = 0 Then GoodAssort = 0
	GoodAssort = Fix(cCur(GoodAssort))
	If CheckGoodAssort(GoodAssort) = 0 Then GoodAssort = GoodAssort_Old
	
	Dim Count
	SQL = "select count(*) from LeadBBS_Announce where RootIDBak=" & RootIDBak
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Count = 0
	Else
		Count = Rs(0)
		If IsNull(Count) then Count = 0
		Count = cCur(Count)
		Count = Count - 1
		If Count < 0 Then Count = 0
	End If
	Rs.Close
	Set Rs = Nothing

	Dim RootMaxID,RootMinID
	SQL = "select max(ID) from LeadBBS_Announce where RootIDBak=" & RootIDBak
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		RootMaxID = Rs(0)
		If IsNull(RootMaxID) then RootMaxID = 0
	Else
		RootMaxID = 0
	End if
	Rs.Close
	Set Rs = Nothing
	SQL = "select Min(ID) from LeadBBS_Announce where RootIDBak=" & RootIDBak
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		RootMinID = Rs(0)
		If IsNull(RootMinID) then RootMinID = 0
	Else
		RootMinID = 0
	End if
	Rs.Close
	Set Rs = Nothing
	Con.Execute("Update LeadBBS_Announce set RootMaxID=" & RootMaxID &_
		",RootMinID=" & RootMinID &_
		",ChildNum=" & Count & ",GoodAssort=" & GoodAssort & " where ID=" & ID)
	GBL_DBNum = GBL_DBNum + 1
	Con.Execute("Update LeadBBS_Topic set RootMaxID=" & RootMaxID &_
		",RootMinID=" & RootMinID &_
		",ChildNum=" & Count & ",GoodAssort=" & GoodAssort & " where ID=" & ID)
	GBL_DBNum = GBL_DBNum + 1

	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
	ChangeGoodAssort GoodAssort_Old,GoodAssort

End Function

Sub ChangeGoodAssort(ID,ID2)

	If ID = ID2 Then Exit Sub
	Dim TArray,N,Num,NN,ExitN
	TArray = Application(DEF_MasterCookies & "BoardInfo" & GBL_Board_ID & "_TI")
	If isArray(TArray) = False Then
		CheckGoodAssort = 0
		Exit Sub
	End If
	Num = Ubound(TArray,2)
	NN = 0
	ExitN = 3
	If ID = 0 or ID2 = 0 Then ExitN = 1
	For N = 0 To Num
		If ID = cCur(TArray(0,N)) Then
			If cCur(TArray(2,N)) = -1 Then
				TArray(3,N) = 0
				TArray(4,N) = 0
			Else
				TArray(2,N) = cCur(TArray(2,N)) - 1
				TArray(3,N) = 0
				TArray(4,N) = 0
			End If
			NN = NN + 1
			If NN >= ExitN Then Exit For
		End If
		If ID2 = cCur(TArray(0,N)) Then
			If cCur(TArray(2,N)) <> 0 Then
				If cCur(TArray(2,N)) = -1 Then
					TArray(2,N) = 1
					TArray(3,N) = 0
					TArray(4,N) = 0
				Else
					TArray(2,N) = cCur(TArray(2,N)) + 1
					TArray(3,N) = 0
					TArray(4,N) = 0
				End If
			End If
			TArray(2,N) = 0
			NN = NN + 1
			If NN >= ExitN Then Exit For
		End If
	Next
	If NN > 0 Then
		Application.Lock
		Application(DEF_MasterCookies & "BoardInfo" & GBL_board_ID & "_TI") = TArray
		Application.UnLock
	End If

End Sub

Function CheckGoodAssort(ID)

	Dim Rs
	If ID = 0 Then
		CheckGoodAssort = 1
		Exit Function
	End If
	Set Rs = Con.ExeCute("Select top 1 BoardID from LeadBBS_GoodAssort where ID=" & ID)
	GBL_DBNUm = GBL_DBNum + 1
	If Rs.Eof Then
		CheckGoodAssort = 0
	Else
		If cCur(Rs(0)) <> GBL_Board_ID Then
			CheckGoodAssort = 0
		Else
			CheckGoodAssort = 1
		End If
	End if
	Rs.Close
	Set Rs = Nothing

End Function%>