<% Response.Buffer=True %>
<!--#include file="conn.asp"-->
<!--#include file="../inc/setup.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../inc/sql.asp"-->
<%
	end if
	if instr(request("uname"),"'")<>0 then
		response.write "<script language=JavaScript>" & "alert('非法数据提交！');" & "history.back()" & "</script>" 
		Response.End
	else
		If Session("getcode")<>int(Trim(Request.Form("CheckCode"))) Then
			response.write"<SCRIPT language=JavaScript>alert('验证码输入错误');"                   
			response.write"javascript:history.go(-1)</SCRIPT>"                   
			response.end
		end if
		uname=replace(trim(Request.Form("uname")),"'","")
		pwd=mistake(replace(trim(Request.Form("pwd")),"'",""))
		usertype=Trim(Request.Form("usertype"))
		if usertype="school" then
			sql="select * from school where sname='"&uname&"'"
			sql1="update school set lasttime='"&now()&"',dlnum=dlnum+1,ip='"&request.servervariables("remote_host")&"' where sname='"&uname&"'"
		end if
		set rs=server.createobject("adodb.recordset")
		rs.open sql,conn,1,1
		if rs.eof and rs.bof then
			response.write "<script language=JavaScript>" &"alert('用户名不存在，请查询！');" & "history.back()" & "</script>" 
			rs.close
			set rs=nothing
			set conn=nothing
			response.end
		else
			if pwd<>rs("pwd") then
				response.write "<script language=JavaScript>" & "alert('密码错误！');" & "history.back()" & "</script>" 
				rs.close
				set rs=nothing
				set conn=nothing
				response.end
			else
				if rs("lock")=1 then
					rs.close
					set rs=nothing
					set conn=nothing
					response.write "<script language=JavaScript>" & "alert('此帐号已被锁定，请与管理员联系！');"&"window.location.href = 'index.asp'"&" </script>"
					response.end
				end if
				set rs1=server.createobject("adodb.recordset")
				rs1.open sql1,conn,2,3
				set rs1=nothing
				
				if Trim(Request.Form("usertype"))="school" then
		
					Response.Cookies("admin_person_name")=""
					Response.Cookies("admin_person_id")=""
					Response.Cookies("company_name")=""
					Response.Cookies("admin_company_name")=""
					Response.Cookies("admin_company_id")=""
					Response.Cookies("school_name")=""
					Response.Cookies("admin_school_name")=""
					Response.Cookies("admin_school_id")=""
					Response.Cookies("train_name")=""
					Response.Cookies("admin_train_name")=""
					Response.Cookies("admin_train_id")=""
					Response.Cookies("school_name")=rs("school_name")
					Response.Cookies("admin_school_name")=rs("sname")
					Response.Cookies("admin_school_id")=rs("id")
					
					Response.Cookies("school_name").expires=(now()+1/24)
					Response.Cookies("admin_school_name").expires=(now()+1/24)
					Response.Cookies("admin_school_id").expires=(now()+1/24)
					
					response.redirect "main.asp"
					
				end if
				
				rs.close
				set rs=nothing
				set conn=nothing
			end if
		end if
		rs.close
		set rs=nothing
		set conn=nothing
	end if
%>