<!--#include file="base.asp"-->
<%
''' EYCMS 关键字回复
''' ==================================================================

	sub adddb()
		dim t0,t1,t2,t3,t4,t5,t6
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.getint(eycms.fpost("t1",0),0)
		t2=(eycms.fpost("t2",0))
		t3=eycms.getint(eycms.fpost("t3",0),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)
		if eycms.strlen(t0)=0 then eycms.ajaxjson "关键字名称不能为空",0:exit sub
		if t1=2 then
			if t3=0 then
				eycms.ajaxjson "请选择素材",0	
				exit sub
			end if
			dim data:data=eycms.db.dbload(1,"id","wx_master_class","id="&t3&"","")
			if ubound(data)<0 then
				eycms.ajaxjson "素材选择错误",0	
				exit sub
			end if
		end if

		data=array(array("keyword",t0,255),array("types",t1,10),array("reply",t2,0),array("replyid",t3,10),array("matchtype",t4,10),array("ordnum",t5,10),array("islock",t6,10))
		if eycms.db.dbnew("wx_key",data,"keyword='"&t0&"'")=0 then
			eycms.ajaxjson "关键字名称已存在，请更换",0
		else
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	sub editdb()
		dim t0,t1,t2,t3,t4,t5,t6
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.getint(eycms.fpost("t1",0),0)
		t2=(eycms.fpost("t2",0))
		t3=eycms.getint(eycms.fpost("t3",0),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)
		if eycms.strlen(t0)=0 then eycms.ajaxjson "关键字名称不能为空",0:exit sub
		if t1=2 then
			if t3=0 then
				eycms.ajaxjson "请选择素材",0	
				exit sub
			end if
			dim data:data=eycms.db.dbload(1,"id","wx_master_class","id="&t3&"","")
			if ubound(data)<0 then
				eycms.ajaxjson "素材选择错误",0	
				exit sub
			end if
		end if
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		data=array(array("keyword",t0,255,1),array("types",t1,10,0),array("reply",t2,0,1),array("replyid",t3,10,0),array("matchtype",t4,10,0),array("ordnum",t5,10,0),array("islock",t6,10,0))
		if eycms.db.dbupdate("wx_key","id="&id&"",data)=1 then
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	sub deldb()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		eycms.db.dbdel "wx_key","id="&id
		eycms.echo "1"
	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=0
				case "nolock":filed="islock":result=1
				case else:eycms.echo "0&#21442;&#25968;&#38169;&#35823;":exit sub
			end select
			eycms.db.dbupdate "wx_key","id in("&id&")",array(array(filed,result,2,0))
			eycms.echo "1"
		end if
	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&#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
				else
					eycms.db.dbdel "wx_key","id="&idarr(i)&""
				end if
			next
			eycms.echo "1"
		end if
	end sub
	
	sub orderdb()
		dim t0,t1,t2,t3,i
		t0=eycms.enhtml(eycms.fpost("ordnum",0))
		t1=eycms.enhtml(eycms.fpost("cid",0))
		t2=split(t0,", ")
		t3=split(t1,", ")
		if ubound(t2)-ubound(t3)<>0 then eycms.ajaxjson "0&#21442;&#25968;&#38169;&#35823;",0:exit sub
		for i=0 to ubound(t2)
			if eycms.isnum(t2(i)) then
				eycms.db.dbupdate "wx_key","id="&t3(i)&"",array(array("ordnum",t2(i),10,0,0))
			end if
		next
		eycms.ajaxjson "保存成功",1
	end sub
	
	islogin
	dim act:act=lcase(eycms.fget("act",0))
	dim sqlwhere,nattitle,nat
	nat=eycms.getint(eycms.fget("nat",0),0)
	select case act
		case "add":load theme_key_add
		case "adddb":adddb
		case "edit"
			dim id:id=eycms.getint(eycms.fget("id",0),0)
			dim rsshow
			set rsshow=eycms.db.exedb("select top 1 * from wx_key where id="&id&"")
			if rsshow.eof then
				eycms.echo "参数错误":eycms.die
			end if
			load theme_key_edit
		case "editdb":editdb
		case "del":deldb
		case "doset":doset
		case "delsome":delsome
		case "order":orderdb
		case else
			select case nat
				case "1":sqlwhere=" and islock=0":nattitle="性质:未审"
				case "2":sqlwhere=" and islock=1":nattitle="性质:已审"
				case else:nattitle="按性质↓"
			end select
			load theme_key
	end select
	eycms.db.dbclose
%>