<!--#include file=conn.asp-->
<!--#Include File="inc/const.asp"-->
<!--#Include File="inc/dv_clsother.asp"-->
<%
Response.Expires=0
Dvbbs.LoadTemplates("list")
Dvbbs.head
Dim outtext,iouttext
Dim num
Dim allnum
Dim RootID
Dim rs,SQL,i
RootID=request("rootID")
If RootID="" Or Not IsNumeric(RootID) Or (Request("action") <> "1" And Request("action")<>"0") Then Response.End
Dim TempStr
TempStr=Split(template.html(13),"||")
If Request("action")="1" Then showtree()
If Request("action")="0" Then closetree()
Sub closeTree()
	TempStr(4)=Replace(TempStr(4),"{$rootid}",rootid)
	TempStr(4)=Replace(TempStr(4),"{$boardid}",Dvbbs.BoardID)
	Response.Write TempStr(4)
End Sub 
Sub showtree()
	Dim Star,page
	Star=Request("Star")
	If Star="" Or Not IsNumeric(Star) Then Star=1
	Star=Clng(Star)
	page=star
	Dim MyTempStr,ii
	num=0
	outtext="กกกกกก&nbsp;&nbsp;"
	Dim totalusetable
	Set Rs=Dvbbs.Execute("Select child,PostTable from dv_topic where topicid="&rootid)
	allnum=rs(0)
	totalusetable=rs(1)
	Dim Board_Setting27
	TempStr(3)=Replace(TempStr(3),"{$rootid}",rootid)
	TempStr(3)=Replace(TempStr(3),"{$boardid}",Dvbbs.BoardID)
	TempStr(3)=Replace(TempStr(3),"{$alertcolor}",Dvbbs.mainsetting(1))
	Response.Write TempStr(3)
	Response.flush
	Board_Setting27=Dvbbs.Board_Setting(27)
	SQL="select layer,rootid,announceid,body,username,postuserid,topic from "&totalusetable&" where boardid="& Dvbbs.boardid &" and rootid="& rootid &" and parentid>0 order by rootid desc,orders"
	Set Rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,1
	If Not (Rs.Eof And Rs.Bof) Then
		If allnum <> Rs.RecordCount Then
			allnum=Rs.RecordCount
			Dvbbs.Execute("Update dv_topic Set child="&allnum&" Where topicid="&rootid)
		End If
		Rs.PageSize=Cint(Dvbbs.Board_Setting(27))
		Rs.AbsolutePage=Star
		SQL=Rs.GetRows(Rs.PageSize)
		Response.Write "<Script Language=JavaScript>"
		Response.Write "var tmpstr='';"	
		For i=0 To Ubound(SQL,2)
			MyTempStr=MyTempStr & TempStr(1)
			For ii=0 to SQL(0,i)
				If ii>0 Then
					iouttext = iouttext & outtext
				Else
					iouttext = outtext
				End If
			Next
			MyTempStr=Replace(MyTempStr,"{$nbsplength}",outtext)
			MyTempStr=Replace(MyTempStr,"{$pic_nofollow}",Dvbbs.mainpic(10))
			MyTempStr=Replace(MyTempStr,"{$looprootid}",SQL(1,i))
			MyTempStr=Replace(MyTempStr,"{$announceid}",SQL(2,i))
			star=int((allnum-num)/Board_Setting27)+1
			If star>1 Then
				MyTempStr=Replace(MyTempStr,"{$star}",star)
			Else
				MyTempStr=Replace(MyTempStr,"{$star}",1)
			End if
			MyTempStr=Replace(MyTempStr,"{$atitle}",Dvbbs.HtmlEncode(SQL(6,i)))
			If SQL(6,i)="" Then
				MyTempStr=Replace(MyTempStr,"{$title}",Dvbbs.HtmlEncode(Left(SQL(3,i),22)))
			Else
				If Len(SQL(6,i))>22 Then
					MyTempStr=Replace(MyTempStr,"{$title}",Dvbbs.HtmlEncode(Left(SQL(6,i),22)) & "...")
				Else
					MyTempStr=Replace(MyTempStr,"{$title}",Dvbbs.HtmlEncode(SQL(6,i)))
				End If
			End If
			MyTempStr=Replace(MyTempStr,"{$userid}",SQL(5,i))
			MyTempStr=Replace(MyTempStr,"{$username}",Dvbbs.HtmlEncode(SQL(4,i)))
			num=num+1
			iouttext=""
		Next
		MyTempStr=Replace(MyTempStr,"{$boardid}",Dvbbs.BoardID)
		MyTempStr=Replace(TempStr(0),"{$loadtopicreplyloop}",MyTempStr)
		MyTempStr=Replace(Replace(Replace(Replace(Replace(Replace(MyTempStr,"\","\\"),"'","\'"),VbCrLf,""),chr(13),""),"<BR>",""),"</P><P>","")
		Response.Write "tmpstr='"&MyTempStr&"';"	
		MyTempStr=""
		SQL=Null
		TempStr(2)=Replace(TempStr(2),"{$rootid}",rootid)
		Response.Write "tmpstr+=showpage("&page&","&Rs.RecordCount&","&Rs.PageSize&","&Rs.PageCount&");"		
		Response.Write TempStr(2)
		Response.Write "</Script>"
		TempStr=Null
	End If
	Set Rs=Nothing
End Sub 
%>
</body>
</html>