<!--#INCLUDE FILE="setup.asp" -->
<!--#include file=checkuser.asp-->
<%Server.ScriptTimeOut=99999%>
<html><head>
<title><%=StrVar(1)%>--管理页面</title>
<link href="css.asp" rel="stylesheet" type="text/css">
<!--#include file=theme.css-->
<body class=adminbody>
<%
if  not sysadmin or session("adminlogin")<>"0K" Then
	Errmsg=Errmsg+"<br>"+"<li>本页面为管理员专用，请<a href=superindex.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=100% 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>
<form method="POST" action=sysadm_update.asp?Action=update>
<table width="85%" border="0" cellspacing="1" cellpadding="5"  align=center Class=TableBorder>
<tr> 
<th height="11" colspan="2" ><b>数据统计与更新</b></font></th>
</tr>
<tr Class=LightTableBody> 
<td width="5%"><input type="radio" name="DoWhat" value="1"></td>
<td>更新同学录注册用户总数、注册班级总数,校友论坛主题数、帖子数等数据.</font></td>
</tr>
<tr Class=LightTableBody >
<td width="5%"><input type="radio" name="DoWhat" value="2"></td>
<td>重新统计班级成员数</font></td>
</tr>
<tr Class=LightTableBody >
<td width="5%"><input type="radio" name="DoWhat" value="3"></td>
<td>重新统计用户注册的班级数</font></td>
</tr>
<tr Class=LightTableBody >
<td width="5%"><input type="radio" name="DoWhat" value="4"></td>
<td>重新统计校友论坛主题回复数</font></td>
</tr>
<tr Class=DarkTableBody> 
<td height="23" colspan="2" align=right >
<input type="submit" name="Submit" value="执行操作" class=button>
</td>
</tr>
</table>
</form>
<%

End Sub


Sub update()

	Dim rs,sql
	dim uClassNum,uUserNum,uTopicNum,uBBSNum

	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="delete from joinclass where classid is null or userid is null"
		conn.execute(sql)

		sql="delete from append where classid=0 or classid is null"
		conn.execute(sql)

		sql="delete from classboard where classid=0 or classid is null"
		conn.execute(sql)

		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)

		if BoolVar(9) then
			sql="select count(userid) from student where userid<>'' and userid is not null and locked<2"
		else
			sql="select count(userid) from student where userid<>'' and userid is not null"
		end if
		Set rs=conn.execute(sql)
		if isnull(rs(0)) then uUserNum=0 else uUserNum=rs(0)

		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

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

case "2"
		
		dim uStudCount
		sql="delete from joinclass where classid is null or userid is null"
		conn.execute(sql)

		sql="update class Set studcount=0"
		conn.execute(sql)

		sql="Select classid,count(classid) from joinclass where isauditing=false group by classid"
		Set rs=conn.execute(sql)
		do until rs.eof
			'if isnull(rs(1)) then uStudCount=0 else uStudCount=rs(1)
			conn.execute("update class Set studcount="&rs(1)&" where classid="&rs(0))
			rs.movenext
		loop
		Set rs=Nothing

case "3"
		dim uClassCount
		sql="delete from joinclass where classid is null or userid is null"
		conn.execute(sql)

		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
			'if isnull(rs(1)) then uClassCount=0 else uClassCount=rs(1)
			conn.execute("update student Set classcount="&rs(1)&" where userid='"&rs(0)&"'")
			rs.movenext
		loop
		Set rs=Nothing
case "4"

		dim uReplyNum
		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)-1
			if uReplyNum>0 then
				conn.execute("update topic Set replys="&uReplyNum&" where postid="&rs(0))
			elseif uReplyNum=0 then
				conn.execute("update topic Set replys=0,lastReply=null,lastTime=postTime where postid="&rs(0))
			end if
			rs.movenext
		loop
		Set rs=Nothing

End select

response.write "<BR><BR><CENTER>数据维护成功！</CENTER>"

End Sub
%>



