<? require "header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<html>
<head>
<title><?=$bbs_config_row['bbs_name']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<?=$T_BBS_Style_CSS?>" rel="stylesheet" type="text/css">
</head>
<body>
<form name="form1" id="form1"  method="post" >
  <table border="0" cellpadding="0"  cellspacing="0" class="firsttable">
    <tr>
      <td align="center" valign="top">
	  	<table  cellpadding="0" cellspacing="0"  class="centertable">
      		<tr> 
            	<td align="center"><? include "top.php"?> 
            	</td>
       		</tr>
        	<tr>
        	  <td align="center">&nbsp;</td>
      	  </tr>
        	<tr>
        	  <td align="center"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="bg2">
                <tr>
                  <td height="26" style="padding-left:10px; "><img src="<?=$BBSFolder?>/images/rightarrow.gif" width="11" height="10"> <font class="font1">
                    <a href="<?=$BBSFolder?>/index.php" style="text-decoration:none ">首页</a>
      → 搜索</font></td>
                </tr>
              </table></td>
      	  </tr>
        	<tr>
        	  <td height="40" align="center"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr align="center">
                  <td width="85" height="26" align="center" class="link3"><input name="keyword" type="text" id="keyword" value="<?=$keyword?>"></td>
				  <td width="10" align="center">&nbsp;</td>
                  <td width="85" align="center" class="link3">
				  <select name="category" id="category">
				  <option value="">--Select--</option>
				  	<?
								$sql="select * from ".$TableBbs_category." where pid=0" ;
								$query=$db->query($sql);
								$sql1="select * from ".$TableBbs_category." where pid<>0" ;
								$result=$db->getAll($sql1);
								while($object=$db->fetch_object($query))
								{
									echo "<option value='".$object->id."'>+ 『".$object->name."』</option>";											
									for($i=0;$i<count($result);$i++)
									{
										if($object->id==$result[$i][pid])
										{
											echo "<option value='".$result[$i][id]."'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 『".$result[$i][name]."』</option>";
										}
									}
								}
			 					?>
                  </select>
                  </td>
                  <td align="left"><input type="button" name="search" class="button" onClick="sitesearch()" value="搜索"></td>
                </tr>
              </table></td>
      	  </tr>
		   <?
		   if(!empty($keyword))
		   {
			if(empty($page))
				{$page=1;}
			else
			{
				 if($page<1){ $page=1;}
			}
			$pagenum=20;
			
             $b=false;
             $filter="";
             $fvalue=$category;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" (bcategoryid =$fvalue or categoryid=$fvalue) ";
                 $b=true;
             }
			
             $fvalue=$keyword;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" title like '%$fvalue%' or content like '%$fvalue%' ";
                 $b=true;
             }

           
			$sql="select * from ".$TableBbs_content; 
			$sql1="select count(*) as num from ".$TableBbs_content;
             if($b)
             {
                 $sql.=" where ".$filter."  order by id desc  limit ".(($page-1)*$pagenum).",$pagenum";
                 $sql1.=" where ".$filter."  order by id desc  ";
             }
             else
             {
                 $sql.="  order by id desc  limit ".(($page-1)*$pagenum).",$pagenum";
                 $sql1.="   order by id desc  ";
             }
			$query=$db->query($sql);
			$query1=$db->query($sql1);
			$rows=$db->fetch_row($query1);
			$page_num=ceil($rows[num]/$pagenum);
			  ?>	  
        	<tr>
        	  <td align="center"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="bg2">
                <tr>
                  <td height="26" style="padding-left:10px; ">&nbsp;</td>
                </tr>
              </table></td>
      	  </tr>
        	<tr> 
       		  <td height="400" valign="top" class="fulltd" style="padding-top:10px; padding-left:5px;" >
			  <?
			   $j=1;
				while($object=$db->fetch_object($query))
				{
				?>
			  <table width="90%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="60" style="border-bottom:1px #eeeeee dotted">
				  <?=$j?>.  <a href='<?=$BBSFolder?>/answer.php?cid=<?=$object->id?>&bcatid=<?=$object->bcategoryid?>&scatid=<?=$object->categoryid?>'><?=$object->title?></a> <br><br>
				  &nbsp;&nbsp;&nbsp;&nbsp;<font  style="font-size:12px; color:#669900;">作者: <?=$object->username?> 点击数: <?=$object->click_count?> 回复数: <?=$object->reply_count?></font>
				  </td>
                </tr>
              </table>
			  <?
			    $j++;
				}
				?>			  </td>
        	</tr>
            <tr>
              <td align="right" class="font1">共
                <?=$totalnum?>
条, 共
<?=$page_num?>
页, 第
<?=$page?>
页 <a href="javascript:first()">第一页</a> <a href="javascript:next()">下一页</a> <a  href="javascript:pre()">上一页</a> <a  href="javascript:last()" >最后一页</a>
<select name="position" id="position"  onChange="goposition()">
  <option value=""></option>
  <?
					     			for($i=1;$i<=$page_num;$i++)
					     			{
						   			echo "<option ";
						   				if(page==$i){echo "selected";}
						   					echo " value=$i>";
						   					echo $i;
						   					echo "</option>" ;
					     			}
					     	?>
</select></td>
          </tr>
			<?
			}
			?>
          <tr>
               <td align="center"><span class="link2">
                 <? include "bottom.php"?>
               </span></td>
          </tr>
         </table>
	  </td>
    </tr>
</table>
	<input type="hidden" name="status" value="">
  <input type="hidden" name="page" value=<?=$page?>>
  <input type="hidden" name="totalpage" value=<?=$totalpage?>>
   <input type="hidden" name="id" value="">
   <input type="hidden" name="ids" value="">
</form>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">
  function currentpage(id)
  {
       var form=document.getElementById("form1");
       form.page_start.value=id;
       form.submit();
  }
  
  function sitesearch()
  {
       var form=document.getElementById("form1");
	   if(form.keyword.value=="")
	   {
	   		alert("Please enter search keyword!");
			return;
	   }
       form.submit();
  }
  function first()
  {
       var form=document.getElementById("form1");
       if(eval(form.page.value)==1)
	   	return;
       form.page.value=1;
       form.submit();
  }

  function next()
  {
      var form=document.getElementById("form1");
      if(eval(form.page.value)>=eval(form.totalpage.value))
	  return;
      form.page.value=eval(form.page.value)+1;
      form.submit();
  }

  function last()
  {
       var form=document.getElementById("form1");
       if(eval(form.page.value)==eval(form.totalpage.value))
	   	  return;
       form.page.value=eval(form.totalpage.value);
       form.submit();
  }

  function pre()
  {
       var form=document.getElementById("form1");
       if(form.page.value<=1)
		return;
       form.page.value=eval(form.page.value)-1;
       form.submit();
  }

  function  goposition()
  {
       var form=document.getElementById("form1");
       form.page_start.value=form.position.value;
       form.submit();
  }
</script>
<? $db->close_db();?>
 

