<%
Server.ScriptTimeout=9999999
dim admin_flag
admin_flag="14,28"
if not master or instr(session("flag"),"14")=0 or instr(session("flag"),"28")=0 then
Errmsg=Errmsg+" "+"
您没有管理本页面的权限。"
call dvbbs_error()
else
dim tmprs
dim body
call main()
conn.close
set conn=nothing
end if
sub main()
%>
论坛数据处理
注意事项
下面有的操作可能将非常消耗服务器资源,而且更新时间很长,请仔细确认每一步操作后执行。
<%
if request("action")="updat" then
if request("submit")="更新论坛数据" then
call updateboard()
elseif request("submit")="修 复" then
call fixtopic()
else
call updateall()
end if
if founderr then
response.write errmsg
else
response.write body
end if
elseif request("action")="delboard" then
if isnumeric(request("boardid")) then
conn.execute("update topic set locktopic=2 where boardid="&request("boardid"))
for i=0 to ubound(AllPostTable)
conn.execute("update "&AllPostTable(i)&" set locktopic=2 where boardid="&request("boardid"))
next
end if
response.write "
清空论坛数据成功,请返回更新帖子数据!
"
elseif request("action")="updateuser" then
%>
<%
elseif request("action")="updateuserinfo" then
if request("submit")="重新计算用户发贴" then
call updateTopic()
elseif request("submit")="更新用户等级" then
call updategrade()
else
call updatemoney()
end if
if founderr then
response.write errmsg
else
response.write body
end if
else
%>
更新论坛数据
<%
end if
%>
<%
end sub
sub updateboard()
'先按照所有版面ID得出帖子数,然后计算各个有下属论坛的帖子总和
dim allarticle
dim alltopic
dim alltoday
dim allboard
dim trs,Esql,ars
dim Maxid
dim LastTopic,LastRootid,LastPostTime,LastPostUser
dim LastPost,uploadpic_n,Lastpostuserid,Lastid
dim ParentStr
set rs=server.createobject("adodb.recordset")
if isnumeric(request("boardid")) and request("boardid")<>"" then
sql="select boardid,boardtype from board where boardid="&request("boardid")
else
sql="select boardid,boardtype from board"
end if
set rs=conn.execute(sql)
if rs.eof and rs.bof then
Errmsg=Errmsg+"
还没有论坛版面,请到论坛管理添加!
"
founderr=true
exit sub
else
do while not rs.eof
allarticle=BoardAnnounceNum(rs("BoardID"))
alltopic=BoardTopicNum(rs("BoardID"))
sql="select top 1 T.title,b.Announceid,b.dateandtime,b.username,b.postuserid,b.rootid from "&NowUseBBS&" b inner join Topic T on b.rootid=T.TopicID where b.boardid="&rs("boardid")&" and b.locktopic<2 order by b.Announceid desc"
set trs=conn.execute(sql)
if not(trs.eof and trs.bof) then
Lasttopic=replace(left(trs(0),15),"$","")
LastRootid=trs(1)
LastPostTime=trs(2)
LastPostUser=trs(3)
LastPostUserid=trs(4)
Lastid=trs(5)
else
LastTopic="无"
LastRootid=0
LastPostTime=now()
LastPostUser="无"
LastPostUserid=0
Lastid=0
end if
trs.close
set trs=nothing
LastPost=LastPostUser & "$" & LastRootid & "$" & LastPostTime & "$" & LastTopic & "$" & uploadpic_n & "$" & LastPostUserID & "$" & LastID & "$" & rs("BoardID")
Esql="update board set lastbbsnum="&allarticle&",lasttopicnum="&alltopic&",TodayNum="&todays(rs("boardid"))&",LastPost='"&replace(LastPost,"'","")&"' where boardid="&rs("boardid")
conn.execute(Esql)
rs.movenext
loop
'更新有下属论坛的版面数据
dim LastPostinfo,LastAnnID
LastAnnID=0
if isnumeric(request("boardid")) and request("boardid")<>"" then
set trs=conn.execute("select boardid,ParentStr from board where boardid="&request("boardid")&" and child>0")
else
set trs=conn.execute("select boardid,ParentStr from board where child>0")
end if
do while not trs.eof
if trs(1)="0" then
'ParentStr=trs(0) & ","
ParentStr=trs(0)
else
ParentStr=trs(1) & "," & trs(0)
end if
'帖子总数,主题总数,今日贴总数,下属版面数
set ars=conn.execute("select sum(lastbbsnum),sum(lasttopicnum),sum(todaynum),count(*) from board where ParentStr like '%"&ParentStr&"%'")
allarticle=ars(0)
alltopic=ars(1)
alltoday=ars(2)
allboard=ars(3)
if isnull(allarticle) then allarticle=0
if isnull(alltopic) then alltopic=0
if isnull(alltoday) then alltoday=0
if isnull(allboard) then allboard=0
set ars=conn.execute("select LastPost from board where ParentStr like '%"&ParentStr&"%'")
do while not ars.eof
LastPostinfo=split(ars(0),"$")
if isnumeric(LastPostInfo(1)) and isnumeric(LastAnnID) then
if clng(LastPostInfo(1))>clng(LastAnnID) then
LastPost=ars(0)
else
LastPost="$0$"&Now()&"$$$$$"
end if
else
LastPost="$0$"&Now()&"$$$$$"
end if
LastAnnID=LastPostinfo(1)
ars.movenext
loop
conn.execute("update board set lastbbsnum=lastbbsnum+"&allarticle&",lasttopicnum=lasttopicnum+"&alltopic&",TodayNum=todaynum+"&alltoday&",child="&allboard&",LastPost='"&checkStr(LastPost)&"' where boardid="&trs(0))
'response.write AllBoard & " "
trs.movenext
loop
end if
if isnumeric(request("boardid")) and request("boardid")<>"" then
sql="select boardtype,lastbbsnum,lasttopicnum,todaynum from board where boardid="&request("boardid")
else
sql="select boardtype,lastbbsnum,lasttopicnum,todaynum from board"
end if
set rs=conn.execute(sql)
do while not rs.eof
body=body & "
"
rs.movenext
loop
set rs=nothing
set trs=nothing
set ars=nothing
end sub
sub updateall()
sql="update config set TopicNum="&topicnum()&",BbsNum="&announcenum()&",TodayNum="&alltodays()&",UserNum="&allusers()&",lastUser='"&newuser()&"'"
conn.execute(sql)
body="
"
end sub
sub fixtopic()
if not isnumeric(request.form("beginid")) then
body="
错误的开始参数!
"
exit sub
end if
if not isnumeric(request.form("endid")) then
body="
错误的结束参数!
"
exit sub
end if
if clng(request.form("beginid"))>clng(request.form("endid")) then
body="
开始ID应该比结束ID小!
"
exit sub
end if
dim TotalUseTable,Ers
dim username,dateandtime,rootid,announceid,postuserid,lastpost,topic
set rs=server.createobject("adodb.recordset")
sql="select topicid,PostTable from topic where topicid>="&request.form("beginid")&" and topicid<="&request.form("endid")
set rs=conn.execute(sql)
if rs.eof and rs.bof then
body="
已经到记录的最尾端,请结束更新!
"
exit sub
end if
do while not rs.eof
sql="select top 1 username,dateandtime,topic,Announceid,PostUserID,rootid,body,boardid from "&rs(1)&" where rootid="&rs(0)&" and locktopic<2 order by Announceid desc"
set ers=conn.execute(sql)
if not (ers.eof and ers.bof) then
username=Ers("username")
dateandtime=Ers("dateandtime")
rootid=Ers("rootid")
topic=left(Ers("body"),20)
Announceid=ers("Announceid")
postuserid=ers("postuserid")
LastPost=username & "$" & Announceid & "$" & dateandtime & "$" & replace(topic,"$","") & "$$" & postuserid & "$" & rootid & "$" & ers("BoardID")
conn.execute("update topic set LastPost='"&replace(LastPost,"'","")&"' where topicid="&rs(0))
end if
rs.movenext
loop
set ers=nothing
set rs=nothing
%>
<%
end sub
'分论坛今日帖子
function todays(boardid)
tmprs=conn.execute("Select count(announceid) from "&NowUseBBS&" Where boardid="&boardid&" and locktopic<2 and datediff('d',dateandtime,Now())=0")
todays=tmprs(0)
set tmprs=nothing
if isnull(todays) then todays=0
end function
'全部论坛今日帖子
function alltodays()
tmprs=conn.execute("Select count(announceid) from "&NowUseBBS&" Where locktopic<2 and datediff('d',dateandtime,Now())=0")
alltodays=tmprs(0)
set tmprs=nothing
if isnull(alltodays) then alltodays=0
end function
'所有注册用户数量
function allusers()
tmprs=conn.execute("Select count(userid) from [user]")
allusers=tmprs(0)
set tmprs=nothing
if isnull(allusers) then allusers=0
end function
'最新注册用户
function newuser()
sql="Select top 1 username from [user] order by userid desc"
set tmprs=conn.execute(sql)
if tmprs.eof and tmprs.bof then
newuser="没有会员"
else
newuser=tmprs("username")
end if
set tmprs=nothing
end function
'所有论坛帖子
function AnnounceNum()
dim AnnNum
AnnNum=0
AnnounceNum=0
For i=0 to ubound(AllPostTable)
tmprs=conn.execute("Select Count(announceID) from "&AllPostTable(i)&" where locktopic<2")
AnnNum=tmprs(0)
set tmprs=nothing
if isnull(AnnNum) then AnnNum=0
AnnounceNum=AnnounceNum + AnnNum
next
set tmprs=nothing
end function
'分论坛帖子
function BoardAnnounceNum(boardid)
dim BoardAnnNum
BoardAnnNum=0
BoardAnnounceNum=0
For i=0 to ubound(AllPostTable)
tmprs=conn.execute("Select Count(announceID) from "&AllPostTable(i)&" where boardid="&boardid&" and locktopic<2")
BoardAnnNum=tmprs(0)
set tmprs=nothing
if isnull(BoardAnnNum) then BoardAnnNum=0
BoardAnnounceNum=BoardAnnounceNum + BoardAnnNum
next
set tmprs=nothing
end function
'所有论坛主题
function TopicNum()
tmprs=conn.execute("Select Count(topicid) from topic where locktopic<2")
TopicNum=tmprs(0)
set tmprs=nothing
if isnull(TopicNum) then TopicNum=0
end function
'分论坛主题
function BoardTopicNum(boardid)
tmprs=conn.execute("Select Count(topicid) from topic where boardid="&boardid&" and locktopic<2")
BoardTopicNum=tmprs(0)
set tmprs=nothing
if isnull(BoardTopicNum) then BoardTopicNum=0
end function
'更新用户发贴数
sub updateTopic()
if not isnumeric(request.form("beginid")) then
body="
错误的开始参数!
"
exit sub
end if
if not isnumeric(request.form("endid")) then
body="
错误的结束参数!
"
exit sub
end if
if clng(request.form("beginid"))>clng(request.form("endid")) then
body="
开始ID应该比结束ID小!
"
exit sub
end if
dim userTopic
sql="select userid from [user] where userid>="&request.form("beginid")&" and userid<="&request.form("endid")
set rs=conn.execute(sql)
if rs.eof and rs.bof then
body="
已经到记录的最尾端,请结束更新!
"
exit sub
end if
do while not rs.eof
userTopic=Userallnum(rs(0))
conn.execute("update [user] set article="&userTopic&" where userid="&rs(0))
rs.movenext
loop
set rs=nothing
%>
<%
end sub
'更新用户金钱/经验/魅力
sub updatemoney()
if not isnumeric(request.form("beginid")) then
body="
错误的开始参数!
"
exit sub
end if
if not isnumeric(request.form("endid")) then
body="
错误的结束参数!
"
exit sub
end if
if clng(request.form("beginid"))>clng(request.form("endid")) then
body="
开始ID应该比结束ID小!
"
exit sub
end if
dim userTopic,userReply,userWealth
dim userEP,userCP
sql="select logins,userid from [user] where userid>="&request.form("beginid")&" and userid<="&request.form("endid")
set rs=conn.execute(sql)
do while not rs.eof
userTopic=UserTopicNum(rs(1))
userreply=UserReplyNum(rs(1))
userwealth=rs(0)*Forum_user(4) + userTopic*Forum_user(1) + userreply*Forum_user(2)
userEP=rs(0)*Forum_user(9) + userTopic*Forum_user(6) + userreply*Forum_user(7)
userCP=rs(0)*Forum_user(14) + userTopic*Forum_user(11) + userreply*Forum_user(12)
if isnull(UserWealth) or not isnumeric(userwealth) then userwealth=0
if isnull(Userep) or not isnumeric(userep) then userep=0
if isnull(Usercp) or not isnumeric(usercp) then usercp=0
conn.execute("update [user] set userWealth="&userWealth&",userep="&userep&",usercp="&usercp&" where userid="&rs(1))
rs.movenext
loop
set rs=nothing
%>
<%
end sub
'更新用户等级
sub updategrade()
if not isnumeric(request.form("beginid")) then
body="
错误的开始参数!
"
exit sub
end if
if not isnumeric(request.form("endid")) then
body="
错误的结束参数!
"
exit sub
end if
if clng(request.form("beginid"))>clng(request.form("endid")) then
body="
开始ID应该比结束ID小!
"
exit sub
end if
dim oldMinArticle
oldMinArticle=0
set rs=conn.execute("select * from usertitle order by MinArticle desc")
do while not rs.eof
conn.execute("update [user] set userclass='"&rs("usertitle")&"',titlepic='"&rs("titlepic")&"' where (userid>="&request.form("beginid")&" and userid<="&request.form("endid")&") and (article<"&oldMinArticle&" and article>="&rs("MinArticle")&" ) and usergroupid=4")
oldMinArticle=rs("MinArticle")
rs.movenext
loop
rs.close
set rs=nothing
%>
<%
end sub
'用户所有主题数
function UserTopicNum(userid)
dim topicnum
topicnum=0
usertopicnum=0
set tmprs=conn.execute("select count(*) from topic where PostUserID="&userid&" and locktopic<2")
TopicNum=tmprs(0)
if isnull(TopicNum) then TopicNum=0
UserTopicNum=UserTopicNum + TopicNum
set tmprs=nothing
end function
'用户所有回复数
function UserReplyNum(userid)
dim replynum
replynum=0
userreplynum=0
For i=0 to ubound(AllPostTable)
set tmprs=conn.execute("select count(announceid) from "&AllPostTable(i)&" where ParentID>0 and locktopic<2 and PostUserID="&userid)
replyNum=tmprs(0)
if isnull(replyNum) then replyNum=0
UserReplyNum=UserReplyNum + replynum
next
set tmprs=nothing
end function
'用户所有帖子
function Userallnum(userid)
dim allnum
allnum=0
userallnum=0
For i=0 to ubound(AllPostTable)
set tmprs=conn.execute("select count(announceid) from "&AllPostTable(i)&" where locktopic<2 and PostUserID="&userid)
allnum=tmprs(0)
if isnull(allnum) then allnum=0
userallnum=userallnum+allnum
next
set tmprs=nothing
end function
%>