<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="admin_Checkuser.asp"-->
<%Server.ScriptTimeOut=9999999999%>
<HTML><HEAD><title><%=StrVar(1)%>--管理页面</title>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<!--#include file="inc/admin_main.css"-->
</HEAD>
<BODY leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<%
if  not sysadmin or session("adminlogin")<>"0K" Then
	Errmsg=Errmsg+"<br>"+"<li>本页面为管理员专用，请<a href=admin_index.asp target=_top>登陆</a>后进入。"
	Call Error("Information",ErrMsg)
Else
	Call main()
End if

Call endconnection()


Sub main()

%>
<table cellpadding=5 cellspacing=1 border=0 width=90% Class=TableBorder align=center>
  <tr>
	<th>欢迎<b><%=membername%></b>进入管理页面</th>
</tr>
</table>
		<%
		if Request("action")="update" Then
			Call update()
		Else
			Call updateoption()
		End if
		
End Sub
Sub updateoption()
%>
<BR>
<table width="85%" border="0" cellspacing="1" cellpadding="5"  align=center Class=TableBorder>
  <form method="POST" action=admin_Update.asp?Action=update>
    <tr> 
      <th height="11" colspan="4" ><b>数据统计与更新</b></font></th>
    </tr>
    <tr> 
      <td width="5%" class=forumrow><div align="center"> 
          <input type="radio" name="DoWhat" value="1">
        </div></td>
      <td width="45%" class=forumrow>更新注册用户总数、注册学校总数</td>
      <td width="5%" class=forumrow><div align="center"> 
          <input type="radio" name="DoWhat" value="2">
        </div></td>
      <td width="45%" class=forumrow>重新统计学校成员数、重新统计用户注册的学校数</td>
    </tr>
    <tr> 
      <td width="5%" class=forumrow><div align="center"> 
          <input type="radio" name="DoWhat" value="3">
        </div></td>
      <td class=forumrow>重新统计学校留言总数、重新统计学校相片总数</font></td>
      <td class=forumrow><div align="center"> 
          <input type="radio" name="DoWhat" value="4">
        </div></td>
      <td class=forumrow>更新论坛主题数、帖子数、主题回复数</td>
    </tr>
    <tr> 
      <td width="5%" class=forumrow><div align="center"> 
          <input type="radio" name="DoWhat" value="5">
        </div></td>
      <td class=forumrow>重新统计每个用户的帖子总数</td>
      <td class=forumrow><div align="center"> 
          <input type="radio" name="DoWhat" value="6">
        </div></td>
      <td class=forumrow>清空在线用户</td>
    </tr>
    <tr> 
      <td height="23" colspan="4" align=right Class=forumrowhighlight> <input type="submit" name="Submit" value="执行操作" class=button> 
      </td>
    </tr>
  </form>
</table>
<%
End Sub
%>
<%Sub update()

	Dim rs,sql
	dim uClassNum,uUserNum,uTopicNum,uBBSNum
	dim uphotonum,uliuyannum
	dim uReplyNum

	select case request("DoWhat")
	case "1"
        ''删无效用户数据
		sql="delete from student where userid='' or userid is null"
		conn.execute(sql)
		
		''删无效学校数据
		sql="delete from class where classname='' or classname is null"
		conn.execute(sql)
		
        ''统计用户总数
		sql="select count(userid) from student where userid<>'' and userid is not null"
		Set rs=conn.execute(sql)
		if isnull(rs(0)) then uUserNum=0 else uUserNum=rs(0)
				
        ''统计学校总数
		Set rs=conn.execute("select count(classid) from class where classname<>'' and classname is not null")
		if isnull(rs(0)) then uClassNum=0 else uClassNum=rs(0)

		Set rs=Nothing

		sql="update config set classnum="&uClassNum&",usernum="&uUserNum
		conn.execute(sql)

case "2"
		
		'''删除加入学校无效数据
		sql="delete from joinclass where classid is null or userid is null"
		conn.execute(sql)
        '''将学校人数设为0
		sql="update class Set studcount=0"
		conn.execute(sql)
        '''统计学校的人数
		sql="Select classid,count(classid) from joinclass where isauditing=0 group by classid"
		Set rs=conn.execute(sql)
		do until rs.eof
			conn.execute("update class Set studcount="&rs(1)&" where classid="&rs(0))
			rs.movenext
		loop
		Set rs=Nothing

		''将学校数设为0
		sql="update student Set classcount=0"
		conn.execute(sql)
        '''统计用户加入的学校数
		sql="Select userid,count(userid) from joinclass group by userid"
		Set rs=conn.execute(sql)
		do until rs.eof
			conn.execute("update student Set classcount="&rs(1)&" where userid='"&rs(0)&"'")
			rs.movenext
		loop
		Set rs=Nothing

case "3"
        '''删除无效留言数据
		sql="delete from ClassTopic where classid=0 or classid is null or userid=''"
		conn.execute(sql)
		sql="delete from ClassTopicReply where classid=0 or classid is null or userid=''"
		conn.execute(sql)

		 ''统计用户总数
		sql="select count(postid) from ClassTopicReply where classid>0 and userid<>''"
		Set rs=conn.execute(sql)
		if isnull(rs(0)) then uliuyannum=0 else uliuyannum=rs(0)
		
		'''删除无效相片数据
		sql="delete from photo where filename='' or classid=0 or name =''"
		conn.execute(sql)
		
		'''删除无效相片评论
		sql="delete from comment where name='' or picid=0 or picid is null or name is null"
		conn.execute(sql)

		'''删除空间上不存在的相片数据
		if IsObjInstalled("Scripting.FileSystemObject") Then
		dim fso,filepath
	    Set fso = CreateObject("Scripting.FileSystemObject")
		sql="Select picid,[file],filename from photo order by picid"
		Set rs=conn.execute(sql)
		do until rs.eof
			filepath=server.mappath("../"&rs(1)&rs(2))
			if fso.FileExists(filepath)<>True Then
		    conn.execute("delete from photo where picid="&rs(0))
			conn.execute("delete from comment where picid="&rs(0))
			End if
			rs.movenext
		loop
		Set rs=Nothing
		Set fso=Nothing
		end if
        ''统计学校总数
		Set rs=conn.execute("select count(picid) from photo where classid>0 and name<>'' and filename<>'' and filename is not null")
		if isnull(rs(0)) then uphotoNum=0 else uphotoNum=rs(0)
		set rs=nothing
		''更新数据
		sql="update config set liuyannum="&uliuyanNum&",photonum="&uphotoNum
		conn.execute(sql)
		
case "4"

        sql="delete from topic where userid='' or title='' or userid is null"
		conn.execute(sql)
		
		sql="delete from reply where userid='' or topicid=0 or topicid is null"
		conn.execute(sql)
		
		sql="Select count(postid) from topic"
		Set rs=conn.execute(sql)
		if isnull(rs(0)) then uTopicNum=0 else uTopicNum=rs(0)

		sql="Select count(postid) from reply"
		Set rs=conn.execute(sql)
		if isnull(rs(0)) then uBBSNum=0 else uBBSNum=rs(0)
		Set rs=Nothing
		

		uBBSNum=uTopicNum+uBBSNum
		
		sql="update config set topicnum="&uTopicNum&",bbsnum="&uBBSNum
		conn.execute(sql)
		
		sql="Select topicid,count(topicid) from reply group by topicid"
		Set rs=conn.execute(sql)
		do until rs.eof
			if isnull(rs(1)) then uReplyNum=0 else uReplyNum=rs(1)
			if uReplyNum>0 then
				conn.execute("update topic Set replys="&uReplyNum&" where postid="&rs(0))
			else
				conn.execute("update topic Set replys=0,lastReply=null,lastTime=postTime where postid="&rs(0))
			end if
			rs.movenext
		loop
		Set rs=Nothing
		
case "5"
		
		dim usertopicnum,userreplynum
	    sql="Select studid,userid from student where studid>=1"
		Set rs=conn.execute(sql)
		do while not rs.eof
			sql="Select count(postid) from topic where userid='"&rs(1)&"'"
		    Set rsp=conn.execute(sql)
			if isnull(rsp(0)) then usertopicnum=0 else usertopicnum=rsp(0)
			Set rsp=Nothing
			sql="Select count(postid) from Reply where userid='"&rs(1)&"'"
		    Set rsr=conn.execute(sql)
			if isnull(rsr(0)) then userreplynum=0 else userreplynum=rsr(0)
			Set rsr=Nothing
			conn.execute("update student Set Topicnum="&usertopicnum&",Replynum="&userreplynum&" where studid="&rs(0))
			rs.movenext
		loop
		Set rs=Nothing
		
case "6"
		sql="delete from online"
		conn.execute(sql)

End select
Call adminmsg("恭喜，数据维护操作成功！")

End Sub

Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
%>
</BODY></HTML>


