<!--#include file="../../lib/base.asp"-->
<!--#include file="../../theme/admin_leo/config.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<%
''' EYCMS 内容替换插件
''' ==================================================================

	'注释：插件是否安装
	is_plug_install "eycms.plug.replace"
	
	'注释：管理权限检查
	is_plug_login
	
	'注释：定义插件模板路径
	dim plug_theme
	plug_theme="module/plug_replace/list.html"
	
	'注释：获取表中的字段
	sub loaddb()
		dim t0:t0=eycms.enhtml(eycms.fget("t0",0))
		dim str01,str02,str03
		str01="<select name=""t1"" class=""ip"">"&vbcrlf&"<option value="""">请选择</option>"&vbcrlf
		str03="</select>"
		dim rsf
		set rsf=eycms.db.conn.openschema(4)
		do until rsf.eof or rsf("table_name")=t0
		rsf.movenext
		loop
		do until rsf.eof or rsf("table_name")<>t0
			str02=str02&"<option value="""&rsf("column_Name")&""">"&rsf("column_Name")&"</option>"&vbcrlf
		rsf.movenext
		loop
		rsf.close
		set rsf=nothing
		eycms.echo str01&str02&str03
	end sub
	
	sub dodb()
		dim t0,t1,t2,t3,t4
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.getint(eycms.fpost("t2",0),0)
		t3=eycms.enhtml(eycms.fpost("t3",0))
		t4=eycms.enhtml(eycms.fpost("t4",0))
		
		dim rs,i
		dim topstr:topstr=""
		if t2<>0 then
			topstr="top "&t2
		end if
		on error resume next
		set rs=server.createobject("adodb.recordset")
		rs.open "select "&topstr&" "&t1&" from "&t0&"",eycms.db.conn,1,3
		if rs.eof then
			eycms.echo "没有信息可替换"
			exit sub
		end if
		i=0
		do while not rs.eof
			if instr(rs(0),t3)>0 then
				rs(0)=replace(rs(0),t3,t4)
				i=i+1
				if t2<>0 then
					if i>=t2 then
						eycms.echo "替换完毕，总计替换了<span>"&i&"</span>条<br>"
						eycms.echo "<script>window.scroll(0,99999)</script><br>"
						response.flush()
						exit sub
					end if
				end if
				eycms.echo "正在替换第<span>"&i&"</span>条<br>"
				eycms.echo "<script>window.scroll(0,99999)</script><br>"
				response.flush()
				rs.update
			end if
		rs.movenext
		loop
		rs.close
		set rs=nothing
		eycms.echo "替换完毕，总计替换了<span>"&i&"</span>条<br>"
		eycms.echo "<script>window.scroll(0,99999)</script><br>"
		response.flush()
		if err then
			eycms.echo "发生错误，错误内容为：<span>"&err.description&"</span><br>"
			eycms.echo "<script>window.scroll(0,99999)</script><br>"
		end if
	end sub

	dim act:act=lcase(eycms.fget("act",0))
	select case act
		case "load":loaddb
		case "do":dodb
		case else:load plug_theme
	end select
	eycms.db.dbclose
%>
