<!--#include file="../conn.asp"-->
<!--#include file="../inc/function.asp"-->
<%
Response.ContentType="application/xml"
Response.Write("<?xml version=""1.0"" encoding=""utf-8""?>")
Response.Write("<mycomments>")
dim action
dim rs,sql,id,commuser,type1,comtext,Role
Dim AskD
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	AskD.GetUserRole
	siteinfo=AskD.siteinfo
	setting=AskD.setting
	UserRole=AskD.UserRole


IF isnumeric(Request.Cookies("Grade")) Then Role=UserRole(Request.Cookies("Grade"))

id=Trim(Request.Form("id"))
type1=Trim(Request.Form("type"))
action=Trim(Request.Form("action"))

if action="add" then
	IF not isnumeric(Request.Cookies("Muser")) Then
	   Response.Write("<errc><comments>3</comments></errc>")
	Else
		IF instr(Role,",8,")=0 Then
		   Response.Write("<errc><comments>1</comments></errc>")
		Else
		   comtext=Trim(Request.Form("comtext"))
		   comtext=AskD.HTMLcode(comtext)
		   comtext=AskD.chkAllow(comtext,4)
		   
		   IF comtext<>"###" Then
			   conn.execute("insert into "&predb&"Comments (toid,type,Comments,Commuser,Commtime) values("&id&","&type1&",'"&comtext&"',"&Request.Cookies("Muser")&",'"&now()&"')")
			   Call AskD.Score(Request.Cookies("Muser"),setting(17),"评论得分")
			   if type1="1" then
				 conn.execute("update "&predb&"ask set ComNum=ComNum+1 where askid="&id)
			   else
				 conn.execute("update "&predb&"ans set ComNum=ComNum+1 where ansid="&id)
			   end if
			   Response.Write("<errc><comments>0</comments></errc>")
		   Else
		       Response.Write("<errc><comments>4</comments></errc>")
		   End IF
		   
		End IF
	End IF
end if

    Response.Write("<errc><comments>0</comments></errc>")
	set rs= Server.CreateObject("adodb.recordset")
	sql="select a.*,b.userid from "&predb&"comments a inner join "&predb&"user b on a.commuser=b.id where toid="&id&" and type="&type1&" order by a.id desc"
	rs.open sql,conn,1,1
	if rs.bof and rs.eof then
		Response.Write("<siteinfo><comments>#</comments><commuser>#</commuser><commtime>#</commtime></siteinfo>")
	else
	do while not rs.eof
	commuser="<a href=""user/userinfo.asp?id="&rs("commuser")&""">"&rs("userid")&"</a>"

	Response.Write("<siteinfo><comments><![CDATA["&rs("comments")&"]]></comments><commuser><![CDATA["&commuser&"]]></commuser><commtime>"&rs("commtime")&"</commtime></siteinfo>")
	rs.movenext
	loop
	end if
	rs.close
	set rs=nothing
	set AskD.myConn =Nothing
closedb
Set AskD = Nothing
Response.Write("</mycomments>")
%>