<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
	//置顶
	if($status=="setSetupest")
	{	
		  $checkednums=array();
		  $checkednums=explode('.',$ids);
		  $filter="";
		  for($i=0;$i<count($checkednums)-2;$i++)
		  {
				$filter=$filter.$checkednums[$i].",";
		  }
		  $filter=$filter.$checkednums[count($checkednums)-2].")";
	      $sql="update ".$TableBbs_content." set setupest=".$setupest."  where id  in (".$filter;
		 
	      $query=$db->query($sql);	
	}
	
	//删除
	if($status=="remove")
	{
		$sql="delete from ".$TableBbs_answer."  where cid=".$id;
	    $query=$db->query($sql);
		$sql=" select id,pic from ".$TableBbs_content."  where id=$id;";
		$row=$db->getRow($sql);
		$FileName=$上传Path."/bbs/".$row[id].$row[pic];
		if(file_exists($FileName))
		{     
			 unlink($FileName);
		}
	    $sql="delete from ".$TableBbs_content."  where id=".$id;
	    $query=$db->query($sql);
	}
	//删除全部选择的
	if($status=="removeSelect")
	{
	  $checkednums=array();
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql=" select id,pic from ".$TableBbs_content."  where id=".$checkednums[count($checkednums)-2];
	  $row=$db->getRow($sql);
	 $FileName=$上传Path."/bbs/".$row[id].$row[pic];
	 if(file_exists($FileName))
	 {     
		 unlink($FileName);
	 }
	  $sql="delete from ".$TableBbs_answer."  where cid in (".$filter;
	   $query=$db->query($sql);
	  $sql="delete from ".$TableBbs_content."  where id in (".$filter;
	  $query=$db->query($sql);
	}
	//推荐
	if($status=="recommend")
	{
	  $checkednums=array();
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql="update  ".$TableBbs_content." set IsRecommend='1'  where id in (".$filter;
	  $query=$db->query($sql);
	}
	//不推荐
	if($status=="unrecommend")
	{
	  $checkednums=array();
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql="update  ".$TableBbs_content." set IsRecommend='0'  where id in (".$filter;
	  $query=$db->query($sql);
	}
	
	
	if(empty($page))
    	{$page=1;}
    else
    {
		 if($page<1){ $page=1;}
	}
             $b=false;
             $filter="";
             $fvalue=$bcategoryid;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" bcategoryid =$fvalue";
                 $b=true;
             }
             $fvalue=$categoryid;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" categoryid =".$fvalue;
                 $b=true;
             }
             $fvalue=$title;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" title like '%$fvalue%' or content like '%$fvalue%' ";
                 $b=true;
             }
			if($_SESSION['SessionAdminUser']['UserGrade']!=1)
			 {
				 $fvalue=$_SESSION['SessionAdminUser']['username'];
				 if(!empty($fvalue))
				 {
					 if($b)
						 $filter.=" and";
					 $filter.=" (CONCAT(',',b.admin_user,',') like '%,".$fvalue.",%') ";
					 $b=true;
				 }
			 }
			  $fvalue="link";
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" a.categoryid=b.id ";
                 $b=true;
             }

           
	$sql="select a.* from ".$TableBbs_content." as a,".$TableBbs_category." as b "; 
	$sql1="select count(*) as num from ".$TableBbs_content." as a,".$TableBbs_category." as b "; 
             if($b)
             {
                 $sql.=" where ".$filter."  order by a.setupest desc,a.update_time desc  limit ".(($page-1)*$pagenum).",$pagenum";
                 $sql1.=" where ".$filter."  order by a.setupest desc,a.update_time desc  ";
             }
             else
             {
                 $sql.="  order by  a.setupest desc,a.update_time desc  limit ".(($page-1)*$pagenum).",$pagenum";
                 $sql1.="   order by a.setupest desc,a.update_time desc  ";
             }
		
	$query=$db->query($sql);
	$query1=$db->query($sql1);
	$rows=$db->fetch_row($query1);
	$page_num=ceil($rows[num]/$pagenum);
?>
<html>
<head>
<title><?=$bbs_config_row['bbs_name']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../css/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="form1" method="post" >
  <table border="0" cellpadding="0"  cellspacing="0" class="firsttable">
    <tr>
      <td align="center" valign="top">
	  	<table   class="centertable">
      		<tr> 
            	<td>&nbsp; 
            	</td>
       		</tr>
        	<tr> 
       		  <td align="center" valign="top">
				  <table class="containContentsTable">
              			<tr align="right">
               				 <td colspan="2" >论坛一级分类:
               				   <select name="bcategoryid" id="bcategoryid" onChange="select_kind(this)">
                                 <option value=""></option>
                                 <?
									$sql = "select * from ".$TableBbs_category." where pid = 0";
									$result = $db->getAll($sql);
									for($i=0;$i<count($result);$i++) 
									{
										if($bcategoryid == $result[$i][id])
										{
											echo "<option value='".$result[$i][id]."' selected>".$result[$i][name]."</option>";
										}
										else
										{
											echo "<option value='".$result[$i][id]."' >".$result[$i][name]."</option>";
										}
									}
								?>
                               </select>
               				   论坛板块分类:
       				           <select name="categoryid" id="categoryid">
							   <option value=""></option>
							   <? 
							   $sql = "select * from ".$TableBbs_category." where pid=".$bcategoryid;
								$result2 = $db->getAll($sql);
								for($i=0; $i<count($result2); $i++)
								{
									if($categoryid==$result2[$i][id])
									{
										echo "<option selected value='".$result2[$i][id]."'>".$result2[$i][name]."</option>";
									}
									else
									{
										echo "<option  value='".$result2[$i][id]."'>".$result2[$i][name]."</option>";
									}
									
								}
							    ?>
 				               </select>
							   <input type="text" size=20 name="title" value="<?=$title?>">			                   <input name="button" type='button'  class='button' onClick="javascript:query()" value='查询' ></td>
       				    </tr>
              			<tr>
               				 <td colspan="2">
								<?
								echo "<table  class='contentsTable'  border='0'  cellpadding='0'  cellspacing='1'>";
								echo "<tr class='tr1'  align=center ><td width=5% ></td><td  >标题</td><td  width=12% >作者</td><td  width=10% >最后更新日期</td>";
								echo "<td width=6% >点击数</td>";
								echo "<td width=6%>回复数</td>";
								echo "<td width=10%>级别</td>";
									echo "<td width=10% >&nbsp;</td>";
								echo "</tr>";
								while($object=$db->fetch_object($query))
								{
				  					echo "<tr   onMouseOver=\"old_bg=this.getAttribute('bgcolor');this.setAttribute('bgcolor', '".$T_Bgcolor[1]."', 0);\" onMouseOut=\"this.setAttribute('bgcolor', old_bg, 0);\" bgColor='".$T_Bgcolor[2]."' >";
				  					echo "<td><input type='checkbox' name=checkvalue value='$object->id'></td>";
				  					echo "<td>".$T_Content_type[$object->content_type].$object->title."</td>";
									echo "<td  align=center >$object->username</td>";
				  					echo "<td align='center'>".FormatDate($object->publictime)."</td>";
									echo "<td align='center'>$object->click_count</td>";
									echo "<td align='center' >$object->reply_count</td>";
									echo "<td align='center' >"; 
										echo $T_Setupest[$object->setupest];
									echo "</td>";
											echo "<td align=center>";
												echo "<a   href='javascript:remove(".$object->id.")'>删除</a>";
												echo " <a href='javascript:edit(".$object->id.")'>修改</a><br>";
												echo " <a href='javascript:answer($object->id)' >回复</a>";
												echo " <a target='_blank' href='".$BBSFolder."/answer.php?bcatid=".$object->bcategoryid."&scatid=".$object->categoryid."&cid=".$object->id."'>浏览</a>";
											echo "</td>";
									echo "</tr>";								
								}
				 				echo "</table>";
								?>                			        </td>
              			</tr>
              			<tr>
              			  <td colspan="2"><input name="cboAll" type="checkbox" id="cboAll" value="checkbox" onClick="checkBoxAll()" >
选择所有
  <input name="button3" type='button'  class='button' onClick="javascript:add()" value='添加'>
                            <input name="button2" type='button'  class='button' style='width:80px' onClick="javascript:removeSelect()" value='删除' >
                            <input name="button25" type='button'  class='button' onClick="javascript:setSetupest()" value='设置' >
                            <select name="setupest" id="setupest">
                              <?
								for($i=1;$i<=count($T_Setupest);$i++)
								{
									 if((int)$T_Setupest==$i)
										echo "<option value=".$i." selected>".$T_Setupest[$i]."</option>";
									else
										echo "<option value=".$i.">".$T_Setupest[$i]."</option>";
								}
							?>
                            </select></td>
       			    </tr>
              			<tr>
						<td>&nbsp;</td>
                			       <td align="right">共
                                     <?=$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>
                        </table>
              </td>
                        </tr>
                        <tr>
                             <td></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=<?=$page_num?>>
   <input type="hidden" name="id" value="">
   <input type="hidden" name="ids" value="">
</form>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">
 function checkBoxAll()//全选
 {
    	var form = form1;
     for(i=0; i<form.elements.length; i++)
    	{
        	if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        	{
                	form.elements[i].checked = form.cboAll.checked;
       	}
    	}
  }
  
 function setSetupest(){
     var form=form1;
	 for(i=0; i<form.elements.length; i++)
    {
        if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        {
                if(form.elements[i].checked==true)
		   {
			form.ids.value+=form.elements[i].value+".";
		   }
        }
    }
	if(form.ids.value=="")
    {
		alert("请选择记录!");
		return;
	}
	form.status.value="setSetupest";  
	form.submit();
 }
 


 function edit(id){
     var form=form1;
     form.id.value=id;
	form.action="bbs_contentedit.php";
	form.submit();
  }

  function look(id){
     var form=form1;
     form.id.value=id;
	form.action="bbs_contentlook.php";
	form.submit();
  }
  
  function answer(id){
     var form=form1;
	form.action="bbs_answer.php?cid="+id;
	form.submit();
  }

  function remove(id){
     if(confirm("真的想要删除吗?")==true){
  		var form=form1;
  		form.id.value=id;
		form.status.value="remove";
		form.submit();
	}
  }

  function removeSelect(){
  	var form=form1;
  	
  	for(i=0; i<form.elements.length; i++)
    {
        if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        {
                if(form.elements[i].checked==true)
		   {
			form.ids.value+=form.elements[i].value+".";
		   }
        }
    }
	if(form.ids.value=="")
    {
		alert("请选择记录");
		return;
	}
	if(confirm("真的想要删除吗?")==false)
		return;
	form.status.value="removeSelect";
	form.submit();
  }
  
   function recommend(){
  	var form=form1;
  	
  	for(i=0; i<form.elements.length; i++)
    {
        if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        {
                if(form.elements[i].checked==true)
		   {
			form.ids.value+=form.elements[i].value+".";
		   }
        }
    }
	if(form.ids.value=="")
    {
		alert("请选择要推荐的记录");
		return;
	}
	form.status.value="recommend";
	form.submit();
  }
  
   function unrecommend(){
  	var form=form1;
  	
  	for(i=0; i<form.elements.length; i++)
    {
        if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        {
                if(form.elements[i].checked==true)
		   {
			form.ids.value+=form.elements[i].value+".";
		   }
        }
    }
	if(form.ids.value=="")
    {
		alert("请选择要不推荐的记录");
		return;
	}
	form.status.value="unrecommend";
	form.submit();
  }



  function add(){
  	location="bbs_contentadd.php";
  }

  function query()
  {
  	   var form=form1;
       form.submit();
  }

  function first()
  {
       var form=form1;
       if(eval(form.page.value)==1)
	   	return;
       form.page.value=1;
       form.submit();
  }

  function next()
  {
      var form=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=form1;
       if(eval(form.page.value)==eval(form.totalpage.value))
	   	  return;
       form.page.value=eval(form.totalpage.value);
       form.submit();
  }

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

  function  goposition()
  {
       var form=form1;
       form.page.value=form.position.value;
       form.submit();
  }
</script>
<script language="javascript">
function select_kind(obj)
{ //把产品的类别列出
	var f2Array = new Array();
	<?
		$sql = "select * from ".$TableBbs_category." where pid<>0";
		$result2 = $db->getAll($sql);
		for($i=0; $i<count($result); $i++)
		{
			echo "f2Array[".$result[$i][id]."] = new Array();"."\n";
			$j = 0;
			for($k=0; $k<count($result2); $k++)
			{
				if($result2[$k][pid] == $result[$i][id])
				{
					echo "f2Array[".$result[$i][id]."][".$j."] = new Option();"."\n";
					echo "f2Array[".$result[$i][id]."][".$j."].value = ".$result2[$k][id].";\n";
					echo "f2Array[".$result[$i][id]."][".$j."].text = '".$result2[$k][name]."';\n";
					$j++;
				}
				
			}
		}
	?>
	var form = form1;
	var i = eval(obj.value);
	form.categoryid.length = 1;
	for(var j=0; j<f2Array[i].length; j++)
	{
		form.categoryid.options[form.categoryid.length] = f2Array[i][j];
	}
}
</script>
<? $db->close_db();?>

