<!--#INCLUDE FILE="setup.asp" -->
<!--#INCLUDE FILE="checkuser.asp" -->
<!--#INCLUDE FILE="theme.asp" -->
<%locat="班级管理"

if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=login.asp>登录</a>。"
	Call top(1,1)
	Call Error("Information",ErrMsg)
Else
	Dim ClsID,Degree,ClassName
	clsid=Request("ClassID")
	joinstatus=chkjoinclass(ClsID)
	if joinstatus<>"" Then
		Call top(1,1)
		Call Error("Exclamation",joinstatus)
	Else
		Select Case Request("Action")
		Case "Delete"
			act="删除班级成员"
			Call top(3,1)
			Call DelMember()
		Case "HandOver"
			act="移交班委职务给他人"
			Call top(3,1)
			Call HandOver()
		Case "Deposal"
			act="免除同学班委职务"
			Call top(3,1)
			Call Deposal()
		Case "Appoint"
			act="任命同学班委职务"
			Call top(3,1)
			Call Appoint()
		Case "通过审核"
			act="审核同学加入本班"
			Call top(3,1)
			Call PassJoin()
		Case "禁止加入"
			act="禁止待审同学加入本班"
			Call top(3,1)
			Call RefuseJoin()
		Case Else
			act="人事管理"
			Call top(3,1)
			Call ClassmateList()
		End Select
	End if
End if


Sub Appoint()

	Dim AptID
	Dim mbstatus

	AptID=Request.form("id")
	Cmt=cint(Request.form("Cmt"))

	if AptID="" Then
		ErrMsg=ErrMsg+"<li>操作失败，请选择相关同学进行操作！"
		FoundErr=True
	ElseIf Cmt<2 or Cmt>8 Then
		ErrMsg=ErrMsg+"<li>非法操作，不存在的班委职务！"
		FoundErr=True
	ElseIf not (Degree>6 or sysadmin) Then
		ErrMsg=ErrMsg+"<li>操作失败，您没有执行此项操作的权限！"
		FoundErr=True
	ElseIf not sysadmin and Degree=7 and Cmt=8 Then
		ErrMsg=ErrMsg+"<li>操作失败，副班长无权任命班长！"
		FoundErr=True
	End if

	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	AptID=Clng(AptID)
	mbstatus=ChkMember(AptID)
	if mbstatus=0 Then
		ErrMsg=ErrMsg+"<li>操作失败，您要任命班委职务的同学不是本班成员！"
		FoundErr=True
	'ElseIf not sysadmin and mbstatus=Degree Then
	'	ErrMsg=ErrMsg+"<li>操作失败，您不能对自己执行此项操作！"
	'	FoundErr=True
	ElseIf mbstatus>1 Then
		ErrMsg=ErrMsg+"<li>操作失败，您所选的同学已经是本班的"&Grade(mbstatus,False)&"，不能重复担任班内的职务！"
		FoundErr=True
	Else
		Set Rs=Conn.Execute("Select userid from joinclass where classid="&ClsID&" and degree="&Cmt)
		if not (Rs.eof and Rs.bof) Then
			ErrMsg=ErrMsg+"<li>操作失败，本班的"&Grade(Cmt,False)&"职位已由"&getrealname(Rs(0))&"担任！"
			FoundErr=True
		End if
		Set Rs=Nothing
	End if


	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	DoAppoint="update student Set point=point+"&Round(PointSet(12)*Cmt/8)&" where studid="&AptID
	Conn.Execute(DoAppoint)

	Set Rs=Conn.Execute("Select userid from student where studid="&AptID)

	DoAppoint="update joinclass Set degree="&Cmt&" where classid="&ClsID&" and userid='"&Rs(0)&"'"
	Conn.Execute(DoAppoint)

	if Cmt=8 Then
		Conn.Execute("update class Set admin1='"&Rs(0)&"' where classid="&ClsID)
	ElseIf Cmt=7 Then
		Conn.Execute("update class Set admin2='"&Rs(0)&"' where classid="&ClsID)
	End if

	'write log
	IP=Request.ServerVariables("REMOTE_ADDR") 
	body="任命"&getrealname(Rs(0))&"为本班的"&Grade(Cmt,False)
	sql="insert into log(userid,content,classid,ip)"&_
		" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
	Conn.Execute(sql)

	'send message
	title="恭喜你成为"&ClassName&"的"&Grade(Cmt,False)&"！"
	if Degree=7 or Degree=8 Then
		body=ClassName&"的班级管理员"&getrealname(membername)&"任命你为本班的"&Grade(Cmt,False)&_
		",请经常访问这个您的班级，并正确行使你的管理权限来管理好这个班级！"
	Else
		body="系统管理员任命你为"&ClassName&"的"&Grade(Cmt,False)&_
		",请经常访问这个您的班级，并正确行使你的管理权限来管理好这个班级！"
	End if
	sql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS)"&_
		" values('"&Rs(0)&"','"&StrVar(1)&"','"&title&"','"&body&"',Now(),0,1,2)"
	Conn.Execute(sql)

	Set Rs=Nothing


	rURL="ClsAdm_Member.asp?ClassID="&ClsID
	rTitle="任命班委职务"
	rMsg="你已经成功将所选同学任命为本班的"&Grade(Cmt,False)&"！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&htmlencode(ClassName)&"首页</a></li>"&_
		"<li><a href=""ClsAdm_Class.asp?ClassID="&ClsID&"&Action=Main"">返回班级管理</a></li>"&_
		"<li><a href="""&rURL&""">继续成员管理</a></li></ul>"
	Redirect 3,rURL,rTitle,rMsg

End Sub



Sub deposal()

	Dim DepID
	Dim mbstatus

	DepID=Request.form("id")
	if DepID="" Then
		ErrMsg=ErrMsg+"<li>操作失败，请选择相关同学进行操作！"
		FoundErr=True
	ElseIf not (Degree>6 or sysadmin) Then
		ErrMsg=ErrMsg+"<li>操作失败，您没有执行此项操作的权限！"
		FoundErr=True
	End if

	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	DepID=Clng(DepID)

	mbstatus=ChkMember(DepID)
	if mbstatus=0 Then
		ErrMsg=ErrMsg+"<li>操作失败，您要免除职务的同学不是本班成员！"
		FoundErr=True
	ElseIf mbstatus=1 Then
		ErrMsg=ErrMsg+"<li>操作失败，您所选的同学不是本班的班委成员，没有职务可以免除！"
		FoundErr=True
	ElseIf mbstatus=Degree Then
		ErrMsg=ErrMsg+"<li>操作失败，您不能对自己执行此项操作，请使用辞职功能！"
		FoundErr=True
	ElseIf mbstatus=8 and Degree=7 and not sysadmin Then
		ErrMsg=ErrMsg+"<li>操作失败，副班长不能对班长执行此项操作！"
		FoundErr=True
	End if

	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if


	DoResign="update student Set point=point+"&Round(PointSet(13)*mbstatus/8)&" where studid="&DepID
	Conn.Execute(DoResign)

	Set Rs=Conn.Execute("Select userid from student where studid="&DepID)

	DoResign="update joinclass Set degree=1 where classid="&ClsID&" and userid='"&Rs(0)&"'"
	Conn.Execute(DoResign)

	if mbstatus=8 Then
		Conn.Execute("update class Set admin1=null where classid="&ClsID)
	ElseIf mbstatus=7 Then
		Conn.Execute("update class Set admin2=null where classid="&ClsID)
	End if

	'write log
	IP=Request.ServerVariables("REMOTE_ADDR") 
	body="免除"&getrealname(Rs(0))&"在本班的"&Grade(Cmt,False)&"职务"
	sql="insert into log(userid,content,classid,ip)"&_
		" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
	Conn.Execute(sql)

	'send message
	title="你在"&ClassName&"的"&Grade(Cmt,False)&"职务被免除！"
	if Degree=7 or Degree=8 Then
		body="很抱歉，由于某种原因，"&ClassName&"的管理员免除了您在该班的"&_
			Grade(Cmt,False)&"职务,您如果有什么问题，请与该班的管理员联系！"
	Else
		body="很抱歉，由于某种原因，系统管理员免除了您在"&ClassName&"的"&_
			Grade(Cmt,False)&"职务,您如果有什么问题，请与管理员联系！"
	End if
	sql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS) values('"&Rs(0)&"','"&StrVar(1)&"','"&title&"','"&body&"',Now(),0,1,2)"
	Conn.Execute(sql)

	Set Rs=Nothing

	rURL="ClsAdm_Member.asp?ClassID="&ClsID
	rTitle="免除班委职务"
	rMsg="你已经成功将所选同学的"&Grade(mbstatus,False)&"职务免除！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&htmlencode(ClassName)&"首页</a></li>"&_
		"<li><a href=""ClsAdm_Class.asp?ClassID="&ClsID&"&Action=Main"">返回班级管理</a></li>"&_
		"<li><a href="""&rURL&""">继续成员管理</a></li></ul>"
	Redirect 3,rURL,rTitle,rMsg

End Sub



Sub ClassmateList()

	Dim studcount
	Dim Rs,sql

	Response.Write "<br><br>"&_
		"<script language=JavaScript src=script/mgrcls.js></script>"&_
		"<form action=ClsAdm_Member.asp?ClassID="&ClsID&" method=post name=classmate onsubmit=""return chkradio();"">"&_
		"<table align=center cellpadding=5 cellspacing=1 border=0 width=650 Class=TableBorder>"&_
		"<TR align=middle Class=DarkTableBody>"
	if Degree=1 and not sysadmin Then
		Response.Write "<Td height=24 colspan=5>"
	Else
		Response.Write "<Td height=24 colspan=6>"
	End if
	Response.Write "<b>班级成员管理</b></Td></TR>"&_
		"<tr><th align=center>序号</th><th align=center>姓&nbsp;&nbsp;名</th>"&_
		"<th align=center>身&nbsp;&nbsp;份</th><th align=center>访问次数</th><th align=center>最近访问时间</th>"
	if Degree>1 or sysadmin Then
		Response.Write "<th align=center>选择</th>"
	End if
	Response.Write "</tr>"

	sql="Select S.studid,S.Userid,S.realname,J.visitcount,J.lastvisit,J.degree from "&_
		"student S inner join joinclass J on S.userid=J.userid where J.classid="&ClsID&_
		" and J.isauditing=False order by J.degree desc,J.visitcount desc,J.lastVisit desc"
	Set Rs=Conn.Execute(sql)
	studcount=1
	do until Rs.eof
		Response.Write "<TR height=10 Class=LightTableBody>"&_
		"<TD align=center>"&studcount&"</TD><TD>&nbsp;&nbsp;"
		if membername<>Rs(1) Then
			Response.Write "<a href=""Profile.asp?Name="&Rs(1)&_
				"&Action=showdetail"" target=_blank>"&htmlencode(Rs(2))&"</a>"
		Else
			Response.Write "<font color=blue>"&htmlencode(Rs(2))&"</font>"
		End if
		Response.Write "</TD><TD align=center>"&Grade(Rs(5),True)&"</TD><td align=center>"&Rs(3)&"</td>"&_
		"<td>&nbsp;&nbsp;"&Rs(4)&"</td>"

		if Degree>1 or sysadmin Then
			Response.Write "<TD align=center><input type=Radio name=id value="&Rs(0)
			if membername=Rs(1) or not sysadmin and (Degree<7 and Rs(5)>1 or Degree=7 and Rs(5)=8) Then Response.Write " disabled"
			Response.Write "></td>"
		End if
		Response.Write "</tr>"
		Rs.movenext
		studcount=studcount+1
	loop
	Set Rs=Nothing

	if Degree>1 or sysadmin Then
		Response.Write "<TR align=middle Class=DarkTableBody>"&_
			"<TD height=24 colspan=6 align=right valign=top>"&_
			"<input type=radio name=Action id=ac1 value=Delete onclick=""Cmt.disabled=true""><label for=ac1>赶出班级</label>&nbsp;"&_
			"<input type=radio name=Action id=ac2 value=HandOver onclick=""Cmt.disabled=true"""

		if Degree=9 Then Response.Write " disabled"
		Response.Write "><label for=ac2>移交大权</label>&nbsp;"

		if Degree>6 or sysadmin Then
			Response.Write "<input type=radio name=Action id=ac3 value=Deposal onclick=""Cmt.disabled=true""><label for=ac3>免去班内职务</label>&nbsp;"&_
				"<input type=radio name=Action id=ac4 value=Appoint onclick=""Cmt.disabled=false""><label for=ac4>任命为</label>&nbsp;"
			if sysadmin Then
				TopRight=8
			ElseIf Degree=8 Then
				TopRight=7
			ElseIf Degree=7 Then
				TopRight=6
			End if	
			Response.Write "<Select name=Cmt disabled>"
			for StudLevel=TopRight to 2 step -1
				Response.Write "<option value="&StudLevel&">"&Grade(StudLevel,False)&"</option>"	
			next 
			Response.Write "</Select>"
		End if

		Response.Write "&nbsp;<INPUT TYPE=submit value=执行(E) style=""width:40pt;height:22"" accesskey=e class=button></TD></TR>"

	End if
	Response.Write "</TABLE></form>"

	'Set Rs=Conn.Execute("Select openlevel from class where classid="&ClsID)
	'if Rs(0)=2 Then Call Auditinglist()
	'Set Rs=Nothing
	Call Auditinglist()

End Sub




Sub Auditinglist()

	dim i
	dim sql,rs
	Dim NoOne

	Response.Write "<BR><form action=ClsAdm_Member.asp?ClassID="&ClsID&" method=post>"&_
	"<table align=center cellpadding=5 cellspacing=1 border=0 width=650 Class=TableBorder>"&_
	"<TR><Th>管理未审核的同学</Th></TR>"

	sql="Select S.userid,S.studid,S.realname from student S inner join joinclass J "&_
		"on S.userid=J.userid where J.classid="&ClsID&" and J.isauditing=True"
	Set Rs=Conn.Execute(sql)

	if Rs.eof and Rs.bof Then
		Response.Write "<tr height=50 Class=LightTableBody>"&_
		"<td><font color=brown>没有未审核的同学:(</font></td></tr>"
		NoOne=true
	Else
		Response.Write "<TR  height=10 Class=LightTableBody><td>"&_
		"<table width=""100%"" border=0>"
		i=1
		do until rs.eof
			if i mod 4 =1 then response.write "<tr>"
			if Degree>1 or sysadmin Then
				Response.Write "<td width=""25%""><input type=checkbox name=wid value="&Rs(1)&">"
			End if
			response.write Rs(2)&"("&htmlencode(Rs(0))&")</TD>"
			if i mod 4=0 then Response.Write "</TR>"
			Rs.movenext
			i=i+1
		loop
		response.write "</table></td></tr>"
	End if

	if Degree>1 or sysadmin Then
		Response.Write "<TR align=middle Class=DarkTableBody>"&_
			"<TD align=right><input type=submit name=Action value=""通过审核"""
		if NoOne then response.write " disabled"
		response.write " class=button>"&_
		"&nbsp;&nbsp;<input type=submit name=Action value=""禁止加入"""
		if NoOne then response.write " disabled"
		response.write " class=button></TD></TR>"
	End if

	Response.Write "</TABLE></form>"

End Sub



Sub DelMember()

	Dim delid,mbstatus,sql,Rs,UserRs
	Dim ErrMsg,FoundErr

	delid=Request.form("id")

	if delid="" Then
		ErrMsg=ErrMsg+"<li>操作失败，请选择相关同学进行操作！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	delid=Clng(delid)

	mbstatus=ChkMember(delid)
	if mbstatus=0 Then
		ErrMsg=ErrMsg+"<li>操作失败，该同学不是本班成员！"
		FoundErr=True
	'ElseIf mbstatus=Degree Then
	'	ErrMsg=ErrMsg+"<li>操作失败，您不能对自己执行此项操作，请使用注销班级功能！"
	'	FoundErr=True
	Else
		if not sysadmin Then
			if ChkRights(1)=False Then		
				ErrMsg=ErrMsg+"<li>操作失败，您不是班委成员或班长没有赋予你此项操作的权限！"
				FoundErr=True
			ElseIf mbstatus>1 and Degree<7 Then
				ErrMsg=ErrMsg+"<li>操作失败，您不能对其他班委成员执行此项操作！"
				FoundErr=True
			ElseIf mbstatus=8 and Degree=7 Then
				ErrMsg=ErrMsg+"<li>操作失败，副班长无权对班长执行此项操作！"
				FoundErr=True		
			End if
		End if
	End if

	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	sql="update class Set studcount=studcount-1 where classid="&ClsID
	Conn.Execute(sql)

	sql="update student Set classcount=classcount-1,point=point+"&PointSet(11)&" where studid="&delid
	Conn.Execute(sql)

	Set UserRs=Conn.Execute("Select userid from student where studid="&delid)

	sql="delete from joinclass where classid="&ClsID&" and userid='"&UserRs(0)&"'"
	Conn.Execute(sql)

	if mbstatus>1 Then
		ResignPoint=Round(PointSet(13)*mbstatus/8)
		sql="update student Set point=point+"&ResignPoint&" where studid="&delid
		Conn.Execute(sql)

		if mbstatus=8 Then
			Conn.Execute("update class Set admin1=null where classid="&ClsID)
		ElseIf mbstatus=7 Then
			Conn.Execute("update class Set admin2=null where classid="&ClsID)
		End if

		if Degree=9 Then

			Set Rs=Conn.Execute("Select openlevel,studcount from class where classid="&ClsID)
			'如果班级内已经没有成员，而且加入班级需要审核，则需要把未通过审核同学加进来
			if Rs(0)=2 and Rs(1)=0 Then
				Conn.Execute("update student Set point=point+"&PointSet(10)&" where userid"&_
					" in (Select userid from joinclass where isauditing=True and classid="&ClsID&")")
				Set WaitNum=Conn.Execute("Select count(userid) from joinclass where isauditing=True and classid="&ClsID)
				Conn.Execute("update class Set studcount=studcount+"&WaitNum(0)&" where classid="&ClsID)
				Set WaitNum=Nothing
				Conn.Execute("update joinclass Set isauditing=False,jointime=now(),lastvisit=now() "&_
					"where isauditing=True and classid="&ClsID)
			End if
			Set Rs=Nothing

			'如果班级内已经没有成员，而且已经限制加入班级，则需要把班级属性修改
			sql="update class Set openlevel=0,classpwd=null where studcount=0 and openlevel>0 and classid="&ClsID
			Conn.Execute(sql)

		End if

	End if

	'write log
	IP=Request.ServerVariables("REMOTE_ADDR") 
	body="把"&getrealname(UserRs(0))&"的从本班成员列表中除名！"
	sql="insert into log(userid,content,classid,ip)"&_
		" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
	Conn.Execute(sql)

	'send message
	title="你被赶出了"&ClassName&"！"
	if Degree=9 or sysadmin and ChkRights(1)=False Then
		body="很抱歉，由于某种原因，系统管理员把你赶出了"&ClassName&",您如果有什么问题，可与管理员联系！"
	Else
		body="很抱歉，由于某种原因，"&ClassName&"的管理员把你赶出了这个班级,您如果有什么问题，可与该班的管理员联系！"
	End if
	sql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS) values('"&UserRs(0)&"','"&StrVar(1)&"','"&title&"','"&body&"',Now(),0,1,2)"
	Conn.Execute(sql)

	Set UserRs=Nothing


	rURL="ClsAdm_Member.asp?ClassID="&ClsID
	rTitle="成员管理"
	rMsg="你已经成功将所选成员从本班删除！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&htmlencode(ClassName)&"首页</a></li>"&_
		"<li><a href=""ClsAdm_Class.asp?ClassID="&ClsID&"&Action=Main"">返回班级管理</a></li>"&_
		"<li><a href="""&rURL&""">继续成员管理</a></li></ul>"
	Redirect 3,rURL,rTitle,rMsg

End Sub


Sub HandOver()

	Dim toid
	Dim mbstatus

	toid=Request.form("id")
	if toid="" Then
		ErrMsg=ErrMsg+"<li>操作失败，请选择相关同学进行操作！"
		FoundErr=True
	ElseIf Degree=1 or Degree=9 Then
		ErrMsg=ErrMsg+"<li>操作失败，您不是本班的班委成员，没有职务可以移交！"
		FoundErr=True
	End if

	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	toid=Clng(toid)

	mbstatus=ChkMember(toid)
	if mbstatus=0 Then
		ErrMsg=ErrMsg+"<li>操作失败，您要移交职务的同学不是本班成员！"
		FoundErr=True
	ElseIf mbstatus>1 Then
		ErrMsg=ErrMsg+"<li>操作失败，您要移交职务的同学已经是本班的"&Grade(mbstatus,False)&"，不能再担任其他职务！"
		FoundErr=True
	End if

	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if


	if Degree=8 Then
		Conn.Execute("update class Set admin1='"&membername&"' where classid="&ClsID)
	ElseIf Degree=7 Then
		Conn.Execute("update class Set admin2='"&membername&"' where classid="&ClsID)
	End if

	DoApply="update student Set point=point+"&Round(PointSet(12)*Degree/8)&" where studid="&toid
	Conn.Execute(DoApply)

	Set UserRs=Conn.Execute("Select userid from student where studid="&toid)

	DoApply="update joinclass Set degree="&Degree&" where classid="&ClsID&" and userid='"&UserRs(0)&"'"
	Conn.Execute(DoApply)

	DoResign="update student Set point=point+"&Round(PointSet(13)*Degree/8)&" where userid='"&membername&"'"
	Conn.Execute(DoResign)

	DoResign="update joinclass Set degree=1 where userid='"&membername&"' and classid="&ClsID
	Conn.Execute(DoResign)

	'write log
	IP=Request.ServerVariables("REMOTE_ADDR") 
	body="把自己在本班的"&Grade(Degree,False)&"的职务移交给"&getrealname(UserRs(0))
	sql="insert into log(userid,content,classid,ip)"&_
		" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
	Conn.Execute(sql)

	'send message
	title="恭喜你成为"&ClassName&"的"&Grade(Degree,False)&"！"
	body=getrealname(membername)&"把在"&ClassName&"的"&Grade(Degree,False)&_
		"职务移交给了你，委托你代管权限之内的班级事务，请正确行使您的管理员权限和履行管理员义务！"
	sql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS) values('"&UserRs(0)&"','"&StrVar(1)&"','"&title&"','"&body&"',Now(),0,1,2)"
	Conn.Execute(sql)

	Set UserRs=Nothing

	rURL="ClsAdm_Member.asp?ClassID="&ClsID
	rTitle="班委职务移交"
	rMsg="你已经成功将"&Grade(Degree,False)&"身份移交给所选同学！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&htmlencode(ClassName)&"首页</a></li>"&_
		"<li><a href=""ClsAdm_Class.asp?ClassID="&ClsID&"&Action=Main"">返回班级管理</a></li>"&_
		"<li><a href="""&rURL&""">继续成员管理</a></li></ul>"
	Redirect 3,rURL,rTitle,rMsg

End Sub



Sub  RefuseJoin()

	Dim passid,idlist,SucNum,NameList
	passid=Request.form("wid")

	if passid="" Then
		ErrMsg=ErrMsg+"<li>"+"请选择要禁止加入的同学。"
		FoundErr=True
	ElseIf ChkRights(1)=False Then
		ErrMsg=ErrMsg+"<li>"+"对不起，您没有此项操作的权限！"
		FoundErr=True
	End if

	if FoundErr Then
		Call Error("Information",ErrMsg)
		Exit Sub
	End if

	idlist=Split(passid,",")
	SucNum=0
	NameList=""
	for i= 0 to ubound(idlist)
		if ChkAuditing(Clng(idlist(i)))=True Then
			Conn.Execute("update student Set classcount=classcount-1 where studid="&Clng(idlist(i)))

			Set UserRs=Conn.Execute("Select userid from student where studid="&Clng(idlist(i)))
			
			Conn.Execute("delete from joinclass where classid="&ClsID&" and userid='"&UserRs(0)&"'")
			
			'send message
			body=ClassName&"的管理员已经审核了您的注册请求，但不允许你加入这个班级，如果你有什么问题，可与该班的管理员联系！"
			sql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS) values('"&UserRs(0)&"','"&StrVar(1)&"','注册班级失败！','"&body&"',Now(),0,1,2)"
			Conn.Execute(sql)

			SucNum=SucNum+1
			NameList=NameList&getrealname(UserRs(0))&","

			Set UserRs=Nothing
	End if
	next


	'write log
	if SucNum<>0 Then
		NameList=left(NameList,len(NameList)-1)
		IP=Request.ServerVariables("REMOTE_ADDR") 
		body="审核待审核同学，"&NameList&"等"&SucNum&"位同学被禁止加入本班"
		sql="insert into log(userid,content,classid,ip)"&_
			" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
		Conn.Execute(sql)
	End if

	rURL="ClsAdm_Member.asp?ClassID="&ClsID
	rTitle="审核班级成员"
	rMsg="有"&SucNum&"位同学被您禁止加入你们班级！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&htmlencode(ClassName)&"首页</a></li>"&_
		"<li><a href=""ClsAdm_Class.asp?ClassID="&ClsID&"&Action=Main"">返回班级管理</a></li>"&_
		"<li><a href="""&rURL&""">继续成员管理</a></li></ul>"
	Redirect 3,rURL,rTitle,rMsg

End Sub


Sub  PassJoin()

	Dim passid,idlist,SucNum,NameList
	passid=Request.form("wid")

	if passid="" Then
		ErrMsg=ErrMsg+"<li>"+"请选择要通过审核的同学。"
		FoundErr=True
	ElseIf ChkRights(1)=False Then
		ErrMsg=ErrMsg+"<li>"+"对不起，您没有此项操作的权限！"
		FoundErr=True
	End if

	if FoundErr Then
		Call Error("Information",ErrMsg)
		Exit Sub
	End if

	idlist=Split(passid,",")
	SucNum=0
	NameList=""
	for i= 0 to ubound(idlist)
		if ChkAuditing(Clng(idlist(i)))=True Then
			Conn.Execute("update class Set studcount=studcount+1 where classid="&ClsID)
			Conn.Execute("update student Set point=point+"&PointSet(10)&" where studid="&Clng(idlist(i)))

			Set UserRs=Conn.Execute("Select userid from student where studid="&Clng(idlist(i)))

			Conn.Execute("update joinclass Set isauditing=False,jointime=now(),lastvisit=now() "&_
			"where isauditing=True and classid="&ClsID&" and userid='"&UserRs(0)&"'")

			'send message
			body=ClassName&"的管理员已经审核了您的注册请求，现在你已经成为该班的成员，请进入班级页面访问这个班级！"
			sql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS) 										values('"&UserRs(0)&"','"&StrVar(1)&"','注册班级成功！','"&body&"',Now(),0,1,2)"
			Conn.Execute(sql)

			SucNum=SucNum+1
			NameList=NameList&getrealname(UserRs(0))&","

			Set UserRs=Nothing
		End if
	next


	'write log
	if SucNum<>0 Then
		NameList=left(NameList,len(NameList)-1)
		IP=Request.ServerVariables("REMOTE_ADDR") 
		body="审核待审核同学，"&NameList&"等"&SucNum&"位同学通过审核加入到本班成员列表中"
		sql="insert into log(userid,content,classid,ip)"&_
			" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
		Conn.Execute(sql)
	End if


	rURL="ClsAdm_Member.asp?ClassID="&ClsID
	rTitle="审核班级成员"
	rMsg="有"&SucNum&"位同学通过您的审核并加入到你们班级！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&htmlencode(ClassName)&"首页</a></li>"&_
		"<li><a href=""ClsAdm_Class.asp?ClassID="&ClsID&"&Action=Main"">返回班级管理</a></li>"&_
		"<li><a href="""&rURL&""">继续成员管理</a></li></ul>"
	Redirect 3,rURL,rTitle,rMsg

End Sub


Function ChkMember(byval memberid)

	Dim tmpRs,tmpsql
	tmpsql="Select degree from joinclass where classid="&ClsID&_
	" and isauditing=False and userid=(Select userid from student where studid="&memberid&")"

	Set tmpRs=Conn.Execute(tmpsql)
	if tmpRs.eof and tmpRs.bof Then
		chkmember=0
	Else
		chkmember=tmpRs(0)
	End if
	Set tmpRs=Nothing

End Function


Function ChkAuditing(byval memberid)

	Dim tmpRs,tmpsql
	tmpsql="Select isauditing from joinclass where classid="&ClsID&_
	" and isauditing=True and userid=(Select userid from student where studid="&memberid&")"
	Set tmpRs=Conn.Execute(tmpsql)
	ChkAuditing=not (tmpRs.eof and tmpRs.bof)

End Function


function GetRealname(byval username)
	Dim rSQL,rRs
	GetRealname=""
	if isnull(username) or username="" then exit function
	rSQL = "select realname from student where userid='"&username&"'"
	set rRs=conn.execute(rSQL)
	if not (rRs.eof and rRs.bof) then
		GetRealname=rRs(0)
	else
		GetRealname=""
	end if
	Set rRs=Nothing
end function


%>
<!--#INCLUDE FILE="include/grade.asp" -->
<%Call footer%>

