<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<%
id=request("id")
tab=request("tab")
if id="" or tab="" then response.Redirect"./"

data=cw_redtemp(cf_root&"skins/"&cf_skin,tp_wap_show)
data=cw_include(data)     
data=cw_system(data)

set rs=server.CreateObject("adodb.recordset")
sql="select * from "&tab&" where id="&id
rs.open sql,conn,1,1
if not rs.eof then
f1=rs.fields.count-1'字段总数
for f=0 to f1 '替换当前表中的字段
	if rs(f)<>"" then
       data=replace(data,"{cw:show_"&rs.fields(f).name&"}",rs(f))  'fields(0).name是字段名称
	end if        
next
classid=rs("classid")
end if
rs.close
set rs=nothing
classname=cw_class("title",tab&"_class",classid)
data=Replace(data,"{cw:show_tab}",tab)
data=Replace(data,"{cw:show_classid}",classid)
data=Replace(data,"{cw:show_classname}",classname)

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
  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
%>