<!--#include file="Include/Conn.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/Upiconfig.asp"-->
<%
'完整调用形式：
'<script src="Interface.asp?action=操作类型&name=用户名&Md5Info=验证串&pass=密码&lock=是否锁定&question=提示问题&answer=答案&email=电子邮件&sex=性别&save=Cookies保存选项"
'action、name、Md5Info是必填参数
'删除用户时不需要其它参数
'更新资料时，提供所要更新的信息即可
'注意：这里传递的用户密码为32位MD5加密
Dim Action,UpiUserName,UpiUserPass

UpiUserName=trim(request("name"))
Action=trim(request("action"))
UpiUserPass = Trim(Request("pass"))
UpiMd5Info = Trim(Request("Md5Info"))
If Len(UpiUserPass) = 32 Then UpiUserPass = Mid(UpiUserPass,9,16)

If Action="LogoutUser" then Call LogoutUser()
If Not (Action = "" or UpiUserName = "" or UpiMd5Info = "") And HLAdminIntegration = True Then
       HLMd5Info = MD5(UpiUserName & AdminSecurityKey,32)
	 'HLMd5Info =MID(UpiMd5Info,9,16)
	If UpiMd5Info = HLMd5Info Then
	
     Select Case Action
		Case "AddUser"
			Call AddUser()
		Case "LoginUser"
			Call LoginUser()
		Case "LogoutUser"
			Call LogoutUser()
		Case "ModifyInfo"
			Call ModifyUserInfo()
		Case "DelUser"
			Call DelUser()
		End Select
	End If
End If

Sub AddUser()
  set rs=server.CreateObject("ADODB.recordset") 
  mSql="Select * From T_Admin"
  rs.open mSql,conn,1,3
  rs.AddNew
  rs("F_UserName")=UpiUserName
  rs("F_Password")=UpiUserPass
  rs("F_UserGrade")="0"
  rs("F_Flag")="01, 02, 03, 04, 05, 06, 07, 08, 09, 11, 12, 13, 14, 15, 16, 21, 22, 23, 24"
  rs("F_LoginCount")=0
  rs("F_IPInfo")=Request.ServerVariables("HTTP_HOST")
  rs.update
  rs.close

End Sub '添加新管理员

Sub LoginUser()
	dim mSql,rs
	mSql="Select F_UserName,F_PassWord,F_UserGrade,F_LoginCount,F_Flag from T_Admin Where F_UserName='" & UpiUserName & "'"
    set rs=server.createobject("adodb.recordset")
    rs.open mSql,conn,1,2
		if not rs.bof and not rs.eof then
			if UpiUserPass=rs("F_PassWord") then
				Session("curUserName") = UpiUserName
				session("curAddtime") = now()
				session("curLoginCount") = rs("F_LoginCount")
				if rs("F_UserGrade") = 1 then
				   session("curUserGrade") = "超级用户"
				else
				   Session("curUserGrade") = "普通管理员"
				end if
				Session("master") = UpiUserName
                Session("flag") = rs("F_Flag")
				mIPInfo=request.ServerVariables("REMOTE_HOST")
				mSql="update T_Admin set F_LoginCount=F_LoginCount+1,F_AddTime='"&now&"',F_IPInfo='"&mIPInfo&"' Where F_UserName='" & UpiUserName &"'"
				conn.execute(mSql)
			end if
		end if
    rs.close
	set rs=nothing
End Sub

Sub LogoutUser()
session.abandon
session("master")=""
response.Redirect("Admin_Index.asp")
End Sub

Sub ModifyUserInfo()
	set	rs=server.createobject("adodb.recordset")
	sql="select	* from T_Admin where F_UserName='"&UpiUserName&"'"
	rs.open	sql,conn,1,3
	if not rs.eof and not rs.bof then
	Rs("F_Password") = UpiUserPass
	rs.update
	End	if
	rs.close
	set	rs=nothing
End Sub

Sub DelUser()
    On Error Resume Next
    conn.Execute("delete from T_Admin where F_UserName='"& UpiUserName &"'")
End Sub

%>
