<!--#INCLUDE FILE="setup.asp" -->
<!--#include file=checkuser.asp-->
<!--#include file=include/htmlencode.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%>

	<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()
	elseif request("action")="Determiner" then
		call DelNoDeterminer()
	else
		call classlist()
	end if

end if

call endconnection()



sub SendNotifyMail(classid)

	dim Mailsql,Mailrs
	dim classrs
	Mailsql="select S.email from student S inner join joinclass J on S.userid=J.userid where J.classid="&classid&" and isauditing=false"
	Set Mailrs=conn.execute(Mailsql)

	if not (Mailrs.eof and Mailrs.bof) Then
		mailto=Mailrs("email")
		Mailrs.movenext
		do until Mailrs.eof
			mailto=mailto&","&Mailrs("email")
			Mailrs.movenext
		loop
		set classrs=conn.execute("select classname from class where classid="&classid)
		mailfrom=StrVar(2)
		MailFromName=StrVar(1)
		mailtopic="很抱歉，您注册的班级已被删除--"&StrVar(1)
		mailbody="亲爱的同学，您好！"&vbCrLf&vbCrLf&_
		"   可能您的班级名称命名不规范、或者和其他班级重复或由于其他原因，系统管理员已将您注册的班级： "&_
		classrs(0)&" 删除！"&vbCrLf&_
		"   我们对此操作给您带来的不便和可能引起的信息丢失表示歉意！"&vbCrLf&_
		"   欢迎您常来"&StrVar(1)&"看看，让我们一起来建设这个网上家园！"&vbCrLf&vbCrLf&_
		string(44,"-")&vbCrLf&space(4)&StrVar(1)&vbCrLf&_
		space(4)&SchoolmateURL&vbCrLf
		set classts=nothing
		if IntVar(5)=1 Then
			Call jmail_smtp()		
		ElseIf IntVar(5)=2 Then
			Call Cdonts()		
		ElseIf IntVar(5)=3 Then
			Call aspemail()
		ElseIf IntVar(5)=4 Then
			Call jmail_msg()		
		End if
	end if
	Set Mailrs=Nothing

end sub



sub DelNoDeterminer()

	dim sql,rs
	dim RestrictWord
	dim i,cond

	RestrictWord=trim(request("RestrictWord"))
	if RestrictWord="" then
		response.write "<br><br><CENTER>操作失败，请输入班级名限定词！</CENTER>"
		response.end
	end if

	RestrictWord=split(RestrictWord,"|")

	for i=0 to ubound(RestrictWord)
		if i<>0 then cond=cond&" or "
		cond=cond&"not classname like '%"&RestrictWord(i)&"%'" 
	next

	sql="select classid from class where "&cond
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,1
	i=0
	do until rs.eof
		call DeleteClass(rs(0),false)
		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 BatchDel()

	dim idlist,idarr
	dim i
	dim isupdatepoint

	if isempty(request("selclass")) then
		response.write "<br><br><CENTER>操作失败，请选择你要进行操作的班级！</CENTER>"
	else
		isupdatepoint=not cbool(request("isupdatepoint"))
		idlist=Request("selclass")
		idArr=Split(idlist,",")
		for i = 0 to ubound(idarr)
			if request("isendmail")="1" and IntVar(5)<>0 then 
				Call SendNotifyMail(Clng(idarr(i))) 
			end if
			Call DeleteClass(Clng(idarr(i)),isupdatepoint)
		next
		response.write "<br><br><center>操作成功，请返回！</center>"
	end if

end sub


sub delempty()
	
	dim sql,rs
	dim i
	i=0
	sql="Select classid from class where studcount=0"
	Set rs=conn.execute(sql)
	do until rs.eof
		Call DeleteClass(rs(0),false)
		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"))
	if ExpiringDate<>182 then ExpiringDate=ExpiringDate*365
	sql="select classid from joinclass group by classid having datediff('d',max(lastvisit),date())>="&ExpiringDate
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,1
	do until rs.eof
		call deleteclass(rs(0),false)
		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 classlist()

   	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>
(4)发送邮件通知功能以邮件的形式通知班级内学生班级已经被删除的信息。<BR>
(5)在删除没有成员的班级时，建议先用数据维护功能重新统计班级成员数，否则有可能引起数据丢失！<br>
(6)在进行不规范班级管理操作时，<font color=brown>如果限定词输入不当，有可能造成大量班级数据丢失</font>。因此如果你已经在系统参数设置中设定了合理的限定词，建议不要进行此项操作！
<BR><BR></td></tr></table>

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

<table border="0" cellspacing="1" width="90%"  cellpadding="0" Class=TableBorder>
        <tr><form method=Post action="sysadm_class.asp"><input type=hidden name=action value=BatchDel>
          <th width="46" align="center"  height="20">ID</th>
          <th width="300" align="center">班级名</th>
          <th width=60 align="center">成员数</th>
          <th width=80 align="center">班长</th>
          <th width=80 align="center">副班长</th>
          <th width=80 align="center">注册日期</th>
		  <th width="80" align="center">选择</th>
        </tr>
<%
title=trim(Request("txtitle"))

if title<>"" Then
	sql="Select classid,classname,studcount,admin1,admin2,regdate from class where classname like '%"&title&"%' order by classid"
Else
	sql="Select classid,classname,studcount,admin1,admin2,regdate from class order by classid"
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

if not isempty(Request("page")) Then
	currentPage=cint(Request("page"))
Else
	currentPage=1
End if

totalrec=rs.recordcount
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(0)&"</td>"&_
	"<td>&nbsp;&nbsp;<a href=""MyClass.asp?ClassID="&rs(0)&""" target=_blank title=转到班级页面>"&htmlencode(rs(1))&"</a></td>"&_
	"<td align=center>"&rs(2)&"</td><td align=center>"&rs(3)&"</td>"&_
	"<td align=center>"&rs(4)&"</td><td>&nbsp;"&rs(5)&"</td>"&_
	"<td align=center><input type=checkbox name=selclass value="&rs(0)&"></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="&totalpages&"&txtitle="&title&"""><font face=webdings>"&chr(58)&"</font></a>"
  End if

%>
</td>
<td align=right>
<input type=checkbox name=isendmail value=1>发送邮件通知&nbsp;
<input type=checkbox name=isupdatepoint value=1>不对用户进行积分操作&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_class.asp"><td>&nbsp;&nbsp;清理所有班级成员数为 <B>0</B> 的班级，请在操作前先查看<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_class.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>
	<option value=182>半年</option>
	</Select>
<input type=hidden name=action value=DelExpire><input type=submit value="执行操作" onclick="return confirm('您确认要执行此项操作吗？')" 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_class.asp"><td>&nbsp;&nbsp;清除班级名称中<B>不包含</B>指定限定词的班级(用"|"分隔限定词)&nbsp;<input type=hidden name=action value=StrVar(3)><input type=text name=RestrictWord value=<%=StrVar(3)%>><input type=submit value="执行操作" onclick="return confirm('您目前进行的操作有可能造成大量数据丢失!\n请仔细核对限定词是否和绝大多数班级名称匹配!!!\n\n是否现在就执行操作?')" class=button></td></form></tr>

</table><BR><BR>
<%end sub


Sub DeleteClass(byval classid,updatepoint)

	Dim rs,sql

	if updatepoint then

		'sql="update student set S.point=S.point+"&PointSet(18)&" from student S "&_
		'"inner join classboard B on S.userid=B.name where B.classid="&classid
		sql="update student set point=point+"&PointSet(18)&" where userid in (select userid from "&_
		"classboard where classid="&classid&")"
		conn.execute(sql)
		
		'sql="update student set S.point=S.point+"&PointSet(7)&" from student S "&_
		'"inner join append A on S.userid=A. collector where A.classid="&classid
		sql="update student set point=point+"&PointSet(7)&" where userid in (select userid from "&_
		"append where classid="&classid&")"
		conn.execute(sql)

		'sql="update student Set S.point=S.point+"&PointSet(13)&" from student S "&_
		'"inner join joinclass J on S.userid=J.userid where J.classid="&classid&" and degree>1"
		sql="update student Set point=point+"&PointSet(13)&" where userid in (select userid from "&_
		"joinclass where classid="&classid&" and degree>1)"
		conn.execute(sql)


	end if

	sql="delete from votebox where classid="&classid
	conn.execute(sql)

	sql="delete from log where classid="&classid
	conn.execute(sql)

	sql="delete from classboard where classid="&classid
	conn.execute(sql)

	sql="delete from append where classid="&classid
	conn.execute(sql)


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

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

	do until rs.eof

		if updatepoint then
			sql="update student Set point=point+"&PointSet(21)&" where userid='"&rs(0)&"'"
			conn.execute(sql)
		end if
		if IsFSOInstalled=True Then
			photofile=StrVar(8)&rs(1)
			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(2)
		conn.execute(sql)

		rs.movenext
	loop

	if IsFSOInstalled Then
		Set file=Nothing:Set fso=Nothing
	End if
	Set rs=Nothing

	sql="delete from photo where classid="&classid
	conn.execute(sql)

	'sql="update student Set S.classcount=S.classcount-1"
	'if updatepoint then sql=sql&",S.point=S.point+"&PointSet(11)
	'sql=sql&" from student S inner join joinclass J on S.userid=J.userid where J.classid="&classid
	sql="update student Set classcount=classcount-1"
	if updatepoint then sql=sql&",point=point+"&PointSet(11)
	sql=sql&" where userid in (select userid from joinclass where classid="&classid&")"
	conn.execute(sql)


	sql="delete from joinclass where classid="&classid
	conn.execute(sql)


	sql="delete from class where classid="&classid
	conn.execute(sql)

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

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


