<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<%
'Reply
If Request.Form("save")=1 Then
  Call Cw_login()
  Call Cw_yzm()
  Call Cw_yz(60)'间隔回复
  set hf=server.CreateObject("adodb.recordset")
  hfq="select * from cw_bbs_reply"
  hf.open hfq,conn,1,3
  hf.addnew
  hf("recontent")=trim(Request.Form("content"))
  hf("userid")=session("userid")
  hf("bbsid")=Request.Form("bbsid")
  hf("ip")=Request.ServerVariables("REMOTE_ADDR")
  hf("ispass")=reply_pass
  hf.update
  hf.close
  set hf=nothing
  call cw_jf("+",1)
  response.Redirect"show.asp?id="&Request("bbsid")
  response.End()
End If

'Write
id=trim(Request("id"))
if id="" then
  response.Redirect cf_root&"bbs/"
end if
set rs=server.CreateObject("adodb.recordset")
sql="select * from cw_bbs where id="&id
rs.open sql,conn,1,1
if err then
  response.Write("非法操作！")
  response.Redirect cf_root
  err.clear
  response.End()
end if
if not rs.eof then
title=rs("title")
content=rs("content")
hits=rs("hits")
ip=rs("ip")
adddate=rs("adddate")
ispass=rs("ispass")
isnice=rs("isnice")
istop=rs("istop")
showurl=cf_root&"bbs/show.asp?id="&id
classid=rs("classid")
classname=cw_class("title","cw_bbs_class",classid)
classurl=cf_root&"bbs/list.asp?id="&classid
userid=rs("userid")
username=cw_class("user","cw_user",userid)
userpic=cw_class("pic","cw_user",userid)
userjf=cw_class("jf","cw_user",userid)
usergrade=cw_class("grade","cw_user",userid)
usergr=Cw_grade(usergrade)
userlogindate=cw_class("logindate","cw_user",userid)
else
response.Write("<script>alert('非法操作，你己被记录！');location.href='"&cf_root&"bbs/'</script>")
response.End()
end if
rs.close
set rs=nothing
data=cw_redtemp(cf_root&"skins/"&cf_skin,tp_bbs_show)
data=cw_include(data)     
data=cw_system(data)
data=Replace(data,"{cw:show_title}",title)
data=Replace(data,"{cw:show_content}",content)
data=Replace(data,"{cw:show_reply}",cw_bbsreply(id))
data=Replace(data,"{cw:show_hits}",hits)
data=Replace(data,"{cw:show_url}",showurl)
data=Replace(data,"{cw:show_ip}",ip)
data=Replace(data,"{cw:show_id}",id)
data=Replace(data,"{cw:show_logindate}",userlogindate)
data=Replace(data,"{cw:show_adddate}",adddate)
data=Replace(data,"{cw:show_ispass}",ispass)
data=Replace(data,"{cw:show_isnice}",isnice)
data=Replace(data,"{cw:show_istop}",istop)
data=Replace(data,"{cw:show_classid}",classid)
data=Replace(data,"{cw:show_classurl}",classurl)
data=Replace(data,"{cw:show_classname}",classname)
data=Replace(data,"{cw:show_position}"," &gt; <a href='"&cf_root&"bbs/'>论坛社区</a> &gt; <a href='"&classurl&"'>"&classname&"</a> &gt; <a href='"&showurl&"'>"&title&"</a>")
data=Replace(data,"{cw:show_username}",username)
data=Replace(data,"{cw:show_userid}",userid)
data=Replace(data,"{cw:show_userpic}",userpic)
data=Replace(data,"{cw:show_userjf}",userjf)
data=Replace(data,"{cw:show_userjb}",userjb)
data=Replace(data,"{cw:show_usergr}",usergr)
if Session("userid")<>"" then
data=Replace(data,"{cw:userid}",session("userid"))
else
data=Replace(data,"{cw:userid}",0)
end if
data=cw_loop(data)
pags="10" '每页记录数
dpage=cw_pag(data,pags)'获取分页数
page=Request("page")'当前页
if dpage=0 then page=1
if page="" then page=1
if page>1 then'替换标题中的分页数
  data=Replace(data,"{cw:show_page}","(第"&page&"页)") 
else
  data=Replace(data,"{cw:show_page}","")
end if
  Set Reg = New RegExp
  Reg.IgnoreCase = True
  Reg.Global = True
  Reg.Pattern="{@cw:page ([\s\S]+?)}([\s\S]+?){/@cw:page}"
  Set Matches=Reg.Execute(data)
  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)	 
      data=Replace(data,Match.value,f4)'for循环内容替换	  
      data=Replace(data,"{cw:showpage}",cw_searchpage(f1,pags,page,key))'替换分页标签
     Next
  End If
  Set Reg=nothing
  set Matches=nothing  
data=cw_function(data)
data=cw_if(data)
Response.Write(data)

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='?id="&id&"'>首页</a>"
  end if
  if pa>1 then
     if pa=2 then
     pagetitle=pagetitle&"<a href='?id="&id&"'>上一页</a>"
     else
     pagetitle=pagetitle&"<a href='?id="&id&"&page="&pa-1&"'>上一页</a>"
     end if
  else
     pagetitle=pagetitle&"<a>上一页</a>"
  end if
  if page>4 then
     pagetitle=pagetitle&"<a href='?id="&id&"&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='?id="&id&"'>"&i&"</a>"
          else
             pagetitle=pagetitle&"<a href='?id="&id&"&page="&i&"'>"&i&"</a>"
          end if
        end if 
     end if 
  next 
  if page+3 < m then
     pagetitle=pagetitle&"<a href='?id="&id&"&page="&page+3&"'>...</a>"
  end if 
  if rl.pagecount<pa+1 then
     pagetitle=pagetitle&"<a>下一页</a>"
  else
     pagetitle=pagetitle&"<a href='?id="&id&"&page="&pa+1&"'>下一页</a>"
  end if
  if rl.pagecount=<pa+1 then
     pagetitle=pagetitle&"<a>尾页</a>"
  else
     pagetitle=pagetitle&"<a href='?id="&id&"&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
%>