<!--#INCLUDE FILE="setup.asp" -->
<!--#include file=checkuser.asp-->
<!--#include file=include/htmlencode.asp-->
<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%>
	<table cellpadding=5 cellspacing=1 border=0 width=100% Class=TableBorder align=center>
			<tr>
			<th>欢迎<b><%=membername%></b>进入管理页面</th>
			</tr>
	</table>
	<%
	if request("Action")="BatchDel" then%>
		<!--#include file=include/email.asp-->
		<%call batchdel()
	elseif request("action")="DelEmpty" then
		call delempty()
	elseif request("action")="DelExpire" then
		call delexpire()
	else
		call UserList()
	end if

end if

call endconnection()


sub BatchDel()

	dim idlist,idarr
	dim i

	if isempty(request("seluser")) then
		response.write "<br><br><CENTER>操作失败，请选择你要删除的用户！</CENTER>"
	else
		idlist=Request("seluser")
		idArr=Split(idlist,",")
		for i = 0 to ubound(idarr)
			Call DeleteUser(Clng(idarr(i)))
		next
		response.write "<br><br><center>操作成功，请返回！</center>"
	end if

end sub



sub delempty()
	
	dim sql,rs
	dim i
	i=0
	sql="select studid from student where classcount=0 and locked<2"
	Set rs=conn.execute(sql)
	do until rs.eof
		Call deleteuser(rs(0))
		rs.movenext
		i=i+1
	loop

	if i<>0 then
		response.write "<br><br><center>成功删除"&i&"个用户，请返回！</center>"
	else
		response.write "<br><br><center>没有找到需要进行操作的用户记录，请返回！</center>"
	end if

	set rs=nothing

end sub



sub delexpire()

	dim sql,rs
	dim i
	i=0
	ExpiringDate=cint(request("ExpiringDate"))
	sql="select studid from student where datediff('yyyy',lastlogin,date())>="&ExpiringDate
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,1
	do until rs.eof
		call DeleteUser(rs(0))
		rs.movenext
		i=i+1
	loop

	if i<>0 then
		response.write "<br><br><center>成功删除"&i&"个用户，请返回！</center>"
	else
		response.write "<br><br><center>没有找到需要进行操作的用户，请返回！</center>"
	end if

	rs.close:set rs=nothing

end sub



sub UserList()

Dim totalRec   
Dim CurrentPage
Dim TotalPages
Dim i
Dim title
Dim sql,rs
dim MaxRecPerPage

MaxRecPerPage=20

%>


<center>
<table border=0 width=90%><tr><td class=mp><BR><B><a name=top>说明</a></B>：<br>
(1)删除用户的操作在删除用户信息的同时，将删除所有该用户的留言、上传的照片、发表的相片评论以及所有该用户添加的教师和附加同学信息，且删除后不可恢复！<br>
(2)如果服务器不支持FSO组件，相片文件会被保留。<br>
(3)在清除游离用户时，建议先用数据维护功能重新统计每个用户注册的班级数，否则有可能误操作！<br>
<BR><BR></td></tr></table>

<table border="0" cellspacing="1" width="90%"  cellpadding="0">
<form method="POST" action="sysadm_user.asp">
<tr>
	<td height=30>点击用户名进行相应操作</td>
	<td align=right>查找用户:  <input type="text" name="txtitle" size="20">
	<input type="submit" value="查询" name="title" class=button></td>
</tr>
</form>
</table>

<table border="0" cellspacing="1" width="90%"  cellpadding="0" Class=TableBorder>
<tr>
	<form method=Post action="sysadm_user.asp">
	<input type=hidden name=Action value=BatchDel>
	<th width="46" align="center" height="20">ID</th>
	<th align="center">用户名</th>
	<th align="center">姓名</th>
	<th align="center">邮件</th>
	<th align="center">登陆次数</th>
	<th align="center">登陆IP</th>
	<th align="center">最近访问时间</th>
	<th align="center">锁定</th>
	<th align="center">选择</th>
</tr>
<%
title=trim(Request("txtitle"))

if title<>"" Then
	sql="select userid,studid,realname,email,point,lastip,lastlogin,locked from student where userid like '%"&trim(title)&"%' order by studid"
Else
	sql="select userid,studid,realname,email,point,lastip,lastlogin,locked from student order by studid"
End if

Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1

if rs.eof and rs.bof Then
	Response.Write "<tr Class=LightTableBody><td colspan=7 height=30> &nbsp;&nbsp;还 没 有 任 何 用 户 </td></tr></table>"
Else

totalRec=rs.recordcount 
if not isempty(Request("page")) Then
	currentPage=cint(Request("page"))
Else
	currentPage=1
End if

rs.pagesize=MaxRecPerPage
totalpages=rs.pagecount
rs.AbsolutePage=currentpage

for i=1 to MaxRecPerPage

response.write "<tr Class=LightTableBody>"&_
	"<td height=23 align=center>"&rs(1)&"</td>"&_
	"<td>&nbsp;&nbsp;<a href=""sysadm_modiuser.asp?name="&rs(0)&""" title=查看和修改用户信息>"&htmlencode(rs(0))&"</a></td>"&_
	"<td>&nbsp;&nbsp;"&rs(2)&"</td><td>&nbsp;"&rs(3)&"</td>"&_
	"<td align=center>"&rs(4)&"</td><td align=center>"&rs(5)&"</td>"&_
	"<td align=center>"&rs(6)&"</td><td align=center>"
if rs(7)=1 then response.write "1" else response.write "0"
response.write "</td><td align=center width=50>"&_
	"<input type=checkbox name=seluser value="&rs(1)
if rs(7)=3 Then response.write " disabled"
response.write "></td></tr>"
rs.movenext
if currentpage=totalpages then
	if rs.eof then exit for
end if

next%>
</table>
<table border=0 width=90%><tr><td>
<%

Response.Write "页次:</font><strong><font color=red>"&CurrentPage&"</font>/"&totalpages&"</strong> "
Response.Write "&nbsp;用户:<b>"&totalrec&"</b> &nbsp;每页:<b>"&MaxRecPerPage&"</b>&nbsp;&nbsp;"

if CurrentPage=1 Then
	Response.Write "<font face=webdings color=gray>9</font> <font face=webdings color=gray>7</font>&nbsp;"
Else
	Response.Write "<a href=""?page=1&txtitle="&title&"""><font face=webdings>9</font></a>&nbsp;"
	Response.Write "<a href=""?page="&CurrentPage-1&"&txtitle="&title&"""><font face=webdings>7</font></a>&nbsp;"
End if
if currentpage=totalpages Then
	Response.Write "<font face=webdings color=gray>8</font> <font face=webdings color=gray>"&chr(58)&"</font>"
Else
	Response.Write "<a href=""?page="&(CurrentPage+1)&"&txtitle="&title&""">"
	Response.Write "<font face=webdings>8</font></a> <a href=""?page="&n&"&txtitle="&title&"""><font face=webdings>"&chr(58)&"</font></a>"
End if

%>
</td>
<td align=right>&nbsp;<input type='submit'  value="删除用户" name="submit" onclick="return confirm('您确认要删除所选用户吗？')" class=button>
</td></tr></table>
</form>
<%
End if

rs.close
Set rs=Nothing  
%>
<BR><table border=0 cellspacing=1 cellpadding=5 Class=TableBorder width=90%>
<tr Class=DarkTableBody><th>游离用户管理</th></tr>
<tr Class=LightTableBody align=left height=40>
<form method="POST" action="sysadm_user.asp">
	<td>&nbsp;&nbsp;清理没有加入任何班级的用户，请在操作前先查看<a href=#top>说明</a>，管理员不受影响&nbsp;
	<input type=hidden name=action value=DelEmpty>
	<input type=submit value="执行操作" onclick="return confirm('建议在此操作前先用数据维护功能重新统计用户注册的班级数，\n否则有可能引起误操作!\n\n是否现在就执行删除操作？')" class=button></td>
</form>
</tr>
</table>
<BR>
<table border=0 cellspacing=1 cellpadding=5 Class=TableBorder width=90%>
<tr Class=DarkTableBody><th>超期用户管理</th></tr>
<tr Class=LightTableBody align=left height=40>
<form method="POST" action="sysadm_user.asp">
<td>&nbsp;&nbsp;删除超过指定日期内没有访问系统的用户&nbsp;<Select name="ExpiringDate" size=1>
	<option value=5>五年以上</option>
	<option value=4>四年</option>
	<option value=3>三年</option>
	<option value=2>两年</option>
	<option value=1>一年</option>
	</Select>
<input type=hidden name=action value=DelExpire><input type=submit value="执行操作" onclick="return confirm('您确认要执行此项操作吗？')" class=button></td></form></tr><table><BR><BR>
<%
End Sub 


Sub DeleteUser(id)

    Dim rs,sql
    sql="Select userid from student where studid="&cstr(id)
	Set rs=conn.execute(sql)
	username=rs(0)
	
	sql="delete from classboard where name='"&username&"'"
	conn.execute(sql)

	sql="delete from append where collector='"&username&"'"
	conn.execute(sql)

	sql="delete from teacher where collector='"&username&"'"
	conn.execute(sql)

	sql="delete from friend where F_username='"&username&"'"
	conn.execute(sql)

	sql="delete from friend where F_friend='"&username&"'"
	conn.execute(sql)


	rem delete user message

	sql="delete from message where sender='"&username&"' and issend=0"
	conn.execute(sql)

	sql="delete from message where sender='"&username&"' and delR=2 or incept='"&username&"' and delS=2"
	conn.execute(sql)

	sql="update message Set delR=2 where incept='"&username&"'"
	conn.execute(sql)

	sql="update message Set delS=2 where sender='"&username&"'"
	conn.execute(sql)

	sql="select postid from topic where userid='"&username&"'"
	set rs=conn.execute(sql)
	do until rs.eof
		conn.execute("delete from reply where topicid="&rs(0))
		rs.movenext
	loop

	sql="delete from topic where userid='"&username&"'"
	conn.execute(sql)

	sql="delete from reply where userid='"&username&"'"
	conn.execute(sql)

	sql="Select filename,picID from photo where name='"&username&"'"
	Set rs=conn.execute(sql)

	if IsFSOInstalled=True Then
		Set fso = CreateObject("Scripting.FileSystemObject")
	end if

	do until rs.eof
		if IsFSOInstalled=True Then
			photofile=StrVar(8)&rs(0)
			filepath=server.mappath(photofile)
			if fso.FileExists(filepath)=True Then
				Set file = fso.GetFile(filepath)
				file.delete  
			End if
		end if
		sql="delete from comment where picID="&rs(1)
		conn.execute(sql)

		rs.movenext
	loop

	if IsFSOInstalled=True Then
		Set file=Nothing:Set fso=Nothing
	end if

	sql="delete from photo where name='"&username&"'"
	conn.execute(sql)

	sql="delete from comment where name='"&username&"'"
	conn.execute(sql)

	sql="delete from VoteBox where username='"&username&"'"
	conn.execute(sql)

	sql="delete from log where userid='"&username&"'"
	conn.execute(sql)


	sql="Select classid,degree from joinclass where userid='"&username&"' and isauditing=False"
	Set rs=conn.execute(sql)
	do until rs.eof 
		studclass=rs(0)
		userclass=rs(1)

		sql="update class Set studcount=studcount-1 where classid="&studclass
		conn.execute(sql)

		if userclass=8 Then
			sql="update class Set admin1=null where admin1='"&username&"' and classid="&studclass
			conn.execute(sql)
		ElseIf userclass=7 Then
			sql="update class Set admin2=null where admin2='"&username&"' and classid="&studclass
			conn.execute(sql)
		End if

		rs.movenext
	loop
	set rs=nothing

	sql="delete from joinclass where userid='"&username&"'"
	conn.execute(sql)

	sql="delete from student where userid='"&username&"'"
	conn.execute(sql)

	conn.execute("update config Set UserNum=UserNum-1")


End Sub%>
<!--#include file=include/chkfso.asp-->
