<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="admin_Checkuser.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/htmlencode.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%>
<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")="edituser" then
	    Call userinfo()
	elseif request("action")="editname" then
	    Call editname()
    else
		call UserList()
	end if

end if

call endconnection()

sub editname()
dim rs,rss,sql,oldname,newname
dim myoldname,myid
oldname=trim(request.form("oldname"))
newname=trim(request.form("newname"))
if oldname="" or newname="" then
ErrMsg=ErrMsg+"<br>"+"<li>操作失败，请输入您要修改的用户名和修改后的用户名！"
Call Error("Information",ErrMsg)
else
sql="Select studid,userid from student where userid='"&oldname&"'"
Set rs=conn.execute(sql)
if rs.bof and rs.eof then
ErrMsg=ErrMsg+"<br>"+"<li>操作失败，用户表中找不到<font color=red>"&oldname&"</font>这个用户名！"
Call Error("Information",ErrMsg)
else
sql="Select studid,userid from student where userid='"&newname&"'"
Set rss=conn.execute(sql)
if not (rss.bof and rss.eof) then
ErrMsg=ErrMsg+"<br>"+"<li>操作失败，<font color=red>"&newname&"</font>这个用户名已经有人使用！"
Call Error("Information",ErrMsg)
else
myoldname=rs(1)
myid=rs(0)
conn.execute="update admin Set username='"&newname&"' where username='"&myoldname&"'"
conn.execute="update append Set collector='"&newname&"' where collector='"&myoldname&"'"
conn.execute="update clasky_diary Set whois='"&newname&"' where whois='"&myoldname&"'"
conn.execute="update clasky_msg Set whois='"&newname&"' where whois='"&myoldname&"'"

conn.execute="update class Set creator='"&newname&"' where creator='"&myoldname&"'"
conn.execute="update class Set admin1='"&newname&"' where admin1='"&myoldname&"'"
conn.execute="update class Set admin2='"&newname&"' where admin2='"&myoldname&"'"
conn.execute="update ClassTopic Set userid='"&newname&"' where userid='"&myoldname&"'"
conn.execute="update ClassTopicReply Set userid='"&newname&"' where userid='"&myoldname&"'"
conn.execute="update comment Set name='"&newname&"' where name='"&myoldname&"'"
conn.execute="update Friend Set F_username='"&newname&"' where F_username='"&myoldname&"'"
conn.execute="update Friend Set F_friend='"&newname&"' where F_friend='"&myoldname&"'"
conn.execute="update joinclass Set userid='"&newname&"' where userid='"&myoldname&"'"
conn.execute="update Log Set userid='"&newname&"' where userid='"&myoldname&"'"

conn.execute="update message Set sender='"&newname&"' where sender='"&myoldname&"'"
conn.execute="update message Set incept='"&newname&"' where incept='"&myoldname&"'"
conn.execute="update photo Set name='"&newname&"' where name='"&myoldname&"'"
conn.execute="update Reply Set UserID='"&newname&"' where UserID='"&myoldname&"'"
conn.execute="update scfav Set username='"&newname&"' where username='"&myoldname&"'"
conn.execute="update scurl Set username='"&newname&"' where username='"&myoldname&"'"
conn.execute="update teacher Set collector='"&newname&"' where collector='"&myoldname&"'"
conn.execute="update Topic Set userid='"&newname&"' where userid='"&myoldname&"'"
conn.execute="update VoteBox Set username='"&newname&"' where username='"&myoldname&"'"
conn.execute="update student Set userid='"&newname&"' where userid='"&myoldname&"'"
Call adminmsg("操作成功，已经将用户名：<font color=red>"&myoldname&"</font>修改成<font color=red>"&newname&"</font>！")
end if
set rss=nothing
end if
set rs=nothing
end if
end sub

sub BatchDel()

	dim idlist,idarr
	dim i,adminture


	if isempty(request("seluser")) then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，请选择你要删除的用户！"
Call Error("Information",ErrMsg)
	else
		idlist=Request("seluser")
		idArr=Split(idlist,",")
		for i = 0 to ubound(idarr)
		sql="Select username from admin where managerid="&Clng(idarr(i))
	    Set rs=conn.execute(sql)
	    if not rs.eof then
	   adminture=adminture+rs(0)+"，"
	   else
			Call DeleteUser(Clng(idarr(i)))
		end if
		next
		if adminture<>"" then
		Call adminmsg("删除用户成功，其中<font color=red>"&adminture&"</font>是管理员，无法删除，如须删除请取消其管理员身份！")
		else
		Call adminmsg("恭喜，删除用户成功！")
	end if
	end if

end sub

sub delempty()
	
	dim sql,rs
	dim i,ii,adminture
	i=0
	ii=0
		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
			conn.execute("update student Set classcount="&rs(1)&" where userid='"&rs(0)&"'")
			rs.movenext
		loop
		Set rs=Nothing
	
	sql="select studid from student where classcount=0 and locked<2"
	Set rs=conn.execute(sql)
	do until rs.eof
	Set rss=conn.execute("Select username from admin where managerid="&rs(0))
	if not rss.eof then
	   adminture=adminture+rss(0)+"，"
	   ii=ii+1
	   else
		Call deleteuser(rs(0))
		end if
		rs.movenext
		i=i+1
	loop

	if i<>0 and ii=0 then
	Call adminmsg("恭喜，成功删除"&i&"个用户！")
	elseif ii<>0 then
	Call adminmsg("成功删除"&i-ii&"个用户，其中"&adminture&"是管理员，无法删除，如须删除请取消其管理员身份！")
	else
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，没有找到需要进行操作的用户记录！"
    Call Error("Information",ErrMsg)	
	end if

	set rs=nothing

end sub



sub delexpire()

	dim sql,rs
	dim i,ii,adminture
	i=0
	ii=0
	ExpiringDate=cint(request("ExpiringDate"))
	sql="select studid from student where datediff(month,lastlogin,getdate())>"&ExpiringDate
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,1
	do until rs.eof
	Set rss=conn.execute("Select username from admin where managerid="&rs(0))
	if not rss.eof then
	   adminture=adminture+rss(0)+"，"
	   ii=ii+1
	else
		call DeleteUser(rs(0))
	end if
		rs.movenext
		i=i+1
	loop

	if i<>0 and ii=0 then
	Call adminmsg("恭喜，成功删除"&i&"个用户！")
	elseif ii<>0 then
		Call adminmsg("成功删除"&i-ii&"个用户，其中"&adminture&"是管理员，无法删除，如须删除请取消其管理员身份！")
		else	
    ErrMsg=ErrMsg+"<br>"+"<li>操作失败，没有找到需要进行操作的用户记录！"
    Call Error("Information",ErrMsg)
	end if

	rs.close
	set rs=nothing

end sub



sub UserList()

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

MaxRecPerPage=20

%>
<center>
<script language=JavaScript src="../inc/jsfun.asp"></script>
<table border=0 width=90%  Class=TableBorder>
  <tr> 
    <td colspan="3" Class=forumrowhighlight><B><a name=top>说明</a></B>：<br>
      (1)删除用户的操作在删除用户信息的同时，将删除所有该用户的留言、帖子、个人网签、日记、上传的照片和头像、发表的相片评论<br> &nbsp;&nbsp;&nbsp;以及所有该用户添加的教师和附加同学信息，且删除后不可恢复！<br>
      (2)如果服务器不支持FSO组件，相片文件会被保留。<br>
      (3)在清除游离用户时，建议先用数据维护功能重新统计每个用户注册的学校数，否则有可能误操作！<br> </td>
  </tr>
  <form action="admin_user.asp" method="POST" name="search" id="search">
    <tr> 
      <td width="18%" class=forumrow><font color="#660033">点击用户名进行相应操作</font></td>
      <td width="43%" class=forumrow><div align="center"><a href="?action=nojoinclass"><strong>没有加入学校的用户</strong></a> 
          | <a href="?action=lastlogin"><strong>最近登陆的用户</strong></a> | <a href="?action=lockeduser"><strong>锁定的用户</strong></a></div></td>
      <td width="39%" align=right class=forumrow>查找用户: 
        <input name="txtitle" type="text" value="<%=Request.form("txtitle")%>" size="20">
        姓名: 
        <input type="radio" name="realname" value="1"> <input type="submit" value="查询" name="title" class=button></td>
    </tr>
  </form>
</table>
<form method=Post action="admin_user.asp">
<input type=hidden name=Action value=BatchDel>
<table border="0" cellspacing="1" width="90%"  cellpadding="0" Class=TableBorder>

<tr>
    <th width="46" align="center" height="20">ID</th>
	<th align="center">用户名</th>
	<th align="center">姓名</th>
	<th align="center">QQ</th>
	<th align="center">Email</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>
<%if request("action")="nojoinclass" then
	sql="select userid,studid,realname,email,visitcount,lastip,lastlogin,locked,oicq,classcount from student where classcount=0 order by studid"
elseif request("action")="lastlogin" then
	sql="select userid,studid,realname,email,visitcount,lastip,lastlogin,locked,oicq,classcount from student where datediff(day,lastlogin,getdate())<10 order by lastlogin desc"
elseif request("action")="lockeduser" then
	sql="select userid,studid,realname,email,visitcount,lastip,lastlogin,locked,oicq,classcount from student where locked=1 order by studid"
else
realname=Request.form("realname")
title=trim(Request.form("txtitle"))
if title<>"" and realname=1 Then
	sql="select userid,studid,realname,email,visitcount,lastip,lastlogin,locked,oicq,classcount from student where realname like '%"&title&"%' order by studid"
Elseif title<>"" and realname="" Then
	sql="select userid,studid,realname,email,visitcount,lastip,lastlogin,locked,oicq,classcount from student where userid like '"&title&"%' order by studid"
else
	sql="select userid,studid,realname,email,visitcount,lastip,lastlogin,locked,oicq,classcount from student order by studid"
End if
end if
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof Then
	Response.Write "<tr><td colspan=11 height=30 class=forumrow> &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>"&_
	"<td height=23 align=center Class=forumrowhighlight>"&rs(1)&"</td>"&_
	"<td Class=forumrowhighlight>&nbsp;&nbsp;<a href=""javascript:openScript('admin_user.asp?action=edituser&name="&rs(0)&"',400,300)"" title=查看和修改用户信息>"&htmlencode(rs(0))&"</a></td>"&_
	"<td Class=forumrowhighlight>&nbsp;&nbsp;"&rs(2)&"</td><td Class=forumrowhighlight>&nbsp;<a title=""查看QQ信息"" href=http://friend.qq.com/cgi-bin/friend/user_show_info?ln="&rs(8)&" target=_blank>"&rs(8)&"</A></td><td Class=forumrowhighlight>&nbsp;"&rs(3)&"</td><td align=center Class=forumrowhighlight>&nbsp;"&rs(9)&"</td>"&_
	"<td align=center Class=forumrowhighlight>"&rs(4)&"</td><td align=center Class=forumrowhighlight>"&rs(5)&"</td>"&_
	"<td align=center Class=forumrowhighlight>"&rs(6)&"</td><td align=center Class=forumrowhighlight>"
if rs(7)=1 then response.write "<font color=red>锁</a>" else response.write "0"
response.write "</td><td align=center width=20 Class=forumrowhighlight>"&_
	"<input type=checkbox name=seluser value="&rs(1)
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% Class=TableBorder><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=""?action="&request("action")&"&page=1&txtitle="&title&"""><font face=webdings>9</font></a>&nbsp;"
	Response.Write "<a href=""?action="&request("action")&"&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=""?action="&request("action")&"&page="&(CurrentPage+1)&"&txtitle="&title&""">"
	Response.Write "<font face=webdings>8</font></a> <a href=""?action="&request("action")&"&page="&totalpages&"&txtitle="&title&"""><font face=webdings>"&chr(58)&"</font></a>"
End if
%>
&nbsp;&nbsp;转到第
<select name="page" style="width:35px" onChange="location.href='?action=<%=request("action")%>&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>页  <input type=checkbox name=chkall onClick="CheckAll(this.form)">全选/取消
</td>
<td align=right class=forumrow>&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><th>删除没有加入任何学校的用户</th></tr>
<tr align=left height=40>
<form method="POST" action="admin_user.asp">
	<td class=forumrow>&nbsp;&nbsp;清理没有加入任何学校的用户前，系统会自动重新统计每个用户加入的学校数，管理员不受影响！&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><th>超期用户管理</th></tr>
<tr align=left height=40>
<form method="POST" action="admin_user.asp">
<td class=forumrow>&nbsp;&nbsp;删除超过指定日期内没有访问系统的用户&nbsp;<Select name="ExpiringDate" size=1>
	<option value="60">五年以上</option>
	<option value="48">四年以上</option>
	<option value="36">三年以上</option>
	<option value="24">两年以上</option>
	<option value="12">一年以上</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><th>修改用户名</th></tr>
<tr align=left height=40>
<form method="POST" action="admin_user.asp">
      <td class=forumrow>&nbsp;&nbsp;旧用户名：
        <input name="oldname" type="text" id="oldname" size="20">
        &nbsp;&nbsp;新用户名：
        <input name="newname" type="text" id="newname" size="20"> 
        <input type=hidden name=action value=editname>
        <input type=submit value="执行操作" onClick="return confirm('您确认要执行此项操作吗？')" class=button>
</td></form></tr></table>
<BR>
<%
End Sub
Sub userinfo()
if Request("editaction")="save" Then
  Call update()
Else
  Call info()
End if
End Sub

Sub classlist(byval username)
	tmpsql="Select C.classid,C.classname from class C inner join joinclass J on C.classid=J.classid "&_
	"where J.userid='"&username&"'  and J.isauditing=0 order by C.classname"
	Set tmprs=Conn.Execute(tmpsql)
	if tmprs.eof Then
		Response.write "<font color=red>尚未加入任何学校</font>"
	Else
		Response.write "<select name=classlist onchange=""if(this.selectedIndex!=0&&this.selectedIndex!=1)"&_
				"{window.open('../Class_index.asp?ClassID='+options[this.selectedIndex].value);this.selectedIndex=0;}"">"
		Response.write "<option value=0>浏览所注册学校</option>"
		Response.write "<option value=1>--------------</option>"
		do until tmprs.eof
			Response.write 	"<option value="&tmprs(0)&">"&htmlencode(tmprs(1))&"</option>"
			tmprs.movenext
		loop		
	End if
	set tmprs=nothing
	
End Sub

Sub info()

	dim sql,rs

	sql="Select * from student where userid='"&trim(Request("name"))&"'"
	set rs=conn.execute(sql)
	if rs.eof and rs.bof Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，该用户名不存在！<a href=""javascript:window.close();""><font color=red>关闭窗口</font></a>"
   Call Error("Information",ErrMsg)
	Else
%>

  <table width="100%" border="0" cellspacing="1" cellpadding="5"  align=center Class=TableBorder>
   <form method="POST" action=admin_user.asp?action=edituser&editaction=save>
   <tr> 
      <th height="11" colspan="2" ><b><%=htmlencode(rs("userid"))%>的个人资料</b></font></th>
    </tr>
    <tr> 
      <td width="95" height="18" class=forumrow>用&nbsp;户&nbsp;名</td>
      <td width="863" height="18" class=forumrow> 
        <a target=_blank title=发短信 href=Class_UserSms.asp?Action=new&touser=<%=rs("userid")%>><%=htmlencode(rs("userid"))%></a> 
        <input type="hidden" name="Name" size="35" value="<%=rs("userid")%>"> 
      </td>
    </tr>
    <tr> 
      <td width="95" height="18" class=forumrow>用户密码</td>
      <td width="863" height="18" class=forumrow> 
        <input type="text" name="userpwd" size="35"> 
      </td>
    </tr>
    <tr> 
      <td height="11" class=forumrow>真实姓名</td>
      <td height="11" class=forumrow> 
        <input type="text" name="realname" size="35" value="<%=rs("realname")%>"> 
      </td>
    </tr>
    <tr>
      <td height="11" class=forumrow>所在学校</td>
      <td height="11" class=forumrow>
        <%Call classlist(rs("userid"))%>
      </td>
    </tr>
    <tr> 
      <td width="95" height="18" class=forumrow>邮件地址</font></td>
      <td width="863" height="18" class=forumrow> 
        <input type="text" name="Email" size="35" value="<%=rs("Email")%>"> 
      </td>
    </tr>
    <tr> 
      <td width="95" height="18" class=forumrow>个人主页</font></td>
      <td width="863" height="18" class=forumrow> 
        <input type="text" name="homepage" size="35" value="<%=rs("homepage")%>"> 
      </td>
    </tr>
    <tr> 
      <td width="95" height="8" class=forumrow>用户积分</font></td>
      <td width="863" height="8" class=forumrow> 
        <input type="text" name="point" size="35" value="<%=rs("point")%>"> 
      </td>
    </tr>
    <tr> 
      <td width="95" height="18" class=forumrow>锁定用户</font></td>
      <td width="863" height="18" class=forumrow> 
        <select name="locked">
          <option value="0" <%if rs("locked")=0 Then%>selected<%End if%>>否 
          <option value="1" <%if rs("locked")=1 Then%>selected<%End if%>>是 
        </Select> 
      </td>
    </tr>
    <tr> 
      <td height="23" colspan="2" Class=forumrowhighlight align=center> 
        <input type="submit" name="Submit" value="更 新" class=button>
        &nbsp;
        <input type="button" value="关 闭" onClick="javascript:window.close();" class=button> 
      </td>
    </tr>
	</form>
  </table>

<%
End if
Set rs=Nothing
End Sub
Sub update()
	dim sql,rs
	dim locked
	Set rs=server.createobject("adodb.recordset")
	sql="Select * from student where userid='"&trim(Request.form("name"))&"'"
	rs.open sql,conn,1,3
	if rs.eof and rs.bof Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，该用户名不存在！<a href=""javascript:window.close();""><font color=red>关闭窗口</font></a>"
    Call Error("Information",ErrMsg)
		Exit Sub
	Else
	if (Request.form("userpwd"))<>"" then rs("userpwd")=md5(Request.form("userpwd"))
		rs("realname")=Request.form("realname")
		rs("email")=Request.form("email")
		rs("homepage")=Request.form("homepage")
		rs("point")=Request.form("point")
		locked=request.form("locked")
		rs("locked")=cint(locked)
		rs.update
        rs.close
	End if
	Set rs=Nothing
	Call adminmsg("恭喜，更新用户数据成功！<a href=""javascript:window.close();""><font color=red>关闭窗口</font></a>")
%>
<%
End Sub 

Sub DeleteUser(id)

    Dim rs,sql
    sql="Select userid,ImageID from student where studid="&cstr(id)
	Set rs=conn.execute(sql)
	username=rs(0)
	userfacephoto=rs(1)
	'''删除用户头像
if left(userfacephoto,22)="UploadFiles/UserFaces/" then
	if IsFSOInstalled=True Then
	Set fso = CreateObject("Scripting.FileSystemObject")
			facephotofile="../"&userfacephoto
			facefilepath=server.mappath(facephotofile)
			if fso.FileExists(facefilepath)=True Then
				Set file = fso.GetFile(facefilepath)
				file.delete
			End if
			Set file=Nothing
			Set fso=Nothing
		end if
	end if
	'''结束
	
	'结束
	'删除收藏夹
    sql="delete from scurl where username='"&username&"'"
	conn.execute(sql)
	
	sql="delete from scfav where username='"&username&"'"
	conn.execute(sql)
	'结束
	''删除学校日志
	sql="delete from log where userid='"&username&"'"
	conn.execute(sql)
'''结束
''删除日记
    sql="select id from clasky_diary where whois='"&username&"'"
	set rs=conn.execute(sql)
	do until rs.eof
		conn.execute("delete from clasky_msg where diaryid="&rs(0))
		rs.movenext
	loop
	sql="delete from clasky_diary where whois='"&username&"'"
	conn.execute(sql)
	sql="delete from clasky_msg where whois='"&username&"'"
	conn.execute(sql)
'''结束

	sql="delete from ClassTopic where userid='"&username&"'"
	conn.execute(sql)
	
	sql="delete from ClassTopicReply where userid='"&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,[file],smallfilename 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="../"&rs(2)&rs(0)
			filepath=server.mappath(photofile)
			if fso.FileExists(filepath)=True Then
				Set file = fso.GetFile(filepath)
				file.delete  
			End if
			photofile="../"&rs(2)&rs(3)
			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="Select classid,degree from joinclass where userid='"&username&"' and isauditing=0"
	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=8 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="inc/chkfso.asp"-->
</BODY></HTML>