<% Option Explicit %>
<!--#include file="Function.asp" -->
<!--#include file="../../Inc/Function.asp" -->
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="RefreshFunction.asp" -->
<!--#include file="SelectFunction.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0402") then Call ReturnError1()
Dim Types,SearchSql,NewsNo,RsSearchObj,NewsTotalNum,PromptInfo
NewsNo = Request("NewsNo")
if NewsNo = "" then
	NewsNo = 1
else
	NewsNo = CInt(NewsNo)
end if
SearchSql = Request("SearchSql")
if SearchSql = "" then
	Types = Request("Types")
	if Types = "ClassOne" then
		SearchSql = "Select * from NewsClass where DelFlag=0 and ClassID='" & Request.Form("ClassID") & "'" 
	elseif Types = "ClassAll" then
		SearchSql = "Select * from NewsClass where DelFlag=0"
	else
		SearchSql = ""
	end if
end if
if SearchSql <> "" then
	Set RsSearchObj = Server.CreateObject("ADODB.RecordSet")
	RsSearchObj.Open SearchSql,Conn,1,1
	NewsTotalNum = RsSearchObj.RecordCount
	if RsSearchObj.Eof then
		PromptInfo = "没有要刷新的栏目&nbsp;&nbsp;<font color=""red""><a href=""RefreshClass.asp"">返回</a></font>"
		Set RsSearchObj = Nothing
		Call PromptFunction
	else
		RsSearchObj.Move NewsNo - 1
		if Not RsSearchObj.Eof then
			RefreshClass RsSearchObj
			NewsNo = NewsNo + 1
			Response.Write("<meta http-equiv=""refresh"" content=""0;url=RefreshClassSave.asp?NewsNo=" & NewsNo & "&SearchSql=" & SearchSql & """>")
			PromptInfo = "共有<font color=red><b>" & NewsTotalNum & "</b></font>个栏目需要刷新<br><br>正在刷新第<font color=red><b>" & NewsNo - 1 & "</b></font>个栏目"
			PromptInfo = PromptInfo & "按确定键返回！<br><br><input name=""imageField"" type=""image"" src=""../Images/back.gif"" width=""75"" height=""21"" border=""0"">"
		else
			PromptInfo = "共刷新<b>" & NewsTotalNum & "</b>栏目,刷新成功<font color=red><b>" & Session("RefreshSuccessClass") & "</b></font>个栏目<br>" & Session("RefreshFindTwoLastClass") & "<br> <input name=""imageField"" type=""image"" src=""../Images/back.gif"" width=""75"" height=""21"" border=""0"">"
			Session("RefreshFindTwoLastClass") = ""
			Session("RefreshSuccessClass") = 0
		end if
		Set RsSearchObj = Nothing
		Call PromptFunction
	end if
	Set RsSearchObj = Nothing
else
	PromptInfo = "参数传递错误&nbsp;&nbsp;<font color=""red""><a href=""RefreshClass.asp"">返回</a></font>"
	Call PromptFunction
end if

Function RefreshClass(RefreshClassRsObj)
	Dim FSOObj,FileObj,FileStreamObj,TempletFileName,SaveFilePath,FileContent,TempSysRootDir
	Dim TempArray,LoopVar,TempReturnValue,ReturnLoopVar
	SetRefreshValue "Class",RefreshClassRsObj("ClassID")
	GetAvailableDoMain
	if SysRootDir = "" then
		TempSysRootDir = ""
	else
		TempSysRootDir = "/" & SysRootDir
	end if
	TempletFileName = Server.MapPath(TempSysRootDir & RefreshClassRsObj("ClassTemp"))
	Set FSOObj = Server.CreateObject("Scripting.FileSystemObject")
	if FSOObj.FileExists(TempletFileName) = False then
		FileContent = "模板不存在，请添加模板后再生成！"
	else
		Set FileObj = FSOObj.GetFile(TempletFileName)
		Set FileStreamObj = FileObj.OpenAsTextStream(1)
		if Not FileStreamObj.AtEndOfStream then
			FileContent = FileStreamObj.ReadAll
			if (RefreshClassRsObj("BrowPop") <> 0) And (RefreshClassRsObj("FileExtName") = "asp") then
				FileContent = GetPopStr(RefreshClassRsObj("BrowPop"),RefreshClassRsObj("SaveFilePath")) & FileContent
			end if
			FileContent = ReplaceAllServerFlag(ReplaceAllLable(FileContent))
		else
			FileContent = "模板内容为空"
		end if
	end if
	Set FileStreamObj = Nothing
	Set FileObj = Nothing
	Set FSOObj = Nothing
	CheckFolderExists TempSysRootDir & RefreshClassRsObj("SaveFilePath"),RefreshClassRsObj("ClassEName"),"index"
	if NotReplaceLableArray <> "" then
		TempArray = Split(NotReplaceLableArray,"$$$")
		if UBound(TempArray) = 0 then
			if TempArray(0) <> "" then
				TempReturnValue = GetLableContent(TempArray(0))
				'If TempReturnValue = "" then
					'TempReturnValue = Array("")
				'End If
				for ReturnLoopVar = LBound(TempReturnValue) to UBound(TempReturnValue)
					TempReturnValue(ReturnLoopVar) = Replace(FileContent,Split(NotReplaceLableOldArray,"$$$")(0),TempReturnValue(ReturnLoopVar))
				Next
				FileContent = TempReturnValue
			else
				FileContent = Array(FileContent)
			end if
		else
			if Session("RefreshFindTwoLastClass") = "" then
				Session("RefreshFindTwoLastClass") = RefreshClassRsObj("ClassCName") & "栏目捆绑的模板" & RefreshClassRsObj("ClassTemp") & "发现两个终极列表"
			else
				if InStr(Session("RefreshFindTwoLastClass"),RefreshClassRsObj("ClassCName") & "栏目捆绑的模板" & RefreshClassRsObj("ClassTemp") & "发现两个终极列表") = 0 then
					Session("RefreshFindTwoLastClass") = Session("RefreshFindTwoLastClass") & "<br>" & RefreshClassRsObj("ClassCName") & "栏目捆绑的模板" & RefreshClassRsObj("ClassTemp") & "发现两个终极列表"
				end if
			end if
			Exit Function
		end if
	else
		FileContent = Array(FileContent)
	end if
	Session("RefreshSuccessClass") = Session("RefreshSuccessClass") + 1
	for LoopVar = LBound(FileContent) to UBound(FileContent)
		if LoopVar = 0 then
			if RefreshClassRsObj("SaveFilePath") = "/" then
				SaveFilePath = TempSysRootDir & RefreshClassRsObj("SaveFilePath") & RefreshClassRsObj("ClassEName") & "/" & "index." & RefreshClassRsObj("FileExtName")
			else
				SaveFilePath = TempSysRootDir & RefreshClassRsObj("SaveFilePath") & "/" & RefreshClassRsObj("ClassEName") & "/" & "index." & RefreshClassRsObj("FileExtName")
			end if
		else
			if RefreshClassRsObj("SaveFilePath") = "/" then
				SaveFilePath = TempSysRootDir & RefreshClassRsObj("SaveFilePath") & RefreshClassRsObj("ClassEName") & "/" & "index_" & LoopVar + 1 & "." & RefreshClassRsObj("FileExtName")
			else
				SaveFilePath = TempSysRootDir & RefreshClassRsObj("SaveFilePath") & "/" & RefreshClassRsObj("ClassEName") & "/" & "index_" & LoopVar + 1 & "." & RefreshClassRsObj("FileExtName")
			end if
		end if
		Select Case AvailableRefreshType
			Case 0
				FSOSaveFile FileContent(LoopVar),SaveFilePath
			Case 1
				SaveFile FileContent(LoopVar),SaveFilePath
			Case Else
				FSOSaveFile FileContent(LoopVar),SaveFilePath
		End Select
	Next
End Function
Sub PromptFunction()
	Set Conn = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<link rel="stylesheet" href="../../CSS/css.css">
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <form method=post action=RefreshClass.asp>
    <tr> 
      <td><div align="center"> 
          <% = PromptInfo %>
        </div></td>
    </tr>
  </form>
</table>
</body>
</html>
<%
End Sub
%>