<!--#include file="../../fy.Function.asp"-->
<!--#include file="../../../fy_inc/fy.Code.asp"-->
<!--#include file="../../fycms.asp"-->
 <% 	 
		Dim ACTCode,ModeID,Table
		Set ACTCode =New ACT_Code
		Dim StartRefreshTime,RefreshFlag
		Dim FsoHtmlList,ItemName
		RefreshFlag = Request("RefreshFlag")
		StartRefreshTime = Request("StartRefreshTime")
		If StartRefreshTime = "" Then StartRefreshTime = Timer()
 
	
	Server.ScriptTimeOut=9999999
	Table=fycms.ACT_C(ModeID,2)
	Application(fycmsN&"ModeID")=1
	Call MakeContent
 	 Set ACTCode=Nothing:Set fycms=Nothing
		Sub Main()
		Dim ReturnInfo
		   echo ("<html>")
		  echo ("<head>")
		  echo ("<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">")
		  echo ("<title>系统信息</title>")
		  echo ("</head>")
		  echo ("<body>")
 				echo "<br><br><br><table id=""BarShowArea"" width=""400"" border=""0"" align=""center"" cellspacing=""1"" cellpadding=""1"">"
 				echo "<tr> "
				echo "<td bgcolor=000000>"
				echo " <table width=""400"" border=""0"" cellspacing=""0"" cellpadding=""1"">"
				echo "<tr> "
				echo "<td bgcolor=ffffff height=20><img src=""../../images/bar9.gif"" width=0 height=19 id=img2 name=img2 align=absmiddle></td></tr></table>"
				echo "</td></tr></table>"
				echo "<table width=""550"" border=""0"" align=""center"" cellspacing=""1"" cellpadding=""1""><tr> "
				echo "<td align=center> <span id=txt2 name=txt2 style=""font-size:9pt"">0</span><span id=txt4 style=""font-size:9pt"">%</span></td></tr> "
				echo "<tr><td align=center><span id=txt3 name=txt3 style=""font-size:9pt"">0</span></td></tr>"
				echo "</table>"
		 echo ("   <div id=""fsohtml"">")
		 echo (FsoHtmlList)
		  echo ("   </div>")
		 echo ("</body>")
		 echo ("</html>")
 		End Sub
		Sub MakeContent()
		Dim AlreadyRefreshByID,MaxNum,NowNum,TotalNum,StartDate,EndDate,ClassID,StartID,EndID
		Dim r_sql,R_RS,ID
		AlreadyRefreshByID = Request.QueryString("AlreadyRefreshByID")
		MaxNum = Request.QueryString("MaxNum")
		NowNum = Request.QueryString("NowNum") '正在刷新第几篇文章
 			If NowNum = "" Then NowNum = 0
 
		Select Case RefreshFlag
		   Case "ID"
				ID =fycms.S("ID")
				MaxNum=1
				R_Sql = "select * from  DiyPage_fy where id="&id
 		  Case "All"
				MaxNum=fycms.actexe("select count(id) from  DiyPage_fy")(0)
				R_Sql = "Select * from DiyPage_fy order by ID desc"
		 Case Else
				R_Sql = ""
				MaxNum = 0
		End Select



 		Call Main
		If R_Sql <> "" Then
			Set R_RS = Server.CreateObject("ADODB.RecordSet")
			R_RS.Open R_Sql, Conn, 1, 1
			If R_RS.EOF And R_RS.BOF Then
				echo "<script>img2.width=""0"";" & vbCrLf
				echo "txt2.innerHTML=""没有可生成的单页！<br><br><input name='button1' type='button' onclick=javascript:location='Index.asp'; class='button' value=' 返 回 '>"";" & vbCrLf
				echo "txt3.innerHTML="""";" & vbCrLf
				echo "txt4.innerHTML="""";" & vbCrLf
				echo "document.all.BarShowArea.style.display='none';" & vbCrLf
				echo "</script>" & vbCrLf
				response.Flush
				R_RS.Close:Set R_RS=Nothing
				Exit Sub
			Else

 				For NowNum=1 To MaxNum
				 
				  FsoHtmlList="<div align=center><li>标题为<font color=red>"  & R_RS("title") & "</font>已生成</div>"
 				 
 				
				
					Dim TemplateContent,DiyPath,filename
 
 					Application(fycmsN & "fycms_TCJ_Type")= "OTHER"
					Application(fycmsN & "fycmsTCJ")=R_RS("title")
 				

					Dim namearr,makehtmlname,i,namearrs
					makehtmlname=R_RS("DiyPath")
					If InStr(makehtmlname,"/")>0 Then 
						namearr=Split(makehtmlname,"/")
						 For i=0 To UBound(namearr)-1
							namearrs=namearrs&namearr(i)&"/"
						 Next
						Call fycms.CreateFolder(fycms.ActSys&namearrs)
						If Right(makehtmlname,1)="/"   Then
							namearrs=namearrs&"index.html"
						Else
							namearrs=makehtmlname
						End If 
						FileName=fycms.ActSys&namearrs
					Else 
						FileName=fycms.ActSys&makehtmlname
					End If 
					
			  
					Application(fycmsN & "link")=makehtmlname
 
 					If R_RS("tempurl")<>"" Then 
					TemplateContent = LoadTemplate(R_RS("tempurl"))
					End If 
					IF TemplateContent <> "" Then
						TemplateContent = ACTCode.LabelReplaceAll(TemplateContent)
					End If 
					If InStr(TemplateContent, "[get:id]") > 0   Then
						TemplateContent = Replace(TemplateContent, "[get:id]", R_RS("id"))
					End If 
					If InStr(TemplateContent, "{info:content}") > 0   Then
						TemplateContent = Replace(TemplateContent, "{info:content}", R_RS("content"))
					End If 
					If InStr(TemplateContent, "{info:title}") > 0  And  R_RS("title")<>""  Then
						TemplateContent = Replace(TemplateContent, "{info:title}", R_RS("title"))
					Else
						TemplateContent = Replace(TemplateContent, "{info:title}", "")
					End If 
					TemplateContent=ACTCode.LabelReplaceAll(TemplateContent)
 					Call SaveFile(TemplateContent,FileName)				
				
				
				 FileName="":TemplateContent=""
				
 				If Err.Number <> 0 Then
				 FsoHtmlList = "操作失败!<br><font color=red>" & Err.Description & "</font>"
				 Call TypeJS(NowNum,MaxNum,fycms.ACT_C(ModeID,5))
				 R_RS.Close:Set R_RS=Nothing
				 Exit Sub
				End If
 				if Not Response.IsClientConnected then Exit FOR
			  r_rs.movenext
			Next
				echo "<script>"
				echo "fsohtml.innerHTML='';" & vbCrLf
				echo "img2.width=400;" & vbCrLf
				echo "txt2.innerHTML=""生成单页结束！100"";" & vbCrLf
				echo "txt3.innerHTML=""总共生成了 <font color=red><b>" & MaxNum & "</b></font> 条,总费时:<font color=red>" & Left((Timer() - StartRefreshTime), 4) & "</font> 秒<br><br><input name='button1' type='button' onclick=javascript:location='Index.asp'; class='button' value=' 返 回 '>"";" & vbCrLf
				echo "img2.title=""(" & NowNum & ")"";</script>" & vbCrLf
			
			End If
		Else
				echo "<script>img2.width=""0"";" & vbCrLf
				echo "txt2.innerHTML=""没有可生成的单页！<br><br><input name='button1' type='button' onclick=javascript:location='Index.asp'; class='button' value=' 返 回 '>"";" & vbCrLf
				echo "txt3.innerHTML="""";" & vbCrLf
				echo "txt4.innerHTML="""";" & vbCrLf
				echo "document.all.BarShowArea.style.display='none';" & vbCrLf
				echo "</script>" & vbCrLf
		End If
 		End Sub
		Sub TypeJS(NowNum,TotalNum,itemname)
		    echo "<script>"
				echo "fsohtml.innerHTML='" & FsoHtmlList & "';" & vbCrLf
				echo "img2.width=" & Fix((NowNum / TotalNum) * 400) & ";" & vbCrLf
				echo "txt2.innerHTML=""生成进度:" & FormatNumber(NowNum / TotalNum * 100, 2, -1) & """;" & vbCrLf
				echo "txt3.innerHTML=""总共需要生成 <font color=red><b>" & TotalNum & "</b></font> " & itemname & ",<font color=red><b>在此过程中请勿刷新此页面！！！</b></font> 系统正在生成第 <font color=red><b>" & NowNum & "</b></font> " & itemname & """;" & vbCrLf
				echo "img2.title=""(" & NowNum & ")"";</script>" & vbCrLf
				response.Flush
 		End Sub
 %>
