<!--#include file="../../inc/MainClass.asp"-->
<%
response.Charset="gbk"
dim id,page,itype,json,h,pCount:id=getForm("gid","both"):itype=getForm("type","both"):page=getForm("page","get"):pCount=0
if not isNum(id) then:id=0:else:id=Clng(id):id=ifthen(id<0,0,id):end if
if not isNum(page) then:page=1:else:page=Clng(page):page=ifthen(page<1,1,page):end if
if not isNum(itype) then:itype=1:else:itype=Clng(itype):end if
'{"mlist":[{"cmid":7250330,"uid":0,"tmp":"","nick":"","face":"","star":"","anony":0,"from":"北京","time":"2010-6-25 13:55","reply":"7250278,7250288,7250306","content":"三楼[em:4:]","agree":0,"aginst":0,"pic":"","vote":"","allow":"0","check":"0"},{"cmid":7250306,"uid":0,"tmp":"","nick":"","face":"","star":"","anony":0,"from":"北京","time":"2010-6-25 13:54","reply":"7250278,7250288","content":"二楼[em:4:][em:4:]","agree":0,"aginst":0,"pic":"","vote":"","allow":"0","check":"0"},{"cmid":7250288,"uid":0,"tmp":"","nick":"","face":"","star":"","anony":0,"from":"北京","time":"2010-6-25 13:53","reply":"7250278","content":"高楼[em:4:][em:4:]","agree":0,"aginst":0,"pic":"","vote":"","allow":"0","check":"0"},{"cmid":7250278,"uid":0,"tmp":"","nick":"","face":"","star":"","anony":0,"from":"北京","time":"2010-6-25 13:52","reply":"","content":"[em:11:][em:1:][em:10:]字节","agree":0,"aginst":0,"pic":"","vote":"","allow":"0","check":"0"}],"rlist":{"7250306":{"uid":0,"tmp":"","nick":"","face":"","star":"","anony":0,"from":"北京","time":"2010-6-25 13:54","reply":"7250278,7250288","content":"二楼[em:4:][em:4:]","agree":0,"aginst":0,"pic":"","vote":"","allow":"0","check":"0"},"7250288":{"uid":0,"tmp":"","nick":"","face":"","star":"","anony":0,"from":"北京","time":"2010-6-25 13:53","reply":"7250278","content":"高楼[em:4:][em:4:]","agree":0,"aginst":0,"pic":"","vote":"","allow":"0","check":"0"},"7250278":{"uid":0,"tmp":"","nick":"","face":"","star":"","anony":0,"from":"北京","time":"2010-6-25 13:52","reply":"","content":"[em:11:][em:1:][em:10:]字节","agree":0,"aginst":0,"pic":"","vote":"","allow":"0","check":"0"}},"page":{"page":1,"count":1,"size":15,"type":1,"id":39554}}

dim rlist,FC:FC="../../webcache/review/"&itype&"/"&id&".js"
response.clear()
if page<2 then
	if isExistFile(FC) then
		json=LoadFile(FC):terminateAllObjects:die json
	end if
end if

SET rlist=Object()::h=ReadData(id,page):if page<2 then:CreateTextFile h,FC,"gbk":end if:echo h:SET rlist=nothing

Function Object():SET Object = Server.CreateObject(DICTIONARY_OBJ_NAME):Object.CompareMode=1:End Function

Function ReadData(ByVal gid,ByVal page)
Dim ret,x:ret=array("","",page,0,10,itype,gid)
if gid>0 then
	ret(0)=Readmlist(gid,page,ret(4)):ret(3)=pCount
	x=rlist.keys:x=Join(x,",")
	if x<>"" then
		ret(1)=Readrlist(x,1,10000)
	end if
end if
ReadData=FormatJson(ret)
End Function

Function Readmlist(ByVal gid,ByVal page,ByVal size)
	dim dl,x,i,n,z,ml:ml=array()
	if gid>0 then
		set dl =  mainClassobj.createObject("MainClass.DataList")
		dl.dataCurrentPage=page:dl.dataPageSize=size
		dl.whereStr="m_type="&itype&" AND m_videoid="&gid
		dl.primaryfield = "m_id"
		dl.fieldsStr = "m_id,m_author,m_addtime,m_reply,m_content,m_agree,m_anti,m_pic,m_vote,m_check"
		dl.tableStr = "{pre}review"
		x = dl.getPageList():pCount=dl.pagesCount
		if page > pCount then page=pCount
		if isArray(x) then
			n=ubound(x,2)
			for i=0 to n
				if isNum(x(3,i)) then
					x(3,i)=x(3,i)&ReadReplyID(gid,x(3,i))
				else
					x(3,i)=""
				end if
				Push ml,"{""cmid"":"&x(0,i)&",""uid"":0,""tmp"":"""",""nick"":"""",""face"":"""",""star"":"""",""anony"":"&ifthen(x(1,i)<>"",0,1)&",""from"":"""&x(1,i)&""",""time"":"""&x(2,i)&""",""reply"":"""&x(3,i)&""",""content"":"""&x(4,i)&""",""agree"":"&x(5,i)&",""aginst"":"&x(6,i)&",""pic"":"""&x(7,i)&""",""vote"":"""&x(8,i)&""",""allow"":"""&ifthen(x(6,i)<>"",1,0)&""",""check"":"""&x(9,i)&"""}"
			next
		end if
		set dl = nothing
	end if
	Readmlist=Join(ml,",")
End Function

Function Readrlist(ByVal ids,ByVal page,ByVal size)
	dim dl,x,i,n,z,rl:rl=array()
	set dl =  mainClassobj.createObject("MainClass.DataList")
	dl.dataCurrentPage=page:dl.dataPageSize=size
	dl.whereStr="m_type="&itype&" AND m_id IN ("&ids&")"
	dl.primaryfield = "m_id"
	dl.fieldsStr = "m_id,m_author,m_addtime,m_reply,m_content,m_agree,m_anti,m_pic,m_vote,m_check"
	dl.tableStr = "{pre}review"
	x = dl.getPageList()'die dl.recordsCount
	if page > dl.pagesCount then page=dl.pagesCount
	if isArray(x) then
		n=ubound(x,2)
		for i=0 to n
			Push rl,""""&x(0,i)&""":{""uid"":0,""tmp"":"""",""nick"":"""",""face"":"""",""star"":"""",""anony"":"&ifthen(x(1,i)<>"",0,1)&",""from"":"""&x(1,i)&""",""time"":"""&x(2,i)&""",""reply"":"""&x(3,i)&""",""content"":"""&x(4,i)&""",""agree"":"&x(5,i)&",""aginst"":"&x(6,i)&",""pic"":"""&x(7,i)&""",""vote"":"""&x(8,i)&""",""allow"":"""&ifthen(x(6,i)<>"",1,0)&""",""check"":"""&x(9,i)&"""}"
		next
	end if
	set dl = nothing
	Readrlist=Join(rl,",")
End Function

Function ReadReplyID(ByVal gid,ByVal cmid)
	cmid=Clng(cmid)
	if cmid>0 then
		if not rlist.Exists(cmid) then rlist(cmid)="":end if
		Dim cnid:cnid=conn.db("SELECT m_reply FROM {pre}review WHERE m_id="&cmid,"array")
		if isArray(cnid) then
			ReadReplyID=","&cnid(0,0)&ReadReplyID(gid,cnid(0,0))
		else
			ReadReplyID=""
		end if
	else
		ReadReplyID=""
	end if
End Function

Function ifthen(a,b,c)
	if a=true then:ifthen=b:else:ifthen=c:end if
End Function

Function FormatJson(ByVal ary)
	Dim i,x:x="{""mlist"":[%0%],""rlist"":{%1%},""page"":{""page"":%2%,""count"":%3%,""size"":%4%,""type"":%5%,""id"":%6%}}"
	for i=6 to 0 step -1
		x=Replace(x,"%"&i&"%",ary(i))
	next
	FormatJson=jsonescape(x)
End Function

Function jsonescape(ByVal txt)
	jsonescape=Replace(Replace(unescape(ReplaceStr(escape(""&txt),"%u","\u")),chr(10),"\n"),chr(13),"\r")
End Function

Sub Push(ByRef ary,ByRef Val):on Error resume next:Dim l:l=UBound(ary)+1:l=ifthen(err,0,l):ReDim Preserve ary(l):if isObject(Val) then:SET ary(l)=Val:else:ary(l)=Val:end if:End Sub
%>