<!--#include file="../../lib/base.asp"-->
<!--#include file="../../theme/admin_leo/config.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<%
''' EYCMS 附件管理工具
''' ==================================================================
	eycms.stophack
	'注释：插件是否安装
	is_plug_install "eycms.plug.attachment"
	
	'注释：管理权限检查
	is_plug_login
	
	'注释：定义插件模板路径
	dim plug_theme
	plug_theme="module/plug_attachment/list.html"
	
	'注释：删除附件
	sub deldb()
		dim tpath,tsite
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		dim data:data=eycms.db.dbload(1,"fullname","ey_attachment","id="&id&"","")
		if ubound(data)>=0 then
			'注释：删除此文件
			tpath=Split(data(0,0),"/upfile")(0)
			tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
			If InStr(tpath,"/site/")>0 Then      '仅删除本站点上传的图片
				data(0,0)=replace(data(0,0),"/"&tsite&"/","/"&site_root&"/")
			Else
				data(0,0)=replace(data(0,0),"/"&tsite&"/","/"&theme_root&"/")
			End if
			eycms.delfile data(0,0)
			eycms.db.dbdel "ey_attachment","id="&id
		end if
		eycms.echo "1"
	end sub
	
	'注释：批量删除附件
	sub delsome()
		dim id:id=eycms.enhtml(eycms.fget("id",0))
		dim idarr:idarr=split(id,",")
		dim data,tpath,tsite
		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
				else
					data=eycms.db.dbload(1,"fullname","ey_attachment","id="&idarr(i)&"","")
					if ubound(data)>=0 then
						tpath=Split(data(0,0),"/upfile")(0)
						tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
						If InStr(tpath,"/site/")>0 Then      '仅删除本站点上传的图片
							data(0,0)=replace(data(0,0),"/"&tsite&"/","/"&site_root&"/")
						Else
							data(0,0)=replace(data(0,0),"/"&tsite&"/","/"&theme_root&"/")
						End if
						eycms.delfile data(0,0)   '注释：删除此文件
						eycms.db.dbdel "ey_attachment","id="&idarr(i)
					end if
				end if
			next
			eycms.echo "1"
		end if
	end sub
	
	'注释：清空无效文件
	sub clearall()
		dim data,i,tpath,tsite
		data=eycms.db.dbload("","id,fullname","ey_attachment","cid<=0","")
		dim j:j=0
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				tpath=Split(data(1,i),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				If InStr(tpath,"/site/")>0 Then      '仅删除本站点上传的图片
					data(1,i)=replace(data(1,i),"/"&tsite&"/","/"&site_root&"/")
				Else
					data(1,i)=replace(data(1,i),"/"&tsite&"/","/"&theme_root&"/")
				End if
				eycms.delfile data(1,i)   '注释：删除此文件
				eycms.db.dbdel "ey_attachment","cid<=0 and id="&data(0,i)&""
				j=j+1
			next
		end if
		eycms.echo "1本次共清理"&j&"个无效附件"
	end sub
	
	'注释：自动修复图片路径
	sub replaceall()
		err.clear
		on error resume Next
		dim shop_lock:shop_lock=eycms.db.dbloadone("islock","ey_model","tablename='ey_model_pro'")
		dim rs,data,i,tpath,tsite,otheme,temp
		data=eycms.db.dbload("","id,fullname,filepath","ey_attachment","id>0","")
		dim j:j=0
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				tpath=Split(data(1,i),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				If InStr(tpath,"/site/")>0 Then      '仅删除本站点上传的图片
					data(1,i)=replace(data(1,i),"/"&tsite&"/","/"&site_root&"/")
					data(2,i)=replace(data(2,i),"/"&tsite&"/","/"&site_root&"/")
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						data(1,i)=replace(data(1,i),Split(data(1,i),"site/")(0)&"site/",webroot&"site/")
						data(2,i)=replace(data(2,i),Split(data(2,i),"site/")(0)&"site/",webroot&"site/")
					End if
					If tsite<>site_root Then 
						j=j+1
					End if
				Else
					data(1,i)=replace(data(1,i),"/"&tsite&"/","/"&theme_root&"/")
					data(2,i)=replace(data(2,i),"/"&tsite&"/","/"&theme_root&"/")
					If tsite<>theme_root Then 
						otheme=tsite
						j=j+1
					End if
				End if
				eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("fullname",data(1,i),255,1),array("filepath",data(2,i),255,1))
			next
		end If
		
		If shop_lock=1 then
			set rs=server.createobject("adodb.recordset")
			rs.open "select piclist,content from ey_model_pro",eycms.db.conn,1,3
			do while not rs.eof
				If InStr(rs(0),"/upfile")>0 then
					tpath=Split(rs(0),"/upfile")(0)
					tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
					temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
					temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
					If InStr(tpath,"/site/")>0 Then
						tpath=Replace(tpath,"array(""","")
						If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
							temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
						End If
					End If
					temp=Replace(temp,"array(""","")
					rs(0)="array("""&replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
				End If
				
				If InStr(rs(1),"/upfile")>0 then
					tpath=Split(rs(1),"/upfile")(0)
					tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
					temp=replace(rs(1),"/site/"&tsite&"/","/site/"&site_root&"/")
					temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
					If InStr(tpath,"/site/")>0 Then
						If InStr(tpath,"src=")>0 Then tpath=Split(tpath,"src=")(UBound(Split(tpath,"src=")))
						If InStr(tpath,"=")>0 Then tpath=Split(tpath,"=")(UBound(Split(tpath,"=")))
						tpath=Replace(tpath,"""","")
						tpath=Replace(tpath,"'","")
						tpath=Replace(tpath," ","")
						If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
							temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
						End If
					End if
					rs(1)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
				End If
				
				rs.update
				rs.movenext
			loop
			rs.close
			set rs=Nothing
		End if

		set rs=server.createobject("adodb.recordset")
		rs.open "select piclist,content from ey_model_photo",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					tpath=Replace(tpath,"array(""","")
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
					End If
				End If
				temp=Replace(temp,"array(""","")
				rs(0)="array("""&replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			
			If InStr(rs(1),"/upfile")>0 then
				tpath=Split(rs(1),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(1),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If InStr(tpath,"src=")>0 Then tpath=Split(tpath,"src=")(UBound(Split(tpath,"src=")))
					If InStr(tpath,"=")>0 Then tpath=Split(tpath,"=")(UBound(Split(tpath,"=")))
					tpath=Replace(tpath,"""","")
					tpath=Replace(tpath,"'","")
					tpath=Replace(tpath," ","")
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(1)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select content from ey_model_news",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If InStr(tpath,"src=")>0 Then tpath=Split(tpath,"src=")(UBound(Split(tpath,"src=")))
					If InStr(tpath,"=")>0 Then tpath=Split(tpath,"=")(UBound(Split(tpath,"=")))
					tpath=Replace(tpath,"""","")
					tpath=Replace(tpath,"'","")
					tpath=Replace(tpath," ","")
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select content from ey_model_down",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If InStr(tpath,"src=")>0 Then tpath=Split(tpath,"src=")(UBound(Split(tpath,"src=")))
					If InStr(tpath,"=")>0 Then tpath=Split(tpath,"=")(UBound(Split(tpath,"=")))
					tpath=Replace(tpath,"""","")
					tpath=Replace(tpath,"'","")
					tpath=Replace(tpath," ","")
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select content from ey_model_video",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If InStr(tpath,"src=")>0 Then tpath=Split(tpath,"src=")(UBound(Split(tpath,"src=")))
					If InStr(tpath,"=")>0 Then tpath=Split(tpath,"=")(UBound(Split(tpath,"=")))
					tpath=Replace(tpath,"""","")
					tpath=Replace(tpath,"'","")
					tpath=Replace(tpath," ","")
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select content from ey_model_page",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If InStr(tpath,"src=")>0 Then tpath=Split(tpath,"src=")(UBound(Split(tpath,"src=")))
					If InStr(tpath,"=")>0 Then tpath=Split(tpath,"=")(UBound(Split(tpath,"=")))
					tpath=Replace(tpath,"""","")
					tpath=Replace(tpath,"'","")
					tpath=Replace(tpath," ","")
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select pic from ey_content",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(temp,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select catepic from ey_category",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(temp,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select fileurl from ey_expand_ad",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(temp,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		set rs=server.createobject("adodb.recordset")
		rs.open "select weblogo from ey_expand_link",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(temp,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		If eycms.db.dbcount("ey_admin_menu","title='微信'")>0 then
			set rs=server.createobject("adodb.recordset")
			rs.open "select piclist from wx_master",eycms.db.conn,1,3
			do while not rs.eof
				If InStr(rs(0),"/upfile")>0 then
					tpath=Split(rs(0),"/upfile")(0)
					tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
					temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
					temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
					If InStr(tpath,"/site/")>0 Then
						If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
							temp=replace(temp,Split(temp,"site/")(0)&"site/",webroot&"site/")
						End If
					End if
					rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
				End If
				rs.update
				rs.movenext
			loop
			rs.close
			set rs=Nothing

			set rs=server.createobject("adodb.recordset")
			rs.open "select piclist from wx_master_temp",eycms.db.conn,1,3
			do while not rs.eof
				If InStr(rs(0),"/upfile")>0 then
					tpath=Split(rs(0),"/upfile")(0)
					tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
					temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
					temp=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
					If InStr(tpath,"/site/")>0 Then
						If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
							temp=replace(temp,Split(temp,"site/")(0)&"site/",webroot&"site/")
						End If
					End if
					rs(0)=replace(temp,"/theme/"&otheme&"/","/theme/"&theme_root&"/")
				End If
				rs.update
				rs.movenext
			loop
			rs.close
			set rs=Nothing
		end if

		set rs=server.createobject("adodb.recordset")
		rs.open "select setvalue from ey_config where left(setkey,3)='my_' and left(setvalue,6)='/site/'",eycms.db.conn,1,3
		do while not rs.eof
			If InStr(rs(0),"/upfile")>0 then
				tpath=Split(rs(0),"/upfile")(0)
				tsite=Split(tpath,"/")(UBound(Split(tpath,"/")))
				temp=replace(rs(0),"/site/"&tsite&"/","/site/"&site_root&"/")
				If InStr(tpath,"/site/")>0 Then
					If left(tpath,Len(webroot&"site/"))<>webroot&"site/" Then
						temp=replace(temp,Split(tpath,"site/")(0)&"site/",webroot&"site/")
					End If
				End if
				rs(0)=replace(temp,"/site/"&theme_root&"/","/site/"&site_root&"/")
			End If
			rs.update
			rs.movenext
		loop
		rs.close
		set rs=Nothing

		eycms.db.dbupdate "ey_config","setname='eycms.upload' and setkey='upfile'",array(array("setvalue","site/"&site_root&"/upfile",50,1))

		eycms.echo "1本次共自动修复"&j&"个附件地址"
		eycms.clearcache
		if err then
			eycms.errlog "函数：replaceall<br>详情："&err.description,0
			eycms.echo "0发生错误："&err.description
			err.clear
		End if
	end Sub

	'注释：自动关联附件
	sub autoset()
		err.clear
		on error resume Next
		dim shop_lock:shop_lock=eycms.db.dbloadone("islock","ey_model","tablename='ey_model_pro'")
		dim data,i,cid,islock
		dim j:j=0
		data=eycms.db.dbload("","id,fullname","ey_attachment","classid>0 and (cid<=0 or zt<0)","")    '模型内容表
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				cid=""
				cid=eycms.db.dbloadone("id","ey_content","pic='"&data(1,i)&"'")
				If cid="" Then cid=eycms.db.dbloadone("cid","ey_model_photo","piclist like '%"&data(1,i)&"%' or content like '%"&data(1,i)&"%'")
				If cid="" Then cid=eycms.db.dbloadone("cid","ey_model_news","content like '%"&data(1,i)&"%'")
				If cid="" Then cid=eycms.db.dbloadone("cid","ey_model_down","content like '%"&data(1,i)&"%'")
				If shop_lock=1 then
					If cid="" Then cid=eycms.db.dbloadone("cid","ey_model_pro","piclist like '%"&data(1,i)&"%' or content like '%"&data(1,i)&"%'")
					If cid="" Then cid=eycms.db.dbloadone("cid","ey_model_gift","content like '%"&data(1,i)&"%'")
				End if
				If cid="" Then cid=eycms.db.dbloadone("cid","ey_model_video","content like '%"&data(1,i)&"%'")
				If cid="" Then cid=eycms.db.dbloadone("classid","ey_model_page","content like '%"&data(1,i)&"%'")
				If cid="" Then cid=eycms.db.dbloadone("cateid","ey_category","catepic like '%"&data(1,i)&"%'")
				If Len(cid)>0 then
					islock=eycms.db.dbloadone("islock","ey_content","id="&cid)
					If islock>-3 Then 
						eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",cid,0,0),array("zt",0,0,0))
						j=j+1
					End If
				Else
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",0,0,0))
					j=j+1
				End If
			next
		end If

		data=eycms.db.dbload("","id,fullname","ey_attachment","classid=3","")    '栏目分类表
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				cid=""
				cid=eycms.db.dbloadone("cateid","ey_category","catepic='"&data(1,i)&"'")
				If Len(cid)>0 then
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",cid,0,0),array("zt",0,0,0))
				Else
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",0,0,0))
					j=j+1
				End If
			next
		end If

		data=eycms.db.dbload("","id,fullname","ey_attachment","classid=5","")    '友情链接表
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				cid=""
				cid=eycms.db.dbloadone("id","ey_expand_link","weblogo='"&data(1,i)&"'")
				If Len(cid)>0 then
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",cid,0,0),array("zt",0,0,0))
				Else
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",0,0,0))
					j=j+1
				End If
			next
		end If

		data=eycms.db.dbload("","id,fullname","ey_attachment","classid=6","")    '广告表
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				cid=""
				cid=eycms.db.dbloadone("id","ey_expand_ad","fileurl='"&data(1,i)&"'")
				If Len(cid)>0 then
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",cid,0,0),array("zt",0,0,0))
				Else
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",0,0,0))
					j=j+1
				End If
			next
		end If

		data=eycms.db.dbload("","id,fullname","ey_attachment","classid=7","")    '微信素材表
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				cid=""
				cid=eycms.db.dbloadone("id","wx_master","piclist like '"&data(1,i)&"'")
				If Len(cid)>0 then
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",cid,0,0),array("zt",0,0,0))
				Else
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",0,0,0))
					j=j+1
				End If
			next
		end If

		data=eycms.db.dbload("","id,fullname","ey_attachment","classid=8","")    '微信素材模板表
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				cid=""
				cid=eycms.db.dbloadone("id","wx_master_temp","piclist like '"&data(1,i)&"'")
				If Len(cid)>0 then
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",cid,0,0),array("zt",0,0,0))
				Else
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",0,0,0))
					j=j+1
				End If
			next
		end If

		data=eycms.db.dbload("","id,fullname,cid","ey_attachment","classid=0","")    '自定义参数表
		if ubound(data)>=0 then
			for i=0 to ubound(data,2)
				cid=""
				cid=eycms.db.dbloadone("setkey","ey_config","setvalue like '"&data(1,i)&"'")
				If Len(cid)=0 Then
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",0,0,0))
					j=j+1
				Else
					eycms.db.dbupdate "ey_attachment","id="&data(0,i),array(array("cid",abs(data(2,i)),0,0),array("zt",0,0,0))
				End If
			next
		end If

		eycms.echo "1本次共关联"&j&"个附件"
		if err then
			eycms.errlog "函数：autoset<br>详情："&err.description,0
			eycms.echo "0发生错误："&err.description
			err.clear
		End if
	end Sub

	dim act:act=lcase(eycms.fget("act",0))
	dim sqlwhere,nattitle,nat
	nat=eycms.getint(eycms.fget("nat",0),0)
	select case act
		case "del":deldb
		case "delsome":delsome
		case "clearall":clearall
		case "replaceall":replaceall
		case "autoset":autoset
		case else
			select case nat
				case "1":sqlwhere=" and ispic=1":nattitle="性质:图片"
				case "2":sqlwhere=" and fileext='swf'":nattitle="性质:Flash"
				case "3":sqlwhere=" and (fileext='rar' or fileext='zip' or fileext='7z')":nattitle="性质:压缩文件"
				case "4":sqlwhere=" and not(ispic=1 or fileext='swf' or fileext='rar' or fileext='zip' or fileext='7z')":nattitle="性质:其他类型"
				case "5":sqlwhere=" and cid<=0":nattitle="性质:无效文件"
				case else:nattitle="按性质↓"
			end select
			load plug_theme
	end select
	eycms.db.dbclose
	
	function getsrc(byval t0)
		t0=lcase(t0)
		if t0="docx" then t0="doc"
		if t0="xlsx" then t0="xls"
		if t0="pptx" then t0="ppt"
		select case t0
		case "htm","tml"
			getsrc="html"
		case "swf","pdf","psd","ppt","xls","doc","flv"
			getsrc=t0
		case "rar","zip","7z"
			getsrc="rar"
		case "bmp","jpg","gif","png":
			getsrc="bmp"
		case else
			getsrc="txt"
		end select
	end function
%>
