<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="admin_Checkuser.asp"-->
<!--#include file="inc/htmlencode.asp"-->
<!--#include file="../inc/email.asp"-->
<%Server.ScriptTimeOut=999999999%>
<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%>
<table cellpadding=5 cellspacing=1 border=0 width=90% Class=TableBorder align=center>
  <tr>
			<th>欢迎<b><%=membername%></b>进入管理页面</th>
  </tr>
</table>
	<%
	if request("Action")="BatchDel" then
		call batchdel()
	elseif request("action")="DelEmpty" then
		call delempty()
	elseif request("action")="DelExpire" then
		call delexpire()
	elseif request("action")="Determiner" then
		call DelNoDeterminer()
	elseif request("action")="setclassphoto" then
		call setclassphoto()
	elseif request("action")="passed" then
		call passed()
	else
		call classlist()
	end if

end if

call endconnection()

sub setclassphoto()
dim sql,classid,photom
photom=request("photom")
classid=request("classid")
if photom="" then
photom=0
end if
sql="update class set classphoto="&photom&" where classid="&classid
conn.execute(sql)
Call adminmsg("恭喜，成功修改该学校相册容量为 "&photom&" M！")
end sub

sub passed()
dim id,classid
id=trim(request("id"))
classid=trim(request("classid"))
if id="1" then
id=1
else
id=0
end if
sql="update class set passed="&id&" where classid="&classid
conn.execute(sql)
Call adminmsg("恭喜，成功对该学校操作！")
end sub

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=0"
	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)&StrVar(0)&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
		Errmsg=Errmsg+"<br>"+"<li>操作失败，请输入学校名限定词！"
	Call Error("Information",ErrMsg)
	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
	Call adminmsg("恭喜，成功删除"&i&"个学校！")
	else
		Errmsg=Errmsg+"<br>"+"<li>操作失败，没有找到需要进行操作的学校！"
	Call Error("Information",ErrMsg)
	end if
	rs.close:set rs=nothing

end sub



sub BatchDel()

	dim idlist,idarr
	dim i
	dim isupdatepoint

	if isempty(request("selclass")) then
	Errmsg=Errmsg+"<br>"+"<li>操作失败，请选择你要进行操作的学校！"
	Call Error("Information",ErrMsg)
	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
		Call adminmsg("恭喜，删除学校成功！")
	end if

end sub


sub delempty()
	
	dim sql,rs
	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(userid) from joinclass 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
	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
	Call adminmsg("恭喜，成功删除"&i&"个学校！")
	else
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，没有找到需要进行操作的学校！"
    Call Error("Information",ErrMsg)
	end if

	set rs=nothing

end sub


sub delexpire()

	dim sql,rs
	dim i,ExpiringDate
	i=0
	ExpiringDate=cint(request("ExpiringDate"))
	if ExpiringDate<>182 then ExpiringDate=ExpiringDate*365
	sql="select classid from joinclass group by classid having datediff(day,max(lastvisit),getdate())>"&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
	Call adminmsg("恭喜，成功删除"&i&"个学校！")
	else
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败，没有找到需要进行操作的学校！"
    Call Error("Information",ErrMsg)
	end if

	rs.close:set rs=nothing

end sub



sub classlist()

   	Dim CurrentPage
   	Dim TotalPages
   	Dim i
   	Dim title
   	Dim sql,rs
	dim MaxRecPerPage
    dim nopassed
	dim schooltypeid,provinceid,areaid
MaxRecPerPage=20
title=trim(Request("txtitle"))
nopassed=trim(request("nopassed"))
provinceid=trim(request("provinceid"))
schooltypeid=trim(request("schooltypeid"))
areaid=trim(request("areaid"))
if provinceid="" or not isnumeric(provinceid) then provinceid=0
if schooltypeid="" or not isnumeric(schooltypeid) then schooltypeid=0
if areaid="" or not isnumeric(areaid) then areaid=0
if nopassed="" then nopassed=0

%>
<script language=JavaScript src="../inc/jsfun.asp"></script>
<table border=0 width=90% Class=TableBorder align=center>
  <tr> 
    <td class=forumRowHighlight><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>
  <form method="POST" action="admin_class.asp">
    <tr> 
      <td class=forumrow>
        <%
	  set rss=server.createobject("adodb.recordset")%>
	    学校类型： 
          <select name="schooltypeid" onChange="document.location.href='?provinceid=<%=provinceid%>&areaid=<%=areaid%>&schooltypeid='+this.options[selectedIndex].value;">
            <option value=0>请选择</option>
            <%sql1="select * from schooltype order by schooltypeid"
              rss.open sql1,conn
              while not rss.eof
              selectedseach=""
              if clng(schooltypeid)=clng(rss("schooltypeid")) then
                 selectedseach="selected"
              end if
              %>
            <option <%=selectedseach%> value=<%=rss("schooltypeid")%>><%=rss("schooltypename")%></option>
            <%
               rss.movenext
               wend
               rss.close
              %>
          </select>
学校所在省：
<select name="provinceid" onChange="document.location.href='?areaid=<%=areaid%>&schooltypeid=<%=schooltypeid%>&provinceid='+this.options[selectedIndex].value;">
          <option value=0>请选择</option>
          <%
             sql2="select * from province order by seed "
             rss.open sql2,conn
             while not rss.eof
             selectedseach2=""
             if clng(provinceid)=clng(rss("provinceid")) then
                selectedseach2="selected"
             end if
              %>
          <option <%=selectedseach2%> value="<%=rss("provinceid")%>"><%=rss("provincename")%></option>
          <%
               rss.movenext
               wend
               rss.close
              %>
          </select>
学校所在地区：
<select name="areaid" onChange="document.location.href='?provinceid=<%=provinceid%>&schooltypeid=<%=schooltypeid%>&areaid='+this.options[selectedIndex].value;">
          <option value=0>请选择</option>
          <%
             sql3="select * from areainfo where provinceid="&clng(provinceid)&" order by seed "
             rss.open sql3,conn
             while not rss.eof
             selectedseach3=""
             if clng(areaid)=clng(rss("areaid")) then
                selectedseach3="selected"
             end if
              %>
          <option <%=selectedseach3%> value="<%=rss("areaid")%>"><%=rss("areaname")%></option>
          <%
               rss.movenext
               wend
               rss.close
              %>
          </select> &nbsp;&nbsp;&nbsp;<a href="?schoolid=<%=schoolid%>&nopassed=1"><strong>没有审核的学校</strong></a>&nbsp;&nbsp;查找学校: 
        <input name="txtitle" type="text" value="<%=title%>" size="20">        <input type="submit" value="查询" name="title" class=button></td>
    </tr>
  </form>
</table>
<form method=Post action="admin_class.asp">
 <input type=hidden name=action value=BatchDel>
<table border="0" cellspacing="1" width="90%"  cellpadding="0" Class=TableBorder align=center>
 
 <tr>
          <th width="46" align="center"  height="20">ID</th>
          <th width="200" align="center">学校名</th>
		  <th width="100" 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="40" align="center">审核</th>
		  <th width="40" align="center">选择</th>
    </tr>
<%
Dim SqlStr
if provinceid>0 Then SqlStr=SqlStr &" And provinceid="&provinceid&" "
if schooltypeid>0 Then SqlStr=SqlStr &" And schooltypeid="&schooltypeid&" "
if areaid>0 Then SqlStr=SqlStr &" And areaid="&areaid&" "
if nopassed>0 Then SqlStr=SqlStr &" And passed=0 "
if title<>"" Then SqlStr=SqlStr &" And classname like '%"&title&"%' "

sql="Select classid,classname,studcount,admin1,admin2,regdate,classphoto,passed from class where classid>0 "&SqlStr&" order by classid"

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

if rs.eof and rs.bof Then
	Response.Write "<tr><td colspan=9 height=30 class=forumrow> &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>"&_
	"<td height=23 align=center class=forumrow>"&rs(0)&"</td>"&_
	"<td class=forumrow>&nbsp;&nbsp;<a href=""../Class_index.asp?ClassID="&rs(0)&""" target=_blank title=转到学校页面>"&htmlencode(rs(1))&"</a></td>"&_
	"<td align=center class=forumrow><select name=classphoto size=1 onChange=""document.location.href='admin_Class.asp?action=setclassphoto&classid="&rs(0)&"&photom='+this.options[selectedIndex].value;""><option value=0>0 M</option>"
for ii=1 to 100
	Response.write "<option" 
if rs(6)=ii then 
Response.write " selected" 
end if 
Response.write " value="&ii&">"&ii&" M</option>"
next
response.write "</Select></td>"
response.write "<td align=center class=forumrow>"&rs(2)&"</td><td align=center class=forumrow><a href=../Class_userinfo.asp?name="&rs(3)&" target=_blank title=查看资料>"&rs(3)&"</a></td>"&_
	"<td align=center class=forumrow><a href=../Class_userinfo.asp?name="&rs(4)&" target=_blank title=查看资料>"&rs(4)&"</a></td><td class=forumrow>&nbsp;"&rs(5)&"</td>"&_
	"<td align=center class=forumrow>"
	if rs(7)=1 then
	 response.write"<a href=admin_Class.asp?classid="&rs(0)&"&action=passed&id=0 title=反审核>已审</a>"
	 else
	  response.write"<a href=admin_Class.asp?classid="&rs(0)&"&action=passed&id=1 title=审核><font color=red>未审</font></a>"
	   end if
response.write "</td><td align=center class=forumrow><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% Class=TableBorder align=center>
    <tr> 
      <td class=forumrow> 
        <% 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&"&provinceid="&provinceid&"&schooltypeid="&schooltypeid&"&areaid="&areaid&"&nopassed="&nopassed&"""><font face=webdings>9</font></a>&nbsp;"
    Response.Write "<a href=""?page="&CurrentPage-1&"&txtitle="&title&"&provinceid="&provinceid&"&schooltypeid="&schooltypeid&"&areaid="&areaid&"&nopassed="&nopassed&"""><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&"&provinceid="&provinceid&"&schooltypeid="&schooltypeid&"&areaid="&areaid&"&nopassed="&nopassed&""">"
    Response.Write "<font face=webdings>8</font></a> <a href=""?page="&totalpages&"&txtitle="&title&"&provinceid="&provinceid&"&schooltypeid="&schooltypeid&"&areaid="&areaid&"&nopassed="&nopassed&"""><font face=webdings>"&chr(58)&"</font></a>"
  End if

%>
        &nbsp;&nbsp;转到第 
        <select name="page" style="width:35px" onChange="location.href='?provinceid=<%=provinceid%>&schooltypeid=<%=schooltypeid%>&areaid=<%=areaid%>&nopassed=<%=nopassed%>&txtitle=<%=title%>&page='+this.options[selectedIndex].value">
          <%
             dim ii
             ii=1
             do while ii<=totalpages
             if ii=currentPage then
             response.write("<option selected value="&ii&">"&ii&"</option>")
             else
             response.write("<option value="&ii&">"&ii&"</option>")
             end if
             ii=ii+1
             loop
              %>
        </select>
        页 &nbsp; 
        <input type=checkbox name=chkall onClick="CheckAll(this.form)">
        全选/取消&nbsp; <input type=checkbox name=isendmail value=1>
        发送邮件通知 <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% align=center>
<tr><th>零成员学校管理</th></tr>
<tr align=left height=40><form method="POST" action="admin_class.asp"><td class=forumrow>&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是否现在就执行删除操作？')" class=button></td></form></tr></table>
<BR>
<table border=0 cellspacing=1 cellpadding=5 Class=TableBorder width=90% align=center>
<tr><th>超期学校管理</th></tr>
<tr align=left height=40>
<form method="POST" action="admin_class.asp">
<td class=forumrow>&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% align=center>
<tr><th>不规范学校管理(不推荐使用!)</th></tr>
<tr align=left height=40><form method="POST" action="admin_class.asp"><td class=forumrow>&nbsp;&nbsp;清除学校名称中<B>不包含</B>指定限定词的学校(用"|"分隔限定词)&nbsp;
        <input type=hidden name=action value=Determiner>
        <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 point=point+"&PointSet(18)&" where userid in (select userid from "&_
		"ClassTopicReply where classid="&classid&")"
		conn.execute(sql)
		
		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 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 ClassTopic where classid="&classid
	conn.execute(sql)
	
	sql="delete from ClassTopicReply 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,[file],smallfilename 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="../"&rs(3)&rs(1)
	'		filepath=server.mappath(photofile)

	'		if fso.FileExists(filepath)=True Then
	'			Set file = fso.GetFile(filepath)
	'			file.delete  
	'		End if
			
	'		photofile="../"&rs(3)&rs(4)
	'		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

	'''删除文件夹
if IsFSOInstalled Then
dim classfile
sql="Select [file] from photo where classid="&classid
Set rs=conn.execute(sql)
if not rs.eof then
classfile="../"&rs(0)
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
if fso.FolderExists(Server.MapPath(classfile)) then
FSO.DeleteFolder(Server.MapPath(classfile))
end if
Set fso=nothing
end if
set rs=nothing
end if

'''''''

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

	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="inc/chkfso.asp"-->
</BODY></HTML>

