<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<%
tab=request("tab")
id=request("id")
if tab="" then response.Redirect"./"
if id="" or id=0 then
  sql="select * from "&tab
  select case tab
  case "cw_news"
     title="新闻资讯"
	 followid=0
  case "cw_info"
     title="分类信息"
	 followid=0
  case "cw_hous"
     title="房产信息"
	 followid=0
  case "cw_job"
     title="招聘信息"
	 followid=0
  case "cw_shop"
     title="商家黄页"
	 followid=0
  case "cw_bbs"
     title="交流论坛"
	 followid=0
  end select
  id=0   
else
  sql="select * from "&tab&"_class where id="&id
  set rs=server.CreateObject("adodb.recordset")
  rs.open sql,conn,1,1
  if not rs.eof then
  title=rs("title")
  followid=rs("followid")
  end if
  rs.close
  set rs=nothing
end if
'当ID为0时获取所有ID
  id1=allid(id,tab)
  id2=allid(id1,tab)
  id3=allid(id2,tab)
  id4=allid(id3,tab)
if id1<>"" then
  fid=id1
  if id2<>"" then
     fid=id1&","&id2
	 if id3<>"" then
	    fid=fid&","&id3
		if id4<>"" then
		   fid=fid&","&id4
		end if
	 end if
  end if
else
  fid=id
end if

data=cw_redtemp(cf_root&"skins/"&cf_skin,tp_wap_list)
data=cw_include(data)     
data=cw_system(data)
data=replace(data,"{cw:class_tab}",tab)
data=replace(data,"{cw:class_title}",title)
data=replace(data,"{cw:class_followid}",followid)
data=replace(data,"{cw:class_allid}",fid)

pags="10" '每页记录数
data=cw_loop(data)
dpage=cw_pag(data,pags)'获取分页数
page=cint(request("page"))'当前页
key="tab="&tab&"&id="&id'分页传递参数
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)'循环内容
	  if fid=0 then
	    f1="select * from "&tab&" order by id desc"
	  else
	    f1="select * from "&tab&" where classid in("&fid&") order by id desc"
	  end if
      f4=Cw_page_sql(f1,f2,pags,page)	  
      html=Replace(html,Match.value,f4) 
      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)


Function cw_searchpage(sql,pag,pa,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>&lt;&lt;</a>"
  else
     pagetitle=pagetitle&"<a href='?"&key&"'>&lt;&lt;</a>"
  end if
  if pa>1 then
     if pa=2 then
     pagetitle=pagetitle&"<a href='?"&key&"'>&lt;</a>"
     else
     pagetitle=pagetitle&"<a href='?"&key&"&page="&pa-1&"'>&lt;</a>"
     end if
  else
     pagetitle=pagetitle&"<a>&lt;</a>"
  end if
  if page>4 then
     pagetitle=pagetitle&"<a href='?"&key&"&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='?"&key&"'>"&i&"</a>"
          else
             pagetitle=pagetitle&"<a href='?"&key&"&page="&i&"'>"&i&"</a>"
          end if
        end if 
     end if 
  next 
  if page+3 < m then
     pagetitle=pagetitle&"<a href='?"&key&"&page="&page+3&"'>...</a>"
  end if 
  if rl.pagecount<pa+1 then
     pagetitle=pagetitle&"<a>&gt;</a>"
  else
     pagetitle=pagetitle&"<a href='?"&key&"&page="&pa+1&"'>&gt;</a>"
  end if
  if rl.pagecount=<pa then
     pagetitle=pagetitle&"<a>&gt;&gt;</a>"
  else
     pagetitle=pagetitle&"<a href='?"&key&"&page="&rl.pagecount&"'>&gt;&gt;</a>"
  end if
 end if 
 cw_searchpage=pagetitle
 rl.close
 set rl=nothing
End Function

Function allid(fid,tab)
Set ai=Server.CreateObject("adodb.recordset")
aiq="select * from "&tab&"_class where followid in("&fid&")"
ai.open aiq,conn,1,1
if not ai.eof then
do while not ai.eof
aid=aid&ai("id")&","
ai.movenext
loop
aid=left(aid,len(aid)-1)
else
aid=""
end if
ai.close
set ai=nothing
allid=aid
End Function

%>