<!--#include file="base.asp"-->
<%
''' EYCMS 内容
''' ==================================================================

	sub get_tags()
		dim t0:t0=eycms.enhtml(eycms.fpost("t0",0))
		if eycms.strlen(t0)=0 then eycms.echo "0&#26631;&#39064;&#19981;&#33021;&#20026;&#31354;":exit sub
		eycms.echo eycms.split_tags(t0)
	end sub

	sub adddb()
		dim t0,t1,t2,t3,t4,t5,t6,t7,t8
		dim o0,o1
		dim s0,s1,s2,style
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.enhtml(eycms.fpost("t2",0))
		t3=eycms.enhtml(eycms.fpost("t3",0))
		t4=eycms.getint(eycms.fpost("t4",0),0)
		t5=eycms.getint(eycms.fpost("t5",0),0)
		t6=eycms.getint(eycms.fpost("t6",0),0)
		t7=eycms.enhtml(eycms.fpost("t7",0))
		t8=eycms.enhtml(eycms.fpost("t8",1))
		s0=eycms.enhtml(eycms.fpost("c0",0))
		s1=eycms.enhtml(eycms.fpost("c1",0))
		s2=left(eycms.enhtml(eycms.fpost("s2",0)),7)
		
		t7=eycms.iif(isdate(t7),t7,now())
		o1=eycms.is_pic(t3)
		t3=eycms.iif(o1=0,"",t3)
		
		t2=replace(t2," ",",")
		t2=replace(t2,"　",",")
		t2=replace(t2,"，",",")
		t2=eycms.deal_strmid(t2,",")
		if eycms.strlen(s2)>0 then s2="color:"&s2
		style=s0&s1&s2
		if eycms.strlen(style)>0 then style="style="""&style&""""
		if eycms.strlen(t0)=0 then eycms.ajaxjson "&#26631;&#39064;&#19981;&#33021;&#20026;&#31354;",0:exit sub
		if eycms.strlen(t1)=0 then eycms.ajaxjson "&#38142;&#25509;&#22320;&#22336;&#19981;&#33021;&#20026;&#31354;",0:exit sub
		deal_tags "",t2
		data=array(array("title",t0,255,1),array("url",t1,255,1),array("isurl",1,1,0),array("tags",t2,255,1),array("pic",t3,255,1),array("ispic",o1,1,0),array("hits",0,1,0),array("islock",t4,1,0),array("isnice",t5,1,0),array("ontop",t6,1,0),array("intro",t8,0,1),array("iscomment",1,1,0),array("createdate",fuckdate(t7),50,1),array("likeid",0,0,1),array("style",style,0,1),array("lastupDate",fuckdate(t7),50,1),array("classid",classid,0,0),array("comments",0,0,0),array("adminid",adminid,0,0),array("userid",0,0,0),array("point",0,0,0))
		eycms.db.insert "ey_content",data
		dim cid:cid=eycms.db.insertid("id","ey_content")
		deal_file cid,1
		eycms.ajaxjson "保存成功",1
	end sub
	
	sub editdb()
		dim t0,t1,t2,t2_0,t3,t4,t5,t6,t7,t8
		dim o0,o1
		dim s0,s1,s2,style
		dim t3_1
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.enhtml(eycms.fpost("t2",0))
		t2_0=eycms.enhtml(eycms.fpost("t2_0",0))
		t3=eycms.enhtml(eycms.fpost("t3",0))
		t4=eycms.getint(eycms.fpost("t4",0),0)
		t5=eycms.getint(eycms.fpost("t5",0),0)
		t6=eycms.getint(eycms.fpost("t6",0),0)
		t7=eycms.enhtml(eycms.fpost("t7",0))
		t8=eycms.enhtml(eycms.fpost("t8",1))
		s0=eycms.enhtml(eycms.fpost("c0",0))
		s1=eycms.enhtml(eycms.fpost("c1",0))
		s2=left(eycms.enhtml(eycms.fpost("s2",0)),7)
		
		t7=eycms.iif(isdate(t7),t7,now())
		o1=eycms.is_pic(t3)
		t3=eycms.iif(o1=0,"",t3)
		t2=replace(t2," ",",")
		t2=replace(t2,"　",",")
		t2=replace(t2,"，",",")
		t2=eycms.deal_strmid(t2,",")
		if eycms.strlen(s2)>0 then s2="color:"&s2
		style=s0&s1&s2
		if eycms.strlen(style)>0 then style="style="""&style&""""
		
		if eycms.strlen(t0)=0 then eycms.ajaxjson "&#26631;&#39064;&#19981;&#33021;&#20026;&#31354;",0:exit sub
		if eycms.strlen(t1)=0 then eycms.ajaxjson "&#38142;&#25509;&#22320;&#22336;&#19981;&#33021;&#20026;&#31354;",0:exit sub
		deal_tags t2_0,t2
		data=array(array("classid",classid,0,0),array("title",t0,255,1),array("url",t1,255,1),array("tags",t2,255,1),array("pic",t3,255,1),array("ispic",o1,1,0),array("islock",t4,1,0),array("isnice",t5,1,0),array("ontop",t6,1,0),array("intro",t8,0,1),array("createdate",fuckdate(t7),50,1),array("style",style,0,1),array("lastupDate",sqltime,50,0))
		eycms.db.dbupdate "ey_content","id="&id&"",data
		eycms.ajaxjson "保存成功",1
	end sub
	
	sub deldb()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		eycms.db.dbupdate "ey_content","id="&id&"",array(array("islock",-3,2,0))
		'eycms.echo "0"&id&"***"&classid
		eycms.echo "1"
	end sub
	
	sub delall()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			eycms.echo "0&#33267;&#23569;&#36873;&#25321;&#19968;&#26465;&#20449;&#24687;"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0&#21442;&#25968;&#65306;"&id(i)&"&#19981;&#27491;&#30830;&#65292;&#35831;&#30830;&#35748;&#21518;&#20877;&#25805;&#20316;"
					exit sub
				end if
			next
			eycms.db.dbupdate "ey_content","id in("&id&")",array(array("islock",-3,2,0))
			eycms.echo "1"
		end if
	end sub
	
	sub doset()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim go:go=eycms.enhtml(eycms.fget("go",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			eycms.echo "0&#33267;&#23569;&#36873;&#25321;&#19968;&#26465;&#20449;&#24687;"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0&#21442;&#25968;&#65306;"&idarr(i)&"&#19981;&#27491;&#30830;&#65292;&#35831;&#30830;&#35748;&#21518;&#20877;&#25805;&#20316;"
					exit sub
				end if
			next
			dim filed,result
			select case go
				case "islock":filed="islock":result=1
				case "nolock":filed="islock":result=0
				case "isnice":filed="isnice":result=1
				case "nonice":filed="isnice":result=0
				case "istop":filed="ontop":result=1
				case "notop":filed="ontop":result=0
				case "iscomment":filed="iscomment":result=1
				case "nocomment":filed="iscomment":result=0
				case else:eycms.echo "0&#21442;&#25968;&#38169;&#35823;":exit sub
			end select
			eycms.db.dbupdate "ey_content","id in("&id&")",array(array(filed,result,2,0))
			eycms.echo "1"
		end if
	end sub
	
	sub movedb()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim go:go=eycms.enhtml(eycms.fget("go",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			eycms.echo "0&#33267;&#23569;&#36873;&#25321;&#19968;&#26465;&#20449;&#24687;"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0&#21442;&#25968;&#65306;"&idarr(i)&"&#19981;&#27491;&#30830;&#65292;&#35831;&#30830;&#35748;&#21518;&#20877;&#25805;&#20316;"
					exit sub
				end if
			next
			eycms.db.dbupdate "ey_content","id in("&id&")",array(array("classid",go,0,0))
			eycms.echo "1"
		end if
	end sub
	
	sub movecate()
		dim comecate:comecate=eycms.getint(eycms.fget("comecate",0),0)
		dim gocate:gocate=eycms.getint(eycms.fget("gocate",0),0)
		eycms.db.dbupdate "ey_content","classid="&comecate&"",array(array("classid",gocate,0,0))
		eycms.echo "1"
	end sub
	
	sub redo()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			eycms.echo "0&#33267;&#23569;&#36873;&#25321;&#19968;&#26465;&#20449;&#24687;"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0&#21442;&#25968;&#65306;"&id(i)&"&#19981;&#27491;&#30830;&#65292;&#35831;&#30830;&#35748;&#21518;&#20877;&#25805;&#20316;"
					exit sub
				end if
			next
			eycms.db.dbupdate "ey_content","id in("&id&") and classid="&classid&"",array(array("islock",1,2,0))
			eycms.echo "1"
		end if
	end sub
	
	sub redoall()
		eycms.db.dbupdate "ey_content","classid="&classid&"",array(array("islock",1,2,0))
		eycms.echo "1"
	end sub
	
	sub clearall()
		dim idarr
		data=eycms.db.dbload("","id","ey_content","classid="&classid&" and islock=-3","")
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				if i=0 then
					idarr=data(0,i)
				else
					idarr=idarr&","&data(0,i)
				end if
			next
			eycms.db.dbdel tablename,"cid in("&idarr&")"
		end if
		eycms.db.dbdel "ey_content","classid="&classid&" and islock=-3"
		eycms.echo "1"
	end sub
	
	sub delclear()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		data=eycms.db.dbload(1,"id","ey_content","classid="&classid&" and islock=-3 and id="&id&"","")
		if ubound(data)>=0 then
			eycms.db.dbdel tablename,"cid="&id&""
			eycms.db.dbdel "ey_content","classid="&classid&" and islock=-3 and id="&id&""
		end if
		eycms.echo "1"
	end sub
	
	sub likedb()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim classid:classid=eycms.enhtml(eycms.fget("classid",0))
		dim t0:t0=eycms.enhtml(eycms.fpost("key",0))
		t0=replace(t0,"　"," ")
		dim arr:arr=split(t0," ")
		dim j,sql
		sql=" and ("
		for j=0 to ubound(arr)
			if j>0 then sql=sql&" or "
			if datatype then
				sql=sql&" instr(lcase(title),lcase('"&arr(j)&"'))>0"
			else
				sql=sql&" title like '%"&arr(j)&"%'"
			end if
		next
		sql=sql&" ) "
		dim t1,classin
		classin=" and classid in("&eycms.get_sonid(classid)&")"
		t1=eycms.db.dbload(15,"id,title","ey_content","islock=1 and id<>"&id&classin&sql&"","ontop desc,id desc")
		if ubound(t1)<0 then
			eycms.echo "0没有相关信息"
		else
			dim i,t2
			t2="1"
			for i=0 to ubound(t1,2)
			t2=t2&"<li><span><a href=""javascript:;"" infoid="""&t1(0,i)&""" infotitle="""&eycms.cutstr(t1(1,i),40,1)&""" title=""添加"" class=""infoadd""></a></span><a href=""../show.asp?id="&t1(0,i)&""" target=""_blank"">"&eycms.cutstr(t1(1,i),40,1)&"</a></li>"
			next
			eycms.echo t2
		end if
	end sub
	
	sub treedb()
		dim data:data=eycms.getclassdb(classid)
		getcategory classid,data(10)
		load theme_content_tree
	end sub
		
	sub getdate()
		dim t0:t0=eycms.getint(eycms.fget("t0",0),0)
		dim t1:t1=eycms.getint(eycms.fget("classid",0),0)
		dim sqlwhere:sqlwhere="isurl=0 and islock=1 and classid="&t1&""

		dim datestr,daystr,weekstr,monthstr
		if datatype then
			datestr="date()"
			daystr="'d'"
			weekstr="'w'"
			monthstr="'m'"
		else
			datestr="getdate()"
			daystr="d"
			weekstr="w"
			monthstr="m"
		end if
		select case t0
			case "1"
				sqlwhere=sqlwhere&" and datediff("&daystr&",createdate,"&datestr&")=0"
			case "2"
				sqlwhere=sqlwhere&" and datediff("&daystr&",createdate,"&datestr&")=1"
			case "3"
				sqlwhere=sqlwhere&" and datediff("&weekstr&",createdate,"&datestr&")=0"
			case "4"
				sqlwhere=sqlwhere&" and datediff("&monthstr&",createdate,"&datestr&")=0"
		end select

		dim data:data=eycms.db.dbload("","id","ey_content",sqlwhere&"","id")

		if ubound(data)<0 then
			exit sub
		else
			dim i,str
			for i=0 to ubound(data,2)
				if i=0 then
					str=data(0,i)
				else
					str=str&","&data(0,i)
				end if
			next
			eycms.echo str
		end if
	end sub	

	sub getcategory(byval t0,byval t1)
		dim data
		data=eycms.db.dbload("","cateid,catename,followid,sonid","view_category","modeid="&t1&"","ordnum,cateid")
		dim i
		if isarray(data) then
			if ubound(data)>=0 then
				for i=0 to ubound(data,2)
					get_tree=get_tree&""&eycms.iif(i=0,"",",")&"{"
					get_tree=get_tree&"id:"&data(0,i)&""
					get_tree=get_tree&",pId:"&data(2,i)&""
					get_tree=get_tree&",name:"""&data(1,i)&""""
					if t0=data(0,i) then
						get_tree=get_tree&",checked:true"
					end if
					if data(0,i)<>data(3,i) then
						get_tree=get_tree&",open:true"
					end If
					if data(0,i)=t0 then
						get_tree=get_tree&",chkDisabled:true"
					end if
					get_tree=get_tree&"}"
				next
			end if
		end If
	end Sub

	function getadminurl(byval t0)
		If Not IsNumeric(t0) Then Exit function
		getadminurl=eycms.db.dbloadone("adminurl","ey_model","modelid="&t0&"")
	end Function

	function getpostion_admin(byval t0,byval t1)
		getpostion_admin=""
		Dim pstr:pstr=t0
		If InStr(pstr,"[")>0 Then
			pstr=Replace(pstr,"][",",")
			pstr=Replace(pstr,"]","")
			pstr=Replace(pstr,"[","")
		End if
		dim arr:arr=split(pstr,",")
		dim i
		for i=ubound(arr) to 0 step -1
			getpostion_admin=t1&"<a href='?classid="&arr(i)&"'>"&eycms.getcatename(arr(i))&"</a>"&getpostion_admin
		next
	end Function
	
	islogin
	dim act:act=lcase(eycms.fget("act",0))
	dim rootid,sonids,parents
	dim sqlwhere,statitle,nattitle,orderby,ordtitle,wherekey
	if act<>"left" and act<>"list" Then
		sqlwhere="id>0"
		dim classid:classid=eycms.getint(eycms.fget("classid",0),0)
		dim bclassid:bclassid=eycms.getint(eycms.fget("bclassid",0),0)
		If bclassid=0 Then bclassid=classid
		dim catedata,catename,modeid,adminurl,tablename		
		catedata=eycms.getclassdb(classid)
		if not isarray(catedata) then
			eycms.echo "&#26639;&#30446;&#19981;&#23384;&#22312;&#25110;&#24050;&#34987;&#21024;&#38500;"
			eycms.db.dbclose
			eycms.die
		end if
		catename=catedata(1)
		modeid=catedata(10)
		adminurl=catedata(14)
		tablename=catedata(12)
		parents=eycms.get_parentid(classid)
		rootid=split(parents,"]")(0)
		rootid=replace(rootid,"[","")
		rootid=CInt(rootid)
	end if
	dim sta,nat,order,keyword,data
	sta=eycms.getint(eycms.fget("sta",0),0)
	nat=eycms.getint(eycms.fget("nat",0),0)
	order=eycms.getint(eycms.fget("order",0),0)
	keyword=eycms.enhtml(eycms.fget("keyword",1))
	If keyword="请输入关键字" Then keyword=""
	select case sta
		case "1":sqlwhere=sqlwhere&" and ey_content.islock=1":statitle="状态:已发"
		case "2":sqlwhere=sqlwhere&" and ey_content.islock=0":statitle="状态:草稿"
		case else:statitle="按状态↓":sqlwhere=sqlwhere&" and (ey_content.islock=1 or ey_content.islock=0)"
	end select
	select case nat
		case "1":sqlwhere=sqlwhere&" and ispic=1":nattitle="性质:有缩略图"
		case "2":sqlwhere=sqlwhere&" and ispic=0":nattitle="性质:无缩略图"
		case "3":sqlwhere=sqlwhere&" and isnice=1":nattitle="性质:已推荐"
		case "4":sqlwhere=sqlwhere&" and isnice=0":nattitle="性质:未推荐"
		case "5":sqlwhere=sqlwhere&" and ontop=1":nattitle="性质:已置顶"
		case "6":sqlwhere=sqlwhere&" and ontop=0":nattitle="性质:未置顶"
		case "7":sqlwhere=sqlwhere&" and iscomment=1":nattitle="性质:允许评论"
		case "8":sqlwhere=sqlwhere&" and iscomment=0":nattitle="性质:禁止评论"
		case "9":sqlwhere=sqlwhere&" and isurl=1":nattitle="性质:外部链接"
		case else:nattitle="按性质↓"
	end select
	select case order
		case "1":orderby="hits desc,id desc":ordtitle="状态:访问人气↑"
		case "2":orderby="hits,id":ordtitle="状态:访问人气↓"
		case "3":orderby="createdate desc,id desc":ordtitle="状态:发布日期↑"
		case "4":orderby="createdate,id":ordtitle="状态:发布日期↓"
		case "5":orderby="comments desc,id desc":ordtitle="状态:评论数量↑"
		case "6":orderby="comments,id":ordtitle="状态:评论数量↓"
		case else:orderby="ontop desc,id desc":ordtitle="按排序↓"
	end select
	if eycms.strlen(keyword)>0 then
		if datatype then
			wherekey=" and instr(lcase(title),lcase('"&keyword&"'))>0 "
		else
			wherekey=" and title like '%"&keyword&"%'"
		end if
	end if
	select case act
		case "list"
			dim cid:cid=eycms.getint(eycms.fget("classid",0),0)
			if cid<>0 then
				sqlwhere=sqlwhere&" and classid="&cid&""
			end if
			if admingroupid<>0 then	
				sqlwhere=sqlwhere&" and classid in("&admin_cate_array&")"
			end if
			load theme_content_list
		case "gettags":get_tags
		case "add":checkcateaction(1):load theme_contentadd
		case "adddb":checkcateaction(1):adddb
		case "edit":checkcateaction(2):dim id:id=eycms.getint(eycms.fget("id",0),0):load theme_contentedit
		case "editdb":checkcateaction(2):editdb
		case "del":checkcateaction(3):deldb
		case "delall":checkcateaction(3):delall
		case "doset":checkcateaction(5):doset
		case "move":checkcateaction(4):movedb
		case "movecate":checkcateaction(4):movecate
		case "redo":checkcateaction(5):redo
		case "redoall":checkcateaction(5):redoall
		case "clearall":checkcateaction(5):clearall
		case "delclear":checkcateaction(5):delclear
		case "getdate":getdate
		case "likedb":likedb
		case "tree":dim get_tree:treedb
		case else
			checkcatelever(classid)
			sqlwhere=Replace(sqlwhere,"ey_content.","")
			sonids=eycms.get_sonid_one(classid)
			parents=eycms.get_parentid(classid)
			If InStr(sonids,",")>0 Then
				sqlwhere=sqlwhere&" and left(parentid,"&Len(parents)&")='"&parents&"'"
				if admingroupid<>0 Then    '普通管理员
					sqlwhere=sqlwhere&" and classid in("&admin_cate_array&")"
				end if
			Else
				sqlwhere=sqlwhere&" and classid="&classid
			End If
			rootid=split(parents,"]")(0)
			rootid=replace(rootid,"[","")
			rootid=CInt(rootid)

			load theme_contentlist
	end select
	eycms.db.dbclose
%>
