<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/dv_clsother.asp"-->
<!--#include file="inc/dv_ubbcode.asp"-->
<%
Dvbbs.LoadTemplates("dispbbs")
Showtitle()
GetBoardPermission
Dvbbs.Head()
Showtree()
Dvbbs.Footer()
Sub Showtitle()
	Dim treeData
	treeData=template.html(11)
	treeData=Replace(treeData,"{$treeloop}",template.html(14))
	Response.Write "<script language=""javascript"">"
	Response.Write Chr(10)
	Response.Write "var treedata='"
	Response.Write Replace(Replace(Replace(Replace(treeData,"\","\\"),"'","\'"),VbCrLf,"\n"),chr(13),"")
	Response.Write "';"
	Response.Write vbNewLine
	template.html(13)=split(template.html(13),"||")
	Response.Write template.html(13)(0)
	Response.Write Chr(10)
	Response.Write "</script>"
	Response.flush
End Sub 
Sub Showtree()
	'接收参数
	Dim AnnounceID,ReplyID,Star,TotalUseTable,openid
	openid=Request("openid")
	If openid="" Or Not IsNumeric(openid) Then openid=0
	openid=CLng(openid)
	AnnounceID=Request("ID")
	If AnnounceID="" Or Not IsNumeric(AnnounceID) Then Exit Sub 
	AnnounceID=CLng(AnnounceID)
	ReplyID=Request("ReplyID")
	If ReplyID="" Or Not IsNumeric(ReplyID) Then ReplyID=AnnounceID
	ReplyID=CLng(ReplyID)
	Star=Request("Star")
	If Star="" Or Not IsNumeric(Star) Then Star=1
	Star=Clng(Star)
	Dim SQl,Rs
	sql="Select PostTable from Dv_topic where topicID="&Announceid
	Set rs=Dvbbs.Execute(sql)
	If Not Rs.eof Then
		 TotalUseTable=Rs(0)
	End If
	Dim tmpstr,treedata,blank,i,j,RecordCount,PageCount
	PageCount=0
	If TotalUseTable <>"" Then 
		Set Rs=server.createobject("adodb.recordset")
		sql="select AnnounceID,parentID,BoardID,UserName,PostUserid,Topic,DateAndTime,length,RootID,layer,orders,Expression,body from "&TotalUseTable&" where BoardID="&Dvbbs.BoardID&" and RootID="&Announceid&" and Locktopic<2 order by RootID desc,orders"
		rs.open sql,conn,1,1
		j=0
		RecordCount=Rs.RecordCount
		If Not(Rs.EOF And Rs.BOF) Then
			Rs.PageSize=Cint(Dvbbs.Board_Setting(27))
			Rs.AbsolutePage=Star
			PageCount=Rs.PageCount
			Do while Not Rs.EOF
				treedata=template.html(12)
				For i=1 to Rs(9)
					blank=blank&"&nbsp;"
				Next
				If Rs("topic")="" or isnull(rs("topic")) Then
					If len(rs("body"))>30 Then
						treedata=Replace(treedata,"{$topic}",reubbcode(mid(Dvbbs.htmlencode(replace(rs("body"),chr(10),"")),1,30))&"..")
					Else
						treedata=Replace(treedata,"{$topic}",reubbcode(Dvbbs.htmlencode(replace(rs("body"),chr(10),""))))
					End If
				Else
					If len(rs("Topic"))>35 Then
						treedata=Replace(treedata,"{$topic}",mid(Dvbbs.htmlencode(rs("Topic")),1,30)+"..")
					Else
						treedata=Replace(treedata,"{$topic}",Rs(5))
					End If
				End If
				Response.Write "<br>"			
				If Rs(0)=openid Then
					treedata=Replace(treedata,"{$alertcolor}",Dvbbs.mainsetting(1))
				Else
					treedata=Replace(treedata,"{$alertcolor}","")
				End If 
				treedata=Replace(treedata,"{$announceid}",Rs(0))
				treedata=Replace(treedata,"{$boardid}",Rs(2))
				treedata=Replace(treedata,"{$username}",Rs(3))
				treedata=Replace(treedata,"{$DateAndTime}",Rs(6))
				If Rs(7)=0 Then 
					treedata=Replace(treedata,"{$length}",template.Strings(14))
				Else
					treedata=Replace(treedata,"{$length}",Rs(7)&template.Strings(13))
				End If
				treedata=Replace(treedata,"{$rootid}",Rs(8))
				treedata=Replace(treedata,"{$Expression}",Rs(11))
				treedata=Replace(treedata,"{$blank}",blank)
				blank=""
				tmpstr=tmpstr&treedata
				Rs.MoveNext
				j=j+1
				If j=Cint(Dvbbs.Board_Setting(27)) Then Exit Do
			Loop
		End If
		Rs.close
		Set rs=Nothing 
	End If
	template.html(11)=Replace(template.html(11),"{$treeloop}",tmpstr)
	Response.Write "<script language=""javascript"">"
	Response.Write Chr(10)
	Response.Write "var treedata='"
	Response.Write Replace(Replace(Replace(Replace(template.html(11),"\","\\"),"'","\'"),VbCrLf,"\n"),chr(13),"")
	Response.Write "';"
	Response.Write vbNewLine
	Response.Write template.html(13)(0)
	tmpstr=template.html(13)(1)
	tmpstr=Replace(tmpstr,"{$alertcolor}",Dvbbs.mainsetting(1))
	tmpstr=Replace(tmpstr,"{$boardid}",Dvbbs.BoardID)
	tmpstr=Replace(tmpstr,"{$replyid}",ReplyID)
	tmpstr=Replace(tmpstr,"{$announceid}",AnnounceID)
	tmpstr=Replace(tmpstr,"{$openid}",openid)
	Response.Write tmpstr
	'//树型分页代码,参数：页码,记录总数，每页显示数,页数
	'function showpage(page,RecordCount,PageSize,PageCount)
	Response.Write "showpage("&Star&","&RecordCount&","&Cint(Dvbbs.Board_Setting(27))&","&PageCount&");"
	
	Response.Write Chr(10)
	Response.Write "</script>"
End Sub
Function dvHTMLEncode(fString)
	If Not IsNull(fString) Then
		fString = replace(fString, ">", "&gt;")
		fString = replace(fString, "<", "&lt;")
		fString = replace(fString, "&#", "<I>&#</I>")
		fString = Replace(fString, CHR(32), "<I></I>&nbsp;")
		fString = Replace(fString, CHR(9), "&nbsp;")
		fString = Replace(fString, CHR(34), "&quot;")
		fString = Replace(fString, CHR(39), "&#39;")
		fString = Replace(fString, CHR(13), "")
		fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
		fString = Replace(fString, CHR(10), "<br> ")
		fString=Dvbbs.ChkBadWords(fString)
		dvHTMLEncode = fString
	End If
End Function
Function reUBBCode(strContent)
	strContent = dvHTMLEncode(strContent)
	Dim re
	Set re=new RegExp
	re.IgnoreCase =True
	re.Global=True
	strContent=replace(strContent,"&nbsp;"," ")
	re.Pattern="(\[QUOTE\])(.[^\[]*)(\[\/QUOTE\])"
	strContent=re.Replace(strContent,"")
	re.Pattern="(\[point=*([0-9]*)\])(.*)(\[\/point\])"
	strContent=re.Replace(strContent,"&nbsp;")
	re.Pattern="(\[post=*([0-9]*)\])(.*)(\[\/post\])"
	strContent=re.Replace(strContent,"&nbsp;")
	re.Pattern="(\[power=*([0-9]*)\])(.*)(\[\/power\])"
	strContent=re.Replace(strContent,"&nbsp;")
	re.Pattern="(\[usercp=*([0-9]*)\])(.*)(\[\/usercp\])"
	strContent=re.Replace(strContent,"&nbsp;")
	re.Pattern="(\[money=*([0-9]*)\])(.*)(\[\/money\])"
	strContent=re.Replace(strContent,"&nbsp;")
	re.Pattern="(\[replyview\])(.*)(\[\/replyview\])"
	strContent=re.Replace(strContent,"&nbsp;")
	re.Pattern="(\[usemoney=*([0-9]*)\])(.*)(\[\/usemoney\])"
	strContent=re.Replace(strContent,"&nbsp;")
	strContent=replace(strContent,"<I></I>","")
	set re=Nothing
	reUBBCode=strContent
End Function
%>