<!--#INCLUDE FILE="setup.asp" -->
<!--#INCLUDE FILE="checkuser.asp" -->
<!--#INCLUDE FILE="theme.asp" -->
<!--#INCLUDE FILE="include/char.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
		Call top(2,1)
		if Request("Action")="logout" Then
			Call logout()
		Else
			Call confirm()
		End if
	End if
End if


Sub confirm()

Dim Rs

Set Rs=Conn.Execute("Select classname from class where classid="&ClsID)
%>
<br><br>
<FORM action="ExitClass.asp?ClassID=<%=ClsID%>" method=post name="userform" onsubmit="return submitonce(this);">
<input type=hidden name=action value=logout>
<table cellpadding=0 cellspacing=0 border=0 width=680 bgcolor=#ccccff align=center>
        <tr>
            <td>
                <table cellpadding=5 cellspacing=1 border=0 width=100% Class=TableBorder>
  <TBODY>
  <TR>
    <Th height=24><b>从班级注销!!!</b></Th></TR>
  <TR Class=LightTableBody>
    <TD height=120 valign=center class=p9> &nbsp;&nbsp;<li>此项操作您将退出您目前所在的班级。</li>
	&nbsp;&nbsp;<li>注销后您将不能以成员身份访问此班级。</li>
		&nbsp;&nbsp;<li>如果你是本班的管理员，注销后此身份将被取消。</li>
	&nbsp;&nbsp;<li>在尚未加入任何班级时，您仍然可以再加入本班级。</li>
	
	</TD>
   </TR>
  <TR Class=LightTableBody>
    <TD>&nbsp;&nbsp;&nbsp;&nbsp;您确认要从班级：<font color=blue><%=htmlencode(Rs(0))%></font>注销吗？</TD>
    </TR>
  
<TR align=middle Class=DarkTableBody>
    <TD><DIV align=center><INPUT value="我要注销" name=Submit type=submit class=button>
</DIV></TD></TR></TBODY></TABLE></td></tr></table>
</FORM>
<%
set rs=nothing

End Sub


Sub logout()

	dim sql,Rs

	if Degree=9 Then 
		ErrMsg=ErrMsg+"<br>"+"<li>对不起，您还没有加入这个班级！"
		Call Error("Information",ErrMsg)
	Else

		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 userid='"&membername&"'"
		Conn.Execute(sql)

		if Degree>1 then
			sql="update student set point=point+"&Round(PointSet(13)*Degree/8)&" where userid='"&membername&"'"
			conn.execute(sql)
		end if

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

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

		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 S.point=S.point+"&PointSet(10)&" from student S inner join joinclass J on S.userid=J.userid where J.isauditing=True and J.classid="&ClsID&")")
			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)

		rURL="Default.asp"
		rtitle="注销班级"
		rmsg="你已经成功的从班级：<font color=brown>"&htmlencode(ClassName)&"</font> 注销<br><ul>"&_
				"<li><a href=Default.asp>返回同学录首页</a></li>"&_
				"</ul>"
		Redirect 3,rurl,rtitle,rmsg

	End if

End Sub
%>

<%Call footer%>
