<!-- #include file=../../inc/BBSSetup.asp -->
<!-- #include file=../../inc/Board_Popfun.asp -->
<%
'----------------------------------------------------------------------------------------
'----- LeadBBS    官方新增参数：
'----- LeadBBS 主题帖子调用(2003-7-2)
'----- 调用举例: <script language=javascript src=http://安装目录/other/Article/topic.asp?BoardID=1&Number=20&StrLen=12&NewWindow=yes></script>
'----- 表示显示版面ＩＤ号为1的版面的最新20条主题，主题字数超过12个字节的以12字节显示(一个汉字为两个字节)
'----- 参数：BoardID 版面ＩＤ号，如果不指定，则表示调用论坛最新10条主题
'----- Number：显示记录条数，最多允许调用100条，不指定默认调用10条主题
'----- StrLen：有的帖子主题可能太长，为了美化显示效果，限制显示主题的字节长度
'----- NewWindow：在新窗口中打开请设置为yes，其它表示否
'----- PithFlag ：是否调用精华，1表示仅调用精华帖(可以加上BoardID限制调用版面)
'----------------------------------------------------------------------------------------
'----- simeonz  新增参数：
'----- TORA     ：从哪个表取结果。设为1从LeadBBS_Topic取结果，结果只含有主题帖；
'-----            设为0从LeadBBS_Announce取结果，结果有主题贴和回复贴；
'----- STime    ：是否在主题后面跟上日期时间。
'-----            1为显示日期和时间：如2003-08-29 20:30；
'-----            2为显示日期：如2003-08-29；
'-----            0日期与时间均不显示。
'----- POLL     ：可提取所有未过期的投票贴在首页上显示。1为显示。
'----------------------------------------------------------------------------------------
'----- Johnson_han 新增参数： 
'----- HotFlag  : 是否调用热帖（点击排行的主题帖）,注意 HotFlag 和 PithPlag 不能同时使用
'----- Hits     : 0 为不显示点击次数(人气)
'----- 十大新帖 ： <script language=javascript src=./other/article/topic.asp></script>
'----- 十大新帖(却掉点击) ： <script language=javascript src=./other/article/topic.asp?Hits=0></script>
'----- 十大热门 ： <script language=javascript src=./other/article/topic.asp?Hotflag=1></script>
'----- 十大热门(却掉点击) ： <script language=javascript src=./other/article/topic.asp?Hotflag=1&Hits=0></script>
'----------------------------------------------------------------------------------------

Dim HomeUrl
HomeUrl = "http://"&Request.ServerVariables("server_name")
If Request.ServerVariables("SERVER_PORT") <> "80" Then HomeUrl = HomeUrl & ":" & Request.ServerVariables("SERVER_PORT")
HomeUrl = Lcase(HomeUrl & Request.Servervariables("SCRIPT_NAME"))
HomeUrl = Replace(HomeUrl,"other/article/topic.asp","")

DEF_BBS_HomeUrl = "../../"
Const LMT_MaxDisplayAnnounce = 100
OpenDatabase
DisplayAnnounceList
closeDataBase

Function DisplayAnnounceList

	'--- By LeadBBS
	Dim BoardID,ListNum,StrLen 
	BoardID = Left(Request.QueryString("BoardID"),14)
	ListNum = Left(Request.QueryString("Number"),14)
	StrLen = Left(Request.QueryString("StrLen"),14)
	If isNumeric(StrLen) = False or StrLen = "" Then StrLen = 20
	StrLen = Fix(cCur(StrLen))
	If isNumeric(ListNum) = False or ListNum = "" Then ListNum = 10
	If isNumeric(BoardID) = False Then BoardID = 0
	BoardID = Fix(cCur(BoardID))
	
	ListNum = Fix(cCur(ListNum)) 
	If ListNum < 1 or ListNum > 100 Then ListNum = 10
	If StrLen < 1 or StrLen > 255 Then StrLen = 255
	
	'--- By simeonz
	Dim NewWindow,STime,TORA,POLL,NOWTIME,HotFlag
	NewWindow = Request.QueryString("NewWindow")
	STime = Request.QueryString("STime")
	TORA = Request.QueryString("TORA")
	POLL = Request.QueryString("POLL")
	
	If NewWindow <> "yes" Then
		NewWindow = ""
	Else
		NewWindow = " target=_blank"
	End If


	Select Case STime
	Case "" 
	Stime = 10
	Case 0 
	Stime = 0
	Case 1
	Stime = 16
	Case 2
	Stime = 10
	Case Else
	Stime = 10
	End Select


	If TORA <> "1" Then
		TORA = "LeadBBS_Announce"
	Else
		TORA = "LeadBBS_Topic"
	End If
   
    NOWTIME = CCUR(GetTimeValue(Now()))
	
	Dim Rs,SQL

	'--- 精华调用
	If Request.QueryString("PithFlag") = "1" Then
		If BoardID = "0" Then
			IF POLL="1" then
			SQL = "select DISTINCT TOP " & ListNum & " TA.ID,TA.Title,TA.TitleStyle,TA.BoardID,TA.LastTime,TA.UserName,TA.hits from " &TORA & " AS TA INNER JOIN LeadBBS_VoteItem AS TB on TA.ID=TB.AnnounceID Where TA.GoodFlag=1 and TA.TopicType=80 and (TB.ExpiresTime=0 or TB.ExpiresTime>" & NOWTIME & ") Order by TA.ID DESC"
			Else
			SQL = "select TOP " & ListNum & " ID,Title,TitleStyle,BoardID,LastTime,UserName,hits from " &TORA& " Where GoodFlag=1 Order by ID DESC"		  
			End if			
		Else
		  	IF POLL="1" then
			SQL = "select DISTINCT TOP " & ListNum & " TA.ID,TA.Title,TA.TitleStyle,TA.BoardID,TA.LastTime,TA.UserName,TA.hits from " &TORA & " AS TA INNER JOIN LeadBBS_VoteItem AS TB on TA.ID=TB.AnnounceID Where TA.BoardID=" & BoardID & " and TA.GoodFlag=1 and TA.TopicType=80 and (TB.ExpiresTime=0 or TB.ExpiresTime>" & NOWTIME & ") Order by TA.ID DESC"		  
          		Else
			SQL = "select TOP " & ListNum & " ID,Title,TitleStyle,BoardID,LastTime,UserName,hits from " &TORA& " Where GoodFlag=1 and BoardID=" & BoardID & " Order by ID DESC"
		  	End if			
		End If
	
	'---- 热帖调用
	ElseIf  Request.QueryString("HotFlag") = "1" Then 
		If BoardID = "0" Then
		    	If POLL="1" then
			  SQL = "select DISTINCT TOP " & ListNum & " TA.ID,TA.Title,TA.TitleStyle,TA.BoardID,TA.LastTime,TA.UserName,TA.hits from " &TORA & " AS TA INNER JOIN LeadBBS_VoteItem AS TB on TA.ID=TB.AnnounceID Where TA.TopicType=80 and (TB.ExpiresTime=0 or TB.ExpiresTime>" & NOWTIME & ") Order by TA.hits DESC,TA.ID DESC"
			Else
			  SQL = "select TOP " & ListNum & " ID,Title,TitleStyle,BoardID,LastTime,UserName,hits from " &TORA & " Order by hits DESC,ID DESC"			
			End if
		Else
		    	IF POLL="1" then
			  SQL = "select DISTINCT TOP " & ListNum & " TA.ID,TA.Title,TA.TitleStyle,TA.BoardID,TA.LastTime,TA.UserName,TA.hits from " &TORA & " AS TA INNER JOIN LeadBBS_VoteItem AS TB on TA.ID=TB.AnnounceID Where TA.BoardID=" & BoardID & " and TA.TopicType=80 and (TB.ExpiresTime=0 or TB.ExpiresTime>" & NOWTIME & ") Order by TA.hits DESC, TA.ID DESC"
            		Else
 			  SQL = "select TOP " & ListNum & " ID,Title,TitleStyle,BoardID,LastTime,UserName,hits from " &TORA& " Where BoardID=" & BoardID & " Order by hits DESC,ID DESC"
			End if			  
		End If
	
	'--- 新帖调用
	Else  	
		If BoardID = "0" Then
		    	If POLL="1" then
			  SQL = "select DISTINCT TOP " & ListNum & " TA.ID,TA.Title,TA.TitleStyle,TA.BoardID,TA.LastTime,TA.UserName,TA.hits from " &TORA & " AS TA INNER JOIN LeadBBS_VoteItem AS TB on TA.ID=TB.AnnounceID Where TA.TopicType=80 and (TB.ExpiresTime=0 or TB.ExpiresTime>" & NOWTIME & ") Order by TA.ID DESC"
			Else
			  SQL = "select TOP " & ListNum & " ID,Title,TitleStyle,BoardID,LastTime,UserName,hits from " &TORA & " Order by ID DESC"			
			End if
		Else
		    	IF POLL="1" then
			  SQL = "select DISTINCT TOP " & ListNum & " TA.ID,TA.Title,TA.TitleStyle,TA.BoardID,TA.LastTime,TA.UserName,TA.hits from " &TORA & " AS TA INNER JOIN LeadBBS_VoteItem AS TB on TA.ID=TB.AnnounceID Where TA.BoardID=" & BoardID & " and TA.TopicType=80 and (TB.ExpiresTime=0 or TB.ExpiresTime>" & NOWTIME & ") Order by TA.ID DESC"
            		Else
 			  SQL = "select TOP " & ListNum & " ID,Title,TitleStyle,BoardID,LastTime,UserName,hits from " &TORA& " Where BoardID=" & BoardID & " Order by ID DESC"
			End if			  
		End If
	End if
	
	
	Set Rs = Con.ExeCute(SQL)
	Dim Num
	Dim GetData
	If Not rs.Eof Then
		GetData = Rs.GetRows(-1)
		Num = Ubound(GetData,2)
	Else
		Num = -1
	End If
	Rs.close
	Set Rs = Nothing
	Response.Write "document.write(""<table width=100% border=0 cellspacing=4><tr><td><table width=100% border=0 cellspacing=1 cellpadding=0>"
	For SQL = 0 to Num
		If GetData(2,SQL) = 1 Then GetData(1,SQL) = KillHTMLLabel(GetData(1,SQL))
		
		Dim FullTitle
		FullTitle = GetData(1,SQL)
		
		If Len(GetData(1,SQL)) > StrLen/2 Then
			If StrLength(GetData(1,SQL)) > StrLen Then
				GetData(1,SQL) = LeftTrue(GetData(1,SQL),StrLen - 3) & "..."
			End If
		End If
		Response.Write "<tr><td><img border=0 src=" & HomeUrl & "other/article/tmark.gif width=7 height=7 align=absmiddle>&nbsp;<a href=" & HomeUrl & "announce/announce.asp?BoardID=" & GetData(3,SQL) & "&id=" & GetData(0,SQL) & NewWindow &_
		               " title=' 主题：" & FullTitle & "\n 作者：" &Replace(htmlencode(GetData(5,SQL)),"\","\\") & "&nbsp;" &Left(Replace(htmlencode(RestoreTime(GetData(4,SQL))),"\","\\"),20) & " (Hits:" & GetData(6,SQL) &")'>" &_
		               Replace(htmlencode(GetData(1,SQL)),"\","\\") & "</a></td><td>" & "</td>" 
		'Response.write "<td><font color=gray><i>" & Left(Replace(htmlencode(RestoreTime(GetData(4,SQL))),"\","\\"),STime) & "</i></font></td>"
				
			Dim Temp
			Temp = htmlencode(RestoreTime(GetData(4,SQL)))
			If DateDiff("d",Temp,now)<1 Then 
			Response.write "<td><font color=red><i>" & Left(Replace(htmlencode(RestoreTime(GetData(4,SQL))),"\","\\"),STime) & "</i></font></td>"
			Else
			Response.write "<td><font color=gray><i>" & Left(Replace(htmlencode(RestoreTime(GetData(4,SQL))),"\","\\"),STime) & "</i></font></td>"
			End if	
		
		If Request.QueryString("Hits") = "0" Then  
		Response.Write "<tr>"             
		Else
		Response.write "<td>(hits:<font color=red>" & GetData(6,SQL) & "</font>)</td></tr>"
		End if
		               
		Response.Write "<TR><TD colspan='4' background=" &HomeUrl& "other/article/vdot.gif height=1><img src=" &HomeUrl& "other/article/vdot.gif height=1 width=1></TD><TR>"					   
	Next
	Response.Write "</td></tr></table></table>"");"

End Function%>