<%
Dim membername,memberpwd
membername=replace(Request.cookies("fenglingtxl_520")("username"),"'","")
memberpwd=replace(Request.cookies("fenglingtxl_520")("password"),"'","")

Dim SysAdmin,AdmSQL,AdmRs
SysAdmin=False

if membername<>"" Then
	if chkuserlogin(membername,memberpwd,true)<>"" Then
		response.cookies("fenglingtxl_520")("username")=""
		response.cookies("fenglingtxl_520")("password")=""
		response.cookies("fenglingtxl_520")("visitedclasses")=""
		response.cookies("fenglingtxl_520")("logintime")=""
		Response.Cookies("fenglingtxl_520")("usercookies")=""
		membername=""
	Else
		AdmSQL="select A.* from admin A inner join student S "&_
		"on A.managerid=S.studid where S.userid='"&membername&"'"
		Set AdmRs=Conn.Execute(AdmSQL)
		if Not (AdmRs.eof and AdmRs.bof) Then
		    session("txl_Admin_name")=membername
			SysAdmin=True
		End if
		set AdmRs=nothing
	End if
End if


Function chkjoinclass(byval myClassID)

	Dim ClassRs,JoinRs
	Dim ErrMsg,FoundErr
	
	chkjoinclass=""

	if not isNumeric(myClassID) Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您没有选择加入的学校！"
		chkjoinclass=ErrMsg
		Exit Function
	End if
	
	myClassID=Clng(myClassID)
	
	Set ClassRs=Conn.Execute("select classname,passed from class where classid="&myclassID)
	if ClassRs.eof and ClassRs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！您要访问的学校或学校所属的学校不存在或已被删除。"
		chkjoinclass=ErrMsg
		Exit Function
	elseif ClassRs(1)=0 and not sysadmin then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败！您要访问的学校还没有通过管理员的审核,暂时不能访问!"
		chkjoinclass=ErrMsg
		Exit Function
	Else
		ClassName=ClassRs(0)
	End if
	Set ClassRs=Nothing

	Set JoinRs=Conn.Execute("Select isauditing,degree from joinclass where userid='"&membername&"' and classid="&myClassID)
	if JoinRs.eof and JoinRs.bof Then
		if sysadmin Then
			Degree=9
		Else
			ErrMsg=ErrMsg+"<br>"+"<li>对不起，您还没有加入这个学校！"
			FoundErr=True
		End if
	Else
		if JoinRs(0)=1 Then
			ErrMsg=ErrMsg+"<br>"+"<li>操作失败！您还没有通过学校管理员的审核。"
			FoundErr=True
		Else
			Degree=JoinRs(1)
		End if
	End if
	Set JoinRs=Nothing


	if FoundErr Then
		chkjoinclass=ErrMsg
	Else
		chkjoinclass=""
	End if

End Function

Function ChkRights(MgrItem)

	Dim Rights
	Cmt=Degree

	if sysadmin or Degree>6 Then 
		ChkRights=True
	ElseIf Cmt=1 Then
		ChkRights=False
	Else
		Set Rights=Conn.Execute("Select rights from class where classid="&ClsID)
		if mid(Rights(0),(6-Cmt)*7+MgrItem,1)="1" Then
			ChkRights=True
		Else
			ChkRights=False
		End if
		Set Rights=Nothing
	End if

End Function

Function chkUserLogin(byval txluser,byval txlpwd,byval online)

	Dim tmprs
	Dim founderr,errormsg

	chkuserlogin=""

	Set tmprs =Conn.Execute("Select userpwd,locked,userid from student where userid='"&txluser&"'")
	if tmprs.EOF and tmprs.bof Then
		Errormsg=Errormsg+"<br>"+"<li>对不起，您输入的用户名还没有<a href=Class_Register.asp>注册</a>！！"
		founderr=True
	ElseIf txlpwd<>tmprs(0) and online<>true Then
		Errormsg=Errormsg+"<br>"+"<li>密码错误！请重新<a href=Class_Login.asp>登陆</a>！！"
		founderr=True
	Elseif txlpwd<>tmprs(0) and online=true then
		Errormsg=Errormsg+"<br>"+"<li>密码错误！请重新<a href=Class_Login.asp>登陆</a>！！"
		founderr=True
	ElseIf tmprs(1)=1 Then
		Errormsg=Errormsg+"<br>"+"<li>对不起，您的帐号已被锁定，若有任何问题，请与<a href=mailto:"&StrVar(2)&" title=""QQ:"&StrVar(9)&""">系统管理员联系</a>！"
		founderr=True
	End if
	Set tmprs=Nothing

	if founderr=True Then
		chkuserlogin=errormsg
	End if

End Function
%>
