<!-- #Include File="Include/Config.asp" -->
<!-- #Include File="../Include/Cls_Search.asp" -->
<!-- #Include File="../Include/Cls_PageCute.asp" -->
<%

'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

tit_fir="在线论坛"
dim max_num,username,sql_add,sql_order,issearch,isadv
'dim tmp_url,tmp_sql,fid,fids,obj_search,tmp_topic,tmp_keyword,stmp_keyword,j
dim tmp_url,tmp_sql,fid,fids,obj_search,tmp_topic
dim tmp1,tmp,tmpleft
max_num=200
issearch=false
if action="user" or action="user_join" then
  username=Cls.code_query("username")
  if ChkName(username)=false then
    action=""
  end if
end if
isadv=false
if Cls.code_query("search")="isadv" then isadv=true
Select Case Lcase(Action)
Case "search"
  tit="搜索结果"
Case "my"
  tit="我发布的论坛主题"
Case "join"
  tit="我参与的论坛主题"
case "user"
  tit=username&" 发布的主题"
case "user_join"
  tit=username&" 参与的主题"
Case "reply"
  tit="最新回复"
Case "hot"
  tit="论坛热贴"
Case "good"
  tit="论坛精华"
Case "top"
  tit="论坛置顶"
Case else
  tit="论坛新贴"
End Select
call DoWebHead(0,0)
  tmpleft="<table width='100%' border='0' cellspacing='0' cellpadding='0' class=bbs_table><tr class=bbs_tr><td class=bbs_td colspan=2>论坛导航</td></tr><tr class=bbs_tr><td><a href='./index.asp'>论坛首页</a></td><td><a href='search.asp?action=top'>论坛置顶</a></td></tr><tr class=bbs_tr><td><a href='search.asp?action=new'>论坛新贴</a></td><td><a href='search.asp?action=reply'>最新回复</a></td></tr><tr class=bbs_tr><td><a href='search.asp?action=hot'>论坛热贴</a></td><td><a href='search.asp?action=good'>论坛精华</a></td></tr><tr class=bbs_tr><td><a href='search.asp?action=my'>我的主题</a></td><td><a href='search.asp?action=join'>我的回复</a></td></tr><tr class=bbs_tr><td><a href='search.asp?action=search'>论坛搜索</a></td><td><a href=''&Cls.Web_Dir&'Common/help.asp?action=Bbs'>论坛帮助</a></td></tr></table>"&ukong
  tmpleft=tmpleft&search_left()
  HtmlContent = Cls.ReadTemplate("search") 
  HtmlContent = LoadWebHead(HtmlContent)
  HtmlContent = LoadWebEnd(HtmlContent)
  HtmlContent = Replace(HtmlContent,"{$left}",tmpleft)
  HtmlContent = Replace(HtmlContent,"{$main}",search_list())
  Response.Write Cls.ReHtml(HtmlContent,0)
call DoWebEnd()
Function serach_err(byval strer)
  select case strer
  case "login"
    tmp1="请先登陆后再执行本操作！"
  case "condition"
    tmp1="请在左侧输入搜索关键字及相关选项！"
  case "space"
    tmp1="搜索时间间隔不得少于 <font class=red>"&Format_Mid_Num(17)&"</font> 秒钟！请勿重复搜索。"
  case else
    tmp1="未知的错误信息！"
  end select
  tmp="<table border=0><tr height=280 align=center><td><img border=0 src='../images/load.gif'></td><td width=10></td><td class=blue>"&tmp1&"</td></tr></table>"
  serach_err=vbcrlf&"<table cellspacing=1 cellpadding=4 class=bbs_table>" & _
         vbcrlf&"<tr><td class=bbs_td colspan=2> 错误提示</td></tr>" & _
         vbcrlf&"<tr class=bbs_tr><td align=center>"&tmp&"</td></tr>" & _
         vbcrlf&"</table>"
end Function
Function search_list()
tmp_url="?action="&action&"&"
if isadv then tmp_url=tmp_url&"search=isadv&"
select case action
case "search"
  if Is_LoginTrue=false then
    search_list = serach_err("login")
    exit function
  end if
  if request.QueryString("keyword")<>"" then
    if not Cls.Put_Space("search_tim",Format_Mid_Num(17)) then
      search_list = serach_err("space")
      exit function
    end if
  else
    search_list = serach_err("condition")
    exit function
  end if
  fid=Cls.code_id("sea_fid")
  fids=bbs_search_fid(fid)
  if fids="" then
    fid=0
  else
    tmp_sql=" bbs_id in ("&fids&")"
  end if
  tmp_url=tmp_url&"sea_fid="&fid&"&"
  set obj_search=new Cls_Search
  obj_search.inc_url=tmp_url
  obj_search.inc_sql=tmp_sql
  call obj_search.format_search("topic","topic,username",2,1,0)
  tmp_url=obj_search.inc_url
  tmp_sql=obj_search.inc_sql
  tmp_keyword=obj_search.keyword
  if obj_search.keyword="" then
    set obj_search=nothing
	search_list = serach_err("condition")
    exit function
  end if
  sql_add=tmp_sql
  sql_order=" id desc"
  issearch=true
case "my"
  if Is_LoginTrue=false then
    search_list = serach_err("login")
    exit function
  end if
  sql_add="userid="&login_id
  sql_order="id desc"
case "join"
  if Is_LoginTrue=false then
    search_list = serach_err("login")
    exit function
  end if
  sql_add="id in (select reply_id from AsaiMHBbsData where userid="&login_id&")"
  sql_order="order_id desc"
case "user"
  tmp_url=tmp_url&"username="&username&"&"
  sql_add="username='"&username&"'"
  sql_order="id desc"
  tit=username&" 发布的主题"
case "user_join"
  sql_add="id in (select reply_id from AsaiMHBbsData where username='"&username&"')"
  sql_order="id desc"
  tit=username&" 参与的主题"
case "reply"
  sql_order="re_tim desc"
  tit="最新回复"
case "hot"
  sql_order="re_counter desc,id desc"
  tit="论坛热贴"
case "good"
  sql_add="isgood=1"
  sql_order="id desc"
  tit="论坛精华"
case "top"
  sql_add="istop>0"
  sql_order="istop desc,id desc"
  tit="论坛置顶"
case else
  sql_order="id desc"
  tit="论坛新贴"
end select
  if sql_add="" then
    sql_add="bbs_id<999999999"
  else
    sql_add="bbs_id<999999999 and "&sql_add
  end if
  dim obj_page
  set obj_page=new Cls_PageCute
  obj_page.pageurl=tmp_url
  obj_page.nummer=Format_Mid_Num(12)
  obj_page.page_t=1
  obj_page.page_p=5
  obj_page.page_unit="贴"
  obj_page.page_tit="主题"
  obj_page.v_id="id"
  Call obj_page.p_init("*","AsaiMHBbsTopic",sql_add,sql_order)
  sql=obj_page.sql_count
  set rs=Cls.exec(sql,1)
  obj_page.rssum=rs(0)
  rs.close
  if obj_page.rssum>max_num and max_num>0 then
    obj_page.rssum=max_num
  end if
  call obj_page.p_main("*","AsaiMHBbsTopic",sql_add,sql_order)
  tmp1=vbcrlf&"<table cellspacing=0 cellpadding=0 class=bbs_table width='100%'>" & _
       vbcrlf&"<tr><td class=bbs_td colspan=5>"&tit&"</td></tr>" & _
       vbcrlf&"<tr class=bbs_th align=center>" & _
       vbcrlf&"<th width=30>状态</th>" & _
       vbcrlf&"<th width=*>主题"
 if issearch then tmp1=tmp1&vbcrlf&"<font style=""font-weight:normal;"" class=Gys>（关键字：<font class=red>"&tmp_keyword&"</font>）</font>"
  tmp1=tmp1&vbcrlf&"</th>" & _
       vbcrlf&"<th width=100>作者</th>" & _
       vbcrlf&"<th width=40>回复</th>" & _
       vbcrlf&"<th width=40 class=tsh>浏览</th>" & _
       vbcrlf&"</tr>"
  if rs.eof then
  tmp1=tmp1&"<tr class=bbs_tr><td colspan=5 class=s>暂时没有找到相关记录！</td></tr>"
  else
  for i=1 to obj_page.page_num
    tmp_topic=rs("topic")
	'tmp_keyword=replace(tmp_keyword,"+"," ")
	'stmp_keyword=split(tmp_keyword," ")
	'For j=0 To ubound(stmp_keyword)
      'tmp_topic=KeyWord_Highlight(tmp_topic,stmp_keyword(j),"<font color=red><b>","</b></font>")
	  tmp_topic = Cls.Channel_Search(tmp_topic)
	'Next
	'Erase stmp_keyword
	tmp1=tmp1&vbcrlf&bbs_topic_type(rs("id"),rs("bbs_id"),tmp_topic,rs("username"),rs("counter"),rs("re_counter"),rs("istop"),rs("islock"),rs("isgood"),rs("isvote"),rs("vote_num"))
    rs.movenext
  next
  end if
  rs.close
  tmp1=tmp1&vbcrlf&"<tr><td class=bbs_trp colspan=5>" & _
            vbcrlf&"<div id=asaipage>" & _
            vbcrlf&""&obj_page.page_var&"" & _
            vbcrlf&"分页：" & _
            vbcrlf&""&obj_page.page_cute&"" & _
            vbcrlf&  obj_page.page_shortcut  & _
            vbcrlf&"</div>" & _
            vbcrlf&"</td>" & _
            vbcrlf&"</tr>" & _
            vbcrlf&"</table>"&ukong & _
            vbcrlf&"<table border=0 class=table>" & _
            vbcrlf&"<tr class=bbs_tr><td align=right>论坛跳转："&bbs_select()&"</td></tr>" & _
            vbcrlf&"</table>" & _
            vbcrlf&"<br /><br /><table border=0 class=table>" & _
            vbcrlf&"<tr class=bbs_tr><td>"&bbs_img_topic()&"</td></tr>" & _
            vbcrlf&"</table>"
  set obj_page=nothing
  set obj_search=nothing
  search_list=tmp1
end function

function bbs_topic_type(t_id,t_bbs_id,t_topic,t_username,t_counter,t_re_counter,t_istop,t_islock,t_isgood,t_isvote,t_vote_num)
  tmp1=vbcrlf&"<tr class=bbs_tr>" & _
       vbcrlf&"<td class=list81><img src='"&Cls.web_skindir&"Bbs/"&bbs_topic_folder(t_re_counter,10,t_istop,t_isvote)&".gif' border=0></td>" & _
       vbcrlf&"<td align=left class=list8><a href='view.asp?id="&t_id&"' target=_blank>"&t_topic&"</a>"&pagecute_topic(10,t_re_counter,"view.asp?id="&t_id)&"</td>" & _
       vbcrlf&"<td class=list8>"&format_user_view(t_username,1,10)&"</td>" & _
       vbcrlf&"<td class=list8>"&t_re_counter&"</td>" & _
       vbcrlf&"<td class=list9>"&t_counter&"</td>" & _
       vbcrlf&"</tr>"
  bbs_topic_type=tmp1
end function

function search_left()
  dim fid,seatype,seatype1,seatype2,seaterm,seaterm1,seaterm2
  seatype=Cls.code_query("sea_type")
  if seatype="username" then 
   seatype1=""
   seatype2="checked"
  else
   seatype1="checked"
   seatype2=""
  end if
  seaterm=Cls.code_query("sea_term")
  if seaterm="only" then 
   seaterm1=""
   seaterm2="checked"
  else
   seaterm1="checked"
   seaterm2=""
  end if
   tmp1=tmp1&vbcrlf&"<form name=bbs_sea_frm action='?' method=get onsubmit=""javascript:frm_submitonce(this);"">" & _
       vbcrlf&"<input type=hidden name=action value='search'>" & _
       vbcrlf&"<tr><td height=5></td></tr>" & _
       vbcrlf&"<tr><td>您要搜索的帖子是：</td></tr>" & _
       vbcrlf&"<tr><td height=5></td></tr>" & _
       vbcrlf&"<tr><td><b>搜索关键字：</b></td></tr>" & _
       vbcrlf&"<tr><td><input type=text class=txt name=keyword value='"&Request.QueryString("keyword")&"' size=22 maxlength=20></td></tr>"
 if isadv then
  tmp1=tmp1&vbcrlf&"<tr><td height=5></td></tr>" & _
       vbcrlf&"<input type=hidden name=search value='isadv'>" & _
       vbcrlf&"<tr><td><b>搜索方式：</b></td></tr>" & _
       vbcrlf&"<tr><td><input type=radio name=sea_type value='topic' "&seatype1&">按帖子主题搜索</td></tr>" & _
       vbcrlf&"<tr><td><input type=radio name=sea_type value='username' "&seatype2&">按发布人搜索</td></tr>" & _
       vbcrlf&"<tr><td height=5></td></tr>" & _
       vbcrlf&"<tr><td><b>搜索条件：</b></td></tr>" & _
       vbcrlf&"<tr><td><input type=radio name=sea_term value='all' "&seaterm1&">满足所有条件</td></tr>" & _
       vbcrlf&"<tr><td><input type=radio name=sea_term value='only' "&seaterm2&">满足一个条件</td></tr>"
 end if
  fid=Cls.code_id("sea_fid")
  tmp1=tmp1&vbcrlf&"<tr><td height=5></td></tr>" & _
       vbcrlf&"<tr><td><b>搜索范围：</b></td></tr>" & _
       vbcrlf&"<tr><td>"&bbs_isaction_list(fid)&"</td></tr>" & _
       vbcrlf&"<tr><td height=5></td></tr>" & _
       vbcrlf&"<tr><td>"
  if isadv then
   tmp1=tmp1&vbcrlf&""&Cls.img("ico_hign")&"<a href='?action=search'>普通搜索</a>"
  else
   tmp1=tmp1&vbcrlf&""&Cls.img("ico_hign")&"<a href='?action=search&search=isadv'>高级搜索</a>"
  end if
   tmp1=tmp1&vbcrlf&"&nbsp;&nbsp;<input type=submit class=btn value='开始搜索'></td></tr>" & _
       vbcrlf&"</form>"
  search_left=vbcrlf&"<br><br><table cellspacing=0 cellpadding=0 class=bbs_table width=;100%'>" & _
         vbcrlf&"<tr><td class=bbs_td colspan=2> 论坛搜索</td></tr>" & _
         vbcrlf&"<tr class=bbs_tr><td><table cellspacing=0 cellpadding=0 border=0>"&tmp1&"</table></td></tr>" & _
         vbcrlf&"</table>"
end function

function bbs_search_fid(nfid)
  if not Cls.is_int(nfid) then
    bbs_search_fid=""
    exit function
  end if
  dim fp,temp1
  sql="select top 1 bbs_parent from AsaiMHBbsClass where bbs_hidden=0 and bbs_id="&nfid
  set rs=Cls.exec(sql,1)
  if rs.eof then
    rs.close
    bbs_search_fid=""
    exit function
  end if
  fp=rs(0)
  rs.close
  temp1=nfid
  sql="select bbs_id from AsaiMHBbsClass where bbs_hidden=0 and left(bbs_parent,"&(len(fp)+1)&")='"&fp&",' order by bbs_id"
  set rs=Cls.exec(sql,1)
  do while not rs.eof
    temp1=temp1&","&rs(0)
    rs.movenext
  loop
  rs.close
  bbs_search_fid=temp1
end function

function bbs_isaction_list(il_Bbsid)
  dim temp1,tmp_cid,tmp_classid,tmp_j,dim_bbs_data,bbs_cnum
  tmp_cid=0
  temp1="<select name=sea_fid><option value='0'>所有论坛版块…</option>"
  dim_bbs_data=Cls.cache_get("bbs_class")
  bbs_cnum=-1
  if isarray(dim_bbs_data) then
    bbs_cnum=ubound(dim_bbs_data,2)
  end if
  for i=0 to bbs_cnum
    tmp_classid=Cls.cache_get("bbs_class")(0,i)
    if int(tmp_cid)<>int(tmp_classid) then
      temp1=temp1&vbcrlf&"<option  value='"&Cls.cache_get("bbs_class")(1,i)&"'"
      if int(Cls.cache_get("bbs_class")(1,i))=int(il_Bbsid) then
        temp1=temp1&" selected"
      end if
 	  temp1=temp1&">╋"&Cls.cache_get("bbs_class")(2,i)&"</option>"
      tmp_cid=tmp_classid
    else
      temp1=temp1&vbcrlf&"<option value='"&Cls.cache_get("bbs_class")(1,i)&"'"
      if int(Cls.cache_get("bbs_class")(1,i))=int(il_Bbsid) then
        temp1=temp1&" selected"
      end if
      temp1=temp1&">"
      for tmp_j=1 to (Cls.cache_get("bbs_class")(6,i)-1)
        temp1=temp1&"│"
      next
      temp1=temp1&"├"&Cls.cache_get("bbs_class")(2,i)
      'if Cls.cache_get("bbs_class")(5,i)=false then temp1=temp1&" <不可发贴>"
      'if Cls.cache_get("bbs_class")(10,i)=1 then temp1=temp1&" <只读>"
      temp1=temp1&"</option>"
    end if
  next
  temp1=temp1&"</select>"
  bbs_isaction_list=temp1
end function
%>
