<!--#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
		If Request("Action")="update" Then
			act="班委权限管理"
			Call top(3,1)
			Call update()
		ElseIf Request("Action")="Apply" Then
			act="申请班委会成员"
			Call top(3,1)
			Call apply()
		ElseIf Request("Action")="Resign" Then
			act="辞去班委身份"
			Call top(3,1)
			Call resign()
		Else 
			act="查看班委权限"
			Call top(3,1)
			Call RightsInfo()
		End If
	End If
End If


Sub RightsInfo()

Dim Rs
Set Rs=Conn.Execute("Select rights from class where classid="&ClsID)
rights=Rs(0)
Set Rs=Nothing

Response.write "<br><br>"&_
	"<FORM action=ClsAdm_Rights.asp?ClassID="&ClsID&" name=clsfrm method=post onsubmit=""submitonce(this)"">"&_
	"<input type=hidden name=Action value=update>"&_
	"<table cellpadding=0 cellspacing=0 border=0 width=700 align=center>"&_
        "<tr><td>"&_
		"<table cellpadding=5 cellspacing=1 border=0 width=100% Class=TableBorder>"&_
		 "<TR align=middle>"&_
		"<Th colSpan=9 height=24><b>班委管理权限分配</b></Th></TR>"&_
		"<tr Class=DarkTableBody align=center>"&_
		"<td></td><td>成员管理</td><td>公告管理</td><td>班级宣言</td><td>留言管理</td>"&_
		"<td>相册管理</td><td>调查管理</td><td>附加信息</td><td>任职情况</td></tr>"

sql="Select J.userid,J.degree,S.realname from joinclass J inner join student S "&_
	"on J.userid=S.userid where J.degree>1 and J.classid="&ClsID&" order by J.degree desc"
Set Rs=Conn.Execute(sql)


for r=8 to 7 step -1
	Response.write "<tr align=center Class=LightTableBody><td>"&Grade(r,True)&"</td>"
	for MgrItem=1 to 7
		If degree>6 or sysadmin Then
			Response.write "<td><INPUT TYPE=checkbox value=1 disabled checked></td>"
		Else
			Response.write "<td><font color=green><B>√</B></td>"
		End If
	next

	Response.write "<td>"
	If Rs.eof Then
		If degree=1 Then
			Response.write "<a onclick=""return confirm('你确认要申请本班的"&Grade(r,False)&"吗?')"" href=""?ClassID="&ClsID&"&Action=Apply&Grade="&r&"""><img src=images/go.gif border=0 hspace=2 align=absmiddle>申请"&"</a>"
		End If
	Else
		If Rs(1)<r Then
			If Degree=1 Then
				Response.write "<a onclick=""return confirm('你确认要申请本班的"&Grade(r,False)&"吗?')"" href=""?ClassID="&ClsID&"&Action=Apply&Grade="&r&"""><img src=images/go.gif border=0 hspace=2 align=absmiddle>申请"&"</a>"
			End If
		Else		
			If membername=Rs(0) Then 
				Response.write "<font color=#4444ff>"&htmlencode(Rs(2))&"</font>&nbsp;<a onclick=""return confirm('你确认要辞去本班的"&Grade(r,False)&"身份吗?')"" href=""?ClassID="&ClsID&"&Action=Resign""><img src=images/go.gif border=0 hspace=2 align=absmiddle>辞职"&"</a>"
			Else
				Response.write "<a href=""profile.asp?Name="&Rs(0)&"&Action=showdetail"" target=_blank>"&htmlencode(Rs(2))&"</a>"
			End If
			Rs.movenext
		End If
	End If

	Response.write "</td></tr>"
next

for Cmt=0 to 4
	Response.write "<tr align=center Class=LightTableBody><td>"&Grade(6-Cmt,True)&"</td>"
	for MgrItem=1 to 7

		If degree>6 or sysadmin Then
			Response.write "<td><INPUT TYPE=checkbox value=1 NAME=rightserial"&cstr(Cmt*7+MgrItem)
			If mid(rights,Cmt*7+MgrItem,1)="1" Then
				Response.write " checked"
			End	If
			Response.write "></td>"
		Else
			If mid(rights,Cmt*7+MgrItem,1)="1" Then
				Response.write "<td><font color=green><B>√</B></td>"
			Else
				Response.write "<td><font color=#FF0000><B>×</B></td>"
			End	If			
		End If
	
	next

	Response.write "<td>"
	If Rs.eof Then
		If degree=1 Then
			Response.write "<a onclick=""return confirm('你确认要申请本班的"&Grade(6-Cmt,False)&"吗?')"" href=""?ClassID="&ClsID&"&Action=Apply&Grade="&(6-Cmt)&"""><img src=images/go.gif border=0 hspace=2 align=absmiddle>申请"&"</a>"
		End If
	Else
		If Rs(1)<(6-Cmt) Then
			If Degree=1 Then
				Response.write "<a onclick=""return confirm('你确认要申请本班的"&Grade(6-Cmt,False)&"吗?')"" href=""?ClassID="&ClsID&"&Action=Apply&Grade="&(6-Cmt)&"""><img src=images/go.gif border=0 hspace=2 align=absmiddle>申请"&"</a>"
			End If
		Else
			If membername=Rs(0) Then 
				Response.write "<font color=#4444ff>"&htmlencode(Rs(2))&"</font>&nbsp;<a onclick=""return confirm('你确认要辞去本班的"&Grade(6-Cmt,False)&"身份吗?')"" href=""?ClassID="&ClsID&"&Action=Resign""><img src=images/go.gif border=0 hspace=2 align=absmiddle>辞职"&"</a>"
			Else
				Response.write "<a href=""profile.asp?Name="&Rs(0)&"&Action=showdetail"" target=_blank>"&htmlencode(Rs(2))&"</a>"
			End If
			Rs.movenext
		End If
	End If

	Response.write "</td></tr>"

next

Set Rs=Nothing

Response.write "<tr Class=LightTableBody><td colspan=9><IMG SRC=Images/REMINDER.GIF hspace=2>"&_
	"&nbsp;担任正副班长可以获得以上所有权限。<BR>"&_
	"&nbsp;&nbsp;&nbsp;&nbsp;班委必须是本班成员，而且访问这个班级<font color=brown>十次</font>以上才有资格申请。"&_
	"</td></tr>"


If Degree>6 or sysadmin Then
	Response.write "<tr Class=DarkTableBody><td align=right colspan=9>"&_
		"<INPUT TYPE=submit value=更&nbsp;&nbsp;新 style=""width:72;height:22"" class=button>&nbsp;&nbsp;</td></tr>"
End If

Response.write "</TABLE>"&_
	"</td></tr></table></FORM>"

End Sub



Sub update()

If not (Degree>6 or sysadmin) Then
	ErrMsg=ErrMsg+"<br>"+"<li>"+"对不起，您不是班级管理员，没有管理班委的权利！"
	Call Error("Exclamation",ErrMsg)
Else

	RightStr=""

	for i=1 to 35

		RightItem=Request.form("rightserial"&i)
		If RightItem<>"1" Then RightItem="0"
		RightStr=RightStr&RightItem

	next

	Conn.Execute("update class Set rights='"&RightStr&"'")
	
	'write log
	IP=Request.ServerVariables("REMOTE_ADDR") 
	body="重新分配本班班委管理权限"
	sql="insert into log(userid,content,classid,ip)"&_
		" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
	Conn.Execute(sql)


	rURL="ClsAdm_Rights.asp?ClassID="&ClsID
	rTitle="管理班委权限"
	rMsg="恭喜您，班委权限修改成功！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&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 If

End Sub



Sub apply()

StudLevel=Request("Grade")

If not isnumeric(StudLevel) Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败！非法的系统参数！"
	FoundErr=True
ElseIf cint(StudLevel)>8 or Cint(StudLevel)<0 Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败！系统参数错误！"
	FoundErr=True
End If

If FoundErr Then
	Call Error("Critical",ErrMsg)
	Exit Sub
End If

StudLevel=Cint(StudLevel)

If Degree=9 Then
	ErrMsg=ErrMsg+"<br>"+"<li>系统管理员可以直接行使班级管理员的权利。如果要申请班级管理员，请先加入这个班级！"
	Call Error("Information",ErrMsg)
	Exit Sub
End If

Set Rs=Conn.Execute("Select visitcount from joinclass where userid='"&membername&"' and classid="&ClsID)

If Degree>1 Then
	If Degree<>StudLevel Then
		ErrMsg=ErrMsg+"<br>"+"<li>您已经是本班的"&Grade(Degree,False)&"了，不能再担任其他职位！"
		FoundErr=True
	Else
		ErrMsg=ErrMsg+"<br>"+"<li>您已经是本班的"&Grade(Degree,False)&"了，不能重复申请此职位！"
		FoundErr=True
	End If
ElseIf not sysadmin and Rs(0)<10 Then
	ErrMsg=ErrMsg+"<br>"+"<li>对不起，您访问本班的次数还不到10次！"
	FoundErr=True
End If

Set Rs=Nothing

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


Set Rs=Conn.Execute("Select userid from joinclass where classid="&ClsID&" and degree="&StudLevel)
If Rs.eof and Rs.bof Then

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

	ApplyPoint=Round(PointSet(12)*StudLevel/8)
	DoApply="update student Set point=point+"&ApplyPoint&" where userid='"&membername&"'"
	Conn.Execute(DoApply)

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

	rURL="ClsAdm_Rights.asp?ClassID="&ClsID
	rTitle="班委申请"
	rMsg="您已经成为本班的<font color=brown>"&_
		Grade(StudLevel,False)&"</font>，请注意行使管理员的权利和履行管理员义务。<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回班级首页</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

Else
	ErrMsg=ErrMsg+"<br>"+"<li>对不起，本班的"&Grade(StudLevel,False)&"已由"&getrealname(Rs(0))&"担任，你不可以再申请这个职位！"
	Call Error("Information",ErrMsg)

End If

Set Rs=Nothing


End Sub



Sub resign()


If Degree=1 or Degree=9 Then
	ErrMsg=ErrMsg+"<br>"+"<li>对不起，您不是本班的班委会成员！"
	Call Error("Exclamation",ErrMsg)
Else

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

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

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

	rURL="ClsAdm_Rights.asp?ClassID="&ClsID
	rTitle="班委辞职"
	rMsg="您已经成功的辞去了本班的"&Grade(Degree,False)&"身份！<br><ul>"&_
		"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回班级首页</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 If

End Sub

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