<!--#include file="../../../inc/cms_admin.asp" -->
<%
dim act,filename,pctempath,waptempath,filepath,filetext,thisurl
dim fileListArray,i,fileAttr,folderListArray,folderAttr,parentPath,CparentPath,newname
dim num,num1,num2,num3,num4,num5,num6,num7
pctempath=sitePath&htmldir
act=getForm("act","get")
filename=getForm("filename","get")
filepath=getForm("filepath","get")
newname=getForm("newname","get")
parentPath=getform("parentPath","both")
CparentPath=getform("CparentPath","both")
thisurl=getthisurl("0")
if isnul(parentPath) then parentPath=sitePath&htmldir
if isnul(CparentPath) then CparentPath=sitePath&CachePath
select case act
	case "del" 			: delhtmlFile(filepath)
	case "delallhtml" 	: delallhtml("")
	case "upindex"		: creatindex
	case "uphtml" 		: creatall	
	case "upabout" 		: creatabout	
	case "upcontent" 	: creatcontent		
	case "uplist" 		: creatlist
	case "upgbook" 		: creatgbook
	case "select"		: selectStyle	
	case "Crefolder"	: CreateFolder parentPath&newname
	case "delfolder"	: delfolder parentPath		
	case "edithtmlfilepath" : editHtmlFilePath
	case "editsystem"	: editsystem
end select

sub editsystem()
	dim newCachePath,newhtmlDir
	if (runMode=1 or runMode=3) and isnum(getForm("runMode","post"))<>1 then
		call delallhtml("")
	end if
	
	if getForm("runMode","post")>1 then
		copyfile sitepath&adminpath&"inc/webconfig/web.config",sitepath&"web.config"
	else
		delfile sitepath&"web.config"
	end if
	
	if IsCache=1 and isnum(getForm("IsCache","post"))<>1 then
		call delhtmlFile("allcache")
	end if
	newCachePath=getForm("CachePath","post")
	newhtmlDir=getForm("htmlDir","post")
	if isnul(newCachePath) then alertgo "缓存目录不能为空或为根目录","html_set.asp"
	if newhtmlDir<>htmlDir and not isnul(newhtmlDir) then 
		newfolder sitepath&newhtmlDir
		delfolder sitepath&htmlDir
	end if
	dim configStr,configPath
	configPath=sitepath&"config/cms_Config.asp"	
	configStr=loadFile(configPath)
	configStr = AddParas("runMode","(\d?)",configStr,false)
	configStr = AddParas("IsCache","(\d?)",configStr,false)
	configStr = AddParas("cacheTime","(\S*?)",configStr,false)
	configStr = AddParas("htmlDir","(\S*?)",configStr,false)
	SaveFile configPath,configStr
	alertgo "修改成功","html_set.asp"
End Sub

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 delhtmlFile(path)
	if ifstrin(path,",") then
		 for  i = 0 to ubound(split(path,","))
			if isFile(split(path,",")(i)) then delFile split(path,",")(i)
	 	next
	 elseif isFile(path) then
	 	delFile path	:	if err.number=0 then echo "删除成功"	
	elseif  path="allcache" then
		if CachePath="" then back "缓存目录为空，不能全部删除"
		delfolder sitepath&CachePath
		newfolder sitepath&CachePath
		if wapmark=1 then
			delfolder sitepath&wappath&CachePath
			newfolder sitepath&wappath&CachePath
		end if
		if err.number=0 then echo "删除成功"	
	else
		 echo "删除失败"	
	 end if	
End Sub

Sub delallhtml(path)
	dim fileListArray,fileAttr,allpath,j
	if isnul(htmlDir) then
	  allpath=dbload("[dbpre]sort","S_Folder,C_Folder","","","S_Folder asc")
	   if ubound(allpath)>=0 then		 
	   for j=0 to ubound(allpath,2)
	    if allpath(0,j)<>"-" then
		  'echop sitepath&path&allpath(0,j)
		  fileListArray= getFileList(sitepath&path&allpath(0,j))
		  for  i = 0 to ubound(fileListArray)
			  fileAttr=split(fileListArray(i),",")
			  if fileAttr(1)="html" then delfile fileAttr(4)
		  next
		end if  
		if allpath(1,j)<>"-" then
		  fileListArray= getFileList(sitepath&path&allpath(1,j))
		  for  i = 0 to ubound(fileListArray)
			  fileAttr=split(fileListArray(i),",")
			  if fileAttr(1)="html" then delfile fileAttr(4)
		  next
		end if  		
	   next
	   end if
	   if wapmark=1 and isnul(path) then delallhtml("wap/")
	   if err.number=0 and isnul(path) then echo "删除成功"	
	else
	  delfile sitepath&"index.html"
	  delfile sitepath&"wap/index.html"
	  delfolder sitepath&htmldir
	  newfolder sitepath&htmldir
	  if wapmark=1 then
		  delfolder sitepath&wappath&htmldir
		  newfolder sitepath&wappath&htmldir
	  end if
	  if err.number=0 then echo "删除成功"	
	end if	
End Sub

Sub creatall
	call creatindex
	call creatabout
	call creatcontent		
	call creatlist
	call creatgbook
	back "静态生成任务已经生成，后台自动生成"
End Sub

Sub creatindex
	dim sql,rs ,HttpUrl ,Http
		delfile sitepath&"index.html"
		echo "<iframe src='"&thisurl&sitepath&"index.asp' style= 'display :none'>  </iframe>"
	if act="upindex" then back "首页生成已提交"
End Sub

Sub creatabout
	dim sql,rs,page,pagei
	Sql = "select * from [dbpre]about  where A_OnOff=1 order by aid asc"
	set rs= dbsql(sql)
	do while not rs.eof   
		page=1
		pagei=""
		if ifstrin(rs("A_Content"),"{list:page}") then page=ubound(split(rs("A_Content"),"{list:page}"))+1
		for  i = 1 to page		
			echo "<iframe src='"&thisurl&sitepath&"about/?"&rs("A_SID")&"_"&i&".html'  style= 'display :none'> </iframe>"			
		next
	rs.movenext
	loop
	closers rs
	if act="upabout" then back "单页生成任务已提交，后台生成中"
	'layerback "生成单页页完成"
End Sub

Sub creatcontent
	dim sql,rs ,page,pagei
		Sql = "select CID,C_SID,C_content from [dbpre]Content as a, [dbpre]Sort as b where C_SID=SID and C_OnOff=1 order by cid desc"
		'die sql
		set rs= dbsql(sql)
		do while not rs.eof  
			page=1
			pagei="" 
			if ifstrin(rs("C_Content"),"{list:page}") then page=ubound(split(rs("C_Content"),"{list:page}"))+1
			for  i = 1 to page		
			IF I=1 THEN PAGEI="" ELSE pagei="_"&i
			echo "<iframe src='"&thisurl&sitepath&"news/?"&rs("C_SID")&"_"&rs("CID")&pagei&".html' style= 'display :none'>  </iframe>"	
			next		
    	rs.movenext
		loop
	closers rs
	if act="upcontent" then back "内容静态页生成任务已提交，后台生成中"
End Sub

Sub creatgbook
	dim TempFile,tempstr,sid,psize,page,pagei,Zreg,labelRule
		num =dbcount( "[dbpre]gbook","G_OnOff=1")
		sid=dbselect("[dbpre]sort","sid","S_Type='gbook'")	
		TempFile=sitepath &"template/pc/"& zset.PcTemplate&zset.PchtmlPath&"gbook.html"
		tempstr=loadfile(TempFile)
		psize=parseArr(tempstr)("size")
		if not ifnum(psize) then psize=10
		page=Int(cint(num)/cint(psize))+1
		for  i = 1 to page
		echo "<iframe src='"&thisurl&sitepath&"gbook/?list_"&sid&"_"&i&".html' style= 'display :none'>  </iframe>"	
		next		
	if act="upgbook" then back "留言生成任务已提交，后台生成中"
End Sub

Sub creatlist
	dim sql,rs ,TemplateFilePath,TempFile,tempstr,psize,page,pagei,Zreg,labelRule
	
	Sql = "select SID,S_Template from [dbpre]sort as a,[dbpre]Model as b  where Model_type=S_Type and Model_table='content' and s_OnOff=1 order by sid asc"	
	set rs= dbsqlr1(sql)	
	do while not rs.eof  		
		num=dbcount("[dbpre]content","C_sid in ("&getSortid(rs(0),3)&") and c_onoff=1") 
		page=1
		TemplateFilePath=sitepath &"template/pc/"& zset.PcTemplate&zset.PchtmlPath
		TempFile= iif(isfile(TemplateFilePath&rs(1)),TemplateFilePath&rs(1),TemplateFilePath&"list.html")
		tempstr=loadfile(TempFile)
   		psize=parseArr(tempstr)("size")
		if not isnul(psize) then 
			if not ifnum(psize) then psize=10
			page=Int(cint(num)/cint(psize))+1
			for  i = 1 to page
			echo "<iframe src='"&thisurl&sitepath&"list/?"&rs("SID")&"_"&i&".html' style= 'display :none'>  </iframe>"			
			next
		else
			echo "<iframe src='"&thisurl&sitepath&"list/?"&rs("SID")&"_1.html' style= 'display :none'>  </iframe>"			
		end if
	rs.movenext
	loop
	closers rs	
	if act="uplist" then back "内容静态页生成任务已提交，后台生成中"
End Sub
%>