<!--#include file="conn.asp"-->
<!--#include file="inc/function.asp"-->
<%
Dim AskD,inHtml,postList
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	AskD.GetTemplate("T-list.html")
	siteinfo=AskD.siteinfo
	setting=AskD.setting

Dim rs,sql,classid,classname,page,TclassID,PageGui,a,key,keyv,idcount

key=Trim(Request.QueryString("key"))
IF key="" Then key=Trim(Request.Form("key"))
keyv=Server.URLEncode(key)
  IF clng(Request.Form("select4"))<1 Then
       IF clng(Request.Form("select3"))<1 Then
             IF clng(Request.Form("select2"))<1 Then
				IF clng(Request.Form("select1"))<1 Then

				Else
					classid=clng(Request.Form("select1"))
				End If 
             Else
                classid=clng(Request.Form("select2"))
             End If
       Else
             classid=clng(Request.Form("select3"))
       End If
  Else
      classid=clng(Request.Form("select4"))
  End If
  
  IF ClassID=0 Then CLassID=Trim(Request.QueryString("classid"))

page=clng(Request.QueryString("page"))
if CLassID="" then CLassID=0
  If page>1 Then
     PageGui="("&page&")"
  End If

 if CLassID>0 then
	set rs=conn.execute("select ClassName from "&predb&"Class where CLassID="&CLassID&"")
	    IF key="" Then classname=rs(0) Else classname="搜索："&key&" > "&rs(0)
	rs.close
	set rs=nothing
 else
        IF key="" Then classname="第一级分类" Else classname="搜索："&key
 end if
 
a=Trim(Request.QueryString("a"))

postList=AskD.postList(ClassID)
inHtml=RexHtml(AskD.tempbody)
inHtml=RexHtml_IF(inHtml)
set AskD.myConn =Nothing
closedb
Set AskD = Nothing
Response.Write(inHtml)
IF idcount=0 and a="s" then
   Response.Write "<script>var a = new xWin(""1"",240,100,"""&siteInfo(4)&""",""您搜索的问题暂不存在，请直接提问！"");</script>"
   Response.Write("<script>setTimeout(""location.href='myask.asp?key="&keyv&"'"",2000)</script>")
End IF

Function childClass()
Dim rs,str
	set rs=conn.execute("select * from "&predb&"Class where esNum="&CLassID&" order by esPai Asc")
	if not(rs.bof and rs.eof) then
	
	str="<div>"&vbcrlf
	str=str&"<div class=""d1""><img src="""&siteInfo(1)&"Template/"&siteInfo(11)&"/images/d2.gif"" alt=""""/></div>"&vbcrlf
	str=str&"<div class=""d2"">"&classname&"</div>"&vbcrlf
	str=str&"</div>"&vbcrlf
	str=str&"<div class=""dclass"">"&vbcrlf
	str=str&"<div class=""dl1""></div>"&vbcrlf
	str=str&"<div class=""br""></div>"&vbcrlf
	str=str&"<div class=""dmid"">"&vbcrlf
	str=str&"<ul>"&vbcrlf

	do while not rs.eof
	
	str=str&"<li><a href="""
    IF setting(34)=0 Then
	str=str&"List.asp?classid="&rs("CLassID")
	Else
	str=str&siteInfo(1)&"List-"&rs("CLassID")&".html"
	End IF
	str=str&""">"&rs("ClassName")&"</a></li>"&vbcrlf

	rs.movenext
	loop
	
	str=str&"</ul>"&vbcrlf
	str=str&"</div>"&vbcrlf
	str=str&"<div class=""br""></div>"&vbcrlf
	str=str&"</div>"&vbcrlf
	str=str&"<div class=""br""></div>"&vbcrlf

	end if
	rs.close
	set rs=nothing
	childClass=str
End Function

Function ClassList()
Dim sqla,rs,rs1,str,keys,keym,m
IF key<>"" Then
   keys=" and title like '%"&key&"%'"
   IF Instr(key," ")>0 Then
      keym=split(key," ")
	  keys=""
	  for m=0 to ubound(keym)
	  keys=keys&" and title like '%"&keym(m)&"%'"
	  next
   End IF
End IF
select case a
  case "h"
     sqla=" and xShang>=50"
  case "t"
     sqla=" and state=4"
  case "o"
     sqla=" and ansNum=0"
  case "y"
     sqla=" and(state=1 or state=5  or state=6  or state=7)"
  case "j"
     sqla=" and isStrong=1"
  case "s"
     sqla=" "
  case else
     sqla=" and state=0"
end select

Dim maxperpage,n,minid,classStr
maxperpage=setting(9)

IF classid>0 then classStr=" and (a.sclass="&classid&" or ','+b.ParentStr+',' like '%,"&classid&",%')"

        set rs=conn.execute("select count(askid) from "&predb&"Ask a inner join "&predb&"Class b on a.sclass=b.classid where a.ispass=1"&sqla&keys&classstr)
		idcount=rs(0) 
		set rs=nothing
		
		If idcount Mod maxperpage = 0 Then
			n = idcount \ maxperpage
		else
			n = idcount \ maxperpage + 1
		end If
		
IF page>n then page=n
IF page<1 then page=1

		if page=1 then
           set rs=conn.execute("select top "&maxperpage&" askid,title,xShang,asktime,ansNum,AskUser,classid,classname from "&predb&"Ask a inner join "&predb&"Class b on a.sclass=b.classid where a.ispass=1"&sqla&keys&classstr&" Order by AskID desc")
		else
			set rs1=conn.execute("select min(askid) from (select top "&(page-1)*maxperpage&" askid from "&predb&"Ask a inner join "&predb&"Class b on a.sclass=b.classid where a.ispass=1"&sqla&keys&classstr&" Order by AskID desc) d")
			    minid=rs1(0)
			set rs1=nothing
			set rs=conn.execute("select top "&maxperpage&" askid,title,xShang,asktime,ansNum,AskUser,classid,classname from "&predb&"Ask a inner join "&predb&"Class b on a.sclass=b.classid where askid<"&minid&" and a.ispass=1"&sqla&keys&classstr&" Order by AskID desc")
		end if
	
	if not(rs.bof and rs.eof) then
	do while not rs.eof
	
	str=str&"<div class=""lb-l"">"&vbcrlf
	str=str&"<ul>"&vbcrlf
	str=str&"<li class=""b1"">[<a href="""
    IF setting(34)=0 Then
	str=str&"List.asp?classid="&rs("CLassID")
	Else
	str=str&siteInfo(1)&"List-"&rs("CLassID")&".html"
	End IF
	str=str&""">"&AskD.leftstr(rs("classname"),10)&"</a>]</li>"&vbcrlf
	str=str&"<li class=""b2""><a href="""
  IF setting(34)=0 Then
  str=str&"ask.asp?id="&rs("askid")&""
  Else
  str=str&siteInfo(1)&"ask-"&rs("askid")&".html"
  End IF
  str=str&""" target=""_blank"">"&AskD.leftstr(rs("title"),50)&"</a>"
	If rs("xShang")>0 Then
	str=str&"<img src=""images/money.gif"" align=""absmiddle""/><font color=""#FF9900"">"&rs("xShang")&"</font>"
	End If
	str=str&"</li>"&vbcrlf
	str=str&"<li class=""b3"">"
	If rs("ansNum")=0 Then
	str=str&"<font color=""#FF9900""><b>"&rs("ansNum")&"</b></font>"
	Else
	str=str&rs("ansNum")
	End If
	str=str&"</li>"&vbcrlf
	str=str&"<li class=""b4"">"&AskD.Ftime(rs("asktime"))&"</li>"&vbcrlf
	str=str&"<li class=""b5""><a href=""user/userinfo.asp?id="&rs("AskUser")&""">"&cUSER(rs("AskUser"))&"</a></li>"&vbcrlf
	str=str&"</ul>"&vbcrlf
	str=str&"</div>"&vbcrlf

	rs.movenext
	loop
	end if
	rs.close
	set rs=nothing
	
If n>1 Then
		str=str&"<div class=""lb-page"">"&vbcrlf

   Select Case setting(10)
   Case 1
    ''样式1
	'带入page、n 即可
	Dim ReClass,RePage,ReP
	if classid>0 then
	   ReClass="-"&classid
	end if
	
	if classid>0 then
	  RePage="-"&page-1
	else
	  RePage=page-1
	end if
	
	if RePage=1 then RePage=""
	
	Dim StartPage,EndPage,p
	StartPage=page-7
	EndPage=page+7
	
	IF StartPage<1 Then
	   StartPage=1
	   EndPage=15
	End IF
	
	IF EndPage>n Then
	   EndPage=n
	End IF  
	
	IF n>=15 and n-StartPage<15 Then
	   StartPage=n-14
	   EndPage=n
	End IF
	   str=str&"共 <font color=""#FF0000"">"&n&"</font> 页"&vbcrlf
	IF page>1 and page<=8 Then
	   str=str&"<a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&page-1&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&page-1&"-"&keyv&".html"
	   End IF
	   str=str&""">上一页</a>"
	ElseIF page>8 Then
	   str=str&"<a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&page-1&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&page-1&"-"&keyv&".html"
	   End IF
	   str=str&""">上一页</a>"
	   str=str&"<a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page=1"
	   Else
	   str=str&"list-"&a&"-"&classid&"-1-"&keyv&".html"
	   End IF
	   str=str&""">1…</a>"
	End IF
	
	For p=StartPage To EndPage
		   if classid>0 then
			  ReP="-"&p
		   else
			  ReP=p
		   end if
		   if p=1 then ReP=""
		   
		   IF page=p Then
		   str=str&"<a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&p&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&p&"-"&keyv&".html"
	   End IF
	   str=str&"""><b><font color=""#FF0000"">"&p&"</font></b></a>"
		   Else
		   str=str&"<a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&p&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&p&"-"&keyv&".html"
	   End IF
	   str=str&""">"&p&"</a>"
		   End If
	Next
	
	Case 2
	''样式2
	str=str&"共<b>"&idcount&"</b>则 <font color=""#FF0000"">"&page&"</font>/"&n&"页&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page=1"
	   Else
	   str=str&"list-"&a&"-"&classid&"-1-"&keyv&".html"
	   End IF
	   str=str&""">首页</a>&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&page-1&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&page-1&"-"&keyv&".html"
	   End IF
	   str=str&""">上一页</a>&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&page+1&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&page+1&"-"&keyv&".html"
	   End IF
	   str=str&""">下一页</a>&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&n&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&n&"-"&keyv&".html"
	   End IF
	   str=str&""">尾页</a>"&vbcrlf
    Case 3
	''样式3
	str=str&"共<b>"&idcount&"</b>则 <font color=""#FF0000"">"&page&"</font>/"&n&"页&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page=1"
	   Else
	   str=str&"list-"&a&"-"&classid&"-1-"&keyv&".html"
	   End IF
	   str=str&""">首页</a>&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&page-1&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&page-1&"-"&keyv&".html"
	   End IF
	   str=str&""">上一页</a>&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&page+1&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&page+1&"-"&keyv&".html"
	   End IF
	   str=str&""">下一页</a>&nbsp;&nbsp; <a href="""
	   IF setting(34)=0 Then
	   str=str&"?a="&a&"&key="&keyv&"&classid="&classid&"&page="&n&""
	   Else
	   str=str&"list-"&a&"-"&classid&"-"&n&"-"&keyv&".html"
	   End IF
	   str=str&""">尾页</a>"&vbcrlf
    str=str&"&nbsp;&nbsp;转到第<Input type=""text"" name=""page"" size=""3"" maxlength=""5"" value="""&page&""" onKeyPress=""if (event.keyCode==13) window.location='"
	IF setting(34)=0 Then
	str=str&"list.asp?a="&a&"&key="&keyv&"&classid="&classid&"&page='+this.value"
	Else
	str=str&"list-"&a&"-"&classid&"-'+this.value+'-"&keyv&".html'"
	End IF
	str=str&";"">页"&vbcrlf
	End Select

    str=str&"</div>"&vbcrlf
end if
ClassList=str
End Function

Function cUSER(uid)
dim rs
  set rs=conn.execute("select userid from "&predb&"user where id="&uid)
  if rs.bof and rs.eof then
  cUSER="用户被删除"
  else
  cUSER=rs(0)
  end if
  set rs=nothing
End Function
%>