<%
Function DisplayAnnouncesSplitPages

	Dim Rs,SQL,Temp,RootFlagStr,RootFlagStr1,RootFlag
	Dim ALL_FirstRootID,ALL_LastRootID

	Dim SQLEndString,WhereFlag,OrderColumn,BoardUrlString
	RootFlag = Request("RootFlag")
	Select Case RootFlag
		Case "1":
			OrderColumn = "ID"
			WhereFlag = 0
			SQLEndString = " from LeadBBS_Topic "
			RootFlagStr = "主题"
			RootFlagStr1 = "<b>查看社区全部主题</b>"
		Case "2":
			OrderColumn = "ID"
			WhereFlag = 1
			SQLEndString = " from LeadBBS_Topic where GoodFlag=1 "
			RootFlagStr = "精华帖子"
			RootFlagStr1 = "查看社区全部精华帖子"
		Case Else:
			WhereFlag = 0
			OrderColumn = "ID"
			SQLEndString = " from LeadBBS_Announce "
			RootFlagStr = "帖子"
			RootFlagStr1 = "<b>查看社区全部帖子</b>"
	End Select
	BoardUrlString = "List.asp"
	SQL = "Select Max(" & OrderColumn & ") " & SQLEndString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		ALL_FirstRootID = Rs(0)
		If isNull(ALL_FirstRootID) Then ALL_FirstRootID = 0
		ALL_FirstRootID = cCur(ALL_FirstRootID)
	Else
		ALL_FirstRootID = 0
	End If
	Rs.Close
	Set Rs = Nothing

	SQL = "Select Min(" & OrderColumn & ") " & SQLEndString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		ALL_LastRootID = Rs(0)
		If isNull(ALL_LastRootID) Then ALL_LastRootID = 0
		ALL_LastRootID = cCur(ALL_LastRootID)
	Else
		ALL_LastRootID = 0
	End If
	Rs.Close
	Set Rs = Nothing
	Dim ALL_Count
	
	Rem SQL = "Select count(*) " & SQLEndString
	Rem 下面的语句比上面的速度快,因为版面少,而当主题和帖子越多时,采下下面的速度就会越快
	
	If RootFlag <> "2" Then
		If RootFlag = "1" Then
			SQL = "Select sum(TopicNum) from LeadBBS_Boards"
		Else
			SQL = "Select sum(AnnounceNum) from LeadBBS_Boards"
		End If
	Else
		'SQL = "Select count(*) " & SQLEndString
		SQL = "Select sum(GoodNum) from LeadBBS_Boards"
	End If
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		If isNull(Rs(0)) Then
			ALL_Count = 0
		Else
			ALL_Count = cCur(Rs(0))
		End If
	Else
		ALL_Count = 0
	End If
	Rs.Close
	Set Rs = Nothing
	Dim RootID,Temp1,Temp2
	Dim Upflag

	RootID = Left(Request("RootID"),14)
	If isNumeric(RootID)=0 Then RootID=0
	RootID = cCur(RootID)

	Dim LastNum
	LastNum = 0

	Upflag = Request("Upflag")
	If Upflag<>"1" and Upflag<>"0" Then Upflag="0"
	If Upflag = "1" Then
		LastNum = Request("Num")
		If LastNum <> "" Then
			LastNum = (ALL_Count mod DEF_MaxListNum)
			If LastNum = 0 Then LastNum = DEF_MaxListNum
		End If
	End If	

	Dim HaveRootIDFlag
	Dim FirstRootID,LastRootID

	If Temp1+1<DEF_MaxListNum Then
		If Upflag="0" Then
			If RootID<>0 Then
				If WhereFlag = 1 Then
					SQLEndString = SQLEndString & " And " & OrderColumn & "<" & RootID
				Else
					SQLEndString = SQLEndString & " Where " & OrderColumn & "<" & RootID
					WhereFlag = 1
				End If
			End If
		Else
			If RootID>=ALL_FirstRootID Then
				RootID = ALL_FirstRootID-1
				TopicSortID = ALL_FirstRootID + 1
			
				If RootID<>0 Then
					If WhereFlag = 1 Then
						SQLEndString = SQLEndString & " And " & OrderColumn & ">" & RootID
					Else
						SQLEndString = SQLEndString & " Where " & OrderColumn & ">" & RootID
						WhereFlag = 1
					End If
				End If
			Else
				If RootID<>0 Then
					If WhereFlag = 1 Then
						SQLEndString = SQLEndString & " And " & OrderColumn & ">" & RootID
					Else
						SQLEndString = SQLEndString & " Where " & OrderColumn & ">" & RootID
						WhereFlag = 1
					End If
				End If
			End If
		End If

		If Upflag="0" Then
			SQLEndString = SQLEndString & " order by " & OrderColumn & " DESC"
		Else
			SQLEndString = SQLEndString & " order by " & OrderColumn & " ASC"
		End If

		Dim FirstRootID_2,LastRootID_2
		Dim GetData_2

		If LastNum > 0 Then
			Temp = LastNum
		Else
			Temp = DEF_MaxListNum
		End If

		If RootFlag = "1" or RootFlag = "2" Then
			SQL = "select top " & Temp & " id,0,ChildNum,0,Title,FaceIcon,LastTime,Hits,Length,UserName,UserID,ID,0,LastUser,NotReplay,GoodFlag,BoardID,TopicType,PollNum,TitleStyle " & SQLEndString
		Else		
			SQL = "select top " & Temp & " id,ParentID,ChildNum,Layer,Title,FaceIcon,LastTime,Hits,Length,UserName,UserID,RootIDBak,TopicSortID,LastUser,NotReplay,GoodFlag,BoardID,TopicType,PollNum,TitleStyle " & SQLEndString
		End If
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Not Rs.Eof Then
			HaveRootIDFlag = 1
			GetData_2 = Rs.GetRows(Temp)
		Else
			HaveRootIDFlag = 0
		End If
		Rs.Close
		Set Rs = Nothing
	
		If HaveRootIDFlag = 1 Then
			Temp2 = Ubound(GetData_2,2)
			If RootFlag = "1" Then
				FirstRootID_2 = cCur(GetData_2(11,0))
				LastRootID_2 = cCur(GetData_2(11,Temp2))
			Else
				FirstRootID_2 = cCur(GetData_2(0,0))
				LastRootID_2 = cCur(GetData_2(0,Temp2))
			End If
				
			If FirstRootID_2<LastRootID_2 Then
				SQL = FirstRootID_2
				FirstRootID_2 = LastRootID_2
				LastRootID_2 = SQL
			End If
	
			LastRootID = LastRootID_2
			FirstRootID = FirstRootID_2
		Else
			Temp2 = 0
		End If
	Else
		HaveRootIDFlag = 0
	End If

	SQL = "?RootFlag=" & urlencode(Request("RootFlag"))
	Dim PageSplitString,PageSplitString2
	PageSplitString = "<tr bgcolor=" & DEF_BBS_LightestColor & " height=25 class=TBBG9><td colspan=5><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td><img src=..images/null.gif width=2 height=3><br>&nbsp;"
	If FirstRootID >= All_FirstRootID Then
		PageSplitString = PageSplitString & "<font color=888888 class=GrayFont>首页</font>"
		PageSplitString = PageSplitString & " <font color=888888 class=GrayFont>上页</font>"
	Else
		PageSplitString = PageSplitString & "<a href=" & BoardUrlString & SQL & ">首页</a>"
		PageSplitString = PageSplitString & " <a href=" & BoardUrlString & SQL & "&RootID=" & FirstRootID & "&Upflag=1>上页</a>"
	End If

	If LastRootID <= All_LastRootID Then
		PageSplitString = PageSplitString & " <font color=888888 class=GrayFont>下页</font>"
		PageSplitString = PageSplitString & " <font color=888888 class=GrayFont>尾页</font>"
	Else
		PageSplitString = PageSplitString & " <a href=" & BoardUrlString & SQL & "&RootID=" & LastRootID & ">下页</a>"
		PageSplitString = PageSplitString & " <a href=" & BoardUrlString & SQL & "&Upflag=1&Num=1>尾页</a>"
	End If
	Rs = Temp1
	Rs = Temp2+Rs
	If HaveRootIDFlag = 1 Then Rs = Rs+1

	PageSplitString = PageSplitString & " 共有<b>" & ALL_Count &"</b>" & RootFlagStr & " 此页<b>" & Rs & "</b>条 每页<b>" & DEF_MaxListNum & "</b>条<td align=right><img src=" & DEF_BBS_HomeUrl & "images/null.gif width=2 height=2><br>"
	PageSplitString2 = "</td></tr></table></td></tr>"
	If Rs < DEF_MaxListNum and GBL_ShowBottomSure = 0 Then GBL_SiteBottomString = ""

	Dim For1,For2,StepValue

	If GBL_TableHeadString <> "" Then
		Response.Write "<table width=100% border=0 cellspacing=0 cellpadding=0 align=center><tr><td>"
		Response.Write GBL_TableHeadString
		Response.Write "</td></tr></table>"
	End If%>

	<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
	<tr bgcolor=<%=DEF_BBS_LightColor%> class=TBBG1>
		<td height=20><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br>&nbsp;<b>查看社区信息</b> - 
		<%If RootFlag <> "2" and RootFlag <> "1" Then%><font color=888888 class=GrayFont>查看社区全部帖子</font><%Else%>
		<a href=List.asp>查看社区全部帖子</a><%End If%>&nbsp;
		<%If RootFlag = "1" Then%><font color=888888 class=GrayFont>查看社区全部主题</font><%Else%>
		<a href=List.asp?RootFlag=1>查看社区全部主题</a><%End If%>&nbsp;
		<%If RootFlag = "2" Then%><font color=888888 class=GrayFont>查看社区全部精华帖子</font><%Else%>
		<a href=List.asp?RootFlag=2>查看社区全部精华帖子</a><%End If%>
		</td>
	</tr>
	</table>
	<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
	<%Response.Write PageSplitString
	Response.Write PageSplitString2%>
	<tr height=20 bgcolor=<%=DEF_BBS_LightDarkColor%> align=center class=TBHead2>
		<td width=20 align=center><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br><b><font color=ffffff class=HeadFont>ID</font></b></td>
		<td align=left><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=300 height=2><br>&nbsp;<b><font color=ffffff class=HeadFont>主题</font></b></td>
		<td width=84><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br><b><font color=ffffff class=HeadFont>作者</font></b></td>
		<td width=50 align=center><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=2 height=2><br><b><font color=ffffff title="回复/点击" class=HeadFont>人气</font></b></td>
		<td width=210 align=left><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=5 height=2><br><img src=<%=DEF_BBS_HomeUrl%>images/null.gif width=3 height=2><b><font color=ffffff class=HeadFont>　　最后更新　　| 回复人</font></b></td>
	</tr><%
	If Upflag="0" Then
		If HaveRootIDFlag = 1 Then
			If Upflag="0" Then
				For1 = 0
				For2 = Temp2
				StepValue = 1
			Else
				For1 = Temp2
				For2 = 0
				StepValue = -1
			End If
			DisplayAnnounceData For1,For2,StepValue,GetData_2,0
		End If
	Else

		If HaveRootIDFlag = 1 Then
			If Upflag="0" Then
				For1 = 0
				For2 = Temp2
				StepValue = 1
			Else
				For1 = Temp2
				For2 = 0
				StepValue = -1
			End If
			DisplayAnnounceData For1,For2,StepValue,GetData_2,0
		End If
	End If
	Response.Write PageSplitString
	%>
	<!-- #include file=../../inc/IncHtm/BoardJump.asp -->
	<%
	Response.Write PageSplitString2
	Response.Write "</table>"
	If GBL_TableBottomString <> "" Then
		%><table width=100% border=0 cellspacing=0 cellpadding=0 align=center><tr><td><%=GBL_TableBottomString%></td></tr></table><%
	End If

End Function

Function DisplayAnnounceData(For1,For2,StepValue,GetData,AllFlag)
	
	Dim AnnounceUrlString
	AnnounceUrlString = "Announce2.asp"

	Dim N,Temp,Temp1
	For N = For1 to For2 Step StepValue
		Response.Write "<tr align=center height=25"

		Response.Write " bgcolor=" & DEF_BBS_LightestColor
		Response.Write " class=TBBG9><td>"

		If cCur(GetData(11,N))>=DEF_BBS_TOPMinID And cCur(GetData(1,N))=0 Then
			Temp = "intop"
		Else
			If GetData(17,n) = 80 Then
				If cCur(GetData(18,N)) >= 20 Then
					Temp = "vthot"
				Else
					Temp = "vt"
				End If
			Else
				If cCur(GetData(2,N)) >= 20 Then
					Temp = "hot"
				Else
					Temp = "tpc"
				End If
			End If
			If GetData(14,n) = 1 Then Temp = Temp & "lock"
		End If
		Response.Write "<img src=../images/" & GBL_DefineImage & Temp & ".gif align=absbottom width=18 height=18 title=""编号" & GetData(0,N) & """>"
		Response.Write "</td><td align=left>"

		Rem 不显示Layer值
		'If GetData(3,N)>DEF_BBS_MaxLayer Then GetData(3,N)=10
		'Response.Write Replace(string((GetData(3,N)-1),"-"),"-","<ul>")
		Response.Write "<img src=../images/" & GBL_DefineImage & "bf/face" & GetData(5,N) & ".gif align=absbottom width=20 height=20>"

		GetData(8,N) = cCur(GetData(8,N))
		If GetData(8,N) > 1024 Then
			GetData(8,N) = cLng(GetData(8,N)/1024) & " KB"
		Else
			GetData(8,N) = GetData(8,N) & " 字节"
		End If

		If cCur(GetData(1,n)) = 0 Then
			AnnounceUrlString = "Announce.asp"
		Else
			AnnounceUrlString = "Announce2.asp"
		End If
		Response.Write " <a href=../Announce/" & AnnounceUrlString & "?BoardID=" & GetData(16,N) & "&ID=" & GetData(0,N) & " title=""" & GetData(8,N) & """"
		If AllFlag = 1 Then
			Response.Write " target=_blank>"
		Else
			Response.Write ">"
		End If

		GetData(2,N) = cCur(GetData(2,N))
		Temp1 = Fix((GetData(2,N)+1)/DEF_TopicContentMaxListNum)
		If ((GetData(2,N)+1) mod DEF_TopicContentMaxListNum) > 0 Then Temp1 = Temp1 + 1
		If GetData(2,N)>=DEF_TopicContentMaxListNum Then
			Temp = DEF_BBS_DisplayTopicLength - (Len(Temp1) + 3)
		Else
			Temp = DEF_BBS_DisplayTopicLength
		End If
		
		If GetData(15,n) = True or GetData(15,n) = 1 Then Temp = Temp - 3

		If left(GetData(4,N),3) = "re:" and GetData(4,N) <> "re:" Then GetData(4,N) = Mid(GetData(4,N),4)
		If GetData(19,n) <> 1 and strLength(GetData(4,N))>Temp Then GetData(4,N) = LeftTrue(GetData(4,N),Temp-3) & "..."
		Response.Write DisplayAnnounceTitle(GetData(4,n),GetData(19,n))
		Response.Write "</a>"

		If GetData(2,N)>=DEF_TopicContentMaxListNum Then
			Response.Write " [<a href=../Announce/Announce.asp?BoardID=" & GetData(16,N) & "&ID=" & GetData(0,N) & "&AUpflag=1&ANum=1>" & Temp1 & "</b></a>]"
		End If

		'If GetData(15,n) = 1 or GetData(15,n) = True Then
		'	Response.Write "<img src=../images/" & GBL_DefineImage & "jh1.GIF border=0 title=精华帖子 align=absbottom width=15 height=16>"
		'End If

		GetData(10,N) = cCur(GetData(10,N))
		If GetData(10,N) > 0 Then
			Response.Write "</td><td><a href=../User/LookUserInfo.asp?ID=" & GetData(10,N) & ">" & htmlencode(GetData(9,N)) & "</a></td><td>"
		Else
			Response.Write "</td><td>" & htmlencode(GetData(9,N)) & "</td><td>"
		End If

		If isNull(GetData(18,N)) Then GetData(18,N) = 0
		If GetData(17,n) = 80 Then
			Response.Write "共" & cCur(GetData(18,N)) & "票"
		Else
			Response.Write GetData(2,N) & "/" & GetData(7,N)
		End If
		Response.Write "</td><td width=210 align=left>&nbsp;"
		Temp = RestoreTime(GetData(6,N))
		If DateDiff("d",Temp,DEF_Now)<1 Then Response.Write "<font color=990000 class=RedFont>"
		If GetData(13,n) = "" or isNull(GetData(13,n)) Then
			Response.Write Left(Temp,16) & " | --------</td></tr>"
		Else
			If GetData(10,N) <> "游客" Then
				Response.Write Left(Temp,16) & " | <a href=" & DEF_BBS_HomeUrl & "User/LookUserInfo.asp?ID=" & urlencode(GetData(13,N)) & ">" & htmlencode(GetData(13,n)) & "</a></td></tr>"
			Else
				Response.Write Left(Temp,16) & " | " & htmlencode(GetData(13,n)) & "</td></tr>"
			End If
		End if
	Next

End Function
%>