<!--#include file="base.asp"-->
<%
''' EYCMS 推荐位管理
''' ==================================================================

	sub adddb()
		dim t0,t1,t2,t3
		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))
		if eycms.strlen(t0)=0 then eycms.ajaxjson "所属模型不能为空",0:exit sub
		if eycms.strlen(t1)=0 then eycms.ajaxjson "推荐位id不能为空",0:exit sub
		if eycms.strlen(t2)=0 then eycms.ajaxjson "推荐位名称不能为空",0:exit sub
	
		dim data:data=array(array("modeid",t0,5,0),array("tag",t1,10,0),array("rname",t2,255,1),array("remark",t3,255,1))
		if eycms.db.dbnew("ey_expand_recommend",data,"tag="&t1)=0 then
			eycms.ajaxjson "0推荐位id已存在，请换个试试"
		else
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	sub editdb()
		dim t0,t1,t2,t3
		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))
		if eycms.strlen(t0)=0 then eycms.ajaxjson "所属模型不能为空",0:exit sub
		if eycms.strlen(t1)=0 then eycms.ajaxjson "推荐位id不能为空",0:exit sub
		if eycms.strlen(t2)=0 then eycms.ajaxjson "推荐位名称不能为空",0:exit sub

		dim data,id
		id=eycms.getint(eycms.fget("id",0),0)
		data=array(array("modeid",t0,5,0),array("tag",t1,10,0),array("rname",t2,255,1),array("remark",t3,255,1))
		if eycms.db.dbupdate("ey_expand_recommend","rid="&id&"",data)=1 then
			eycms.ajaxjson "保存成功",1
		end if
	end sub

	function getnewid()
		getnewid=eycms.db.insertid("rid","ey_expand_recommend")
		if eycms.strlen(getnewid)=0 then getnewid=0
		getnewid=getnewid+1
	end function

	sub deldb()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		eycms.db.dbdel "ey_expand_recommend","rid="&id
		eycms.echo "1"
	end sub
	
	sub delsome()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			eycms.echo "0至少选择一条信息"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0参数："&idarr(i)&"不正确，请确认后再操作"
					exit sub
				else
					eycms.db.dbdel "ey_expand_recommend","rid="&idarr(i)&""
				end if
			next
			eycms.echo "1"
		end if
	end sub
	
	sub infodel()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		dim rscomid:rscomid=eycms.db.dbloadone("rscomid","ey_expand_recommend","rid="&rid&"")
		rscomid=","&rscomid&","
		rscomid=replace(rscomid,","&id&",",",")
		if left(rscomid,1)="," then rscomid=right(rscomid,len(rscomid)-1)
		if right(rscomid,1)="," then rscomid=left(rscomid,len(rscomid)-1)
		eycms.db.dbupdate "ey_expand_recommend","rid="&rid&"",array(array("rscomid",rscomid,255,1))
		eycms.echo "1"
	end sub
	
	sub delinfosome()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			eycms.echo "0至少选择一条信息"
		else
			dim rscomid:rscomid=eycms.db.dbloadone("rscomid","ey_expand_recommend","rid="&rid&"")
			rscomid=","&rscomid&","
			dim i,j
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0参数："&idarr(i)&"不正确，请确认后再操作"
					exit sub
				else
					rscomid=replace(rscomid,","&idarr(i)&",",",")
				end if
			next
			if left(rscomid,1)="," then rscomid=right(rscomid,len(rscomid)-1)
			if right(rscomid,1)="," then rscomid=left(rscomid,len(rscomid)-1)
			eycms.db.dbupdate "ey_expand_recommend","rid="&rid&"",array(array("rscomid",rscomid,255,1))
			eycms.echo "1"
		end if
	end sub
	
	sub addinfodb()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		if id="" then eycms.echo "0至少选择一条内容":exit sub
		dim rscomid:rscomid=eycms.db.dbloadone("rscomid","ey_expand_recommend","rid="&rid&"")
		if eycms.strlen(rscomid)=0 then 
			rscomid=id
		else
			rscomid=rscomid & "," & id
		end if
		dim idarr:idarr=split(rscomid,",")
		if ubound(idarr)<0 then
			eycms.echo "0至少选择一条信息":exit sub
		else
			rscomid=""
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					eycms.echo "0参数："&idarr(i)&"不正确，请确认后再操作"
					exit sub
				else
					if i=0 then
						rscomid=idarr(i)
					else
						rscomid=rscomid & "," & idarr(i)
					end if
				end if
				if i>28 then exit for
			next
		end if
		eycms.db.dbupdate "ey_expand_recommend","rid="&rid&"",array(array("rscomid",rscomid,255,1))
		eycms.echo "1"
	end sub

	function getinfonum(t0)
		if eycms.strlen(t0)=0 then getinfonum=0:exit function
		if t0=0 then getinfonum=0:exit function
		if instr(t0,",") then
			getinfonum=ubound(split(t0,","))+1
		else
			getinfonum=1
		end if
	end function

	function get_myclasstree(byval t0)
		dim data,modeid
		modeid=eycms.db.dbloadone("modeid","ey_expand_recommend","rid="&t0&"")
		data=eycms.db.dbload("","cateid,catename,followid","view_category","modeid="&modeid&"","ordnum,cateid")
		dim i
		if isarray(data) then
			if ubound(data)>=0 then
				for i=0 to ubound(data,2)
					get_myclasstree=get_myclasstree&""&eycms.iif(i=0,"",",")&"{"
					get_myclasstree=get_myclasstree&"id:"&data(0,i)&""
					get_myclasstree=get_myclasstree&",pId:"&data(2,i)&""
					get_myclasstree=get_myclasstree&",name:"""&data(1,i)&""""
					get_myclasstree=get_myclasstree&",open:true}"
				next
			end if
		end If
	End Function

	islogin
	checkpagelever 73
	dim act:act=lcase(eycms.fget("act",0))
	dim sqlwhere,nattitle,nat,ordtitle,ord
	dim rid:rid=eycms.getint(eycms.fget("rid",0),0)
	if rid>0 then
		dim rname:rname=eycms.db.dbloadone("rname","ey_expand_recommend","rid="&rid&"")
		dim modeid:modeid=eycms.db.dbloadone("modeid","ey_expand_recommend","rid="&rid&"")
	end if
	select case act
		case "add":load eval("theme_expand_recommend_"&act)
		case "adddb":adddb
		case "edit"
			dim datadb,id
			id=eycms.getint(eycms.fget("id",0),0)
			datadb=eycms.db.dbload("","modeid,tag,rname,remark","ey_expand_recommend","rid="&id&"","")
			load eval("theme_expand_recommend_"&act)
		case "editdb":editdb
		case "del":deldb
		case "delsome":delsome
		case "ilist":load eval("theme_expand_recommend_"&act)
		case "addi"
			dim classid,catedata,catename
			classid=eycms.getint(eycms.fget("classid",0),0)
			catedata=eycms.getclassdb(classid)
			catename=catedata(1)
			dim orderby,wherekey
			dim order,keyword,data
			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=""
			dim rscomid:rscomid=eycms.db.dbloadone("rscomid","ey_expand_recommend","rid="&rid&"")
			if eycms.strlen(rscomid)=0 then rscomid=0
 			sqlwhere="islock=1 and modeid="&modeid&" and not id in ("&eycms.getrecommend(rid)&")"
			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
			if classid>0 then
				dim parents,sonids
				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
			end if
			load eval("theme_expand_recommend_"&act)
		case "idel":infodel
		case "delisome":delinfosome
		case "addidb":addinfodb
		case else
			load theme_expand_recommend
	end select
	eycms.db.dbclose
%>
