<!--#include file=conn.asp-->
<!--#include file=config.asp-->
<!--#include file=const.asp-->
<!--#include file=char.asp-->
<!--#include file=inc/Ms_admin.asp-->
<!--#include file=Md5.asp-->
<!--#include file="inc/Upiconfig.asp"-->
<%
dim username,password,Action
username=trim(request("name"))
userid=trim(request("name"))
Action=trim(request("action"))
password = Trim(Request("pass"))

If Len(password) = 32 Then password = Mid(password,9,16)
  if not action="" then
		Select Case Action
		Case "LoginUser"
		    Call LoginUser()
		Case "LogoutUser"
			Call LogoutUser()
		Case "ModifyInfo"
			Call ModifyUserInfo()
		Case "AddUser"
			Call AddUser()
		Case "DelUser"
			Call DelUser()
		End Select
end if
sub LoginUser()

	'前台登陆开始

Dim ip
	Dim UserName
	UserName=checkStr(Request("name"))
	ip=UserTrueIP
		MemberName=UserName
	Set Rs=Conn.Execute("Select a.*,u.UserPassword,u.UserGroupID From Ms_Admin a Inner Join Ms_User u On a.AddUser=u.UserName Where a.UserName='"&username&"' And a.AddUser='"&MemberName&"'")
	If Rs.Eof and Rs.Bof Then
		Rs.Close
		Set Rs=Nothing
		errmsg=errmsg+"<br>"+"<li>您输入的用户名和密码不正确或者您不是系统管理员。请<a href=admin_login.asp>重新输入</a>您的密码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
		response.write errmsg
	else
		If Rs("AcceptIP")<>"" And ChkIPLogin=1 Then
			If ChkLoginIP(Rs("AcceptIP"),ip)=False Then
				errmsg=errmsg+"<br>"+"<li>你不是合法的后台管理员。请<a href=admin_login.asp>重新输入</a>您的密码。"
			End If
		End If
		If Trim(Rs("password"))<>PassWord then
			errmsg=errmsg+"<br>"+"<li>您输入的用户名和密码不正确或者您不是系统管理员。请<a href=admin_login.asp>重新输入</a>您的密码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
			'FoundErr=True
			'Exit Sub
		Else
			If MemberName=""  Or Request("adduser") <>"" Then 
				If Trim(Rs("userpassword"))<>md5(Request("password2"),16) Then
					errmsg=errmsg+"<br>"+"<li>您输入的用户名和密码不正确或者您不是系统管理员。请<a href=admin_login.asp>重新输入</a>您的密码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"		
					'FoundErr=True
					'Exit Sub
				End If
			End If
		end if
		Conn.Execute("Update "&admintable&" Set LastLogin="&SqlNowString&",LastLoginIP='"&ip&"' Where UserName='"&UserName&"'")
					Session("flag")=Rs("flag")
					Session.Timeout=45
					Session("MemberName")=MemberName
					Response.Redirect ""&Adminpath&"index.asp"
					
	Rs.Close
	Set Rs=Nothing
	end if
	'后台登陆结束
end sub 

sub LogoutUser()
	Session("flag")=""
	Session("MemberName")=""
end sub

Sub AddUser '添加管理员
''''''''''检验用户不存在时添加
dim	adminuserid,ErrMsg
Dim UserName,birthday
UserName=trim(request("name"))
	set	rs=Conn.Execute("select userid	from [Ms_user] where username='"&replace(request("name"),"'","")&"'")
	if rs.eof and rs.bof then
		'ErrMsg = "您输入的用户名不是一个有效的注册用户！"
		'添加前台用户开始

		birthday="2006-05-02"
						

'以下为存入数据库操作
dim titlepic,UserGroupID,userclass,Viptj,Usersex
Set Rs=Conn.Execute("Select top 1 UserTitle,GroupPic,UserGroupID,IsSetting,ParentGID From Ms_UserGroups Where ParentGID=3 Order By MinArticle asc")
userclass=rs(0)
titlepic=rs(1)
If Regchecked=1 Then
UserGroupID = 5
else
UserGroupID = Rs(2)
end if

set rs=server.createobject("adodb.recordset")
sql="select * from [Ms_user]"

rs.open sql,conn,1,3

	rs.addnew
	rs("UserName")=username
	rs("UserPassword")=password
	rs("UserEmail")="hl@35.com"
	rs("Userclass")=userclass
	rs("TitlePic")=titlepic
	rs("UserQuesion")="你的密码提示问题"
	rs("UserAnswer")="你的提示加答"
	rs("UserIm")="||||||||||||||||||"
	rs("userFace")="images/userface/image1.gif"
	rs("faceinfo")="90|||115"
	rs("UserToday")="0|||0|||0"
	if Request("TemplateId")="" then
	rs("TemplateId")=1
'	else
'	rs("TemplateId")=Request("TemplateId")
'	end if

	rs("Vipset")="0|"&Viptj&""
	if Request("Pheight")<>"" then
	rs("Userheight")=Request("Pheight")
	end if

	If Request("Signature")<>"" Then rs("UserSign")=Htmlencode(Trim(Request("Signature")))
		rs("UserGroupID")=UserGroupID
		rs("Lockuser")=0
		if len(Usersex)<1 then Usersex=1
		rs("UserSex")=Usersex

		If birthday<>"" Then rs("UserBirthday")=birthday
		rs("JoinDate")=NOW()
		rs("UserLogins")=1
		rs("LastLogin")=NOW()
		rs("Userfriends")="||||||||||||||||||||||||普通话"
		rs("UserIm")="||||||||||||||||||"
		rs("UserLastIP")=Request.ServerVariables("REMOTE_ADDR")
		rs.update
		response.write username
		adminuserid=rs(0)
		conn.execute("UpDate Ms_Setup Set UserNum=UserNum+1,LastUser='"&username&"' where Cid=1")
		conn.execute("UpDate Ms_UserGroups Set Useradd=Useradd+1 where UserGroupID="&UserGroupID&"")
     End If
        rs.close

		'添加前台用户结束
	else
		adminuserid=rs(0)
	end	if

	set	rs=Conn.Execute("select username from Ms_Admin where	username='"&replace(request("name"),"'","")&"'")
	if not (rs.eof and rs.bof) then
		ErrMsg = "您输入的用户名已经在管理用户中存在！"
		exit sub
	end	if
	
	dim groupsname
	groupsname="管理员"
	titlepic="images/star/UserGroupIDlevel10.gif"
	'UserGroupID=1
	Conn.Execute("update [Ms_user]	set	UserGroupID=1 ,	Userclass='"&groupsname&"',TitlePic='"&titlepic&"' where UserName='"&username&"'")''更新前台的用户等级
	'Conn.Execute("update [Ms_user]	set	UserGroupID=1 where UserName='"&username&"'")''更新前台的用户等级

	Conn.Execute("insert into Ms_Admin (username,[password],adduser)	values ('"&replace(request("name"),"'","")&"','"&password&"','"&replace(request("name"),"'","")&"')")
	body="用户ID:"&adminuserid&" 添加成功，请记住新管理员后台登录信息，如需修改请返回管理员管理！"
	response.write body
'	ms_suc(body)
'set rss=nothing
	
End Sub '添加新管理员

sub ModifyUserInfo()
	adminid=clng(request.form("superid"))
	sql="update Ms_Admin set password='"&password&"' where UserName='"&username&"'"
	conn.execute(sql)
	sql2="update Ms_user set UserPassword='"&password&"' where UserName='"&username&"'"
	conn.execute(sql2)
	response.write "<br><br><CENTER>成功修改管理帐号!</CENTER>"

end sub 

sub DelUser()

conn.execute("delete * from Ms_Admin where UserName='"&username&"'") 

end sub

Function ChkLoginIP(AcceptIP,ChkIp)
	Dim i,LoginIP,TempIP
	ChkLoginIP = False
	If Instr("|"&AcceptIP&"|","|"&ChkIp&"|") Then ChkLoginIP = True : Exit Function
	LoginIP = Split(ChkIp,".")
	TempIP = LoginIP(0)&"."&LoginIP(1)&"."&LoginIP(2)&".*"
	If Instr("|"&AcceptIP&"|","|"&TempIP&"|") Then ChkLoginIP = True : Exit Function
	TempIP = LoginIP(0)&"."&LoginIP(1)&".*.*"
	If Instr("|"&AcceptIP&"|","|"&TempIP&"|") Then ChkLoginIP = True : Exit Function
	TempIP = LoginIP(0)&".*.*.*"
	If Instr("|"&AcceptIP&"|","|"&TempIP&"|") Then ChkLoginIP = True : Exit Function
End Function
%>