<!--#include file="const.asp"-->
<!--#include file="../inc/common.asp"-->
<!--#include file="../../common/soft/special.asp"-->
<!--#include file="../inc/head.asp"-->
<%
Dim t,d,p,TakeCount,strSQLQuery,m_strNowTitle
Dim totalnumber,MaxHtmlListNum

MaxHtmlListNum=100

totalnumber=NewAsp.ChkNumeric(Request("totalnumber"))
t=NewAsp.ChkNumeric(Request("t"))
p=NewAsp.ChkNumeric(Request("p"))
If p=0 Then p=1
TakeCount=NewAsp.ChkNumeric(Request("TakeCount"))
m_intOrder=NewAsp.ChkNumeric(Request("order"))
d=Request("d")
If d="" Then d=Now()

IsNowOutputText = False

Call createdhtml()
NewAsp.PageEnd()

Sub createdhtml()
	Dim Rs,SQL,ii
	Dim m_strLinkUrl
	m_strLinkUrl=""
	Response.Flush
	Select Case t
		Case 1,3
			strSQLQuery = " And ChangeLink=0 And specialid in ("& NewAsp.CheckStr(Request("inspecialid")) &")"
			m_strLinkUrl="&inspecialid="&Request("inspecialid")
	Case Else
		strSQLQuery = " And ChangeLink=0"
	End Select
	
	If totalnumber=0 Then
		NewAsp.Execute ("UPDATE NC_Special SET isUpdate=1 WHERE ChannelID="&ChannelID & strSQLQuery)
		totalnumber=NewAsp.Execute("SELECT COUNT(*) FROM [NC_Special] WHERE ChannelID="&ChannelID&" And isUpdate=1"&strSQLQuery)(0)
	End If
	
	Response.Write "<script>$('planmain').style.display='';</script>"
	Response.Write "<script>$('plantext').style.display='';</script>"
	Set Rs = NewAsp.Execute("SELECT TOP 1 specialid,specialname FROM NC_Special WHERE ChannelID="&ChannelID&" And isUpdate=1"&strSQLQuery)
	If Rs.BOF And Rs.EOF Then
		Response.Write "<script>"
		Response.Write "plantext("&totalnumber&","&TakeCount&",'" & ElapsedTime() & "','');"
		Response.Write "planpercent('100%');"
		Response.Write "planwidth(500);"
		Response.Write "</script>" & vbCrLf
		Response.Flush
	Else
		
		TakeCount=TakeCount+1
		specialid=Rs(0)
		m_strNowTitle=Replace(Rs(1)&"", "'", "\'")
		pagenow=p
		Call BeginCreated()
		
		Response.Write "<script>"
		Response.Write "plantext("&totalnumber&","&TakeCount&",'" & ElapsedTime() & "','"&m_strNowTitle&" - "&HtmlFileName&"');"
		Response.Write "planpercent('" & FormatPercent(TakeCount/totalnumber,2,-1) & "');"
		Response.Write "planwidth("&Fix((TakeCount/totalnumber) * 500)&");"
		Response.Write "</script>" & vbCrLf
		Response.Flush
		If BuildHtmlDone=0 And Pcount>1 Then
			ii=0
			For pagenow=p+1 To Pcount
				If Not Response.IsClientConnected Then Response.End
				p=p+1
				ii=ii+1
				Call BeginCreated()
				Response.Write "<script>"
				Response.Write "plantext("&totalnumber&","&TakeCount&",'" & ElapsedTime() & "','"&m_strNowTitle&" - "&HtmlFileName&"');"
				Response.Write "</script>" & vbCrLf
				Response.Flush
				If pagenow>=Pcount Then Exit For
				If ii>=MaxHtmlListNum Then Exit For
			Next
			
			If BuildHtmlDone=1 Then
				p=1
			End If
		Else
			p=1
		End If
		m_strLinkUrl="admin_makespecial.asp?ChannelID="&ChannelID&"&order="&m_intOrder&"&totalnumber="&totalnumber&"&t="&t&"&d="&d&"&p="&p&"&TakeCount="&TakeCount&m_strLinkUrl
		If TakeCount<totalnumber Then
			Response.Write "<meta http-equiv=""refresh"" content=""0.5;url='"&m_strLinkUrl&"''"">"
		End If
	End If
	Rs.Close:Set Rs = Nothing
	If IsObject(TPL_XmlDom) Then Set TPL_XmlDom=Nothing
End Sub

Function ElapsedTime()
	Dim ElapsedSeconds
	ElapsedSeconds=DateDiff("s", d, Now())
	If ElapsedSeconds > 3600 then
		ElapsedTime = ElapsedSeconds \ 3600 & " Ê± " & (ElapsedSeconds mod 3600) \ 60 & " ·Ö " & ElapsedSeconds mod 60 & " Ãë"
	ElseIf ElapsedSeconds > 60 then
		ElapsedTime = ElapsedSeconds \ 60 & " ·Ö " & ElapsedSeconds mod 60 & " Ãë"
	Else
		ElapsedTime = ElapsedSeconds mod 60 & " Ãë"
	End If
End Function

Sub BeginCreated()
	Call Main()
	If BuildHtmlDone=1 Then NewAsp.Execute ("UPDATE NC_Special SET isUpdate=0 WHERE specialid="&specialid)
	HtmlFilePath=NewAsp.CheckHtmlFilePath(HtmlFileName)
	NewAsp.CreatPathEx HtmlFilePath
	NewAsp.CreatedTextFile HtmlFileName,TPL_Memory
	TPL_Memory="":iScanCount=0
End Sub
%>