<!-- #include file="Inc.asp" -->
<!--#include file="ydzq1.asp"-->
<%
call head()

dim TP,ids,Action,bbsid
bbsid=Request("bbsid")
if bbsid<>"" then
if bbsid="" or Isnumeric(bbsid)=False then
  Call Error("论坛ID无效！")
  end if
dim namebbs
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select name from ydbbs where id="&bbsid,conn,1,1
if rs.eof then
  Call Error("论坛不存在！")
  end if
namebbs=rs("name")
rs.close
set rs=nothing
  end if
Action=Request("Action")
IF  Action="ok" Then
	call search
else

	call main
end if
sub main

Call saycarda("社区搜索")
if myid<>0 then
mz="[url=/bbs/uinfo.asp?id="&myid&"&amp;saytk="&saytk&"&sid=[sid]]"&myni&"[/url]"
else
mz="游客"
end if
conn.execute("insert into sqdt(shijian,dz)values('"&now&"','"&mz&"使用了(url=/bbs/search.asp?saytk=[saytk]&sid=[sid])社区搜索(/url)')")
If saytk<>1 Then
Response.write "<form name=""form"" method=""post"" action=""search.asp?saytk="&saytk&"&amp;sid="&sid&""">"
End if
response.write "请输入关键词:<br/>"
response.write "<input name=""keyword"" value="""" title=""输入关键词""/><br/>"
response.write "<select name=""sear"" value=""1"">"
response.write "<option value=""1"">按标题搜索</option>"
response.write "<option value=""2"">按内容搜索</option>"
response.write "</select><br/>"
response.write "搜索范围: <br/>"
response.write "<select name=""sear2"" value=""2"">"
if bbsid<>"" then

response.write "<option value=""1"">"&namebbs&"</option>"
end if
response.write "<option value=""2"">本社区</option>"
response.write "</select><br/>"

response.write "发表时间: <br/>"
response.write "<select name=""times"" value=""1"">"
response.write "<option value=""1"">一周内</option>"
response.write "<option value=""2"">一个月内</option>"
response.write "<option value=""3"">三个月内</option>"
response.write "<option value=""4"">不限制</option>"
response.write "</select><br/>"
If saytk<>1 Then
response.write "<input type=""hidden"" name=""Action"" value=""ok""/>"
response.write "<input type=""submit"" name=""Submit"" value=""搜帖子"" style=""background-color:#66FF66;display:inline""></form><br/>"
else
response.write "<anchor>搜帖子<go href=""search.asp?saytk="&saytk&"&amp;sid="&sid&""" method=""post"">"
response.write "<postfield name=""keyword"" value=""$(keyword)""/>"
response.write "<postfield name=""sear"" value=""$(sear)""/>"
response.write "<postfield name=""sear2"" value=""$(sear2)""/>"
response.write "<postfield name=""times"" value=""$(times)""/>"
response.write "<postfield name=""Action"" value=""ok""/>"
End if
if bbsid<>"" then
response.write "<postfield name=""bbsid"" value="""&bbsid&"""/>"
end  if
response.write "</go></anchor><br/>"
end sub

sub search
Call saycarda("搜索结果")

dim keyword,sear,sear2,times
keyword=request("keyword")
if keyword="" then
  Call Error("关键字不能为空！")
  end if
sear=request("sear")
if sear="" or IsNumeric(sear)=False then
  Call Error("搜索类型无效！")
  end if
sear2=clng(request("sear2"))
if sear2="" or IsNumeric(sear2)=False then
  Call Error("搜索范围无效！")
  end if

times=request("times")
if times="" or IsNumeric(times)=False then
  Call Error("发表时间无效！")
  end If
  if sear=1 then
dim gettxt
gettxt="select * from sell where yc=0"


gettxt= gettxt & " and name like '%" & keyword & "%'"
  if sear2=1 then
	if bbsid="" or Isnumeric(bbsid)=False then
	  Call Error("论坛ID无效！")
	  end if
  gettxt= gettxt & "and bbsid="&bbsid&""
  end if


	



times=clng(times)
if times=1 then 
gettxt=gettxt & "and "&datediff("d",Now(),tm)&"<7"
elseif times=2 then 
gettxt=gettxt& " and "&datediff("d",NOw(),tm)&"<30"
else
gettxt=gettxt & "and "&datediff("d",NOw(),tm)&"<90"
end if

  gettxt = gettxt & " ORDER BY ID DESC"

set rs=Server.CreateObject("ADODB.Recordset")
rs.open gettxt,conn,1,1
If Not rs.eof	Then
Dim PageSize,i
	PageSize=10							
	Dim Count,page,pagecount,gopage	
	gopage="search.asp?sid="&sid&"&amp;Action=ok&amp;keyword="&keyword&"&amp;sear="&sear&"&amp;sear2="&sear2&"&amp;times="&times&"&amp;saytk="&saytk&"&amp;"
	Count=rs.recordcount
	page=int(request.QueryString ("page"))
	if page<=0 or page="" then page=1    
	pagecount=(count+pagesize-1)\pagesize
        if page>pagecount then page=pagecount	
	rs.move(pagesize*(page-1))
        response.write ("共:"&count&"条相关帖子<br/>")				
	For i=1 To PageSize       						
	If rs.eof Then Exit For	
response.write ""&i+(page-1)*PageSize&"."
        dim nowtx
        if rs("fs")=1 then
        nowtx="综合"
        elseif rs("fs")=2 then 
        nowtx="经验"
        elseif rs("fs")=3 then 
        nowtx="分享"
        elseif rs("fs")=4 then
        nowtx="提问"
        else 
        nowtx="综合"
        end if
response.write "<a href='topic.asp?tid="&rs("id")&"&amp;saytk="&saytk&"&amp;sid="&sid&"'>"
dim reCount
reCount=conn.execute("Select count(ID) from [relist] where tid="&rs("id"))(0)
response.write ubb(rs("name"))&"</a><br/>["
response.write ubb(rs("fname"))&"/"&nowtx&"/"&ubb(rs("rc"))&"/"
if reCount<=0 then
response.write reCount
else
response.write "<a href=""relist.asp?tid="&rs("id")&"&amp;bbsid="&rs("bbsid")&"&amp;saytk="&saytk&"&amp;sid="&sid&""">"&reCount&"</a>"
end if
response.write"]<br/>"
rs.moveNext
 	Next
	'response.write "<br/>"&chr(13)
	if page-pagecount<0 then response.write "<a href="""&gopage&"page="&page+1&""">下一页</a>"&chr(13)
	if page>1 then response.write "<a href="""&gopage&"page="&page-1&""">上一页</a>"&chr(13)

response.write "<br/>("&page&"/"&pagecount&")共"&count&"帖"
	if pagecount>1 then response.write "<input name=""page"" format=""*N"" value="""&page&""" type=""text"" maxlength=""5"" emptyok=""true"" size=""2""/><a href="""&gopage&"page=$(page)"">页</a>"

response.write "<br/>"
Else
Response.write "没有符合条件的帖子<br/>"
end if
rs.close
set rs=Nothing

End if
response.write "<br/><a href=""search.asp?bbsid="&bbsid&"&amp;saytk="&saytk&"&amp;sid="&sid&""">重新搜索</a><br/>"
end sub
conn.close
set conn=Nothing
If saytk=1 then
Response.write "<anchor>返回上级<prev/></anchor>"
End if
response.write "<br/><a href=""searchuser.asp?bbsid="&bbsid&"&amp;saytk="&saytk&"&amp;sid="&sid&""">搜索会员</a>"
response.write "<br/><a href=""searchbbs.asp?bbsid="&bbsid&"&amp;saytk="&saytk&"&amp;sid="&sid&""">搜索论坛</a>"
response.write "<br/><a href=""/so.asp?saytk="&saytk&"&amp;sid="&sid&""">搜索资源</a>"
%>
<!--#include file="fanhui.asp"-->
<%Call headsay()%>