<%
''' EYCMS 后台base
''' ==================================================================

dim adminid:adminid=eycms.loadsession("adminid")
dim adminname:adminname=eycms.loadsession("adminname")
dim penname:penname=eycms.loadcookie("penname")
dim admingroupid:admingroupid=eycms.getint(eycms.loadsession("admingroupid"),0)
dim admin_loginpwd:admin_loginpwd=eycms.loadcookie("loginpwd")
dim admin_loginkey:admin_loginkey=eycms.loadcookie("loginkey")
dim admin_loginbase:admin_loginbase=admin_loginpwd
dim admin_page_lever:admin_page_lever=""
dim admin_cate_array:admin_cate_array=""
dim admin_cate_lever:admin_cate_lever=""
dim admin_lever_where:admin_lever_where=""
dim pagenum:pagenum=20

sub load(byval t0)
	dim t1:t1=eycms.getsplitname(t0)
	if ubound(t1)<>2 then eycms.echo t0&":&#27169;&#26495;&#21517;&#31216;&#38169;&#35823;":exit sub
	'eycms.temp.iscache=tempcache
	eycms.temp.isencry=tempencry
	eycms.temp.cachepath=webroot&"cache/theme/"&theme_admin_root&t1(0)
	eycms.temp.templatepath=webroot&"theme/"&theme_admin_root&t1(0)
	eycms.temp.templatename=t1(1)
	eycms.temp.templateext=t1(2)
	eycms.temp.load()
	eycms.temp.display()
end sub

sub islogin()
	if eycms.strlen(adminid)=0 or eycms.strlen(adminname)=0 or eycms.strlen(admin_loginbase)=0 then
		dim t0,t1,t2,t3
		if session("currentsite")<>"" And session("prefixsite")<>"" Then
			t0=eycms.enhtml(eycms.loadcookie_prefix(session("prefixsite"),"adminname"))
			t1=eycms.loadcookie_prefix(session("prefixsite"),"loginpwd")
			t2=eycms.loadcookie_prefix(session("prefixsite"),"loginkey")
			If eycms.enhtml(eycms.loadcookie("adminname"))<>"" And t0<>eycms.enhtml(eycms.loadcookie("adminname")) Then
				t0=eycms.enhtml(eycms.loadcookie("adminname"))
				t1=admin_loginpwd
				t3=admin_loginkey
			Else
				eycms.setcookie "adminname",t0
				eycms.setcookie "loginpwd",t1
				eycms.setcookie "loginkey",t2
			End if
		else
			t0=eycms.enhtml(eycms.loadcookie("adminname"))
			t1=admin_loginpwd
			t2=admin_loginkey
		End If
		if eycms.strlen(t0)=0 or eycms.strlen(t1)=0 or eycms.strlen(t2)=0 Then
			eycms.go "login.asp?act=out"
			exit sub
		else
			dim data
			data=eycms.db.dbload(1,"adminid,adminname,adminpass,islock,groupid,g.pagelever,g.catearray,g.catelever,penname","ey_admin u left join ey_admin_group g on u.groupid=g.id","adminname='"&t0&"'","")
			if ubound(data)<0 Then
				eycms.go "login.asp?act=out"
				exit sub
			else
				if md5(data(1,0)&data(2,0)&t2)<>t1 or data(3,0)=0 then
					eycms.go "login.asp?act=out"
					exit sub
				else
					adminid=data(0,0)
					adminname=data(1,0)
					admin_page_lever=data(5,0)
					admin_cate_array=data(6,0)
					admin_cate_lever=data(7,0)
					penname=data(8,0)
					if eycms.strlen(penname)=0 Then penname="eycms"
					if eycms.strlen(admin_page_lever)=0 then admin_page_lever=0
					if eycms.strlen(admin_cate_array)=0 then admin_cate_array=0
					if eycms.strlen(admin_cate_lever)=0 then admin_cate_lever=0
					if clng(admingroupid)<>0 then
						admin_lever_where=" and menuid in("&admin_page_lever&")"
					end if
					eycms.setsession "adminid",adminid
					eycms.setsession "adminname",adminname
					eycms.setcookie "penname",penname
					eycms.setsession "admingroupid",data(4,0)
				end if
			end if
		end if
	else
		data=eycms.db.dbload(1,"g.pagelever,g.catearray,g.catelever,u.adminname,u.penname","ey_admin u left join ey_admin_group g on u.groupid=g.id","adminname='"&adminname&"'","")
			if ubound(data)<0 then
				eycms.go "login.asp?act=out"
				exit sub
			Else
				penname=data(4,0)
				if eycms.strlen(penname)=0 Then penname="eycms"
				eycms.setsession "adminname",data(3,0)
				eycms.setcookie "adminname",data(3,0)
				eycms.setcookie "penname",penname
				admin_page_lever=data(0,0)
				admin_cate_array=data(1,0)
				admin_cate_lever=data(2,0)
				if eycms.strlen(admin_page_lever)=0 then admin_page_lever=0
				if eycms.strlen(admin_cate_array)=0 then admin_cate_array=0
				if eycms.strlen(admin_cate_lever)=0 then admin_cate_lever=0
				if clng(admingroupid)<>0 then
					admin_lever_where=" and menuid in("&admin_page_lever&")"
				end if
			end if
	end if
end sub

sub is_plug_install(byval t0)
	if eycms.strlen(eycms.getsys(t0))=0 then
		eycms.echo "plugin is not installed"
		eycms.die
	end if
end sub

sub is_plug_login()
	dim t0,t1,t2,t3
	if session("currentsite")<>"" And session("prefixsite")<>"" Then
		t0=eycms.enhtml(eycms.loadcookie_prefix(session("prefixsite"),"adminname"))
		t1=eycms.loadcookie_prefix(session("prefixsite"),"loginpwd")
		t3=eycms.loadcookie_prefix(session("prefixsite"),"loginkey")
		If eycms.enhtml(eycms.loadcookie("adminname"))<>"" And t0<>eycms.enhtml(eycms.loadcookie("adminname")) Then
			t0=eycms.enhtml(eycms.loadcookie("adminname"))
			t1=admin_loginpwd
			t3=admin_loginkey
		End if
	else
		t0=eycms.enhtml(eycms.loadcookie("adminname"))
		t1=admin_loginpwd
		t3=admin_loginkey
	End If
	t2="login failed"
	if eycms.strlen(t0)=0 or eycms.strlen(t1)=0 then
		eycms.echo t2
		eycms.die
		exit sub
	end if
	dim data
	data=eycms.db.dbload(1,"adminid,adminname,adminpass,islock","ey_admin","adminname='"&t0&"'","")
	if ubound(data)<0 then
		eycms.echo t2
		eycms.die
		exit sub
	else
		if md5(data(1,0)&data(2,0)&t3)<>t1 or data(3,0)=0 then
			eycms.echo t2
			eycms.die
			exit sub
		end if
	end if
	islogin
	if admingroupid=0 then exit sub
	if instr(","&admin_page_lever&",",",29,")<=0 then
		eycms.echo t2&"=04"
		eycms.die
	end if
end sub

function checkloginstaus()
	checkloginstaus=false
	dim t0,t1,t2
	t0=eycms.enhtml(eycms.fget("admin_name",0))
	t1=eycms.fget("loginbase",0)
	t2=eycms.fget("loginkey",0)
	if eycms.strlen(t0)=0 or eycms.strlen(t1)=0 then
		exit function
	end if
	dim data
	data=eycms.db.dbload(1,"adminid,adminname,adminpass,islock","ey_admin","adminname='"&t0&"'","")
	if ubound(data)<0 then
		exit function
	else
		if md5(data(1,0)&data(2,0)&t2)<>t1 or data(3,0)=0 then
			exit function
		end if
	end if
	checkloginstaus=true
end function

sub checkpagelever(byval t0)
	if admingroupid=0 then exit sub
	if instr(","&admin_page_lever&",",","&t0&",")<=0 then
		eycms.back("对不起，您没有此页面的管理权限")
		eycms.die
	end if
end sub

sub checkcatelever(byval t0)
	if admingroupid=0 then exit sub
	if instr(","&admin_cate_array&",",","&t0&",")<=0 then
		eycms.back("对不起，您没有此栏目的管理权限")
		eycms.die
	end if
end sub

sub checkcateaction(byval t0)
	if admingroupid=0 then exit sub
	dim t1
	select case t0
		case "1":t1="添加"
		case "2":t1="编辑"
		case "3":t1="删除"
		case "4":t1="移动"
		case "5":t1="设置"
	end select
	if instr(","&admin_cate_lever&",",","&t0&",")<=0 then
		eycms.back("对不起，您没有此栏目的"&t1&"权限")
		eycms.die
	end if
end sub

function checkcatestatus(byval t0)
	checkcatestatus=true
	if admingroupid=0 then exit function
	if admin_cate_lever="0" then
		checkcatestatus=false
	end if
	if instr(","&admin_cate_lever&",",","&t0&",")<=0 then
		checkcatestatus=false
	end if
end function

function getcatestatus(byval t0)
	getcatestatus=true
	if admingroupid=0 then exit function
	if admin_cate_array="0" then
		getcatestatus=false
	end if
	if instr(","&admin_cate_array&",",","&t0&",")<=0 then
		getcatestatus=false
	end if
end Function

function isuplogin()
	isuplogin=0
	dim t0,t1,t2
	t0=eycms.enhtml(eycms.fget("admin_name",0))
	t1=eycms.fget("loginbase",0)
	t2=eycms.fget("loginkey",0)
	if eycms.strlen(t0)=0 or eycms.strlen(t1)=0 then
		exit function
	end if
	dim data
	data=eycms.db.dbload(1,"adminid,adminname,adminpass,islock","ey_admin","adminname='"&t0&"'","")
	if ubound(data)<0 then
		exit function
	else
		if md5(data(1,0)&data(2,0)&t2)<>t1 or data(3,0)=0 then
			exit function
		end if
	end if
	isuplogin=1
end function
%>
