<!--#INCLUDE FILE="conn.asp" -->
<!--#INCLUDE FILE="Class_Checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#INCLUDE FILE="inc/char.asp" -->
<%locat="注销学校"

if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=Class_Login.asp><font color=red>登录或注册校友录</font></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()

%>
<br><br>
<FORM action="Class_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(classname)%></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>
<%

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=8 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 point=point+"&PointSet(10)&" where userid in (select userid from joinclass where isauditing=1 and classid="&ClsID&")")
			Set WaitNum=Conn.Execute("Select count(userid) from joinclass where isauditing=1 and classid="&ClsID)
			Conn.Execute("update class Set studcount=studcount+"&WaitNum(0)&" where classid="&ClsID)
			Set WaitNum=Nothing
			Conn.Execute("update joinclass Set isauditing=0,jointime=getdate(),lastvisit=getdate() "&_
				"where isauditing=1 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="main.asp"
		rtitle="注销学校"
		rmsg="你已经成功的从学校：<font color=brown>"&htmlencode(ClassName)&"</font> 注销<br><ul>"&_
				"<li><a href=main.asp>返回校友录首页</a></li>"&_
				"</ul>"
		Redirect 3,rurl,rtitle,rmsg

	End if

End Sub
%>

<%Call footer%>
