<!--#include file="Conn.asp"-->
<!-- #include file="inc/const.asp" -->
<!--#include file="inc/dv_clsother.asp"-->
<%
If Dvbbs.BoardID=0 Then response.redirect "infolist.asp?t=toplist&order=1"
Dvbbs.LoadTemplates("paper_even_toplist")
Dvbbs.stats="发帖排行"

If Dvbbs.GroupSetting(1)="0" Then Dvbbs.AddErrCode(64)
Dvbbs.ShowErr()

Dim Page,Rs,SQL,keyword,fromdate,todate
Dim TempStr,TempStr1,TempStr2,TempStr3,TempArray,TopTempArray
Dim TotalRec,i,Pcount

TotalRec=0
Page=request("page")
If Page="" Or Not IsNumerIc(Page) Then Page=1
Page=Clng(Page)
keyword=Request("keyword")
If keyword<>"" Then keyword = Dvbbs.CheckStr(keyword)
If Dvbbs.Forum_Setting(17)="0" Then keyword = ""

TempStr = Replace(template.html(7), "infolist.asp?t=toplist", "?boardid={$boardid}")
TopTempArray = Split(template.html(9),"||")
If Dvbbs.Forum_Setting(17)="1" Then
	TempStr = Replace(TempStr,"{$isusersearch}",TopTempArray(4))
	TempStr = Replace(TempStr,"{$keyword}",keyword)
Else
	TempStr = Replace(TempStr,"{$isusersearch}","")
End If
If keyword<>"" Then keyword = " And UserName like '%"&keyword&"%'"
fromdate=request("fromdate")
todate=request("todate")
if fromdate<>"" and isdate(fromdate) then
	fromdate=formatdatetime(fromdate,2)
elseif fromdate<>"" then
	Response.redirect "showerr.asp?ErrCodes=<li>开始时间错误！&action=OtherErr"
else
	fromdate=""
end if
if todate<>"" and isdate(todate) then
	todate=formatdatetime(CDate(todate)+1,2)
elseif todate<>"" then
	Response.redirect "showerr.asp?ErrCodes=<li>截止时间错误！&action=OtherErr"
else
	todate=""
end if
if fromdate<>"" and todate<>"" then
	if CDate(Todate)<CDate(Fromdate) then
		Response.redirect "showerr.asp?ErrCodes=<li>截止时间不得早于起始时间！&action=OtherErr"
	end if
end if
if fromdate<>"" then
	If IsSqlDataBase = 1 Then
		fromdate=" and DateAndTime>='"&fromdate&"'"
	Else
		fromdate=" and DateAndTime>=#"&fromdate&"#"
	End If
end if
if todate<>"" then
	If IsSqlDataBase = 1 Then
		todate=" and DateAndTime<'"&todate&"'"
	Else
		todate=" and DateAndTime<#"&todate&"#"
	End If
end if
Dim BoardUserStr
BoardUserStr = ""
For i = 0 To UBound(Dvbbs.BoardUser)
	If BoardUserStr <> "" Then BoardUserStr = BoardUserStr & "','"
	BoardUserStr = BoardUserStr & Dvbbs.BoardUser(i)
Next
if keyword<>"" then
	if CInt(Dvbbs.Board_Setting(2))=1 then
		SQL="select u.username,u.useremail,u.userclass,u.UserIM,b.userpost,u.JoinDate,u.userwealth,u.userid from (select username,useremail,userclass,UserIM,JoinDate,userwealth,userid from [dv_user] where username in ('"&BoardUserStr&"')"&keyword&") u left join (select username,count(username) as userpost from "&Dvbbs.NowUseBBS&" where boardid="&Dvbbs.BoardID&fromdate&todate&" group by username) b on u.username=b.username order by userpost desc"
	else
		SQL="select u.username,u.useremail,u.userclass,u.UserIM,b.userpost,u.JoinDate,u.userwealth,u.userid from (select username,useremail,userclass,UserIM,JoinDate,userwealth,userid from [dv_user] where 2>1"&keyword&") u left join (select username,count(username) as userpost from "&Dvbbs.NowUseBBS&" where boardid="&Dvbbs.BoardID&fromdate&todate&" group by username) b on u.username=b.username order by userpost desc"
	end if
else
	if CInt(Dvbbs.Board_Setting(2))=1 then
		SQL="select u.username,u.useremail,u.userclass,u.UserIM,b.userpost,u.JoinDate,u.userwealth,u.userid from (select username,useremail,userclass,UserIM,JoinDate,userwealth,userid from [dv_user] where username in ('"&BoardUserStr&"')) u left join (select username,count(username) as userpost from "&Dvbbs.NowUseBBS&" where boardid="&Dvbbs.BoardID&fromdate&todate&" group by username) b on u.username=b.username order by userpost desc"
	else
		SQL="select u.username,u.useremail,u.userclass,u.UserIM,b.userpost,u.JoinDate,u.userwealth,u.userid from (select username,useremail,userclass,UserIM,JoinDate,userwealth,userid from [dv_user]) u left join (select username,count(username) as userpost from "&Dvbbs.NowUseBBS&" where boardid="&Dvbbs.BoardID&fromdate&todate&" group by username) b on u.username=b.username order by userpost desc"
	end if
end if
If Dvbbs.Forum_Setting(31)="0" Then Response.redirect "showerr.asp?ErrCodes=<li>"&template.Strings(12)&"&action=OtherErr"

Dvbbs.Nav()
Dvbbs.ShowErr()
Dvbbs.Head_var 1,"","",""

Set Rs=Dvbbs.Execute("select count(*) from "&Dvbbs.NowUseBBS&" where boardid="&Dvbbs.BoardID&fromdate&todate)
TempStr = Replace(TempStr,"{$postnum}",Rs(0))
if CInt(Dvbbs.Board_Setting(2))=1 then
	TempStr = Replace(TempStr,"{$usernum}",UBound(Dvbbs.BoardUser))
	TempStr = Replace(TempStr,"注册","认证")
else
	Set Rs=Dvbbs.Execute("Select Forum_UserNum From Dv_Setup")
	TempStr = Replace(TempStr,"{$usernum}",Rs(0))
end if

Set Rs=Server.CreateObject("ADODB.RecordSet")
If Not IsObject(Conn) Then ConnectionDatabase
Rs.Open SQL,Conn,1,1
If Not Rs.Eof Then TotalRec=Rs.RecordCount
Dvbbs.SqlQueryNum = Dvbbs.SqlQueryNum + 1
If Rs.Eof And Rs.Bof Then
	TempStr = Replace(TempStr,"{$toplistloop}",TopTempArray(0))
	TempStr = Replace(TempStr,"{$pagelist}","")
Else
	If TotalRec Mod Dvbbs.Forum_Setting(11)=0 Then
		Pcount= TotalRec \ Dvbbs.Forum_Setting(11)
	Else
		Pcount= TotalRec \ Dvbbs.Forum_Setting(11)+1
	End If

	RS.MoveFirst
	if Page > Pcount then Page = Pcount
 		if Page < 1 then Page=1
	RS.Move (Page-1) * Dvbbs.Forum_Setting(11)
	SQL=Rs.GetRows(Dvbbs.Forum_Setting(11))
	Set Rs=Nothing
	'username=0,useremail=1,userclass=2,UserIM=3,UserPost=4,JoinDate=5,userwealth=6,userid=7
	TempStr1 = template.html(8)
	For i = 0 To Ubound(SQL,2)
		TempStr2 = TempStr1
		TempArray = Split(Dvbbs.HtmlEncode(Replace(SQL(3,i)&"","'","\'")),"|||")
		TempStr2 = Replace(TempStr2,"{$userid}",SQL(7,i))
		TempStr2 = Replace(TempStr2,"{$email}",SQL(1,i)&"")
		TempStr2 = Replace(TempStr2,"{$username}",Dvbbs.HtmlEncode(SQL(0,i)))
		TempStr2 = Replace(TempStr2,"{$adddate}",SQL(5,i)&"")
		TempStr2 = Replace(TempStr2,"{$userclass}",SQL(2,i)&"")
		if isnull(SQL(4,i)) then
			TempStr2 = Replace(TempStr2,"{$article}","0")
		else
			TempStr2 = Replace(TempStr2,"{$article}",SQL(4,i)&"")
		end if
		TempStr2 = Replace(TempStr2,"{$wealth}",SQL(6,i))
		If Ubound(TempArray)>1 Then
		TempStr2 = Replace(TempStr2,"{$homepage}",TempArray(0))
		TempStr2 = Replace(TempStr2,"{$oicq}",TempArray(1))
		Else
		TempStr2 = Replace(TempStr2,"{$homepage}","")
		TempStr2 = Replace(TempStr2,"{$oicq}","")
		End If
		TempStr3 = TempStr3 & TempStr2
	Next

	TempStr = Replace(TempStr,"{$toplistloop}",TempStr3)
	TempStr = Replace(TempStr,"{$pagelist}",template.html(3))
	TempStr = Replace(TempStr,"""?page=","""?fromdate="&request("fromdate")&"&todate="&request("todate")&"&keyword="&request("keyword")&"&page=")
	TempStr = Replace(TempStr,"{$page}",page)
	TempStr = Replace(TempStr,"{$Pcount}",Pcount)
	TempStr = Replace(TempStr,"{$width}",Dvbbs.mainsetting(0))
	TempStr = Replace(TempStr,"{$alertcolor}",Dvbbs.mainsetting(1))
	TempStr = Replace(TempStr,"{$pagelimited}",Dvbbs.Forum_Setting(11))
	TempStr = Replace(TempStr,"{$listnum}",totalrec)
	TempStr = Replace(TempStr,"{$boardid}",Dvbbs.BoardID)
	TempStr = Replace(TempStr,"{$emailpic}",template.pic(0))
	TempStr = Replace(TempStr,"{$oicqpic}",template.pic(1))
	TempStr = Replace(TempStr,"{$homepagepic}",template.pic(2))
	TempStr = Replace(TempStr,"{$msgpic}",template.pic(3))

End If
TempStr = Replace(TempStr,"toplist.asp","z_toplist.asp")
TempStr = Replace(TempStr,"<select name=orders onchange='javascript:submit()'>","<br><input name=boardid value='"&Dvbbs.BoardId&"' type=hidden>开始时间：<input name=fromdate size=10 maxlength=10 type=text value='"&Dvbbs.CheckStr(request("fromdate"))&"'>")
TempStr = Replace(TempStr,"</select>","截止时间：<input name=todate size=10 maxlength=10 type=text value='"&Dvbbs.CheckStr(request("todate"))&"'>")
TempStr = Replace(TempStr,"{$myselect3}","")
TempStr = Replace(TempStr,"{$myselect1}","")
TempStr = Replace(TempStr,"{$myselect2}","")

TempStr = Replace(TempStr,"{$ordername}","发帖排行")
TempStr = Replace(TempStr,"{$pagelistnum}",Dvbbs.Forum_Setting(11))
TempStr = Replace(TempStr,"{$select1}","")
TempStr = Replace(TempStr,"{$select2}","")
TempStr = Replace(TempStr,"{$select3}","")
TempStr = Replace(TempStr,"{$select7}","")
TempStr = Replace(TempStr,"{$select8}","")
Response.Write TempStr

Dvbbs.ActiveOnline()
Dvbbs.Footer()
%>
