<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<%
if request("act")=1 then
  if session("user")="" or session("userid")="" then 
    response.Write("1您还没有登录！")
    response.End()
  end if
  if session("times")<>"" then
     s=DateDiff("s", CDate(session("times")), CDate(now()))
	 if s<60 then
	 response.write("1你发表频率太快了！")
	 response.End()
	 end if
  end if
  content=trim(request("content"))
  classid=request("classid")
  showid=request("showid")
  if trim(request("yzm"))<>Session("iCode") then
	 response.write("1验证码输入错误！")
	 response.End()
  end if
  if classid="" or showid="" then
     response.write("1参数错误！")
     response.end()
  end if
  if len(content)<5 then
     response.write("1回复内容也太少了！")
     response.end()
  end if
  set rs=server.CreateObject("adodb.recordset")
  sql="select * from cw_comment"
  rs.open sql,conn,1,3
  rs.addnew
  rs("classid")=classid
  rs("showid")=showid
  rs("userid")=session("userid")
  rs("content")=content
  rs("adddate")=now()
  rs("ispass")=comment_pass
  rs("ip")=Request.ServerVariables("REMOTE_ADDR")
  rs.update
  rs.close
  set rs=nothing
  session("times")=now()
  response.write("0评论成功！")
end if

if request("act")=2 then 
   classid=request("classid")
   showid=request("showid")
   if classid="" or showid="" then
     response.write("1参数错误！")
     response.end()
   end if
   set rs=server.CreateObject("adodb.recordset")
   sql="select * from cw_comment where classid='"&request("classid")&"' and showid="&request("showid")
   rs.open sql,conn,1,1
   if not rs.eof then
      response.write("0"&rs.recordcount)
   else
      response.write("00")
   end if
   rs.close
   set rs=nothing
end if

if request("act")=3 then
showid=trim(request("showid"))
classid=trim(request("classid"))
if showid="" or classid="" then
  response.Write("<script>alert('参数错误！');location.href='"&cf_root&"';</script>")
end if
pags="10" '每页记录数
set rs=server.CreateObject("adodb.recordset")
sql="select * from "&classid&" where id="&showid
rs.open sql,conn,1,1
if not rs.eof then
title=rs("title")
link=cf_root&cw_class("html",classid&"_class",rs("classid"))&rs("id")&".html"
end if
rs.close
set rs=nothing
data=cw_redtemp(cf_root&"skins/"&cf_skin,tp_comment)
data=cw_include(data)     
data=cw_system(data)
data=replace(data,"{cw:show_classid}",classid)
data=replace(data,"{cw:show_id}",showid)
data=replace(data,"{cw:show_title}",title)
data=replace(data,"{cw:show_url}",link)
data=cw_loop(data)
dpage=cw_pag(data,pags)'获取分页数
if dpage=0 then page=1
if page="" then page=1
if cint(page)>cint(dpage) then page=dpage
  html=data
  Set Reg = New RegExp
  Reg.IgnoreCase = True
  Reg.Global = True
  Reg.Pattern="{@cw:page ([\s\S]+?)}([\s\S]+?){/@cw:page}"
  Set Matches=Reg.Execute(html)
  IF Matches.Count>0 Then
     For Each Match In Matches
      f1=Match.SubMatches(0)'SQL语句
      f2=Match.SubMatches(1)'循环内容
      f4=Cw_page_sql(f1,f2,pags,page)
      html=Replace(html,Match.value,f4)'for循环内容替换	  
      html=Replace(html,"{cw:listpage}",cw_searchpage(f1,pags,page,key))'替换分页标签
     Next
  End If
  data=html
  Set Reg=nothing
  set Matches=nothing
data=cw_function(data)
data=cw_if(data)
response.Write(data)
end if

Function cw_searchpage(sql,pag,pa,key)
 key=server.URLEncode(key)
 set rl=server.CreateObject("adodb.recordset") 
 rl.open sql,conn,1,1
 if not rl.eof then
  page=pa
  n=rl.RecordCount
  rl.pagesize=pag
  m=cint(rl.pagecount)
  if page="" then 
   page=1
  elseif page<1 then 
    page=1
  end if
  if cint(pa)>m then
        page=m
     end if
  page=cint(page)
  if not rl.eof then 
     rl.absolutepage=page
  end if     
  if m>page+3 then 
     endpage=page+3 
  else 
     endpage=m 
  end if 
  if pa=1 then
     pagetitle=pagetitle&"<a>首页</a>"
  else
     pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"'>首页</a>"
  end if
  if pa>1 then
     if pa=2 then
     pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"'>上一页</a>"
     else
     pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"&page="&pa-1&"'>上一页</a>"
     end if
  else
     pagetitle=pagetitle&"<a>上一页</a>"
  end if
  if page>4 then
     pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"&page=4'>...</a>"
  end if     
  for i=page-3 to endpage
     if not i<1 then 
        if i = page then 
          pagetitle=pagetitle&"<span>"&i&"</span>"     
        else 
          if i=1 then
             pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"'>"&i&"</a>"
          else
             pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"&page="&i&"'>"&i&"</a>"
          end if
        end if 
     end if 
  next 
  if page+3 < m then
     pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"&page="&page+3&"'>...</a>"
  end if 
  if rl.pagecount<pa+1 then
     pagetitle=pagetitle&"<a>下一页</a>"
  else
     pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"&page="&pa+1&"'>下一页</a>"
  end if
  if rl.pagecount=<pa+1 then
     pagetitle=pagetitle&"<a>尾页</a>"
  else
     pagetitle=pagetitle&"<a href='?act=3&classid="&classid&"&showid="&showid&"&page="&rl.pagecount&"'>尾页</a>"
  end if
  pagetitle=pagetitle&"<a>"&page&"/"&rl.pagecount&"页</a>"
 end if 
 cw_searchpage=pagetitle
 rl.close
 set rl=nothing
End Function
%>