<%
Class Create_Article_Cls
	Private Rs, SQL, Rss, SQLS, total, CreateHtml, FSO, objFSO, NewFolderPath
	Private ArticleID, classid, rootid, depth, ClassName, ParentID, strParent, Child
	Private DownloadClass_Ads, Source, Writer, AllHits, Topic, Content
	Private action
	Private Rs1, i, j, k
	Private ArticleTypeSrt
	Private NowStats
	Private HtmlTitle
	Private Style_CSS
	Private HtmlTempStr
	Private Title, InfoTime
	Private stype, ArtType, ii
	Private TempString
	Private HtmlTemplate

	Private Sub Class_Initialize()
		Set Rs = Server.CreateObject("ADODB.Recordset")
		Set DownloadClass_Ads = New Adcolumn_Cls
		DownsysClass.LoadTemplates ("article")
	End Sub

	Private Sub Class_Terminate()
		If IsObject(Conn) Then
			Conn.Close
			Set Conn = Nothing
		End If
		If IsObject(DownloadClass_Ads) Then
			Set DownloadClass_Ads = Nothing
		End If
	End Sub
	'*************************************************************
	'函数作用：生成全部文章
	'*************************************************************
	Public Sub GetArticles()
		DownsysClass.admin_header
		Server.ScriptTimeout = 99999
		Set NC_Admin = New Check
		NC_Admin.AdminChk = "35"
		If Not(DownsysClass.IsObjectFSO(DownsysClass.Script_FSO) And CInt(DownsysClass.Setting(5)) = 0 ) Then
			NC_Admin.Error_Msg ("<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)或你后台没有选择为html方式</font></b>")
			DownsysClass.admin_footer
			Response.End
		End If
		Response.Write "<table width=""400"" border=""0"" cellspacing=""1"" cellpadding=""1"">" & vbCrLf
		Response.Write "<tr> " & vbCrLf
		Response.Write "<td align=center> <span id=txt2 name=txt2 style=""font-size:9pt"">正在生成文件请耐心等待……</span>   <span id=txt3 name=txt3 style=""font-size:9pt""></span></td></tr>" & vbCrLf
		Response.Write "</table>" & vbCrLf
		Response.Flush
		Set Rss = Server.CreateObject("adodb.recordset")
		SQLs = "select id from [NC_Article] where isLock=0"
		Rss.Open SQLs, Conn, 1, 1
		total = Rss.recordcount
		If total = 0 Then
			NC_Admin.Error_Msg ("<script>txt2.innerHTML="""";txt3.innerHTML="""";</script> 没有你选择范围内文章信息页可生成！")
			DownsysClass.admin_footer
			Response.End
		End If
			Rss.MoveFiRst
			k = 1
			Do While Not Rss.EOF
				ArticleID = Rss("id")
				GetArticle(ArticleID) '生成文章信息html页
				Response.Write "<script>txt2.innerHTML=""生成进度:" & FormatNumber(k / total * 100, 2, -1) & "%"";" & vbCrLf
				Response.Write "txt3.innerHTML=""共有 <B><font color=RED>" & total & "</font></B> 个 　正在生成第 " & k & " 个"";</script>" & vbCrLf
				Response.Flush
				Rss.movenext
				DownsysClass.SqlQueryNum = DownsysClass.SqlQueryNum + 1
				k = k + 1
			Loop
		Rss.Close
		Set Rss = Nothing
		Response.Write "<script>txt2.innerHTML="""";txt3.innerHTML="""";</script>"
		NC_Admin.Succeed_Msg ("共有 <B><font color=RED>" & total & "</font></B> 个文章信息页面生成完毕！")
		DownsysClass.admin_footer
	End Sub
	'*************************************************************
	'函数作用：生成文章
	'*************************************************************
	Public Sub GetArticle(ArticleID)
		On Error Resume Next
		Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select * from NC_Article where id = " & ArticleID
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			Response.Write "<p align=center>还没有找到相关文章！</p>"
			Exit Sub
		Else
			Topic = Rs("Title")
			Content = Rs("Content")
			InfoTime = Rs("InfoTime")
			Writer = Rs("Writer")
			Source = Rs("Source")
			AllHits = Rs("Hits")
			classid = Rs("classid")
		End If
		Rs.Close
		Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select classid,rootid,ClassName,depth,ParentID,strParent from [NC_Class] where classid = " & classid
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			Response.Write "Sorry！没有找到任何文章信息。或者您选择了错误的系统参数!"
			Exit Sub
		Else
			ClassName = Rs("ClassName")
			classid = Rs("classid")
			depth = Rs("depth")
			ParentID = Rs("ParentID")
			strParent = Rs("strParent")
		End If
		Rs.Close
		Dim temphtml, NowStats, HtmlTitle, ArticleIndex
		Dim TempTopStr, TempFootStr, Style_CSS
		If CInt(DownsysClass.Setting(5)) = 1 Then
		ArticleIndex = "<A HREF='" & DownsysClass.SetupDir & "Article_Index.Asp'>" & DownsysClass.TempSet(7) & "</A>→"
		Else
		ArticleIndex = "<A HREF='" & DownsysClass.SetupDir & "Article/Index.html'>" & DownsysClass.TempSet(7) & "</A>→"
		End If
		NowStats = ArticleIndex & NowStation(classid, ClassName, ParentID, strParent) & "→" & Topic
		HtmlTitle = Topic
		If Len(DownsysClass.temphtml(0)) < 50 Then
			TempTopStr = DownsysClass.mainhtml(0) & DownsysClass.mainhtml(1) & DownsysClass.mainhtml(2) & DownsysClass.mainhtml(3)
		Else
			TempTopStr = DownsysClass.temphtml(0)
		End If
		If Len(DownsysClass.temphtml(3)) = 0 Then
			TempFootStr = DownsysClass.mainhtml(4)
		Else
			TempFootStr = DownsysClass.temphtml(3)
		End If
		temphtml = TempTopStr & DownsysClass.temphtml(1) & DownsysClass.temphtml(2) & DownsysClass.temphtml(3) & TempFootStr
		temphtml = Replace(temphtml, "{$TopMeun}", DownsysClass.mainset(9))
		temphtml = Replace(temphtml, "{$Width}", DownsysClass.mainset(0))
		temphtml = Replace(temphtml, "{$FootMeun}", DownsysClass.mainset(44))
		temphtml = Replace(temphtml, "{$NavMenu}", DownsysClass.ClassMenu)
		temphtml = Replace(temphtml, "{$Style_CSS}", DownsysClass.Style_CSS)
		temphtml = Replace(temphtml, "{$NowStats}", NowStats)
		temphtml = Replace(temphtml, "{$Title}", HtmlTitle)
		temphtml = Replace(temphtml, "{$ClassID}", classid)
		temphtml = Replace(temphtml, "{$ArticleID}", articleid)
		temphtml = Replace(temphtml, "{$Topic}", Topic)
		temphtml = Replace(temphtml, "{$Content}", Content)
		temphtml = Replace(temphtml, "{$InfoTime}", InfoTime)
		temphtml = Replace(temphtml, "{$AllHits}", AllHits)
		temphtml = Replace(temphtml, "{$Writer}", Writer)
		temphtml = Replace(temphtml, "{$Source}", Source)
		'temphtml = Replace(temphtml, "{$HotArticle}", GetHotArticle)
		temphtml = Replace(temphtml, "{$KeyArticle}", GetKeyArticle(Topic, articleid))
		temphtml = Replace(temphtml, "{$KeySoft}", GetKeySoftware(Topic))
		temphtml = Replace(temphtml, "{$FormerArticle}", FormerArticle(articleid))
		temphtml = Replace(temphtml, "{$NextArticle}", NextArticle(articleid))
		temphtml = Replace(temphtml, "{$Adcolumn(0)}", DownloadClass_Ads.RunScriptAds(6))
		temphtml = Replace(temphtml, "{$Adcolumn(1)}", DownloadClass_Ads.BannerAds(6))
		temphtml = Replace(temphtml, "{$Adcolumn(2)}", DownloadClass_Ads.AdsColumn(6, 2))
		temphtml = Replace(temphtml, "{$Adcolumn(3)}", DownloadClass_Ads.AdsColumn1(6, 3))
		temphtml = Replace(temphtml, "{$Adcolumn(6)}", DownloadClass_Ads.AdsColumn(6, 7))
		temphtml = Replace(temphtml, "{$Adcolumn(7)}", DownloadClass_Ads.AdsColumn(6, 8))
		temphtml = Replace(temphtml, "{$Adcolumn(4)}", DownloadClass_Ads.ScriptFloatAds(6))
		temphtml = Replace(temphtml, "{$Adcolumn(5)}", DownloadClass_Ads.ScriptFixedAds(6))
		HtmlTemplate = temphtml
		Set Rs = Nothing
		NewFolderPath = Server.MapPath(DownsysClass.SetupDir & "Article/Catalog" & ClassID)
		Set objFSO = Server.CreateObject(DownsysClass.Script_FSO)
		If Not objFSO.FolderExists(NewFolderPath) Then
			objFSO.CreateFolder (NewFolderPath)
		End If
		objFSO.Close
		Set objFSO = Nothing
		Set FSO = Server.CreateObject("ADODB.STREAM")
		CreateHtml = Server.MapPath(DownsysClass.SetupDir & "Article/Catalog" & ClassID & "/" & ArticleID & ".html")
		With FSO
			.Open
			.Charset = "GB2312"
			.WriteText HtmlTemplate
			.SaveToFile CreateHtml,2
			.Close
		End With
		Set FSO = Nothing
	End Sub
	'*************************************************************
	'函数作用：删除文章
	'*************************************************************
	Public Sub DelArticle(ArticleID)
		Dim FilePath
                Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select * from NC_Article where id = " & ArticleID
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			Response.Write "<p align=center>还没有找到相关文章！</p>"
			Exit Sub
		Else
			ClassID = Rs("classid")
		End If
		Rs.Close
		Set Rs = Nothing
		If CInt(DownsysClass.Setting(5)) = 0 Then
			FilePath = Server.MapPath(DownsysClass.SetupDir & "Article/Catalog" & ClassID & "/" & ArticleID & ".html")
			Set FSO = Server.CreateObject(DownsysClass.Script_FSO)
			If FSO.FileExists(FilePath) Then
				FSO.DeleteFile FilePath
			End If
			Set FSO = Nothing
		End If
        End Sub
	'*************************************************************
	'函数作用：当前位置
	'*************************************************************
	Private Function NowStation(classid, ClassName, ParentID, strParent)
		Dim Rs, SQL, HtmlString
		Set Rs = Server.CreateObject("adodb.recordset")
		If ParentID <> 0 And Len(strParent) <> 0 Then
			SQL = "select classid,ClassName from [NC_Class] where classid in(" & strParent & ")"
			Rs.Open SQL, Conn, 1, 1
			If Not (Rs.EOF And Rs.bof) Then
				Do While Not Rs.EOF
					If CInt(DownsysClass.Setting(5)) = 0 Then
						HtmlString = HtmlString & "<a href='" & DownsysClass.SetupDir & "Listing/Catalog" & Rs(0) & "/Listing_indate_Desc_1.html'>" & Rs(1) & "</a>→"
					Else
						HtmlString = HtmlString & "<a href='" & DownsysClass.SetupDir & "Listing.Asp?classid=" & Rs(0) & "'>" & Rs(1) & "</a>→"
					End If
					Rs.movenext
				Loop
			End If
			Rs.Close
			Set Rs = Nothing
		End If
		If CInt(DownsysClass.Setting(5)) = 0 Then
			HtmlString = HtmlString & "<a href='" & DownsysClass.SetupDir & "Listing/Catalog" & classid & "/Listing_indate_Desc_1.html'>" & ClassName & "</a>"
		Else
			HtmlString = HtmlString & "<a href='" & DownsysClass.SetupDir & "Listing.Asp?classid=" & classid & "'>" & ClassName & "</a>"
		End If
		NowStation = HtmlString
	End Function
	'*************************************************************
	'函数作用：相关文章
	'*************************************************************
	Private Function GetKeyArticle(Keys, keyid)
		Dim Rss, SQL, HtmlString, Topic, InfoTime
		Set Rss = Server.CreateObject("adodb.recordset")
		SQL = "select top " & CInt(DownsysClass.TempSet(0)) & " id,classid,title,Hits,InfoTime,islock from NC_Article where title like '%" & Left((Keys), 4) & "%' and  ID <> " & keyid & " and islock = 0 "
		Rss.Open SQL, Conn, 1, 1
		If Not (Rss.EOF And Rss.bof) Then
			Do While Not Rss.EOF
				HtmlString = HtmlString & DownsysClass.TempSet(2)
				If CInt(DownsysClass.Setting(5)) = 0 Then
					Topic = "<A HREF='" & DownsysClass.SetupDir & "Article/Catalog" & Rss("classid") & "/" & Rss("id") & ".html'>" & DownsysClass.gotTopic(Rss("Title"), CInt(DownsysClass.TempSet(1))) & "</A>"
				Else
					Topic = "<A HREF='" & DownsysClass.SetupDir & "Article.asp?id=" & Rss("id") & "'>" & DownsysClass.gotTopic(Rss("Title"), CInt(DownsysClass.TempSet(1))) & "</A>"
				End If
				'InfoTime = Month(Rss("InfoTime")) & "/" & Day(Rss("InfoTime"))
				'HtmlString = Replace(HtmlString, "{$Hits}", Rss("Hits"))
				'HtmlString = Replace(HtmlString, "{$InfoTime}", InfoTime)
				HtmlString = Replace(HtmlString, "{$Topic}", Topic)
				Rss.movenext
			Loop
		End If
		Rss.Close
		Set Rss = Nothing
		GetKeyArticle = HtmlString
	End Function

	Private Function FormerArticle(articleid)
		Dim Rss, SQL, HtmlString
		Set Rss = Server.CreateObject("adodb.recordset")
		SQL = "select id,classid,title from NC_Article where id = " & articleid - 1
		Rss.Open SQL, Conn, 1, 1
		If Rss.EOF And Rss.bof Then
			HtmlString = DownsysClass.TempSet(3)
		Else
			If CInt(DownsysClass.Setting(5)) = 0 Then
				HtmlString = "<a href=" & DownsysClass.SetupDir & "Article/Catalog" & Rss("classid") & "/" & Rss("id") & ".html>" & Rss("title") & "</a>"
			Else
				HtmlString = "<a href=" & DownsysClass.SetupDir & "Article.Asp?id=" & Rss("id") & ">" & Rss("title") & "</a>"
			End If
		End If
		Rss.Close
		Set Rss = Nothing
		FormerArticle = HtmlString
	End Function

	Private Function NextArticle(articleid)
		Dim Rss, SQL, HtmlString
		Set Rss = Server.CreateObject("adodb.recordset")
		SQL = "select id,classid,title from NC_Article where id = " & articleid + 1
		Rss.Open SQL, Conn, 1, 1
		If Rss.EOF And Rss.bof Then
			HtmlString = DownsysClass.TempSet(3)
		Else
			If CInt(DownsysClass.Setting(5)) = 0 Then
				HtmlString = "<a href=" & DownsysClass.SetupDir & "Article/Catalog" & Rss("classid") & "/" & Rss("id") & ".html>" & Rss("title") & "</a>"
			Else
				HtmlString = "<a href=" & DownsysClass.SetupDir & "Article.Asp?id=" & Rss("id") & ">" & Rss("title") & "</a>"
			End If
		End If
		Rss.Close
		Set Rss = Nothing
		NextArticle = HtmlString
	End Function


	'*************************************************************
	'函数作用：相关软件
	'*************************************************************
	Private Function GetKeySoftware(Keys)
		Dim Rss, SQL, HtmlString, SoftName, SoftTime
		Set Rss = Server.CreateObject("adodb.recordset")
		SQL = "select top " & CInt(DownsysClass.TempSet(0)) & " SoftID,sortid,SoftName,SoftVer,islock from NC_SoftInfo where SoftName like '%" & Left((Keys), 4) & "%' and islock = 0 "
		Rss.Open SQL, Conn, 1, 1
		If Not (Rss.EOF And Rss.bof) Then
			Do While Not Rss.EOF
				HtmlString = HtmlString & DownsysClass.TempSet(6)
				If CInt(DownsysClass.Setting(5)) = 0 Then
					SoftName = "<A HREF='" & DownsysClass.SetupDir & "Software/Catalog" & Rss(1) & "/" & Rss(0) & ".html'>" & DownsysClass.gotTopic(Rss(2) & " " & Rss(3), CInt(DownsysClass.TempSet(1))) & "</A>"
				Else
					SoftName = "<A HREF='" & DownsysClass.SetupDir & "Software.asp?id=" & Rss(0) & "'>" & DownsysClass.gotTopic(Rss(2) & " " & Rss(3), CInt(DownsysClass.TempSet(1))) & "</A>"
				End If
				HtmlString = Replace(HtmlString,"{$SoftName}",SoftName)
				Rss.movenext
			Loop
		End If
		Rss.Close
		Set Rss = Nothing
		GetKeySoftware = HtmlString
	End Function

	'*************************************************************
	'函数作用：热门文章
	'*************************************************************
	Private Function GetHotArticle()
		Dim Rs, SQL, HtmlString, HotTopic, ClassName, InfoTime
		Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select Top " & CInt(DownsysClass.TempSet(4)) & " id,classid,Title, ClassName,InfoTime,Hits from NC_Article where isLock = 0 order by Hits 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 Rs("InfoTime") >= Date Then
					InfoTime = "<FONT color=red>" & Month(Rs("InfoTime")) & "/" & Day(Rs("InfoTime")) & "</FONT >"
				Else
					InfoTime = "<FONT color=#999999>" & Month(Rs("InfoTime")) & "/" & Day(Rs("InfoTime")) & "</FONT >"
				End If
				If CInt(DownsysClass.Setting(5)) = 0 Then
					HotTopic = "<A HREF='" & DownsysClass.SetupDir & "Article/Catalog" & Rs(1) & "/" & Rs(0) & ".html' title='" & Rs(2) & "' class='TableLink'>" & DownsysClass.gotTopic(Rs(2), CInt(DownsysClass.TempSet(5))) & "</A>"
				Else
					HotTopic = "<A HREF='" & DownsysClass.SetupDir & "Article.asp?id=" & Rs(0) & "' title='" & Rs(2) & "' class='TableLink'>" & DownsysClass.gotTopic(Rs(2), CInt(DownsysClass.TempSet(5))) & "</A>"
				End If
				HtmlString = HtmlString & DownsysClass.TempSet(6)
				HtmlString = Replace(HtmlString, "{$HotTopic}", HotTopic)
				HtmlString = Replace(HtmlString, "{$InfoTime}", InfoTime)
				HtmlString = Replace(HtmlString, "{$ArticleHits}", Rs("Hits"))
				Rs.movenext
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		GetHotArticle = HtmlString
	End Function

End Class
%>
