<!--#include file="../lib/base.asp"-->
<!--#include file="../theme/admin_leo/config.asp"-->
<!--#include file="../lib/cmd.asp"-->
<!--#include file="../lib/class/eycms.pinyin.asp"-->
<%
''' EYCMS base
''' ==================================================================

function fuckdate(byval t0)
	t0=replace(t0,"上午 ","")
	t0=replace(t0,"下午 ","")
	fuckdate=t0
end function

function get_fristletter(byval t0)
	 t0=left(t0,1)
	 dim t1:t1=eycms.get_pinyin(t0)
	 get_fristletter=lcase(left(t1,1))
end function

function get_adminfolder
	dim a,b,c
	a=request.servervariables("script_name")
	b=split(a,"/")
	c=ubound(b)
	get_adminfolder=replace(a,b(c),"")
end function

sub deal_tags(byval t0,byval t1)
	if eycms.strlen(t0)>0 then
		dim t2,i
		t2=split(t0,",")
		for i=0 to ubound(t2)
			if eycms.strlen(trim(t2(i)))>0 then
			dim rs
				set rs=server.createobject("adodb.recordset")
				rs.open "select hits from ey_expand_tags where title='"&trim(t2(i))&"'",eycms.db.conn,1,3
				if not rs.eof then
				dim hits:hits=rs(0)
					if hits>0 then hits=hits-1 else hits=0
					rs.update
					rs(0)=hits
					rs.update
				end if
				rs.close
				set rs=nothing
			end if
		next
	end if
	if eycms.strlen(t1)>0 then
		t2=split(t1,",")
		for i=0 to ubound(t2)
			if eycms.strlen(trim(t2(i)))>0 then
				set rs=server.createobject("adodb.recordset")
				rs.open "select title,hits from ey_expand_tags where title='"&trim(t2(i))&"'",eycms.db.conn,1,3
				if rs.eof then
					rs.addnew
					rs(0)=t2(i)
					rs(1)=1
				else
					rs.update
					rs(1)=rs(1)+1
				end if
				rs.update
				rs.close
				set rs=nothing
			end if
		next
	end if
end sub

sub getcategory02(byval t0,byval t1)
	dim i
	for i=0 to ubound(catedata,2)
		if t0=catedata(3,i) Then
			If getcatestatus(catedata(0,i)) then
				get_category02=get_category02&"<option value="""
				get_category02=get_category02&""&catedata(0,i)&""
				get_category02=get_category02&""" "&eycms.iif(t1=catedata(0,i),"selected","")&" "
				get_category02=get_category02&">"&string(catedata(4,i)-1,"　")&eycms.iif(catedata(3,i)>0,"├ ","")&""&catedata(1,i)&"</option>"
			End if
			getcategory02 catedata(0,i),t1
		end if
	next
end Sub

sub delall(byval t0,byval t1,byval t2)
	on error resume next
	dim img,iarr,i
	eycms.db.dbupdate "ey_attachment","cid="&t1&" and classid="&t2,array(array("zt",-1,0,0))
	if instr(t0,",")>0 then
		iarr=split(t0,",")
		for i=0 to UBound(iarr)
			img = trim(iarr(i))
			if instr(img,"/")>0 then img=split(img,"/")(UBound(split(img,"/")))
			if eycms.strlen(img)>0 then
				eycms.db.dbupdate "ey_attachment","filename='"&img&"' and classid="&t2,array(array("cid",t1,0,0),array("zt",0,0,0))
			end if
		next
	else
		img = trim(t0)
		if instr(img,"/")>0 then img=split(img,"/")(UBound(split(img,"/")))
		if eycms.strlen(img)>0 then
			eycms.db.dbupdate "ey_attachment","filename='"&img&"' and classid="&t2,array(array("cid",t1,0,0),array("zt",0,0,0))
		end if
	end if
	eycms.db.dbupdate "ey_attachment","zt<0 and cid="&t1&" and classid="&t2,array(array("cid",-1,0,0))
end Sub

sub deal_file(byval t0,byval t1)
	eycms.db.dbupdate "ey_attachment","adminid="&adminid&" and cid<=0 and classid="&t1&"",array(array("cid",t0,0,0))
end sub

sub deal_del_file(byval t0,byval t1)
	eycms.db.dbupdate "ey_attachment","cid="&t0&" and classid="&t1&"",array(array("cid",-1,0,0))
end sub
	
function get_tag(byval t0)
	Dim t1
	t1=Replace(Split(t0,"/")(UBound(Split(t0,"/"))),".asp","")
	If InStr(t1,"_")>0 Then t1=Replace(t1,Split(t1,"_")(0),"")
	If InStr(t0,"model/")>0 Then
		get_tag="theme_" & Split(t0,"/")(1) & t1
		get_tag=Replace(get_tag,"_page_page","_page")
	ElseIf InStr(t0,"user/")>0 Then
		If Left(t1,1)="_" Then t1=Right(t1,Len(t1)-1)
		get_tag="theme_user" & t1
	ElseIf InStr(t0,"common/")>0 Then
		If Left(t1,1)="_" Then t1=Right(t1,Len(t1)-1)
		get_tag="theme_common_" & t1
	ElseIf InStr(t0,"block/")>0 Then
		If Left(t1,1)="_" Then t1=Right(t1,Len(t1)-1)
		get_tag="theme_block_" & t1
	Else
		get_tag="theme" & t1
	End if
end function
	
function getblockname(byval t0)
	dim fname,fpath,xml,i,item,seturl,setname,mobile
	if instr(t0,"/")>0 then
		fpath=split(t0,"/")(0)&"/"
		fname=replace(t0,fpath,"")
	else
		fpath=""
		fname=t0
	end if

	if eycms.isfile("../theme/"&theme_root&"/base.xml") then
		set xml=server.createobject("microsoft.xmldom")
		xml.async=false
		xml.load(server.mappath("../theme/"&theme_root&"/base.xml"))
		set item=xml.getelementsBytagname("item")
		for i=0 to (item.length-1)
			set seturl=item.item(i).getelementsBytagname("seturl")
			set setname=item.item(i).getelementsBytagname("setname")
			if seturl.item(0).text=t0 then 
				getblockname=trim(setname.item(0).text)
				if eycms.strlen(getblockname)>0 then exit function
			end if
		next
		set xml=nothing
		set item=nothing
	end if
	if eycms.strlen(getblockname)=0 then
		fname=t0
		if instr(fname,"mobile/") then 
			mobile="手机版_"
			fname=replace(fname,"mobile/","")
		end if
		fname=replace(fname,"model/","")
		select case fname
		case "eycms_top.asp":getblockname="通用包含文件"
		case "eycms_head.asp":getblockname="页头"
		case "eycms_foot.asp":getblockname="页尾"
		case "eycms_index.asp":getblockname="首页"
		case "eycms_book.asp":getblockname="留言"
		case "eycms_comment.asp":getblockname="评论"
		case "eycms_rss.asp":getblockname="RSS地图"
		case "eycms_search.asp":getblockname="搜索"
		case "eycms_tags.asp":getblockname="标签页"
		case "eycms_tags_list.asp":getblockname="标签列表"
		case "eycms_404.asp":getblockname="站内404错误"
		case "eycms_left.asp":getblockname="通用模型侧栏"
		case "eycms_left_all.asp":getblockname="扩展模块侧栏"
		case "eycms_left_pro.asp":getblockname="商品专用侧栏"
		case "eycms_left_news.asp":getblockname="文章专用侧栏"
		case "eycms_left_page.asp":getblockname="单页专用侧栏"
		case "eycms_ajaxlogin.asp":getblockname="顶部AJAX登录"
		case "eycms_cart.asp":getblockname="查看购物车"
		case "eycms_cart_order.asp":getblockname="填写购物信息"
		case "eycms_cart_show.asp":getblockname="完成订单"
		case "eycms_goods.asp":getblockname="商品筛选页"
		case "eycms_point_order.asp":getblockname="礼品订单"
		case "page/eycms_page.asp":getblockname="单页模型"
		case "news/eycms_index.asp":getblockname="文章模型_专题页"
		case "news/eycms_list.asp":getblockname="文章模型_列表页"
		case "news/eycms_list_pic.asp":getblockname="文章模型图_文列表页"
		case "news/eycms_show.asp":getblockname="文章模型_内容页"
		case "news/eycms_publish.asp":getblockname="文章模型_投稿页"
		case "photo/eycms_index.asp":getblockname="图片模型_专题页"
		case "photo/eycms_list.asp":getblockname="图片模型_列表页"
		case "photo/eycms_show.asp":getblockname="图片模型_内容页"
		case "photo/eycms_publish.asp":getblockname="图片模型_投稿页"
		case "pro/eycms_index.asp":getblockname="商品模型_专题页"
		case "pro/eycms_list.asp":getblockname="商品模型_列表页"
		case "pro/eycms_show.asp":getblockname="商品模型_内容页"
		case "pro/eycms_publish.asp":getblockname="商品模型_投稿页"
		case "down/eycms_index.asp":getblockname="下载模型_专题页"
		case "down/eycms_list.asp":getblockname="下载模型_列表页"
		case "down/eycms_show.asp":getblockname="下载模型_内容页"
		case "down/eycms_publish.asp":getblockname="下载模型_投稿页"
		case "video/eycms_index.asp":getblockname="视频模型_专题页"
		case "video/eycms_list.asp":getblockname="视频模型_列表页"
		case "video/eycms_show.asp":getblockname="视频模型_内容页"
		case "video/eycms_publish.asp":getblockname="视频模型_投稿页"
		case "gift/eycms_index.asp":getblockname="礼品模型_专题页"
		case "gift/eycms_list.asp":getblockname="礼品模型_列表页"
		case "gift/eycms_show.asp":getblockname="礼品模型_内容页"
		end select
		getblockname=mobile&getblockname
	end if 
end function

function get_self_field(byval t0,byval t1,byval t2,byval t3,byval t4,byval t5,byval t6,byval t7,byval t8,byval t9,byval t10,byval t11,byval t12,byval t13,byval t14,byval t15)
	dim str:str=""
	Dim mclass:mclass="1"
	If t12=2 Then mclass="0"
	t8=eycms.iif(isnull(t8),"",t8)
	if t12=0 Or t12=2 then t8=eycms.iif(t8="",t11,t8)
	if t8<>"" Then
		dim reg,matches,match
		set reg=new regexp
		reg.ignorecase=true
		reg.global=true
		reg.pattern="\{session\s+(.+?)\}"
		set matches=reg.execute(t8)
		if matches.count>0 then
			for each match in matches
				t8=replace(t8,match.value,eycms.loadsession(match.submatches(0)))
			next
		end if

		reg.pattern="\{var\s+(.+?)\}"
		set matches=reg.execute(t8)
		if matches.count>0 then
			for each match in matches
				t8=replace(t8,match.value,eval(match.submatches(0)))
			next
		end If

		reg.pattern="\{get\s+(.+?)\}"
		set matches=reg.execute(t8)
		if matches.count>0 then
			for each match in matches
				t8=replace(t8,match.value,eycms.fget(match.submatches(0),0))
			next
		end If
		Set reg=nothing
	end if
	If eycms.strlen(t15)=0 Then t15=0
	if t6=1 then
		dim rule
		rule="data-rule="""&t1&":required;"
		select case t7
			case "2":rule=rule&"digits;"
			case "3":rule=rule&"dot;"
			case "4":rule=rule&"tel;"
			case "5":rule=rule&"mobile;"
			case "6":rule=rule&"email;"
			case "7":rule=rule&"date;"
			case "8":rule=rule&"postcode;"
			case "9":rule=rule&"qq;"
			case "10":rule=rule&"url;"
		end select
		rule=rule&""""
	end if
	dim i,arr,m,strlist,transVal
	arr=split(t5,vbcrlf)
	select case t2
	case "1"
		select case t3
			case "2":t4=10
			case "3":t4=50:t8=replace(t8,"/","-")
			case "4":t4=255
			case "5":t4=10
			if t8<>"" then t8=formatnumber(t8,-1,-1)
		end Select
		If t13=0 Then
			If t3="3" Then
				str=str&"<input type=""text"" name="""&t0&""" id="""&t0&""" size=""50"" value="""&t8&""" maxlength="""&t4&""" class=""ip date"" readonly /><script type='text/javascript'>calendar('"& t0 &"',0);</script>"
			else
				str=str&"<input type=""text"" name="""&t0&""" id="""&t0&""" size=""50"" value="""&t8&""" maxlength="""&t4&""" class=""ip"" "&rule&" />"
			End if
		Else
			If t15=0 Then
				If t12>0 And eycms.strlen(t8)>0 Then transVal=eycms.db.dbloadone("title","view_content","id="&t8&"")
				str=str&"<input type=""hidden"" name="""&t0&""" id="""&t0&""" value="""&t8&""" /><input type=""text"" name="""&t0&"show"" id="""&t0&"show"" size=""50"" config='"&t14&":"& t0 &"' class='singlesel ip' value="""&transVal&""" readonly />"
			Else
				strlist=""
				if eycms.strlen(t8)>0 Then
				  If CStr(t8)<>"0" And t8<>t11 then
					Dim rslist:rslist=eycms.db.dbload(10,"id,title","ey_content","islock=1 and id in("&t8&")","ontop desc,id desc")
					if ubound(rslist)>=0 then
						dim tt
						for tt=0 to ubound(rslist,2)
							strlist=strlist&"<li>[ "&rslist(0,tt)&" ]　"&eycms.cutstr(rslist(1,tt),42,1)&"</li>"
						next
					end If
				  End if
				End if
				str=str&"<input type='button' value='点击选择' config='"&t14&":"& t0 &"' class='multisel bnt_sel' /></dt><dt><input type='hidden' rev='field' name='"& t0 &"' id='"& t0 &"' value='"& t8 &"' /><ul id='"& t0 &"show' class='multilist'>"&strlist&"</ul>"
			End if
		End if
		if t3=4 then
			str=str&"<input type=""button"" value=""上传"" config="""&t0&":"&t9&":"&t10&":"&mclass&""" class=""bnt bnt_save"" />"
			If eycms.strlen(t8)>0 Then str=str&"<input onclick=""showimg('"&t8&"')"" type=""button"" value=""预览"" class=""bnt_save""/>"
		end if
		if t3=6 then
			str=str&"<input type=""button"" value=""标注"" config="""&t0&""" class=""bnt_map bnt_save"" />"
			If eycms.strlen(t8)>0 then str=str&"<input onclick=""showtxt('"&t0&"')"" type=""button"" value=""调用代码"" class=""bnt_save""/>"
		end if
	case "3"
		str=str&"<select name="""&t0&""" id="""&t0&""" class=""ip"" "&rule&">"&vbcrlf
		str=str&"<option value="""">请选择"&t1&"</option>"&vbcrlf
		for i=0 to ubound(arr)
			if len(arr(i))>0 then
				if instr(arr(i),"|")>0 then
					m=split(arr(i),"|")
					str=str&"<option value="""&m(1)&""" "
					if m(1)=t8 then
						str=str&" selected"
					end if
					str=str&">"&m(0)&"</option>"&vbcrlf
				end if
			end if
		next
		str=str&"</select>"
	case "4","5"
		dim types:types=eycms.iif(t2=4,"radio","checkbox")
		rule=replace(rule,"required;","checked")
		dim j:j=0
		for i=0 to ubound(arr)
			if len(arr(i))>0 then
				if instr(arr(i),"|")>0 then
					m=split(arr(i),"|")
					str=str&"<input type="""&types&""" name="""&t0&""" id="""&t0&"_"&i&""" value="""&m(1)&""" "
					if j=0 then
						str=str&" "&rule&" "
					end if
					if t2=4 then
						if m(1)=t8 then
							str=str&" checked"
						end if
					else
						if instr(", "&t8&", ",", "&m(1)&", ")>0 then
							str=str&" checked"
						end if
					end if
					str=str&">"&m(0)&""&vbcrlf
					j=j+1
				end if
			end if
		next
	case "2","6"
		str=str&"<textarea name="""&t0&""" id="""&t0&""" "
		if t2=2 then
			str=str&"class=""tt"" cols=""51"" rows=""4"" "&rule&""
		else
			str=str&"style=""width:98%;"""
		end if
		str=str&">"&t8&"</textarea>"
	end select
	get_self_field=str
end function

function deal_model_field(byval t0)
	dim a:a=eycms.get_model_field(t0)
	if not isarray(a) then
		deal_model_field="":exit function
	end if
	dim fi,fstr,istrim,length,fname,fmode,iscn,formstr,rules
	for fi=0 to ubound(a,2)
		fstr=fstr&","
		fname=a(0,fi)
		istrim=a(10,fi)
		length=a(5,fi)
		fmode=a(3,fi)
		iscn=1
		rules=""
		select case a(2,fi)
			case "1"
				select case fmode
					case "2","5":length=10:iscn=0
					case "3":length=50
				end select
				formstr="eycms.enhtml(eycms.fpost("""&fname&""","&istrim&"))"
			case "2":length=0
				formstr="eycms.enhtml(eycms.fpost("""&fname&""","&istrim&"))"
			case "3","4","5":length=255
				formstr="eycms.enhtml(eycms.fpost("""&fname&""","&istrim&"))"
			case "6":length=0
				formstr="eycms.fpost("""&fname&""","&istrim&")"
		end select
		fstr=fstr&"array("""&fname&""","&formstr&","&length&","&iscn&")"
		formstr=eval(formstr)
		if a(8,fi)=1 then
			if eycms.strlen(formstr)=0 then eycms.ajaxjson a(1,fi)&"不能为空",0:eycms.die
			select case a(9,fi)
				case "2":rules="int"
				case "3":rules="price"
				case "4":rules="tel"
				case "5":rules="mobile"
				case "6":rules="email"
				case "7":rules="date"
				case "8":rules="zipcode"
				case "9":rules="qq"
				case "10":rules="url"
			end select
			if rules<>"" then
				if not(eycms.checkstr(formstr,rules)) then
					eycms.ajaxjson a(1,fi)&"格式错误",0:eycms.die
				end if
			end if
		end If
		select case a(2,fi)
			case "1"
				If fmode=4 Then imgArr = imgArr &","& formstr
			case "6"
				imgArr = imgArr &","& eycms.getfilelist(formstr)
		end select
	next
	deal_model_field=fstr
end Function

function deal_model_site(byval t0)
	on error resume next
	dim a:a=eycms.get_model_site(t0)
	if not isarray(a) then
		deal_model_field="":exit function
	end if
	dim fi,fstr,length,fname,fmode,iscn,formstr,rules
	for fi=0 to ubound(a,2)
	    if fi=0 then
			fstr=""
	    else
			fstr=fstr&"{eycms}"
	    end if
		fname=a(0,fi)
		length=a(5,fi)
		fmode=a(3,fi)
		iscn=1
		rules=""
		select case a(2,fi)
			case "1"
				select case fmode
					case "2","5":length=10:iscn=0
					case "3":length=50
				end select
				formstr="eycms.enhtml(eycms.fpost("""&fname&""",0))"
			case "2":length=0
				formstr="eycms.fpost("""&fname&""",2)"
			case "3","4","5":length=255
				formstr="eycms.enhtml(eycms.fpost("""&fname&""",0))"
			case "6":length=0
				formstr="eycms.fpost("""&fname&""",2)"
		end select
		formstr=eval(formstr)
		fstr=fstr&fname&"{|}"&formstr&"{|}"&length&"{|}"&iscn
		
		if a(8,fi)=1 then
			if eycms.strlen(formstr)=0 then eycms.ajaxjson a(1,fi)&"不能为空",0:eycms.die
			select case a(9,fi)
				case "2":rules="int"
				case "3":rules="price"
				case "4":rules="tel"
				case "5":rules="mobile"
				case "6":rules="email"
				case "7":rules="date"
				case "8":rules="zipcode"
				case "9":rules="qq"
				case "10":rules="url"
			end select
			if rules<>"" then
				if not(eycms.checkstr(formstr,rules)) then
					eycms.ajaxjson a(1,fi)&"格式错误",0:eycms.die
				end if
			end if
		end If
		select case a(2,fi)
			case "1"
				If fmode=4 Then delall formstr,a(11,fi),0
			case "6"
				delall eycms.getfilelist(formstr),a(11,fi),0
		end Select
	next
	deal_model_site=fstr
	if err then
		eycms.errlog "文件：base.asp<BR>函数：deal_model_site<BR>参数："&fstr&"<br>详情："&err.description,0
		err.clear
	End if
end Function

sub deal_attr_set(byval t0,byval t1)
	dim a:a=eycms.get_attr_set(t1)
	if not isarray(a) then
		exit sub
	end if
	dim fi,fstr,istrim,length,fname,fmode,iscn,formstr,rules
	for fi=0 to ubound(a,2)
		fstr=fstr&","
		fname=a(0,fi)
		istrim=a(10,fi)
		length=a(5,fi)
		fmode=a(3,fi)
		iscn=1
		rules=""
		formstr="eycms.enhtml(eycms.fpost("""&fname&""","&istrim&"))"
		fstr=fstr&"array("""&fname&""","&formstr&","&length&","&iscn&")"
		formstr=eval(formstr)
		if a(8,fi)=1 then
			if eycms.strlen(formstr)=0 then eycms.ajaxjson a(1,fi)&"不能为空",0:eycms.die
		end If
	next
	fstr="array(array(""pid"","&t0&",0,0)"&fstr&")"
	if eycms.db.dbcount("ey_attr","pid="&t0)<=0 then
		eycms.db.insert "ey_attr",eval(fstr)
	else
		eycms.db.dbupdate "ey_attr","pid="&t0&"",eval(fstr)
	End if
end sub

function get_classtree(byval t0)
	dim data,cid
	cid="["&t0&"]"
	data=eycms.db.dbload("","cateid,catename,followid","view_category","left(parentid,"&Len(cid)&")='"&cid&"'","ordnum,cateid")
	dim i
	if isarray(data) then
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				get_classtree=get_classtree&""&eycms.iif(i=0,"",",")&"{"
				get_classtree=get_classtree&"id:"&data(0,i)&""
				get_classtree=get_classtree&",pId:"&data(2,i)&""
				get_classtree=get_classtree&",name:"""&data(1,i)&""""
				get_classtree=get_classtree&",open:true}"
			next
		end if
	end If
End Function
%>
