<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/md5.asp"-->
<%
Dim HtmlContent
HtmlContent = NewAsp.LoadTemplate("index")
HtmlContent = Replace(HtmlContent, "{$IndexMenulist}", NewAsp.IndexMenulist)
HtmlContent = Replace(HtmlContent, "{$HeadTitle}", "สืาณ")
HtmlContent = Replace(HtmlContent, "{$ClassID}", 0)
Response.Write NewAsp.ArchiveHtml(HtmlContent)

NewAsp.CloseConn()

Function LoadXMLTopiclist(action,maxtop,stype)
	Dim SQL,Rs,topiclist,FoundSQL
	Dim XMLDoc,Node
	action = NewAsp.ChkNumeric(action)
	maxtop = NewAsp.ChkNumeric(maxtop)
	If maxtop = 0 Then maxtop = 10
	stype = NewAsp.ChkNumeric(stype)
	If stype=1 Then
		Select Case action
			Case 1
				FoundSQL = " WHERE topicmode=3 And LockTopic=0 ORDER BY LastPostTime DESC"
			Case 2
				FoundSQL = " WHERE topicmode=3 And LockTopic=0 ORDER BY Hits DESC, LastPostTime DESC"
			Case 3
				FoundSQL = " WHERE topicmode=3 And LockTopic=0 And Broadcast=1 ORDER BY LastPostTime DESC"
			Case Else
				FoundSQL = " WHERE topicmode=3 And LockTopic=0 ORDER BY TopicID DESC"
		End Select
	Else
		Select Case action
		Case 1
			FoundSQL = " WHERE topicmode=1 And LockTopic=0 ORDER BY LastPostTime DESC"
		Case 2
			FoundSQL = " WHERE topicmode=0 And LockTopic=0 ORDER BY Reward DESC, LastPostTime DESC"
		Case 3
			FoundSQL = " WHERE topicmode<3 And LockTopic=0 ORDER BY Hits DESC, LastPostTime DESC"
		Case 4,5
			FoundSQL = " WHERE topicmode<3 And LockTopic=0 And Broadcast=1 ORDER BY LastPostTime DESC"
		Case Else
			FoundSQL = " WHERE topicmode=0 And LockTopic=0 ORDER BY TopicID DESC"
	End Select
	End If
	Set XMLDoc = NewAsp.CreateXMLDoc("msxml2.FreeThreadedDOMDocument"& MsxmlVersion)
	XMLDoc.appendChild(XMLDoc.createElement("xml"))
	XMLDoc.documentElement.setAttribute "action",action
	XMLDoc.documentElement.setAttribute "stype",stype
	SQL="SELECT Top " & maxtop & " TopicID,classid,userid,classname,title,PostUsername,DateAndTime,LastPostTime,Reward,Hits,PostNum,TopicMode,Highlight,Anonymous FROM NC_Ask_Topic " & FoundSQL
	Set Rs = NewAsp.Execute(SQL)
	Set topiclist=NewAsp.RecordsetToxml(rs,"row","topic")
	Rs.Close : Set Rs=Nothing
	SQL=Empty
	If Not topiclist Is Nothing Then
		For Each Node in topiclist.documentElement.SelectNodes("row")
			Node.selectSingleNode("@title").text=NewAsp.Checkstr(Node.selectSingleNode("@title").text)
			Node.selectSingleNode("@dateandtime").text=NewAsp.FormatDate(Node.selectSingleNode("@dateandtime").text,5)
		Next
		XMLDoc.documentElement.appendChild(topiclist.documentElement)
	End If
	Set topiclist=Nothing
	LoadXMLTopiclist = TransformXSLTemplate(XMLDoc)
	Set XMLDoc=Nothing
End Function

Function LoadXMLUserslist(action,maxtop,stype)
	Dim SQL,Rs,Userslist,FoundSQL
	Dim XMLDoc,Node
	action = NewAsp.ChkNumeric(action)
	maxtop = NewAsp.ChkNumeric(maxtop)
	If maxtop = 0 Then maxtop = 10
	stype = NewAsp.ChkNumeric(stype)
	Select Case action
		Case 1
			FoundSQL = " WHERE Userlock=0 ORDER BY Points DESC,userid DESC"
		Case 2
			FoundSQL = " WHERE Userlock=0 ORDER BY Asktotal DESC,userid DESC"
		Case 3
			FoundSQL = " WHERE Userlock=0 ORDER BY Answertotal DESC,userid DESC"
		Case 4,5
			FoundSQL = " WHERE Userlock=0 ORDER BY Askoverdue DESC,userid DESC"
		Case Else
			FoundSQL = " WHERE Userlock=0 ORDER BY userid DESC"
	End Select
	Set XMLDoc = NewAsp.CreateXMLDoc("msxml2.FreeThreadedDOMDocument"& MsxmlVersion)
	XMLDoc.appendChild(XMLDoc.createElement("xml"))
	XMLDoc.documentElement.setAttribute "action",action
	XMLDoc.documentElement.setAttribute "stype",stype
	SQL="SELECT Top " & maxtop & " userid,Username,Nickname,Password,UserClass,Useremail,Usersex,Photo,Homepage,Points,Experience,Asktotal,Askoverdue,Answertotal FROM NC_Ask_Users " & FoundSQL
	Set Rs = NewAsp.Execute(SQL)
	Set Userslist=NewAsp.RecordsetToxml(rs,"row","users")
	Rs.Close : Set Rs=Nothing
	SQL=Empty
	If Not Userslist Is Nothing Then
		XMLDoc.documentElement.appendChild(Userslist.documentElement)
	End If
	Set Userslist=Nothing
	LoadXMLUserslist = TransformXSLTemplate(XMLDoc)
	Set XMLDoc=Nothing
End Function

Function TransformXSLTemplate(iXMLDoc)
	Dim proc,XMLStyle,node,cnode,XSLTemplate
	Set XSLTemplate=NewAsp.CreateAXObject("Msxml2.XSLTemplate" & MsxmlVersion )
	Set XMLStyle=NewAsp.CreateXmlDoc("msxml2.FreeThreadedDOMDocument"& MsxmlVersion )
	XMLStyle.load Server.MapPath(NewAsp.TemplatePath & "xslt/index.xslt")
	Set Node=XMLStyle.createNode(1,"xsl:variable","http://www.w3.org/1999/XSL/Transform")
	Set CNode=XMLStyle.createNode(2,"name","")
	CNode.text="installdir"
	Node.attributes.setNamedItem(CNode)
	Node.text=NewAsp.InstallDir
	XMLStyle.documentElement.appendChild(node)
	Set Node=XMLStyle.createNode(1,"xsl:variable","http://www.w3.org/1999/XSL/Transform")
	Set CNode=XMLStyle.createNode(2,"name","")
	CNode.text="skinurl"
	Node.attributes.setNamedItem(CNode)
	Node.text=NewAsp.AskedSkinUrl
	XMLStyle.documentElement.appendChild(node)
	XSLTemplate.stylesheet=XMLStyle
	Set proc = XSLTemplate.createProcessor()
	proc.input = iXMLDoc
	proc.transform()
	Dim procstr
	procstr = proc.output
	Set proc=Nothing
	TransformXSLTemplate = procstr
	Set XMLStyle=Nothing
	Set XSLTemplate=Nothing
End Function
%>