<?php
include_once("inc/config.php");
include_once("inc/ftbbsdbclass.php");
include_once("inc/publicfun.php");
include_once("conn.php");
include_once("inc/pageclass.php");
include_once("inc/checkpost.php");

$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=makecache('ftbbsmb.html',$query,$expire);
include_once("sound.php");
include_once("ftbbs_nav.php");
$getcodeoff=$ftbbsmb[30];
$onlineoff=$ftbbsmb[33];
$linkoff=$ftbbsmb[34];
$htmlsign=$ftbbsmb[37];
$defaulthome=$ftbbsmb[31];

if ($_GET["searchcontent"]!="" && $_POST["b"]==""){
$searchcontent=ftbbs_request($_GET["searchcontent"]);
$searchkind=ftbbs_request($_GET["searchkind"]);
}
else{
$searchcontent=ftbbs_request($_POST["searchcontent"]);
$searchkind=ftbbs_request($_POST["searchkind"]);
}
include_once("homeurl.php");
//以下是新增论坛权限访问的功能
if (get_cookie('username')==""){
   $strqssql="where BBS_Cate_Qs=1 or BBS_Cate_Qs=2 or BBS_Cate_Qs=3";
   }
else{
   if (get_cookie('payuser')==1){
      $strqssql="where BBS_Cate_Qs=3";
	  }
   elseif (get_cookie('bz')==1 || get_cookie('bbsadmin')==1){
      $strqssql="";
	  }
   else{
      $strqssql="where BBS_Cate_Qs=2 or BBS_Cate_Qs=3";
   }
}

$qssql="select BBS_Cate_ID from {$tablepre}bbs_cate ".$strqssql."";
$qsrs=mysql_query($qssql);
$qsrow = mysql_fetch_array($qsrs);
$numrows = mysql_num_rows($qsrs);

if ($numrows!=0 && $strqssql!=""){
    $k=0;
    do {
	  $k++;
      if ($k==$numrows){
	     $qsbbsx1=$qsrow[1];
	  }
	  else{
         $qsbbsx1=$qsrow[1].",";
	  }
	  $qsbbs1=$qsbbs1.$qsbbsx1;
     }
	while ($qsrow = mysql_fetch_array($qsrs));
   if (strrpos($qsbbs1,",")){
     $qsarray1 = explode(",",$qsbbs1);
	 for($b=0; $b<count($qsarray1); $b++){
        if ($b==count($qsarray1)-1){
	    $qssqlstrx = "BoardID_1<>'" . $qsarray1[$b] ."' and BoardID_2<>'" . $qsarray1[$b] ."'";
		}
	    else{
	    $qssqlstrx = "BoardID_1<>'" . $qsarray1[$b] ."' and BoardID_2<>'" . $qsarray1[$b] ."' and ";
	    }
	    $qssqlstr1 = $qssqlstr1.$qssqlstrx;
     }
     $qssqlstr1 = $qssqlstr1." and ";
	 }
   else{
     $qssqlstr1 = "BoardID_1<>'" .$qsbbs1."' and BoardID_2<>'".$qsbbs1."' and ";
   }
   $strqs=$qssqlstr1;
}

if ($searchkind == "menu"){
   $strqs=str_replace("BoardID_1","{$tablepre}bbstitle.BoardID_1",$strqs);
   $strqs=str_replace("BoardID_2","{$tablepre}bbstitle.BoardID_2",$strqs);
   $strsql="SELECT ID,Boardid_1,Boardid_2,user_id,name,title,hit,rep,dateh,redate,bbs_img,bbs_img_display,huati,img_url_display,P_display,picture,sign,zhiye,htmfilename,bbstop,bbstop1,titlecolor,boardsign,reinfo from {$tablepre}bbstitle where ".$strqs." menu like '%".$searchcontent."%' and deleted=0 order by bbstop1 desc,bbstop desc,redate desc";
}
elseif ($searchkind == "remenu"){
   $strqs=str_replace("BoardID_1","bbstitle.BoardID_1",$strqs);
   $strqs=str_replace("BoardID_2","bbstitle.BoardID_2",$strqs);
   $strsql="SELECT {$tablepre}bbstitle.*,{$tablepre}bbsmenu.* FROM {$tablepre}bbstitle LEFT JOIN {$tablepre}bbsmenu ON {$tablepre}bbstitle.id={$tablepre}bbsmenu.pid WHERE ".$strqs." ({$tablepre}bbstitle.menu like '%".$searchcontent."%' or {$tablepre}bbsmenu.remenu like '%".$searchcontent."%') and {$tablepre}bbstitle.deleted=0 and {$tablepre}bbsmenu.pid IS NOT NULL group by {$tablepre}bbstitle.ID having count(*)>1";
}
elseif ($searchkind=="myrepost"){
   $strsql="SELECT {$tablepre}bbstitle.*,{$tablepre}bbsmenu.* FROM {$tablepre}bbstitle LEFT JOIN {$tablepre}bbsmenu ON {$tablepre}bbstitle.id={$tablepre}bbsmenu.pid WHERE {$tablepre}bbsmenu.user_id='".get_cookie('username')."' and {$tablepre}bbstitle.deleted=0 and {$tablepre}bbsmenu.pid IS NOT NULL group by {$tablepre}bbstitle.ID having count(*)>1";
}
elseif ($searchkind=="title"){
   $strsql="SELECT ID,Boardid_1,Boardid_2,user_id,name,title,hit,rep,dateh,redate,bbs_img,bbs_img_display,huati,img_url_display,P_display,picture,sign,zhiye,htmfilename,bbstop,bbstop1,titlecolor,boardsign,reinfo from {$tablepre}bbstitle where ".$strqs." title like '%".$searchcontent."%' and deleted=0 order by bbstop1 desc,bbstop desc,redate desc";
}
elseif ($searchkind=="user_id"){
   $strsql="SELECT ID,Boardid_1,Boardid_2,user_id,name,title,hit,rep,dateh,redate,bbs_img,bbs_img_display,huati,img_url_display,P_display,picture,sign,zhiye,htmfilename,bbstop,bbstop1,titlecolor,boardsign,reinfo from {$tablepre}bbstitle where ".$strqs." user_id='".$searchcontent."' and deleted=0 order by bbstop1 desc,bbstop desc,redate desc";
}
else{
   $strsql="SELECT ID,Boardid_1,Boardid_2,user_id,name,title,hit,rep,dateh,redate,bbs_img,bbs_img_display,huati,img_url_display,P_display,picture,sign,zhiye,htmfilename,bbstop,bbstop1,titlecolor,boardsign,reinfo from {$tablepre}bbstitle where ".$strqs." deleted=0 and (bbstop1=1 or bbstop=1) order by redate desc";
}

$p = new ft_page;
$pagesize=$ftbbsmb[5];
$rs=mysql_query($strsql);
$myrow = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs); 

$p->pvar="page"; 
$p->setvar(array("searchcontent" => $searchcontent, "searchkind" => $searchkind));
$p->set($pagesize,$numrows,$psize); 
$rsx=mysql_query($strsql." limit ".$p->limit());
?>
<HTML><HEAD>
<title>论坛贴子搜索</title>
<META http-equiv=Content-Type content=text/html;charset=utf-8>
<script language=javascript src="inc/cookies.js"></script>
<script>
var stylecook = getCookie("STYLESHOW");
var style;
var strstyle;
if(stylecook=="")
{
 stylecook=1;
}
else
{
 stylecook++;
}
style="main0"+stylecook+".css";
strstyle="<link href=\"css/"+style+"\"  rel=\"stylesheet\" type=\"text/css\"> ";
document.write(strstyle);
</script>
</HEAD>
</head>
<script language="javascript">
<!--
	function check_search(form)
		{
		if (form.searchcontent.value=="")
			{
			alert("请输入搜索内容！");
			form.searchcontent.focus();
			return false;
			}
			return true;
		}
//-->
</script>
<body>
<?
if (get_cookie('ftbbstype')==1){
include_once("pbhead.php");
}
?>
<table width="99%" border="0" cellspacing="0" cellpadding="0" align="center" class="maintbbg">
  <tr>
    <td> 
      <table width="100%" border=0 cellpadding=2 cellspacing=1 class="maintbbg">
        <tbody>
          <tr> 
            <td height="25" colspan="3" class="f12bg">&nbsp;<?=$userinfo?></td>
          </tr>
          <tr> 
            <td height="25" colspan="3" class="maintbtr3">&nbsp;<a href="<?=$homepage?>">论坛首页</a> 
              >> 贴子搜索</td>
          </tr>
          <tr>
            <td height="30" class="maintbtr3">
<fieldset>
			<legend>论坛贴子搜索:</legend>
              <form name="form1" method="post" action="" onSubmit="return check_search(this)">
                &nbsp;&nbsp;搜索关键字:
                <input name="searchcontent" type="text" size="35">
                <select name="searchkind" style="background-color:#ffffff;FONT-FAMILY: Arial; FONT-SIZE: 9pt; FONT-STYLE: normal; WIDTH: 73px">
                  <option value="title" selected>贴子主题</option>
                  <option value="user_id" >贴子作者</option>
				  <option value="menu" >主题内容</option>
				  <option value="remenu" >回贴内容</option>
                </select>
                <input name="search" src="images/d_search.gif" type="image" value="Submit" width="37" height="21" border="0" align="absmiddle" style="width:37px;height:21px;">
                <input name="b" type="hidden" id="b" value="y">
              </form>
			</fieldset>
            </td>
          </tr>
        </tbody>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=0 cellpadding=0 width="99%" align=center border=0>
  <tr> 
    <td height=5></td>
  </tr>
</table>
<table width="99%" border=0 cellpadding=2 cellspacing=0 class="listborder" align="center">
  <tbody>
    <tr align=middle class=f12> 
      <td width="6%" height="28" class="f12bg">状态</td>
      <td width="50%" class="f12bg">论坛主题</td>
      <td width="5%" class="f12bg">作者</td>
      <td width="6%" class="f12bg">回复</td>
      <td width="6%" class="f12bg">点击</td>
      <td width="25%" class="f12bg">最后更新</td>
    </tr>
    <?
if ($myrow = mysql_fetch_array($rsx)){
if ($numrows>0){
    do {
    $i++;
	$indbdate=$myrow["dateh"];
	$indbdate=dateFormat($indbdate,'y-m-d H:i'); 
	$titlecolor=$myrow["titlecolor"];
	$bbstitle=$myrow["title"];
	if ($htmlsign==1){
	$readurl="ftbbs-".$myrow["ID"].".html";
	}
	else{
	$readurl="ftbbs.php?id=".$myrow["ID"];
	}
	if ($titlecolor!=""){
	$title="<font color=".$titlecolor.">".$bbstitle."</font>";
	}
	else{
	$title=$bbstitle;
	}
	$reinfo=$myrow["reinfo"];
	if (strrpos($reinfo,"||")){
	$rearr=explode("||",$reinfo);
	$arrnum=count($rearr)-1;
	$reinfo=$rearr[$arrnum];
	}
	if (reinfo!="" && strrpos($reinfo,",")){
	$reinfo=str_replace("|","",$reinfo);
	$rearr=explode(",",$reinfo);
	$replydate=$rearr[0];
	$replydate=dateFormat($indbdate,'y-m-d H:i');
	$replyuser=" <font color=red>|</font> <a class=map href=ftbbsmyinfo.php?ftbbsuser=".$rearr[1].">".$rearr[1]."</a>";
	}
	else{
	$replydate=$indbdate;
	$replyuser="";
	}
?>
    <tr align=middle> 
      <td width="4%" height="28" class="loopborder1"> 
        <?
			  if ($myrow["bbstop1"]=="1"){
              echo '<a class=f14 href='.$readurl.' target="_blank"><img src="images/ding.gif" alt="总固顶的主题&#xA;点击开新窗口浏览" width="15" height="13" border="0" align="absmiddle" board=0></a>';
              }
			  elseif ($myrow["bbstop"]=="1"){
              echo '<a class=f14 href='.$readurl.' target="_blank"><img src="images/blueding.gif" width="15" height="13" align="absmiddle" border="0" alt="分论坛固顶的主题&#xA;点击开新窗口浏览"></a>';
              }
			  elseif ($myrow["sign"]=="1"){
              echo '<a class=f14 href='.$readurl.' target="_blank"><img src="images/jian.gif" width="15" height="13" align="absmiddle" border="0" alt="版主推荐的话题&#xA;点击开新窗口浏览"></a>'; 
              }
			  elseif ($myrow["huati"]=="1"){
              echo '<a class=f14 href='.$readurl.' target="_blank"><img src="images/jing.gif" width="15" height="13" align="absmiddle" border="0" alt="版主精选的话题&#xA;点击开新窗口浏览"></a>';
              }
			  elseif ($myrow["P_display"]=="0"){
              echo '<a class=f14 href='.$readurl.' target="_blank"><img src="images/suo.gif" width="12" height="13" align="absmiddle" border="0" alt="分论坛固顶的主题&#xA;点击开新窗口浏览"></a>';
              }
			  elseif ($myrow["hit"]>=500){
              echo '<a class=f14 href='.$readurl.' target="_blank"><img src="images/hotpost.gif" width="14" height="16" align="absmiddle" border="0" alt="热门的话题&#xA;点击开新窗口浏览"></a>'; 
              }
			  else{
              echo '<a class=f14 href='.$readurl.' target="_blank"><img src="images/normal.gif" width="14" height="16" align="absmiddle" border="0" alt="开放的话题&#xA;点击开新窗口浏览"></a>'; 
              }
			  ?>
      </td>
      <td width="52%"  align=left valign="middle" class="loopborder2"> 
        <?if ($myrow["zhiye"]=="10"){?>
        <img src="images/rar.gif" width="16" height="16" align="absmiddle"> 
        <?}?>
        <?if ($myrow["P_display"]!="0" && $myrow["bbstop"]!=1 and $myrow["sign"]!="1" && $myrow["huati"]!="1" && $myrow["zhiye"]!="10" && $myrow["picture"]!=""){?>
        <img src="images/<?=$myrow["picture"]?>" width="19" height="19" align="absmiddle"> 
        <?}?>
        <a class=f14 href="<?=$readurl?>" title="<?=$myrow["title"]?>&#xA;作者:<?=$myrow["user_id"]?>&#xA;发表于:<?=$myrow["dateh"]?>" target="_blank">
        <?=$title?>
        </a> 
        <?
			  $pagenum=$ftbbsmb[6];//'贴子每页显示条数
              $k=$myrow["rep"]/$pagenum;
			  $repage=intval($k)+1;
			  if ($repage>1){
				for ($i=0;$i<$repage;$i++){
				   if ($htmlsign==1){
				   $pagehtm='ftbbs-'.$myrow['ID'].'-'.($i+1).'.html';
				   }
				   else{
				   $pagehtm='ftbbs.php?page='.($i+1).'&id='.$myrow['ID'];
				   }
				   if ($i>=4 && $repage>6){
				      if ($htmlsign==1){
					  $pagehtm='ftbbs-'.$myrow['ID'].'-'.$repage.'.html';
					  }
					  else{
				      $pagehtm='ftbbs.php?page='.$repage.'&id='.$myrow["ID"];
					  }
				      echo '..<a class="mainouttd" href='.$pagehtm.' target="_blank">'.$repage.'</a>';
					  break;
				   }
				   if ($i==0){
				   echo '<a class="mainouttd" href='.$pagehtm.' target="_blank">'.($i+1).'</font></a>';
				   }
				   else{
				   echo '<a class="mainouttd" href='.$pagehtm.' target="_blank">'.($i+1).'</a>';
				   }
				}  
			  }
			?>
      </td>
      <td width="7%" class="loopborder1"><a href="ftbbsmyinfo.php?ftbbsuser=<?=$myrow["user_id"]?>">
        <?=$myrow["user_id"]?>
        </a></td>
      <td width="5%" class="loopborder3"> 
        <?=$myrow["rep"]?>
      </td>
      <td width="6%" class="loopborder3">
        <?=$myrow["hit"]?>
      </td>
      <td width="25%" class="loopborder3"><div align="left">
          <?=$replydate?>
          <?=$replyuser?>
        </div></td>
    </tr>
    <?
}
while ($myrow = mysql_fetch_array($rsx));
}
?>
    <tr valign="top"> 
      <td colspan="7" class="maintbtr1"><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr> 
            <td height="26" align="left"> 
              <?
                $p->output(0);
				mysql_free_result($qsrs);
				mysql_free_result($rs);
                mysql_free_result($rsx);
                $db->close(); 
                 ?>
            </td>
          </tr>
        </table></td>
    </tr>
    <?
}
else
{
?>
    <tr class="maintbtr3"> 
      <td colspan=7 align=center height=25 class="f12"> 欢迎到本论坛发表贴子！ </td>
    </tr>
    <?
}
?>
  </tbody>
</table>
<?
include_once("inc/bbstail.php");
?>