<?php include 'yanzheng.php';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link rel="stylesheet" type="text/css" href="css/css.css" />

<script language="javascript" type="text/javascript">
function preg_match(regStr, str)
{
     var objRegExp = new RegExp(regStr);
     return objRegExp.test(str);
}
function SelectAll(form)
{
for(var j = 0;j < form.elements.length;j++)
     {
         var e = form.elements[j];
         if(preg_match(/del_id/, e.name))
         {
             e.checked = form.select_all.checked;
         }
         else
         {
             continue;
         }
     }
}
</script>
</head>

<body>
<?php require_once 'head.php';?>
<div class="box">

   

		<div class="daohang">
		 <a href="news_add.php">发布新闻</a>
		</div>
	
       <div class="shaixuan">		  
		   <a href="news.php">全部</a>		   
		   <?php	
		    						
			$kcarr=listquery("select * from news_type where fid=0 order by id asc");		
			foreach ($kcarr as $v) {
			 ?>
			  <a href="news.php?benpath=<?=$v['benpath']?>"><?=$v['typename']?></a>
		   <?php
		   }		  
		   ?>			   
		</div>
	    
		<?php
		 $ax=$_GET['benpath'];
		 if($ax){		
		?>
	  
			<div class="shaixuan2">		  
			
			   <?php			   
				$row=query("select * from news_type where benpath='$ax'");
				$fid=$row['id'];				
				$kcarr=listquery("select * from news_type where fid='$fid' order by id asc");		
				foreach ($kcarr as $v) {
				 ?>
				  <a href="news.php?benpath=<?=$v['benpath']?>"><?=$v['typename']?></a>
			   <?php
			   }		  
			   ?>			   
			</div>
		
		 <?php
		   }		  
		   ?>	

	 	<form name="del_form" action="" method="post"> 
	
	<table width="100%" height="40" border="0" cellpadding="0" cellspacing="0"   class="borer">
	  <tr style="background-color:#EEEEEE;">
	    <td width="80" height="31" >选择</td>
		<td width="80" height="31" >ID</td>
		<td width="783" >标题</td>
		<td width="200">所属栏目</td>
		<td width="200" >发布时间</td>
		<td width="70" >修改</td>
		
	  </tr>

	<!--list start-->	



<?php 	
  $mx=$_GET['benpath'];
  if($mx){
    $m=" where benpath like '%$mx%' ";
  }
   
	require_once('page.class.php'); //分页类
			$showrow = 10; //一页显示的行数
			$curpage = empty($_GET['page']) ? 1 : $_GET['page']; //当前的页,还应该处理非数字的情况
			$url = "?page={page}"; //分页地址，如果有检索条件 ="?page={page}&q=".$_GET['q']
			//省略了链接mysql的代码，测试时自行添加
			$sql = "SELECT * FROM news $m";
			$total = mysql_num_rows(mysql_query($sql)); //记录总条数
			if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow))
				$curpage = ceil($total_rows / $showrow); //当前页数大于最后页数，取最后一页
			//获取数据
			$sql .= " order by id desc LIMIT " . ($curpage - 1) * $showrow . ",$showrow;";
		//	$query = mysql_query($sql);
			$arr=listquery($sql);
			foreach ($arr as $v){?>
	  <tr>
		<td><input name="del_id[]" type="checkbox" id="del_id[]" value="<?=$v['id']?>" /></td>
		<td><?=$v['id']?></td>
		<td><a href="news_up.php?id=<?=$v[id]?>"><?=$v[title]?></a></td>		
		<td><?=$v['typename']?></td>
	    <td><?=$v['time']?></td>		
		<td><a href="news_up.php?id=<?=$v[id]?>">修改</a></td>		
	  </tr>
   
	<?php }?>
 </table>    
  
	<table width="50%" height="28" border="0" cellpadding="0" cellspacing="0" style="margin-top:20px;">
	  <tr>	
	    <td width="49">全选</td>
		<td width="49"><input id="select_all" name="select_all" type="checkbox" value="1" onClick="SelectAll(this.form)"/></td>
	    <td width="80" ><input name="submitdel" type="submit" value="批量删除" class="reganniu" /></td>
		 <td width="200">
		 
<?php 


function subtree($arr,$id,$lev){
 static $subs=array();                                 //static 静态变量属性，防止递归调用是重新初始化
 foreach($arr as $v){
  if($v['fid']==$id){
   $v['lev']=$lev;
   $subs[]=$v;
   subtree($arr,$v['id'],$lev+1);                //递归调用自身
  }
 }
 return $subs;
}
//print_r(subtree($area,0,1));

$data=listquery("select * from news_type order by id asc");

$tree=subtree($data,0,1);


?>

<select name="lanmu">
<?php 
foreach($tree as $v){
?>

<option value="<?=$v['benpath']?>|<?=$v['typename']?>">
  <?php 

$lev=$v['lev'];

if($lev==1){
echo str_repeat('',$v['lev']).$v['typename'].'';  
}else{

echo str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$v['lev']).$v['typename'].'';  
}





?>
</option>

<?php }?>


</select>
		 <input name="submityi" type="submit" value="批量移动" class="reganniu" />
		 
		 </td>
	  </tr>
	</table>
	 <?php
	    $houzhui='&benpath='.$_GET[benpath].'';
   
		$page = new page($total, $showrow, $curpage, $url, 2,$houzhui);
		echo $page->myde_write();

	?>


	 </form>




<?php
if($_POST['submityi']){


$lanmu=$_POST['lanmu'];
$arr=explode("|",$lanmu);
$benpath=$arr[0];
$typename=$arr[1];

$del_id=$_POST['del_id']; //数组 影藏的ID 用它来遍历所有input文本框对应数组内容

     if($del_id!=""){ 
             $del_num=count($del_id); 
             for($i=0;$i<$del_num;$i++){ 
			 
               
                 mysql_query("update news set benpath='$benpath',typename='$typename' where id='$del_id[$i]'"); 				
             }  
            msg('修改成功',$onurl);
      }else{ 
            msg('请选择',$onurl);
      }

  }
?>  

<!--批量移动-->





  <?php
if($_POST['submitdel']){

$del_id=$_POST['del_id'];
     if($del_id!=""){ 
             $del_num=count($del_id); 
             for($i=0;$i<$del_num;$i++){ 
                 mysql_query("Delete from news where id='$del_id[$i]'"); 				
             }  
             msg('删除成功',$onurl);
      }else{ 
             msg('请选择',$onurl);
      }

  }
?>  


</div>

<?php require_once 'foot.php';?>
</body>
</html>