<!-- #include file=../../inc/BBSsetup.asp -->
<!-- #include file=../../inc/Board_Popfun.asp -->
<!-- #include file=../../inc/Limit_fun.asp -->
<!-- #include file=../inc/bbsmanage_Fun.asp -->
<%
DEF_BBS_HomeUrl = "../../"
server.scriptTimeOut = 9999
initDatabase
GBL_UserID = checkSupervisorPass
GBL_CHK_TempStr = ""
siteHead("   合并(转移)版面")

dim BoardName
%>
<script language=javascript>
	window.moveTo(window.screen.width/2-225,window.screen.height/2-18);
</script>
<%
If GBL_CHK_Flag=1 and GBL_CHK_TempStr = "" Then
	If CheckIsCanMoveSure = 1 Then
		DisplayMoveAnnounce
	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 CheckIsCanMoveSure

	If GetBinarybit(GBL_CHK_UserLimit,9) = 1 Then
		Response.Write "错误,权限不足!<br>" & VbCrLf
		Exit Function
	End if
	Dim MoveFromBoardID
	MoveFromBoardID = Left(Request("MoveFromBoardID"),14)
	If isNumeric(MoveFromBoardID) = 0 or inStr(MoveFromBoardID,",") > 0 or MoveFromBoardID = "" Then
		Response.Write "错误,请提供要全并的原始的论坛ID!<br>" & VbCrLf
		Exit Function
	End if

	MoveFromBoardID = cCur(MoveFromBoardID)
	Dim Rs,SQL
	Set Rs = Server.CreateObject("ADODB.RecordSet")
	SQL = "Select top 1 BoardID,BoardName from LeadBBS_Boards where BoardID=" & MoveFromBoardID
	Rs.Open SQL,con,1,1
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Response.Write "错误,要合并的原始的论坛ID不存在!<br>" & VbCrLf
		Rs.Close
		Set Rs = Nothing
		CheckIsCanMoveSure = 0
		Exit Function
	End if

	Dim BoardID
	BoardID = Rs("BoardID")
	BoardName = Rs(1)

	Rs.Close
	Set Rs = Nothing
	CheckIsCanMoveSure = 1

End Function

Function DisplayMoveAnnounce

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

	Response.Flush
	If Request.Form("MoveSureFlag")="dk9@dl9s92lw_SWxl" Then
		
		MoveFromBoardID = cCur(MoveFromBoardID)
		Dim Rs,SQL
		Set Rs = Server.CreateObject("ADODB.RecordSet")
		SQL = "Select top 1 BoardID,BoardName,BoardAssort from LeadBBS_Boards where BoardID=" & MoveFromBoardID
		Rs.Open SQL,con,1,1
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Response.Write "错误,源版面不存在!<br>" & VbCrLf
			Rs.Close
			Set Rs = Nothing
			Exit Function
		End if
		
		Dim BoardID,BoardAssort
		BoardID = cCur(Rs(0))
		BoardName = Rs(1)
		BoardAssort = cCur(Rs(2))
		Rs.Close
		
		Dim BoardID2
		BoardID2 = Left(Request("BoardID2"),14)
		If isNumeric(BoardID2) = 0 or inStr(BoardID2,",") > 0 or BoardID2 = "" Then BoardID2 = 0
		BoardID2 = cCur(BoardID2)
		If BoardID2 < 1 Then
			Response.Write "错误,目标论坛不存在!!<br>" & VbCrLf
			Set Rs = Nothing
			Exit Function
		End if
		
		If BoardID2 = BoardID Then
			Response.Write "目标论坛就是主题所在论坛,所以不需要转移!!<br>" & VbCrLf
			Set Rs = Nothing
			Exit Function
		End if
	
		Dim BoardName2,BoardAssort2
		Rs.Open "Select BoardName,BoardAssort from LeadBBS_Boards Where BoardID = " & BoardID2,con,1,1
		GBL_DBNum = GBL_DBNum + 1
		If Not Rs.Eof Then
			BoardName2 = Rs("BoardName")
			BoardAssort2 = cCur(Rs(1))
		Else
			Response.Write "错误,目标论坛不存在!<br>" & VbCrLf
			Rs.Close
			Set Rs = Nothing
			Exit Function
		End if
		Rs.Close
		Set Rs = Nothing

		Dim NowID,EndFlag,GetData,n
		EndFlag = 0
		Response.Write "正在转移，请等待出现完成：□"
		Response.Flush
		Do while EndFlag = 0
			SQL = "Select top 100 ID from LeadBBS_Topic where BoardID=" & MoveFromBoardID
			Set Rs = Con.ExeCute(SQL)
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				EndFlag = 1
				Rs.Close
				Set Rs = Nothing
				Exit Do
			Else
				GetData = Rs.GetRows(-1)
				Rs.Close
				Set Rs = Nothing
				SQL = Ubound(GetData,2)
				For N = 0 to SQL
					NowID = cCur(GetData(0,n))
					Con.ExeCute ("Update LeadBBS_Announce Set BoardID=" & BoardID2 & " where RootIDBak=" & NowID)
					Con.ExeCute ("Update LeadBBS_Topic Set BoardID=" & BoardID2 & " where ID=" & NowID)
					MakeAnnounceTop(NowID)
					GBL_DBNum = GBL_DBNum + 1
				Next
				Response.Write "■"
				Response.Flush
			End If
		Loop
		Con.ExeCute ("Update LeadBBS_TopAnnounce Set BoardID=" & BoardID2 & " where BoardID=" & BoardID)
		GBL_DBNum = GBL_DBNum + 1
		UpdateBoardValue(BoardID)
		UpdateBoardValue(BoardID2)
		ReloadTopAnnounceInfo(0)
		ReloadTopAnnounceInfo(BoardAssort)
		ReloadTopAnnounceInfo(BoardAssort2)

		Response.Write "<font color=008800 class=GreenFont>版面" & BoardName & "成功转移到" & BoardName2 & "!!</font>" & VbCrLf
	Else
		%>
		<form name=DellClientForm action=BoardMoveAnnounce.asp method=post>
			<input type=hidden name=MoveSureFlag value="dk9@dl9s92lw_SWxl">
			<input type=hidden name=MoveFromBoardID value="<%=MoveFromBoardID%>">
			<input type=hidden name=BoardID value="<%=GBL_Board_ID%>">
			<b>此操作不可逆,确认要转移版面<font color=ff0000 class=RedFont><%=BoardName%></font>的帖子吗？</b>
			<br>转换时间视帖子总数而定，如果帖子巨多，建议先暂停论坛再作执行．
<!-- #include file=../../inc/incHTM/BoardForMoveList.asp -->
			<br><input type=submit value=确定 class=fmbtn>
			<input type=button value=取消此操作 onclick="javascript:window.close();" class=fmbtn>
		</form>
		<%
	End If

End Function

Function UpdateBoardValue(BoardID)

	Dim Rs,GetData,BoardNum
	Set Rs = Server.CreateObject("ADODB.RecordSet")

		Dim N,TopicNum,AnnounceNum,AllMinRootID,AllMaxRootID,TodayAnnounce,GoodNum
		Dim LastAnnounceID,LastTopicName,LastWriter,LastTime
			Rs.Open "select count(*) from LeadBBS_Topic where GoodFlag=1 and BoardID=" & BoardID,con,1,1
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				GoodNum = 0
			Else
				GoodNum = Rs(0)
				If isNull(GoodNum) Then GoodNum = 0
				GoodNum = cCur(GoodNum)
			End If
			Rs.Close

			Rs.Open "select count(*) from LeadBBS_Announce where BoardID=" & BoardID & " and ndatetime>" & Left(GetTimeValue(DEF_Now),8) & "000000",con,1,1
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				TodayAnnounce = 0
			Else
				TodayAnnounce = Rs(0)
				If isNull(TodayAnnounce) Then TodayAnnounce = 0
				TodayAnnounce = cCur(TodayAnnounce)
			End If
			Rs.Close

			Rs.Open "select count(*) from LeadBBS_Topic where BoardID=" & BoardID,con,1,1
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				TopicNum = 0
			Else
				TopicNum = Rs(0)
				If isNull(TopicNum) Then TopicNum = 0
				TopicNum = cCur(TopicNum)
			End If
			Rs.Close
			
			Rs.Open "select count(*) from LeadBBS_Announce where BoardID=" & BoardID,con,1,1
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				AnnounceNum= 0
			Else
				AnnounceNum = Rs(0)
				If isNull(TopicNum) Then AnnounceNum = 0
				AnnounceNum = cCur(AnnounceNum)
			End If
			Rs.Close
			
			Rs.Open "select Min(RootID) from LeadBBS_Topic where BoardID=" & BoardID,con,1,1
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				AllMinRootID = 0
			Else
				AllMinRootID = Rs(0)
				If isNull(AllMinRootID) Then AllMinRootID = 0
				AllMinRootID = cCur(AllMinRootID)
			End If
			Rs.Close
		
			Rs.Open "select Max(RootID) from LeadBBS_Topic where BoardID=" & BoardID,con,1,1
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				AllMaxRootID = 0
			Else
				AllMaxRootID = Rs(0)
				If isNull(AllMaxRootID) Then AllMaxRootID = 0
				AllMaxRootID = cCur(AllMaxRootID)
			End If
			Rs.Close

			Rs.Open "Select top 1 ID,title,LastUser,UserName,LastTime from LeadBBS_Topic where BoardID=" & BoardID & " and RootID<" & DEF_BBS_TOPMinID & " order By RootID DESC",con,1,1
			GBL_DBNum = GBL_DBNum + 1
			If Rs.Eof Then
				LastAnnounceID = 0
				LastTopicName = ""
				LastTime = 0
			Else
				LastAnnounceID = Rs(0)
				LastTopicName = Rs(1)
				LastWriter = Rs(2)
				If LastWriter = "" or isNull(LastWriter) Then LastWriter = Rs(3)
				LastTime = cCur(Rs(4))
				If isNull(LastTime) then LastTime = 0
			End If
			Rs.Close
			Con.ExeCute ("Update LeadBBS_Boards Set TopicNum=" & TopicNum & ",AnnounceNum=" & AnnounceNum & ",AllMinRootID=" & AllMinRootID & ",AllMaxRootID=" & AllMaxRootID & ",TodayAnnounce=" & TodayAnnounce & ",GoodNum=" & GoodNum & ",LastAnnounceID=" & LastAnnounceID & ",LastTopicName='" & Replace(LastTopicName,"'","''") & "',LastWriter='" & Replace(LastWriter,"'","''") & "',LastWriteTime=" & LastTime & " where boardID=" & BoardID)
			GBL_DBNum = GBL_DBNum + 1
	Set Rs = Nothing
	ReloadBoardInfo(BoardID)

End Function


Function MakeAnnounceTop(AnnounceID)

	Dim Rs,SQL,BoardID,RootID,MaxRootID,RootIDBak
	SQL = "Select top 1 ID,RootID,BoardID,RootIDBak from LeadBBS_Announce where ID=" & AnnounceID
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		RootID = cCur(Rs(1))
		BoardID = cCur(Rs(2))
		RootIDBak = cCur(Rs(3))
		Rs.Close
		Set Rs = Nothing
	Else
		Rs.Close
		Set Rs = Nothing
		Exit function
	End If

	'If RootID<DEF_BBS_TOPMinID Then
		Set Rs = Con.ExeCute("Select Max(RootID) from LeadBBS_Topic where BoardID=" & BoardID & " and RootID<" & DEF_BBS_TOPMinID)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			MaxRootID = 1
		Else
			MaxRootID = Rs(0)
			If isNull(MaxRootID) or MaxRootID="" Then
				MaxRootID=1
			End If
			MaxRootID = cCur(MaxRootID)
		End If
		Rs.Close
		Set Rs = Nothing
		Con.ExeCute(" Update LeadBBS_Announce Set RootID=" & MaxRootID+1 & " where ID=" & RootIDBak)
	 	Con.ExeCute(" Update LeadBBS_Topic Set RootID=" & MaxRootID+1 & " where ID=" & RootIDBak)
	 	GBL_DBNum = GBL_DBNum + 1
	'Else
		
	'End If
	UpdateBoardValue(BoardID)

End Function

Sub ReloadTopAnnounceInfo(TID)

	If isNumeric(TID) = 0 Then Exit Sub
	TID = Fix(cCur(TID))
	Dim Rs,GetDataTop,TIDStr
	If TID = 0 Then
		TIDStr = ""
	Else
		TIDStr = TID
	End If
	Set Rs = Con.ExeCute("Select RootID,BoardID from LeadBBS_TopAnnounce where TopType=" & TID)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Application.Lock
		application(DEF_MasterCookies & "TopAnc" & TIDStr) = "yes"
		application(DEF_MasterCookies & "TopAncList" & TIDStr) = ""
		Application.UnLock
		Rs.Close
		Set Rs = Nothing
		Exit Sub
	Else
		GetDataTop = Rs.GetRows(-1)
		Rs.close
		Set Rs = Nothing
	End If
	
	Dim Temp,N
	Temp = ""
	If cCur(GetDataTop(0,0)) > 0 Then Temp = GetDataTop(0,0)
	For N = 1 to Ubound(GetDataTop,2)
		If cCur(GetDataTop(0,N)) > 0 Then Temp = Temp & "," & GetDataTop(0,N)
	Next
	If Left(Temp,1) = "," Then Temp = Mid(Temp,2)
	If cStr(Temp) <> "" Then
		Set Rs = Con.ExeCute("select top " & Ubound(GetDataTop,2)+1 & " id,ChildNum,Title,FaceIcon,LastTime,Hits,Length,UserName,UserID,RootID,LastUser,NotReplay,GoodFlag,BoardID,TopicType,PollNum,TitleStyle,LastInfo,ndatetime,GoodAssort from LeadBBS_Topic where ID in(" & Temp & ")")
		GBL_DBNum = GBL_DBNum + 1
		If Not Rs.Eof Then
			GetDataTop = Rs.GetRows(-1)
			Rs.Close
			Set Rs = Nothing
			Application.Lock
			application(DEF_MasterCookies & "TopAnc" & TIDStr) = GetDataTop
			Application.UnLock
			Application.Lock
			application(DEF_MasterCookies & "TopAncList" & TIDStr) = "," & Temp & ","
			Application.UnLock
		Else
			Rs.Close
			Set Rs = Nothing
			Application.Lock
			application(DEF_MasterCookies & "TopAnc" & TIDStr) = "yes"
			Application.UnLock
		End If
	Else
		Application.Lock
		application(DEF_MasterCookies & "TopAnc" & TIDStr) = "yes"
		Application.UnLock
	End If

End Sub%>