Get Data for wikitable Plugin

<%@ codepage=65001 %>
<!-- #include file="../../../classes/ConnectToDB.asp" -->
<!-- #include file="../../../classes/CloudUtilities.asp" -->
<!-- #include virtual="/classes/GlobalUtilities.asp" -->
<!-- #include virtual="/classes/CheckSqlInjection.asp" -->
<%
on error resume next

'Connect to database
set util = new GlobalUtilities
set conn = new ConnectToDB
conn.connect
set cloud = new CloudUtilities
errMsg = ""


categoryID = util.filterDataService(request("categoryID"), "int", true)
page = util.filterDataService(request("page"), "int", false)
limit = util.filterDataService(request("limit"), "int", false)
'statusID = util.filterDataService(request("status"), "int", true)
errMsg = util.getError()
'response.Write(categoryID)
'response.End()

if err.number = 0 and len(errMsg) = 0 then
	if page = null or page = "" then page = 1 end if
	if limit = null or limit = "" then limit = 20 end if
end if


if err.number = 0 and len(errMsg) = 0 then
	sql = "select * from table order by created_time desc"
	'response.write err.number & ": " & err.description & "<br/>"
	'response.write sql
	'response.End()
	set rs = conn.useSql(sql)

	rs.pageSize = limit
	total = rs.recordCount
	pageCount = rs.pageCount
	position = (page - 1) * limit + 1
	rs.absolutePosition = position
	'response.write position
	'response.end
end if


response.ContentType = "text/xml"
response.write "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
response.write "<root>"

output = "<status>"

if err.number = 0 and len(errMsg) = 0 then
	output = output & "<code>OK</code>"
	output = output & "<detail page='" & page & "' pageCount='" & pageCount & "' total='" & total & "'></detail>"
elseif len(errMsg) > 0 then
	output = output & "<code>Failed</code>"
	output = output & "<detail>" & errMsg & "</detail>"
else
	output = output & "<code>Failed</code>"
	output = output & "<detail>Error: " & err.number & "</detail>"
end if

output = output & "</status>"


'Write headers
dim headers(9)
headers(0) = "" : headers(1) = "會員姓名"
headers(2) = "會員公司" : headers(3) = "獎金類別"
headers(4) = "客戶名稱" : headers(5) = "產品"
headers(6) = "U數" : headers(7) = "獎金"
headers(8) = "地址" : headers(9) = "更新"

output = output & "<headers>"

for i = 0 to uBound(headers)
	output = output & "<item>"
	output = output & "<fieldLabel>" & headers(i) & "</fieldLabel>"
	output = output & "</item>"
next

output = output & "</headers>"


'Get items
output = output & "<items>"

if err.number = 0 and len(errMsg) = 0 then
	i = 1
	do while not rs.eof
		output = output & "<item id='" & rs("case_id") & "' " & _
			" seatID='" & rs("seat_id") & "' " & _
			" userID='" & rs("user_id") & "' " & _
			" categoryID='" & rs("category_id") & "' " & _
			" promotionID='" & rs("promotion_id") & "' " & _
			" statusID='" & rs("status") & "' " & _
			">"
		output = output & "<field><![CDATA[" & position & "]]></field>"
		output = output & "<field><![CDATA[" & util.CharsetBIG5ToUnicode(rs("username")) & "]]></field>"
		output = output & "<field><![CDATA[" & util.CharsetBIG5ToUnicode(rs("companyname")) & "]]></field>"
		output = output & "<field><![CDATA[" & util.formatXMLValue(rs("category_name")) & "]]></field>"
		output = output & "<field><![CDATA[" & rs("customer") & "]]></field>"
		output = output & "<field><![CDATA[" & util.formatXMLValue(rs("product")) & "]]></field>"
		output = output & "<field><![CDATA[" & rs("seat") & "]]></field>"
		output = output & "<field><![CDATA[" & rs("points") & "]]></field>"
		output = output & "<field><![CDATA[" & util.CharsetBIG5ToUnicode(rs("address")) & "]]></field>"
		output = output & "<field><![CDATA[" & rs("updated_time") & "]]></field>"
		output = output & "</item>"
	
		rs.moveNext
		i = i + 1
		position = position + 1

		if i > limit then exit do end if
	loop
end if

output = output & "</items>"


response.write output
response.write "</root>"

rs.close
set conn = nothing
%>