<!--#include file="../inc/conn.asp"-->
<%
'============================================================
'插件名称：Ajax评论
'Website：http://www.sdcms.cn
'Author：sdcms.cn
'Date：2008-12-14
'============================================================

set sdcms_f=new sdcms_function
id=sdcms_f.Requestint(id)
set rs=conn.execute("select id from sd_info where id="&id&"")
if rs.eof then
echo "1错误的参数":Died
end if
if clng(sdcms_comment_pass)=0 then
echo "1系统未开启评论系统"
else
    if isempty(application(sdcms_cookies&"comment_"&id)) then
		create_app "comment_"&id,sdcms_f.LoadRecord("iscomment","sd_info",id)
	end if
	if application(sdcms_cookies&"comment_"&id)=0 then echo "1此信息禁止评论":died
	select case action
		case "add":add_comment id 
		case "save":save_comment
		case else:shows_comment id
	end select
end if
set sdcms_f=nothing

sub save_comment
	lastpostdate=request.Cookies(sdcms_cookies&"comment"&id)
	if lastpostdate<>"" then
		if int(DateDiff("s",lastpostdate,now()))<=60 then
			echo "1您发表的速度太快，歇歇再发吧":Died
		end if
	end if
	username=trim(request("username"))
	content=trim(request("content"))
	if username="" or content="" then
	echo "1数据不能为空":Died
	end if
	if t1<>0 and isnumeric(t1) then content=left(content,clng(t1))
	username=sdcms_f.HTMLEncode(username)
	content=sdcms_f.contentEncode(content)
	ip=sdcms_f.getip

	set rs=server.CreateObject("adodb.recordset")
	sql="select username,content,ip,infoid,ispass from sd_comment"
	rs.open sql,conn,1,3
	rs.addnew
	rs(0)=left(username,10)
	rs(1)=content
	rs(2)=sdcms_f.HTMLEncode(ip)
	rs(3)=id
	if sdcms_comment_ispass=1 then
	msg_contents="，请等待审核"
	rs(4)=0
	else
	rs(4)=1
	end if
	rs.update
	conn.execute("update sd_info set comment_num=comment_num+1 where id="&id&"")
	conn.execute("update sd_count set comment_num=comment_num+1 where id=1")
	if sdcms_comment_ispass=1 then
	echo "2评论发表成功"&msg_contents&"!"
	else
	echo "0评论发表成功"
	end if
    response.Cookies(sdcms_cookies&"comment"&id)=now()
end sub

sub shows_comment(t0)

	page=request.querystring("page")
	if page="" or not isnumeric(page) then
	page=1
	end if
	pages =5
	set rs=server.CreateObject("adodb.recordset")
	sql="select adddate,username,content from sd_comment where infoid="&id&" and ispass=1 order by id desc"
	rs.open sql,conn,1,1	
	if rs.eof then
	else
	rs.pagesize = pages
	maxpagecount=rs.pagecount
	rs.absolutepage = page 
	rcount1=0
	pagestart=page-5
	pageend=page+5
	if pagestart<1 then
	pagestart=1
	end if
	if pageend>maxpagecount then
	pageend=maxpagecount
	end if
	rcount=rs.RecordCount
	do while not rs.eof and rcount1 <rs.pagesize
	echo "<div id=""comment_title"">"&rs(1)&" <span>于</span> "&rs(0)&" <span>评论道：</span></div>"
	echo "<div id=""comment_content"">"&rs(2)&"</div>"
	rs.movenext
	rcount1=rcount1+1
	loop
	end if
	
	if rcount>0 then
	echo "<div class=""comment_page"">"
	if page=1 then
	echo "<a>首页</a>"
	else
	echo "<a href=javascript:get_comment_page(1,"&id&");>首页</a>"
	end if
	if page<>"1" then
	echo "<a href=javascript:get_comment_page("&page-1&","&id&");>上一页</a>"
	else
	echo "<a>上一页</a>"
	end if
	for i=pagestart to pageend
		if i=0 then i=1 end if
		if i=clng(page) then str="<span>"&i&"</span>" else str="<a href=javascript:get_comment_page("&i&","&id&");>"&i&"</a>" end if
		strurl=""&str&""
		echo strurl
	next
	if page=maxpagecount then
	echo "<a>下一页</a>"
	elseif  page<>""&maxpagecount&"" then
	echo "<a href=javascript:get_comment_page("&page+1&","&id&");>下一页</a>"
	else
	echo "<a>下一页</a>"
	end if
	if clng(page)<clng(pageend) then
	echo "<a href=javascript:get_comment_page("&pageend&","&id&");>未页</a>"
	else
	echo "<a>未页</a>"
	end if
	echo "<a>页次:"&page&"/"&maxpagecount&"</a><a>总计:"&rcount&"</a>"
	echo "</div>"
	end if

end sub

Sub add_comment(t0)
	echo "<div id=""comment_title"">发表评论</div>"
	echo "<div id=""comment_content"">"
	echo "<ul id=""comment_add"">"
	echo "<form onSubmit='return checkcomment(this);'>"
	echo "<li>姓 名：<input name=""username"" type=""text""><button type=""submit"">发表</button><input name=""id"" type=""hidden"" value="""&t0&"""></li>"
	echo "<li><textarea name=""content""></textarea><br><span id=""showmsg""></span></li>"
	echo "</form>"
	echo "</ul>"
	echo "</div>"
End Sub
%>