<!--#include file="../../../inc/cms_admin.asp" -->
<%
dim act,filename,pctempath,waptempath,filepath,filetext
dim fileListArray,i,fileAttr,folderListArray,folderAttr,parentPath,newname
pctempath=sitePath&uploadpath
act=getForm("act","get")
filename=getForm("filename","get")
filepath=getForm("filepath","get")
newname=getForm("newname","get")
parentPath=getform("parentPath","both")
if isnul(parentPath) then parentPath=sitePath&uploadpath
select case act
	case "add" : addFile
	case "upload": upload
	case "rename" : rename
	case "edit" : edithtmlFile
	case "del" : delhtmlFile	
	case "select" : selectStyle	
	case "Crefolder"	: CreateFolder parentPath&newname
	case "delfolder"	: delfolder parentPath		:	echo "文件夹删除成功"
	case "edithtmlfilepath" : editHtmlFilePath
	case "setallsmall" : setallsmall
	case "editsystem" : editsystem
	case "clearall" : NewFolder sitepath&uploadpath&"backups/"&DateFormat(now,"yymmdd")&"/" : clearall(sitepath&uploadpath)	:	 layermsggo  "全部冗余文件已经移动完成，请检查网站是否正常后可删除upload/backups",sitepath&adminpath&"cms_Content/uploads/uploads_list.asp"
end select


sub clearall(folder)
	dim objFolder,objSubFolder,objSubFolders	
	call clearfile(folder)
	set objFolder=fso.GetFolder(setfolder(folder))
	set objSubFolders=objFolder.Subfolders
	for each objSubFolder in objSubFolders
	  With objSubFolder
		call clearfile(folder&.name&"/")
		clearall(folder&.name&"/")
	   End With
	  next	 
end sub

sub clearfile(selfpath)
	dim filePath,objFiles,objFolder,objFile
	on  error resume next 
	if ifstrin(selfpath,"backups") then exit sub
	filePath=setfolder(selfpath)
	Set objFolder=fso.GetFolder(filePath)
	set objFiles=objFolder.Files
	'循环输出文件夹path下的文件的文件名 
	For each objFile in objFiles 
	  if checknum(selfpath&objFile.name)=0 then			 
	   echop "正在移动"&selfpath&objFile.name&"到"&sitepath&uploadpath&"backups/"&DateFormat(now,"yymmdd")&"/"&objFile.name
	   editfile selfpath&objFile.name,sitepath&uploadpath&"backups/"&DateFormat(now,"yymmdd")&"/"&objFile.name
	  end if
	Next	
end sub

Sub setallsmall()
	dim data,i
	data=dbload("[dbpre]content","Cid,C_pic","","C_pic<>''","")
	if ubound(data)>=0 then
	  for i=0 to  ubound(data,2)
		if isfile(data(1,i)) then
			smallimg data(1,i),sitepath&uploadpath&"images/"&data(0,i)&".jpg"
			echo "正在生成第"&i+1&"个，剩余"&ubound(data,2)-i&"个</br>"
		else
			echo "内容ID："&data(0,i)&"图片："&data(1,i)&"不存在，生成失败"
		end if
	  next
	else
	 layermsggo "保存成功",sitepath&adminpath&"cms_Content/uploads/uploads_set.asp"
	end if
	layermsggo "保存成功",sitepath&adminpath&"cms_Content/uploads/uploads_set.asp"
End Sub	

Sub  editsystem()
	dim newupLoadPath:newupLoadPath=getForm("upLoadPath","post")
	if left(newupLoadPath,1)="/" or right(newupLoadPath,1)<>"/" or isnul(newupLoadPath) then alertgo "上传目录不能为空或为根目录","uploads_set.asp"
	dim configStr,configPath
	configPath=sitepath&"config/cms_Config.asp"	
	configStr=loadFile(configPath)
	configStr = AddParas("upLoadMark","(\d?)",configStr,false)
	configStr = AddParas("upLoadPath","(\S*?)",configStr,false)
	configStr = AddParas("datefolder","(\d?)",configStr,false)
	configStr = AddParas("coverMark","(\d?)",configStr,false)
	configStr = AddParas("imageExt","(\S*?)",configStr,false)
	configStr = AddParas("imageMaxSize","(\S*?)",configStr,false)
	configStr = AddParas("imageFormat","(\S*?)",configStr,false)
	configStr = AddParas("compresswidth","(\S*?)",configStr,false)
	configStr = AddParas("compressheight","(\S*?)",configStr,false)
	configStr = AddParas("compressquality","(\S*?)",configStr,false)
	configStr = AddParas("fileExt","(\S*?)",configStr,false)
	configStr = AddParas("fileMaxSize","(\S*?)",configStr,false)
	configStr = AddParas("fileFormat","(\S*?)",configStr,false)
	configStr = AddParas("videoExt","(\S*?)",configStr,false)
	configStr = AddParas("videoMaxSize","(\S*?)",configStr,false)
	configStr = AddParas("videoFormat","(\S*?)",configStr,false)	
	configStr = AddParas("smallMark","(\d?)",configStr,false)
	configStr = AddParas("smallMode","(\d?)",configStr,false)
	configStr = AddParas("smallwidth","(\S*?)",configStr,false)
	configStr = AddParas("smallheight","(\S*?)",configStr,false)
	configStr = AddParas("smallquality","(\S*?)",configStr,false)	
	SaveFile configPath,configStr
	layermsggo "保存成功",sitepath&adminpath&"cms_Content/uploads/uploads_set.asp"
End Sub	

sub file_List(parentPath)
	fileListArray= getFileList(parentPath)
	if instr(fileListArray(0),",")>0 then	
	  for  i = 0 to ubound(fileListArray)
		  fileAttr=split(fileListArray(i),",")
		  echo"<tr>"&vbcrlf  
		   echo "<td>"&fileAttr(0)&"</td>" 
		  echo "<td>"&fileAttr(4)&"</td>"
			if ifstrin("jpg,jpeg,png,gif,",LCase(fileAttr(1))) then
				echo "<td class='social-avatar'><a title='"&fileAttr(0)&"' rel='group1' href="&fileAttr(4)&" class='fancybox img-circle' ><img src="&fileAttr(4)&"></a>"
			elseif ifstrin("htm,html,css,js,asp,",LCase(fileAttr(1))) then
				echo "<td><a  target=""_blank"" href="""&fileAttr(4)&""">"&fileAttr(0)&"</a></td>"
			else
				echo "<td>"&GetFileExt(fileAttr(0))&"</td>"
			end if
		  echo "<td>"&fileAttr(2)&"</td>"&vbcrlf & _	  
		     "<td>"&fileAttr(3)&"</td>"&vbcrlf& _	 
			 "<td>"&checknum(fileAttr(4))&"</td>"&vbcrlf	 				
			if ifstrin("jpg,jpeg,png,gif,",LCase(fileAttr(1))) then
				echo "<td><a title='"&fileAttr(0)&"' rel='group2' href="&fileAttr(4)&" class='fancybox' >查看</a> | "&vbcrlf  
			elseif ifstrin("xml,htm,html,css,js,asp,",LCase(fileAttr(1))) then
				echo "<td><a href=""Template_Edit.asp?filepath="&fileAttr(4)&"&filename="&fileAttr(0)&""" class=""txt_C1"" >编辑</a> | "&vbcrlf  
			else
				echo "<td>"&vbcrlf  
			end if						
		 echo "<a onclick=rename('"&fileAttr(4)&"','"&fileAttr(0)&"') class=""txt_C1"">改名</a> | "	&vbcrlf& _	 
		   "<a onclick=delfile('"&fileAttr(4)&"') class=""txt_C1"" >删除</a></td>"&vbcrlf& _	
		   "</tr>"&vbcrlf  
	  next		
  end if	
end sub

Sub rename()
	dim newfilepath
	if not IfStrIn(newname,".") then newname=newname&"."&cRight(filename,".")
	newfilepath=replacestr(filepath,filename,newname)
	editfile filepath,newfilepath
	'echo replacestr(filepath,filename,newname)
	'echo "filepath:"&filepath&"filename:"&filename&"newname:"&newname
End Sub

function checknum(filename)
	if isnul(filename) then checknum=0 : exit function
	dim num,num0,num1,num2,num3,num4,num5,num6,num7,num8,num9,data,i,wherestr
	data=dbload("[dbpre]Content_custom","custom","","customClass in (7,8,9) and customOnOff=1","")
	if ubound(data)>=0 then
		for i=0 to ubound(data,2)
			wherestr=wherestr&" or "&data(0,i)& " like '%"&filename&"%'" 
		next
	end if
	num1=dbcount("[dbpre]about","A_content like '%"&filename&"%' or A_pic like '%"&filename&"%' or A_picsurl like '%"&filename&"%'")							
	num2=dbcount("[dbpre]ad","AdImg like '%"&filename&"%'")
	num3=dbcount("[dbpre]brand","B_content like '%"&filename&"%' or B_pic like '%"&filename&"%' or B_picsurl like '%"&filename&"%'")	
	num4=dbcount("[dbpre]content","C_content like '%"&filename&"%' or C_pic like '%"&filename&"%' or C_picsurl like '%"&filename&"%' or C_DownURL  like '%"&filename&"%' "&wherestr&"")
	num5=dbcount("[dbpre]labels","Label_pic like '%"&filename&"%' or Label_Content like '%"&filename&"%'")
	num6=dbcount("[dbpre]links","L_pic like '%"&filename&"%'")							
	num7=dbcount("[dbpre]Language","SitePcLogo like '%"&filename&"%'  or SiteWapLogo like '%"&filename&"%' or weixin like '%"&filename&"%'")
	num8=dbcount("[dbpre]slide","SlideImg like '%"&filename&"%'")
	num9=dbcount("[dbpre]sort","S_pic like '%"&filename&"%' or S_ico like '%"&filename&"%'")	
	if len(getfilename(filename))<4 then num0=dbcount("[dbpre]content","cid = "&isnum(getfilename(filename))&"")	else num0=0
	num=num1+num2+num3+num4+num5+num6+num7+num8+num9+num0
	checknum=num
end function

Sub getFile()
	dim flag,mExt,t,tafe
	flag = false	
	mExt = LCase(Mid(filepath,InStrRev(filepath, ".")+1))	
	if IfStrIn(filepath,";") then  back "错误的文件名1！"
	if IfStrIn(filepath,"..") then  back "错误的文件名1！"
	filetext=loadFile(filepath)
End Sub

Sub edithtmlFile()
	filepath=getForm("filepath","post")
	filetext=deHtml(getForm("filetext","post"))	
	SaveFile filepath,filetext
	alertgo "保存成功","-2"
End Sub

Sub addFile()
	filename=getForm("filename","post")
	parentPath=getForm("parentPath","post")
	filetext=deHtml(getForm("filetext","post"))	
	if not ifstrin(filename,".") then back "错误的文件类型！"	
	if not ifstrin("htmljscss,",cRight(filename,".")) then back "只能创建html,js,css文件"&cRight(filename,".")
	SaveFile parentPath&filename,filetext
	layermsggo "保存成功",sitepath&adminpath&"cms_Content/uploads/template_list.asp?parentPath="&parentPath
End Sub


Sub delhtmlFile
	if ifstrin(filepath,",") then
		 for  i = 0 to ubound(split(filepath,","))
			if isFile(split(filepath,",")(i)) then delFile split(filepath,",")(i)
	 	next
	 elseif isFile(filepath) then
	 	delFile filepath	:	 echo "删除成功"	
	else
		 echo "删除失败"	
	 end if	
End Sub

Sub selectStyle
	dim thisTemplate : thisTemplate=getForm("style","get")
	dim	Stype:	Stype=getForm("Stype","get")
	dbconn "update [dbpre]Language set "&Stype&"='"&thisTemplate&"/' where LID="&zset.lid	
	layermsggo "保存成功",sitepath&adminpath&"cms_Content/uploads/template.asp"
End Sub
%>