<!--#include file="setup.asp"-->
<%
Dim DownloadClass_Admin
Set DownloadClass_Admin = New Create_TopJS_Cls
DownloadClass_Admin.Init_CreateTopJS
Set DownloadClass_Admin = Nothing
NothingObject
CloseConn
Class Create_TopJS_Cls
	Private ErrMsg
	Private SucMsg
	Private Founderr
	Private NC_Admin
	Private action, d
	Private Sub Class_Initialize()
		Founderr = False
		Response.Buffer = True
		Server.ScriptTimeout = 99999
		d = Timer()
		DownsysClass.LoadTemplates ("Sorting")
	End Sub

	Private Sub Class_Terminate()
		If IsObject(Conn) Then
			Conn.Close
			Set Conn = Nothing
		End If
		If IsObject(NC_Admin) Then
			Set NC_Admin = Nothing
		End If
	End Sub

	Public Sub Init_CreateTopJS()
		On Error Resume Next
		Server.ScriptTimeout = 99999
		Set NC_Admin = New Check
		NC_Admin.AdminChk = "18"
		NC_Admin.Check
		DownsysClass.LoadTemplates ("")
		DownsysClass.admin_header
		d = Timer
		action = Trim(Request("action"))
		Select Case action
			Case "Sorting"
				Call CreateSortingJS
			Case "Class"
				Call CreateClassJS
			Case Else
				Call JSMain
		End Select
		DownsysClass.admin_footer
	End Sub

	Public Sub JSMain()
		Dim SoftTotal
		Dim Rs1
		Dim SQL
		Dim ArticleTotal
		SQL = "select count(*) from NC_SoftSort"
		Rs1 = DownsysClass.Execute(SQL)
		SoftTotal = Rs1(0)
		Set Rs1 = Nothing
		SQL = "select count(*) from NC_Class"
		Rs1 = DownsysClass.Execute(SQL)
		ArticleTotal = Rs1(0)
		Set Rs1 = Nothing
		Response.Write "<table width=""98%"" border=""0"" align=""center"" cellpadding=""5"" cellspacing=""1"" class=""tableBorder"">"
		Response.Write " <tr>" & Chr(13)
		Response.Write " <th colspan=""2"">批量生成分类排行JS</th></tr>"
		Response.Write " <tr>" & Chr(13)
		Response.Write " <td class=forumrow height=""32"" style=""LINE-HEIGHT: 150%; font-size: 10pt;"" colspan=""2"">"
		If Request("type") = "ok" Then
			Response.Write "操作成功:共生成JS文件<font color=""#FF0000"">" & Request("num") & "</font>个,总费时<font color=""#FF0000"">" & FormatNumber((Timer() - Request("D")), 2) & "</font>秒,完成时间" & Now() & ""
		End If
		Response.Write "</td>"
		Response.Write "</tr>"
		Response.Write " <tr><form name=""myform"" method=""post"" action=""?action=Sorting"">"
		Response.Write " <td class=forumrow height=""22"">生成下载分类排行JS</td>"
		Response.Write " <td class=forumrow><input type=""submit"" class=button name=""Submit"" value=""生成下载分类排行JS""> "
		Response.Write "</td></form>"
		Response.Write " </tr>"
		Response.Write " <tr><form name=""myform"" method=""post"" action=""?action=Class"">"
		Response.Write " <td class=forumrow height=""22"">生成文章分类排行JS</td>"
		Response.Write " <td class=forumrow><input type=""submit"" class=button name=""Submit"" value=""生成文章分类排行JS""> "
		Response.Write "</td></form>"
		Response.Write " </tr>"
		Response.Write " <tr>"
		Response.Write " <td align=""center"" class=forumrow height=""22"" style=""LINE-HEIGHT: 150%; font-size: 10pt;"" colspan=""2"">"
		Response.Write " (共有软件分类 <font color=""#FF3300""><B>"
		Response.Write SoftTotal
		Response.Write "</B></font> 个)　"
		Response.Write " 　(共有文章分类 <font color=""#FF3300""><B>"
		Response.Write ArticleTotal
		Response.Write "</B></font> 个)"
		Response.Write "</td>"
		Response.Write "</tr></table>"
	End Sub

	Private Sub CreateSortingJS()
		Dim totalnumber
		Dim Rsc
		Dim SQL
		Dim i
		Response.Write "<b><font color=""#FF0000"">  正在生成下载分类排行JS文件,请稍候......</font></b><BR>" & vbCrLf
		Response.Write "<table width=""400"" border=""0"" cellspacing=""1"" cellpadding=""1"">" & vbCrLf
		Response.Write "<tr> " & vbCrLf
		Response.Write "<td bgcolor=000000>" & vbCrLf
		Response.Write " <table width=""400"" border=""0"" cellspacing=""0"" cellpadding=""1"">" & vbCrLf
		Response.Write "<tr> " & vbCrLf
		Response.Write "<td bgcolor=ffffff height=9><img src=""images/bar9.gif"" width=0 height=16 id=img2 name=img2 align=absmiddle></td></tr></table>" & vbCrLf
		Response.Write "</td></tr></table></td></tr><tr> " & vbCrLf
		Response.Write "<td align=center bgcolor=000000> <span id=txt2 name=txt2 style=""font-size:9pt"">0</span><span style=""font-size:9pt"">%</span>  <span id=txt3 name=txt3 style=""font-size:9pt"">0</span></td></tr>" & vbCrLf
		Response.Write "</table>" & vbCrLf
		Response.Flush
		CreateDownTop 0, "HotTop.JS"
		CreateDownTop 1, "DayHot.JS"
		CreateDownTop 2, "WeekHot.JS"
		CreateDownTop 3, "MonthHot.JS"
		Set Rsc = CreateObject("adodb.recordset")
		SQL = "select sortid,SortName,rootid,depth from [NC_SoftSort] order by sortid desc"
		Rsc.Open SQL, Conn, 1, 1
		If Rsc.EOF And Rsc.bof Then
			Response.Write "Sorry！没有找到任何分类。或者分类没有更新!"
		Else
			i = 1
			totalnumber = Rsc.recordcount
			Do While Not Rsc.EOF
				CreateSortingTop Rsc("sortid"), Rsc("rootid"), Rsc("depth")
				Response.Write "<script>img2.width=" & Fix((i / totalnumber) * 400) & ";" & vbCrLf
				Response.Write "txt2.innerHTML=""生成进度:" & FormatNumber(i / totalnumber * 100, 4, -1) & """;" & vbCrLf
				Response.Write "txt3.innerHTML=""　　共有 <B><font color=RED>" & totalnumber & "</font></B> 个 　正在生成第 " & i & " 个"";" & vbCrLf
				Response.Write "img2.title=""(" & i & ")"";</script>" & vbCrLf
				Response.Flush
				Response.Write "<table cellpadding=0 cellspacing=0 border=0 width=85% align=center><tr><td colspan=2 class=forumrow> 　生成 [" & Rsc(1) & "] 排行JS完成。</td></tr></table>"
				Response.Flush
				Rsc.movenext
				i = i + 1
			Loop
		End If
		Rsc.Close
		CreateSortingTop "", "", ""
		Set Rsc = Nothing
		Response.Write "<script>img2.width=400;txt2.innerHTML=""100"";</script>"
		Response.Write "<meta http-equiv=""refresh"" content=""1;url='?num=" & totalnumber & "&D=" & d & "&type=ok'"">"
	End Sub

	Private Sub CreateClassJS()
		Dim totalnumber
		Dim Rsc
		Dim SQL
		Dim i
		Response.Write "<b><font color=""#FF0000"">  正在生成文章分类排行JS文件,请稍候......</font></b><BR>" & vbCrLf
		Response.Write "<table width=""400"" border=""0"" cellspacing=""1"" cellpadding=""1"">" & vbCrLf
		Response.Write "<tr> " & vbCrLf
		Response.Write "<td bgcolor=000000>" & vbCrLf
		Response.Write " <table width=""400"" border=""0"" cellspacing=""0"" cellpadding=""1"">" & vbCrLf
		Response.Write "<tr> " & vbCrLf
		Response.Write "<td bgcolor=ffffff height=9><img src=""images/bar9.gif"" width=0 height=16 id=img2 name=img2 align=absmiddle></td></tr></table>" & vbCrLf
		Response.Write "</td></tr></table></td></tr><tr> " & vbCrLf
		Response.Write "<td align=center bgcolor=000000> <span id=txt2 name=txt2 style=""font-size:9pt"">0</span><span style=""font-size:9pt"">%</span>  <span id=txt3 name=txt3 style=""font-size:9pt"">0</span></td></tr>" & vbCrLf
		Response.Write "</table>" & vbCrLf
		Response.Flush
		CreateArticleTop 0, "HotTop.JS"
		CreateArticleTop 1, "DayHot.JS"
		CreateArticleTop 2, "WeekHot.JS"
		CreateArticleTop 3, "MonthHot.JS"
		Set Rsc = CreateObject("adodb.recordset")
		SQL = "select classid,ClassName,rootid,depth from [NC_Class] order by classid desc"
		Rsc.Open SQL, Conn, 1, 1
		If Rsc.EOF And Rsc.bof Then
			Response.Write "Sorry！没有找到任何分类。或者分类没有更新!"
		Else
			i = 1
			totalnumber = Rsc.recordcount
			Do While Not Rsc.EOF
				CreateClassTop Rsc("classid"), Rsc("rootid"), Rsc("depth")
				Response.Write "<script>img2.width=" & Fix((i / totalnumber) * 400) & ";" & vbCrLf
				Response.Write "txt2.innerHTML=""生成进度:" & FormatNumber(i / totalnumber * 100, 4, -1) & """;" & vbCrLf
				Response.Write "txt3.innerHTML=""　　共有 <B><font color=RED>" & totalnumber & "</font></B> 个 　正在生成第 " & i & " 个"";" & vbCrLf
				Response.Write "img2.title=""(" & i & ")"";</script>" & vbCrLf
				Response.Flush
				Response.Write "<table cellpadding=0 cellspacing=0 border=0 width=95% align=center><tr><td colspan=2 class=forumrow> 　生成 [" & Rsc(1) & "] 排行JS完成。</td></tr></table>"
				Response.Flush
				Rsc.movenext
				i = i + 1
			Loop
		End If
		Rsc.Close
		Set Rsc = Nothing
		CreateClassTop "", "", ""
		Response.Write "<script>img2.width=400;txt2.innerHTML=""100"";</script>"
		Response.Write "<meta http-equiv=""refresh"" content=""1;url='?num=" & totalnumber & "&D=" & d & "&type=ok'"">"
	End Sub
	'*************************************************************
	'函数作用：下载排行 hitsID=0:下载总排行 hitsID=1:本日下载排行
	'*************************************************************
	Private Function CreateDownTop(HitsID, Jname)
		Dim Rs
		Dim SQL
		Dim HtmlString
		Dim OrderName
		Dim SoftName
		Dim JString
		Dim SoftTime
		Select Case CInt(HitsID)
			Case 1
				OrderName = "DayHits"
			Case 2
				OrderName = "WeekHits"
			Case 3
				OrderName = "MonthHits"
			Case Else
				OrderName = "Hits"
		End Select
		Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select Top " & CInt(DownsysClass.mainset(13)) & " softid,sortid,SoftName,SoftVer, " & OrderName & ", SoftTime from NC_SoftInfo where isLock = 0 order by " & OrderName & " desc, SoftTime desc, softid desc"
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			HtmlString = "还没有排行软件!"
		Else
			Do While Not Rs.EOF
				If CInt(DownsysClass.Setting(5)) = 1 Then
				SoftName = "<A HREF='" & DownsysClass.SetupDir & "Software.asp?id=" & Rs(0) & "' title='软件名称: " & Rs(2) & " " & Rs(3) & "<BR>更新时间: " & Rs(5) & "<BR>下载次数: " & Rs(4) & "'>" & DownsysClass.gotTopic(Rs(2) & " " & Rs(3), CInt(DownsysClass.mainset(14))) & "</A>"
				Else
				SoftName = "<A HREF='" & DownsysClass.SetupDir & "Software/Catalog" &Rs(1) & "/" & Rs(0) & ".html' title='软件名称: " & Rs(2) & " " & Rs(3) & "<BR>更新时间: " & Rs(5) & "<BR>下载次数: " & Rs(4) & "'>" & DownsysClass.gotTopic(Rs(2) & " " & Rs(3), CInt(DownsysClass.mainset(14))) & "</A>"
				End If
				SoftTime = Month(Rs("SoftTime")) & "/" & Day(Rs("SoftTime"))
				HtmlString = HtmlString & DownsysClass.mainset(15)
				HtmlString = Replace(HtmlString, "{$SoftTopName}", SoftName)
				HtmlString = Replace(HtmlString, "{$SoftHits}", Rs(4))
				HtmlString = Replace(HtmlString, "{$SoftTime}", SoftTime)
				Rs.movenext
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		JString = "document.write (" & Chr(34) & " " & HtmlString & " " & Chr(34) & ");"
		CreateJsFile JString, Jname
	End Function
	'*************************************************************
	'函数作用：软件分类排行
	'*************************************************************
	Private Function CreateSortingTop(sortid, rootid, depth)
		Dim Rs
		Dim SQL
		Dim HtmlString
		Dim SortingTopName
		Dim JString
		Dim Jname
		Dim SoftTime
		Jname = "ThisTop" & sortid & ".JS"
		If sortid = "" Then
			SQL = "select Top " & CInt(DownsysClass.mainset(13)) & " * from NC_softinfo where isLock=0 order by Hits Desc, SoftTime Desc, softid Desc"
		Else
			If depth = 0 Then
				SQL = "select Top " & CInt(DownsysClass.mainset(13)) & " * from NC_softinfo where isLock=0 and rootid=" & rootid & " order by Hits Desc, SoftTime Desc, softid Desc"
			Else
				Dim Rss, AllSortID, ParentStr, i
	        		Set Rss = DownsysClass.Execute("select * from NC_SoftSort where strParent like '%"& sortid &"%'")
	        		If Rss.EOF And Rss.bof Then
	                		AllSortID = sortid
	        		Else
	                		Do While Not Rss.eof
	                        	ParentStr = Split(Rss("strParent"), ",")
					For i = 0 To UBound(ParentStr)
						If CLng(ParentStr(i)) = sortid Then
							AllSortID = AllSortID & Rss("sortid") &","
							Exit For
						End If
					Next
	                		Rss.movenext
	                		loop
	                		AllSortID = AllSortID & sortid
	        		End If
				Rss.Close
        			Set Rss = Nothing
                        	SQL = "select Top " & CInt(DownsysClass.mainset(13)) & " * from NC_softinfo where isLock=0 And sortid in (" & AllSortID & ") order by Hits Desc, SoftTime Desc, softid Desc"
			End If
		End If
		Set Rs = Server.CreateObject("adodb.recordset")
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			HtmlString = "还没有排行软件!"
		Else
			Do While Not Rs.EOF
				If CInt(DownsysClass.Setting(5)) = 1 Then
				SortingTopName = "<A HREF='" & DownsysClass.SetupDir & "Software.asp?id=" & Rs("softid") & "' title='软件名称: " & Rs("SoftName") & " " & Rs("SoftVer") & "<BR>更新时间: " & Rs("SoftTime") & "<BR>下载次数: " & Rs("Hits") & "'>" & DownsysClass.gotTopic(Rs("SoftName") & " " & Rs("SoftVer"), CInt(DownsysClass.mainset(14))) & "</A>"
				Else
				SortingTopName = "<A HREF='" & DownsysClass.SetupDir & "Software/Catalog" & Rs("sortid") & "/" & Rs("softid") & ".html' title='软件名称: " & Rs("SoftName") & " " & Rs("SoftVer") & "<BR>更新时间: " & Rs("SoftTime") & "<BR>下载次数: " & Rs("Hits") & "'>" & DownsysClass.gotTopic(Rs("SoftName") & " " & Rs("SoftVer"), CInt(DownsysClass.mainset(14))) & "</A>"
				End If
				SoftTime = Month(Rs("SoftTime")) & "/" & Day(Rs("SoftTime"))
				HtmlString = HtmlString & DownsysClass.mainset(15)
				HtmlString = Replace(HtmlString, "{$SoftTopName}", SortingTopName)
				HtmlString = Replace(HtmlString, "{$SoftHits}", Rs("Hits"))
				HtmlString = Replace(HtmlString, "{$SoftTime}", SoftTime)
				Rs.movenext
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		JString = "document.write (" & Chr(34) & " " & HtmlString & " " & Chr(34) & ");"
		CreateJsFile JString, Jname
	End Function
	'*************************************************************
	'函数作用：生成JS文件
	'*************************************************************
	Private Function CreateJsFile(JString, Jname)
		Dim CreateHtml
		Dim FSO
		Set FSO = Server.CreateObject("ADODB.STREAM")
		CreateHtml = Server.MapPath(DownsysClass.SetupDir & "JS/SoftTop/" & Jname)
			With FSO
				.Open
				.Charset = "GB2312"
				.WriteText JString
				.SaveToFile CreateHtml,2
				.Close
			End With 						
		Set FSO = Nothing
	End Function
	'*************************************************************
	'函数作用：生成JS文件
	'*************************************************************
	Private Function CreateJsFiles(JString, Jname)
		Dim CreateHtml
		Dim FSO
		Set FSO = Server.CreateObject("ADODB.STREAM")
		CreateHtml = Server.MapPath(DownsysClass.SetupDir & "JS/ArticleTop/" & Jname)
			With FSO
				.Open
				.Charset = "GB2312"
				.WriteText JString
				.SaveToFile CreateHtml,2
				.Close
			End With 
		Set FSO = Nothing
	End Function
	'*************************************************************
	'函数作用：热门文章 hitsID=0:总浏览排行文章 hitsID=1:本日浏览排行
	'*************************************************************
	Private Function CreateArticleTop(HitsID, Jname)
		Dim Rs
		Dim SQL
		Dim HtmlString
		Dim OrderName
		Dim ArticleTitle
		Dim JString
		Dim InfoTime
		Select Case CInt(HitsID)
			Case 1
				OrderName = "DayHits"
			Case 2
				OrderName = "WeekHits"
			Case 3
				OrderName = "MonthHits"
			Case Else
				OrderName = "Hits"
		End Select
		Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select Top " & CInt(DownsysClass.mainset(16)) & " id,classid,Title, " & OrderName & ", InfoTime from NC_Article where isLock = 0 order by " & OrderName & " desc, InfoTime desc, id desc"
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			HtmlString = "还没有排行文章!"
		Else
			Do While Not Rs.EOF
				If CInt(DownsysClass.Setting(5)) = 1 Then
				ArticleTitle = "<A HREF='" & DownsysClass.SetupDir & "Article.asp?id=" & Rs(0) & "' title='文章标题: " & Rs(2) & "<BR>更新时间: " & Rs(4) & "<BR>浏览次数: " & Rs(3) & "'>" & DownsysClass.gotTopic(Rs(2), CInt(DownsysClass.mainset(17))) & "</A>"
				Else
				ArticleTitle = "<A HREF='" & DownsysClass.SetupDir & "Article/Catalog" & Rs(1) & "/" & Rs(0) & ".html' title='文章标题: " & Rs(2) & "<BR>更新时间: " & Rs(4) & "<BR>浏览次数: " & Rs(3) & "'>" & DownsysClass.gotTopic(Rs(2), CInt(DownsysClass.mainset(17))) & "</A>"
				End If
				InfoTime = Month(Rs("InfoTime")) & "/" & Day(Rs("InfoTime"))
				HtmlString = HtmlString & DownsysClass.mainset(18)
				HtmlString = Replace(HtmlString, "{$ArticleTitle}", ArticleTitle)
				HtmlString = Replace(HtmlString, "{$ArticleHits}", Rs(3))
				HtmlString = Replace(HtmlString, "{$InfoTime}", InfoTime)
				Rs.movenext
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		JString = "document.write (" & Chr(34) & " " & HtmlString & " " & Chr(34) & ");"
		CreateJsFiles JString, Jname
	End Function
	'*************************************************************
	'函数作用：文章分类排行
	'*************************************************************
	Private Function CreateClassTop(classid, rootid, depth)
		Dim Rs
		Dim SQL
		Dim HtmlString
		Dim SortingTopName
		Dim JString
		Dim Jname
		Dim InfoTime
		Jname = "ThisTop" & classid & ".JS"
		If classid = "" Then
			SQL = "select Top " & CInt(DownsysClass.mainset(16)) & " * from NC_Article where isLock=0 order by Hits Desc, InfoTime Desc, id Desc"
		Else
			If depth = 0 Then
				SQL = "select Top " & CInt(DownsysClass.mainset(16)) & " * from NC_Article where isLock=0 and rootid=" & rootid & " order by Hits Desc, InfoTime Desc, id Desc"
			Else
				Dim Rss, AllClassID, ParentStr, i
	        		Set Rss = DownsysClass.Execute("select * from NC_Class where strParent like '%"& classid &"%'")
	        		If Rss.EOF And Rss.bof Then
	                		AllClassID = classid
	        		Else
	                		Do While Not Rss.eof
	                       		ParentStr = Split(Rss("strParent"), ",")
					For i = 0 To UBound(ParentStr)
						If CLng(ParentStr(i)) = classid Then
							AllClassID = AllClassID & Rss("classid") &","
							Exit For
						End If
					Next
	                		Rss.movenext
	                		loop
	                		AllClassID = AllClassID & classid
	        		End If
				Rss.Close
        			Set Rss = Nothing
                        	SQL = "select Top " & CInt(DownsysClass.mainset(16)) & " * from NC_Article where isLock=0 And classid in (" & AllClassID & ") order by Hits Desc, InfoTime Desc, id Desc"
			End If
		End If
		Set Rs = Server.CreateObject("adodb.recordset")
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			HtmlString = "还没有排行文章!"
		Else
			Do While Not Rs.EOF
				If CInt(DownsysClass.Setting(5)) = 1 Then
				SortingTopName = "<A HREF='" & DownsysClass.SetupDir & "Article.asp?ID=" & Rs("id") & "' title='文章标题: " & Rs("Title") & "<BR>更新时间: " & Rs("InfoTime") & "<BR>阅读次数: " & Rs("Hits") & "'>" & DownsysClass.gotTopic(Rs("Title"), CInt(DownsysClass.mainset(17))) & "</A>"
				Else
				SortingTopName = "<A HREF='" & DownsysClass.SetupDir & "Article/Catalog" & Rs("classid") & "/" & Rs("id") & ".html' title='软件名称: " & Rs("Title") & "<BR>更新时间: " & Rs("InfoTime") & "<BR>阅读次数: " & Rs("Hits") & "'>" & DownsysClass.gotTopic(Rs("Title"), CInt(DownsysClass.mainset(17))) & "</A>"
				End If
				InfoTime = Month(Rs("InfoTime")) & "/" & Day(Rs("InfoTime"))
				HtmlString = HtmlString & DownsysClass.mainset(18)
				HtmlString = Replace(HtmlString, "{$ArticleTitle}", SortingTopName)
				HtmlString = Replace(HtmlString, "{$ArticleHits}", Rs("Hits"))
				HtmlString = Replace(HtmlString, "{$InfoTime}", InfoTime)
				Rs.movenext
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		JString = "document.write (" & Chr(34) & " " & HtmlString & " " & Chr(34) & ");"
		CreateJsFiles JString, Jname
	End Function
End Class
%>