<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<%
Dim DownloadClass
Set DownloadClass = New Create_Listing_Cls
DownloadClass.ArticleList
Set DownloadClass = Nothing
CloseConn

Class Create_Listing_Cls
	Private id, classid, rootid, depth, ClassName, ParentID, strParent, Child
	Private CurrentPage, maxperpage, totalnumber, bookmark, Pcount
	Private order_name, strOrder, ShowPageHtml, HtmlTemplate
	Private DownloadClass_Ads
	Private action
	Private TotalPageNum, WhereSQL

	Private Sub Class_Initialize()
		Set DownloadClass_Ads = New Adcolumn_Cls
		DownsysClass.LoadTemplates ("listing")
		maxperpage = DownsysClass.TempSet(0)
	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 ArticleList()
		Dim Rs, SQL
		Set Rs = Server.CreateObject("adodb.recordset")
		If Not IsNumeric(Request("classid")) And Request("classid") <> "" Then
			Response.Write"错误的系统参数!ID必须是数字"
			Exit Sub
			Response.End
		Else
			ClassID = CLng(Request("classid"))
		End If
		If Not IsEmpty(Request("page")) Then
			CurrentPage = Request("page")
		Else
			CurrentPage = 1
		End If
		If ClassID <> "" Then
			SQL = "select classid,ClassName,rootid,depth,ParentID,strParent,Child from [NC_Class] where classid = " & ClassID
			Rs.Open SQL, Conn, 1, 1
			If Rs.bof And Rs.EOF Then
				Response.Write "Sorry！没有找到任何文章信息。或者您选择了错误的系统参数!"
				Response.End
			Else
				ClassName = Rs("ClassName")
				ClassID = Rs("ClassID")
				rootid = Rs("rootid")
				depth = Rs("depth")
				ParentID = Rs("ParentID")
				strParent = Rs("strParent")
				Child = Rs("Child")
			End If
			Rs.Close
		Else
			classid = ""
			ParentID = ""
			strParent = 0
			Child = ""
			depth = ""
			rootid = ""
			ClassName = DownsysClass.TempSet(11)
		End If
		order_name = Request("order")
		strOrder = Request("order")
		Select Case order_name
			Case "Title"
				order_name = "title"
			Case "Indate"
				order_name = "InfoTime"
			Case "Hits"
				order_name = "Hits"
			Case Else
				order_name = "InfoTime"
				strOrder = "Indate"
		End Select
		Dim temphtml, NowStats, HtmlTitle, ArticleIndex
		Dim TempTopStr, TempFootStr, Style_CSS
		ArticleIndex = "<A HREF='" & DownsysClass.SetupDir & "Article_Index.Asp'>" & DownsysClass.TempSet(10) & "</A>→"
		If Len(classid) = 0 Then
			NowStats = ArticleIndex & ClassName
		Else
			NowStats = ArticleIndex & NowStation(classid, ClassName, ParentID, strParent)
		End If
		HtmlTitle = ClassName
		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(4)) = 0 Then
			TempFootStr = DownsysClass.mainhtml(4)
		Else
			TempFootStr = DownsysClass.temphtml(5)
		End If
		temphtml = TempTopStr & DownsysClass.temphtml(1) & DownsysClass.temphtml(2) & DownsysClass.temphtml(3) & TempFootStr
		temphtml = Replace(temphtml, "{$NavMenu}", DownsysClass.ClassMenu)
		temphtml = Replace(temphtml, "{$Width}", DownsysClass.mainset(0))
		temphtml = Replace(temphtml, "{$TopMeun}", DownsysClass.mainset(10))
		temphtml = Replace(temphtml, "{$FootMeun}", DownsysClass.mainset(11))
		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, "{$ArticleClass}", ArticleClass(classid, ParentID, Child))
		temphtml = Replace(temphtml, "{$BestArticle}", BestArticle)
		temphtml = Replace(temphtml, "{$PicNews}", PictureNews)
		temphtml = Replace(temphtml, "{$NewPic}", SingleImage("InfoTime"))
		temphtml = Replace(temphtml, "{$HotPic}", SingleImage("Hits"))
		temphtml = Replace(temphtml, "{$ArticleList}", ArticleClassList(classid, rootid, depth, ClassName, order_name, maxperpage, CurrentPage, strOrder))
		temphtml = Replace(temphtml, "{$Adcolumn(0)}", DownloadClass_Ads.RunScriptAds(5))
		temphtml = Replace(temphtml, "{$Adcolumn(1)}", DownloadClass_Ads.BannerAds(5))
		temphtml = Replace(temphtml, "{$Adcolumn(2)}", DownloadClass_Ads.AdsColumn(5, 2))
		temphtml = Replace(temphtml, "{$Adcolumn(3)}", DownloadClass_Ads.AdsColumn(5, 3))
		temphtml = Replace(temphtml, "{$Adcolumn(6)}", DownloadClass_Ads.AdsColumn(5, 7))
		temphtml = Replace(temphtml, "{$Adcolumn(7)}", DownloadClass_Ads.AdsColumn(5, 8))
		temphtml = Replace(temphtml, "{$Adcolumn(4)}", DownloadClass_Ads.ScriptFloatAds(5))
		temphtml = Replace(temphtml, "{$Adcolumn(5)}", DownloadClass_Ads.ScriptFixedAds(5))
		Response.Write temphtml
	End Sub
	'*************************************************************
	'函数作用：文章列表
	'*************************************************************
	Private Function ArticleClassList(classid, rootid, depth, ClassName, order_name, maxperpage, CurrentPage, strOrder)
		Dim Rs, SQL
		Dim HtmlString, i, Icon, isCommend
		Dim Title, InfoTime, j
		Set Rs = Server.CreateObject("adodb.recordset")
		If Len(classid) = 0 Then
			WhereSQL = "where isLock=0"
		Else
			If depth = 0 Then
				WhereSQL = "where isLock=0 and rootid = " & rootid & ""
			Else
				Dim Rs_c, AllClassID, ParentStr
				Set Rs_c = DownsysClass.Execute("select * from NC_Class where strParent like '%"& classid &"%'")
				If Rs_c.EOF And Rs_c.bof Then
					AllClassID = classid
				Else
					Do While Not Rs_c.EOF
						ParentStr = Split(Rs_c("strParent"), ",")
						For i = 0 To UBound(ParentStr)
							If CLng(ParentStr(i)) = classid Then
								AllClassID = AllClassID & Rs_c("classid") &","
							End If
						Next
						Rs_c.movenext
					Loop
					AllClassID = AllClassID & classid
				End If
				Rs_c.Close
				Set Rs_c = Nothing
				WhereSQL = "where isLock=0 and classid in (" & AllClassID & ")"
			End If
		End If
		TotalNumber = Conn.Execute("Select count(id) from [NC_Article] "& WhereSQL &"")(0)
		TotalPageNum = CInt(TotalNumber / maxperpage) '得到总页数
		If TotalPageNum < TotalNumber / maxperpage Then TotalPageNum = TotalPageNum + 1
		If CurrentPage < 1 Then CurrentPage = 1
		If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
		SQL = "select * from NC_Article "& WhereSQL &" order by isTop Desc, " & order_name & " Desc, ID Desc"
		Rs.Open SQL, Conn, 1
		If CInt(DownsysClass.Setting(5)) = 0 Then
			HtmlString = DownsysClass.TempSet(12)
		Else
			HtmlString = DownsysClass.TempSet(13)
		End If
		HtmlString = Replace(HtmlString, "{$ClassID}", classid)
		If Rs.bof And Rs.EOF Then
			HtmlString = HtmlString & "<p align=center>还没有找到任何文章！</p>"
		Else
			If TotalPageNum > 1 Then Rs.Move (CurrentPage - 1) * maxperpage
			i = 0
			j = (CurrentPage - 1) * maxperpage + 1
			Do While Not Rs.EOF And i < CInt(maxperpage)
				HtmlString = HtmlString & DownsysClass.TempSet(14)
				If CInt(Rs("isTop")) = 1 Then
					Icon = "<img src='" & DownsysClass.SetupDir & "images/isTop.gif' align='absmiddle'>"
				Else
					Icon = "<img src='" & DownsysClass.SetupDir & DownsysClass.TempDir & "icon2.gif' align='absmiddle'>"
				End If
				If CInt(Rs("isCommend")) = 0 Then
					isCommend = ""
				Else
					isCommend = DownsysClass.TempSet(16)
				End If
				If CInt(DownsysClass.Setting(5)) = 0 Then
					Title = "<A HREF='" & DownsysClass.SetupDir & "Article/Catalog" & Rs("classid") & "/" & Rs("ID") & ".html'>" & Trim(Rs("Title")) & "</a> "
				Else
					Title = "<A HREF='" & DownsysClass.SetupDir & "Article.Asp?id=" & Rs("ID") & "'>" & Trim(Rs("Title")) & "</a> "
				End If
				If Rs("InfoTime") >= Date Then
					InfoTime = "<FONT color=red>" & FormatDateTime(Rs("InfoTime"), 2) & "</FONT >"
				Else
					InfoTime = FormatDateTime(Rs("InfoTime"), 2)
				End If
				HtmlString = Replace(HtmlString, "{$Title}", Title)
				HtmlString = Replace(HtmlString, "{$InfoTime}", InfoTime)
				HtmlString = Replace(HtmlString, "{$Hits}", Rs("Hits"))
				HtmlString = Replace(HtmlString, "{$Commend}", isCommend)
				HtmlString = Replace(HtmlString, "{$Icon}", Icon)
				HtmlString = Replace(HtmlString, "{$Sequence}", j)
				Rs.movenext
				i = i + 1
				j = j + 1
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		HtmlString = HtmlString & DownsysClass.TempSet(15)
		HtmlString = Replace(HtmlString, "{$ShowPage}", ShowPage(ClassName, maxperpage, CurrentPage, totalnumber))
		ArticleClassList = HtmlString
	End Function
	'*************************************************************
	'函数作用：推荐文章
	'*************************************************************
	Private Function BestArticle()
		Dim Rs, SQL, HtmlString, ArticleTitle, ClassName, InfoTime, InfoDate
		Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select Top " & CInt(DownsysClass.TempSet(4)) & " id,classid,Title, ClassName,InfoTime,Hits,isTop from NC_Article where isLock = 0 And isCommend = 1 order by isTop 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 >"
					InfoDate = "<FONT color=red>" & FormatDateTime(Rs("InfoTime"), 2) & "</FONT >"
				Else
					InfoTime = "<FONT color=#999999>" & Month(Rs("InfoTime")) & "/" & Day(Rs("InfoTime")) & "</FONT >"
					InfoDate = "<FONT color=#999999>" & FormatDateTime(Rs("InfoTime"), 2) & "</FONT >"
				End If
				ArticleTitle = "<A HREF='" & DownsysClass.SetupDir & "Article.asp?id=" & Rs(0) & "' title='文章标题：" & Rs(2) & "<BR>更新时间：" & Rs(4) & "<BR>浏览次数：" & Rs(5) & "' class='TableLink'>" & DownsysClass.gotTopic(Rs(2), CInt(DownsysClass.TempSet(5))) & "</A>"
				ClassName = "<A HREF='" & DownsysClass.SetupDir & "Listing.asp?classid=" & Rs(1) & "' title='" & Rs("ClassName") & "'>" & Rs("ClassName") & "</A>"
				HtmlString = HtmlString & DownsysClass.TempSet(6)
				HtmlString = Replace(HtmlString, "{$BestTopic}", ArticleTitle)
				HtmlString = Replace(HtmlString, "{$ClassName}", ClassName)
				HtmlString = Replace(HtmlString, "{$InfoTime}", InfoTime)
				HtmlString = Replace(HtmlString, "{$ArticleHits}", Rs("Hits"))
				HtmlString = Replace(HtmlString, "{$InfoDate}", InfoDate)
				Rs.movenext
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		BestArticle = HtmlString
	End Function
	'*************************************************************
	'函数作用：图文
	'*************************************************************
	Private Function PictureNews()
		Dim Rs, SQL, HtmlString, ArticleTitle, ClassName, InfoTime, InfoDate
		Set Rs = Server.CreateObject("adodb.recordset")
		SQL = "select Top " & CInt(DownsysClass.TempSet(7)) & " id,classid,Title, ClassName,InfoTime,Hits from NC_Article where isLock = 0 And isImg = 1 order by 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 >"
					InfoDate = "<FONT color=red>" & FormatDateTime(Rs("InfoTime"), 2) & "</FONT >"
				Else
					InfoTime = "<FONT color=#999999>" & Month(Rs("InfoTime")) & "/" & Day(Rs("InfoTime")) & "</FONT >"
					InfoDate = "<FONT color=#999999>" & FormatDateTime(Rs("InfoTime"), 2) & "</FONT >"
				End If
				ArticleTitle = "<A HREF='" & DownsysClass.SetupDir & "Article.asp?id=" & Rs(0) & "' title='文章标题：" & Rs(2) & "<BR>更新时间：" & Rs(4) & "<BR>浏览次数：" & Rs(5) & "' class='TableLink'>" & DownsysClass.gotTopic(Rs(2), CInt(DownsysClass.TempSet(8))) & "</A>"
				ClassName = "<A HREF='" & DownsysClass.SetupDir & "Listing.asp?classid=" & Rs(1) & "' title='" & Rs("ClassName") & "'>" & Rs("ClassName") & "</A>"
				HtmlString = HtmlString & DownsysClass.TempSet(9)
				HtmlString = Replace(HtmlString, "{$Topic}", ArticleTitle)
				HtmlString = Replace(HtmlString, "{$ClassName}", ClassName)
				HtmlString = Replace(HtmlString, "{$InfoTime}", InfoTime)
				HtmlString = Replace(HtmlString, "{$ArticleHits}", Rs("Hits"))
				HtmlString = Replace(HtmlString, "{$InfoDate}", InfoDate)
				Rs.movenext
			Loop
		End If
		Rs.Close
		Set Rs = Nothing
		PictureNews = HtmlString
	End Function

	Private Function SingleImage(orders)
		Dim Rs, SQL, HtmlString, Topic, images, OrderName
		Set Rs = Server.CreateObject("adodb.recordset")
		If orders = "Hits" Then
			OrderName = "Hits"
		Else
			OrderName = "InfoTime"
		End If
		SQL = "select Top 1 id,classid,title,images from NC_Article where isLock = 0 And images <>'' order by " & OrderName & " desc, id desc"
		Rs.Open SQL, Conn, 1, 1
		If Rs.bof And Rs.EOF Then
			HtmlString = "<img src=""" & DownsysClass.SetupDir & "images/NoPic.jpg"" width='" & DownsysClass.TempSet(18) & "' height='" & DownsysClass.TempSet(19) & "' border=0>"
		Else
			images = "<A HREF='" & DownsysClass.SetupDir & "Article.Asp?id=" & Rs("id") & "' title='" & Rs("title") & "'><img src='" & Rs("images") & "' width='" & DownsysClass.TempSet(18) & "' height='" & DownsysClass.TempSet(19) & "' border='0'></A>"
			HtmlString = images
		End If
		Rs.Close
		Set Rs = Nothing
		SingleImage = HtmlString
	End Function
	'*************************************************************
	'函数作用：当然位置
	'*************************************************************
	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
					HtmlString = HtmlString & "<a href='?classid=" & Rs(0) & "'>" & Rs(1) & "</a>→"
					Rs.movenext
				Loop
			End If
			Rs.Close
			Set Rs = Nothing
		End If
		HtmlString = HtmlString & "<a href='?classid=" & classid & "'>" & ClassName & "</a>"
		NowStation = HtmlString
	End Function
	'*************************************************************
	'函数作用：文章分类
	'*************************************************************
	Private Function ArticleClass(classid, ParentID, Child)
		Dim Rs, SQL, HtmlString, ClassName, ListingName
		Set Rs = Server.CreateObject("adodb.recordset")
		HtmlString = DownsysClass.TempSet(1)
		If classid = "" Then
			SQL = "SELECT classid,ClassName,rootid,Child,ArticleNum,Readme FROM NC_Class where depth=0 order by rootid"
		Else
			If Child = 0 Then
				SQL = "SELECT classid,ClassName,rootid,Child,ArticleNum,Readme FROM NC_Class where Parentid=" & ParentID & " order by orders"
			Else
				SQL = "SELECT classid,ClassName,rootid,Child,ArticleNum,Readme FROM NC_Class where Parentid=" & classid & " order by orders"
			End If
		End If
		Rs.Open SQL, Conn, 1, 1
		If Rs.EOF And Rs.bof Then
			HtmlString = HtmlString & "<p align=center>还没有任何分类！</p>"
		Else
			Do While Not Rs.EOF
				HtmlString = HtmlString & DownsysClass.TempSet(2)

				If CStr(Rs("classid")) = CStr(classid) Then
					ListingName = "<A href='" & DownsysClass.SetupDir & "Listing/Catalog" & Rs("classid") & "/Listing_indate_Desc_1.html' class=ShowLink><B><FONT color=red>" & Rs("ClassName") & "</font></B></a>"
					ClassName = "<A href='?classid=" & Rs("classid") & "' class=ShowLink><B><FONT color=red>" & Rs("ClassName") & "</font></B></a>"
				Else
					ListingName = "<A href='" & DownsysClass.SetupDir & "Listing/Catalog" & Rs("classid") & "/Listing_indate_Desc_1.html'  title='" & Rs("Readme") & "<BR>共有文章： " & Rs("ArticleNum") & " 篇'>" & Rs("ClassName") & "</a>"
					ClassName = "<A href='?classid=" & Rs("classid") & "'  title='" & Rs("Readme") & "<BR>共有文章： " & Rs("ArticleNum") & " 篇'>" & Rs("ClassName") & "</a>"
				End If
				If CInt(DownsysClass.Setting(5)) = 0 Then
					HtmlString = Replace(HtmlString, "{$ClassName}", ListingName)
				Else
					HtmlString = Replace(HtmlString, "{$ClassName}", ClassName)
				End If
				HtmlString = Replace(HtmlString, "{$ArticleNum}", Rs("ArticleNum"))
				Rs.movenext
			Loop
		End If
		HtmlString = HtmlString & DownsysClass.TempSet(3)
		Rs.Close
		Set Rs = Nothing
		ArticleClass = HtmlString
	End Function
	'*************************************************************
	'函数作用：分页
	'*************************************************************
	Private Function ShowPage(ClassName, maxperpage, CurrentPage, totalnumber)
		Dim n, HtmlString
		If totalnumber Mod maxperpage = 0 Then
			n = totalnumber \ maxperpage
		Else
			n = totalnumber \ maxperpage + 1
		End If
		HtmlString = "<table cellspacing=1 width='100%' border=0><form method=Post action=?classid=" & Request("classid") & "&order=" & Request("order") & "><tr><td align=center> " & vbCrLf
		HtmlString = HtmlString & "<font color='red'>" & ClassName & "</font> "
		If CurrentPage < 2 Then
			HtmlString = HtmlString & "共有 <font COLOR=#FF0000><strong>" & totalnumber & "</strong></font> 篇&nbsp;首 页&nbsp;上一页&nbsp;"
		Else
			HtmlString = HtmlString & "共有 <font COLOR=#FF0000><strong>" & totalnumber & "</strong></font> 篇&nbsp;<a href=?page=1&classid=" & Request("classid") & "&order=" & Request("order") & ">首 页</a>&nbsp;"
			HtmlString = HtmlString & "<a href=?page=" & CurrentPage - 1 & "&classid=" & Request("classid") & "&order=" & Request("order") & ">上一页</a>&nbsp;"
		End If
		If n - CurrentPage < 1 Then
			HtmlString = HtmlString & "下一页&nbsp;尾 页" & vbCrLf
		Else
			HtmlString = HtmlString & "<a href=?page=" & (CurrentPage + 1) & "&classid=" & Request("classid") & "&order=" & Request("order") & ">下一页</a>"
			HtmlString = HtmlString & "&nbsp;<a href=?page=" & n & "&classid=" & Request("classid") & "&order=" & Request("order") & ">尾 页</a>" & vbCrLf
		End If
		HtmlString = HtmlString & "&nbsp;页次：<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
		HtmlString = HtmlString & "&nbsp;转到："
		HtmlString = HtmlString & "<input name=page size=3> <input type=submit name=Submit value='GO'>"
		HtmlString = HtmlString & "</td></tr></FORM></table>" & vbCrLf
		ShowPage = HtmlString
	End Function

End Class
%>
