<?php
	require_once('_approot.php');	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php 	$selectcate=$_GET['selectcate'];
	$sort_field = $_GET['sort_field'];
	$page=$_GET['page'];
		
	if ($_GET['ls_msg']=="")
	{
		$ls_msg="博客管理";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}
	$searchproductName=($_POST['searchproductName']==""?$_GET['searchproductName']:$_POST['searchproductName']);
	if($searchproductName!="") $ls_msg="包含 $searchproductName 的文章 ";
	if($_POST['gopage']!=""){$gopage =(ctype_digit($_POST['gopage'])?$_POST['gopage']:1);}
	if($gopage!="") $ls_msg="第 $gopage 页的文章 ";
	
		$ls=$_GET['ls'];
		$id=$_GET['id'];
		$cate=$_GET['cate'];
	switch ($ls)
	{
		
	 	case "unenable":
			$unenable_sql="update ls_news set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_news set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
		case "del":
			$del_sql="delete from ls_news where ID=".$id."";
	   		//echo $del_sql;
	   		$del_query=$opendb->query($del_sql);
			writelog($_SERVER['PHP_SELF'],"delete news: ".$newsTitle,"ID: ".$id);
			
			$ls_msg="删除操作成功！";
			break;
		case "view":
			$enable_sql="select * from ls_functioncates where cateName='".$cate."' ";
			$enable_query=$opendb->query($enable_sql);
			$news_rows=mysqli_fetch_assoc($enable_query);
			
			$newspages = "../newspage/news".$news_rows['suffStr'].$id.".html";
			if (is_file ($newspages)){ 
				echo "<script>window.open('".$newspages."')</script>";
			}else{
				echo "<script>alert('请先去生成该页面！')</script>";
			}
			break;
	}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
         <link rel="stylesheet" href="css/style2.css" />
		<script language="JavaScript" src="js/ls.js"></script>
		<title>无标题文档</title>
	</head>

 <body>
	<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
			<tr>
                <td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">博客管理</font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top"><br>
					<form name="del" method="Post" action="delall.php" onSubmit="return ConfirmDel();">
					<table border="0" width="98%" align="center">
						<tr>
							<td width="63%" height="28" >提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
				<td width="9%" align="right" ><div align="left"><span style="padding-left:20px;">
							 
								
								<?php 								if($searchproductName!="") $searhprostr=" and (ls_news.newsTitle like '%".$searchproductName."%' or ls_news.newsText like '%".$searchproductName."%' or ls_news.newsDate like '%".$searchproductName."%'    ) "; 	
								
			$news_sql="SELECT cateName FROM ls_functioncates  where functionName='博客分类' order by Num";//count the error by searchtype
			$news_query=$opendb->query($news_sql);
			?>

							</span></div></td>
							<td width="28%" align="right" ><img src="images/shao.gif">&nbsp;<a href="addblog.php?selectcate=<?=$selectcate?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>">添加</a><?php  if(!(strpos($_SERVER['HTTP_REFERER'],"managearticle")===false)){ ?> <a href="managearticle.php?selectcate=<?=$selectcate?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>">返回</a><?php } ?></td>
						</tr>
						<tr>
						  <td height="26" colspan="3" >
                          分类： 
                          <?php                           while($news_rows2=mysqli_fetch_assoc($news_query))
		  					{
								echo "<a href='?selectcate=".$news_rows2['cateName']."'>".$news_rows2['cateName']."</a> | ";
							}
				 			
						  ?>
                          <a href='?selectcate='> 全部 </a>
                          </td>
					  </tr>
					</table>
					<br>
					
					<?php
// 获取当前页数
					  if( isset($_GET['page']) ){
						 $page = intval( $_GET['page'] );
					  }
					  else{
						 $page = 1;
					  }
					   if($gopage!="")$page = $gopage;
					  
					  // 每页数量
					  $PageSize = $NewPageNum;
					  
					  // 获取总数据量
					  
					  $sort='';
					  if($newsSort=="ID") {
						  $sort = "ID";
					  }else if($newsSort=="Num"){
						  $sort = "Num";
					  }else{
						  $sort = "ID";
					  }
					  if($sort_field != NULL){
						  if($sort_field == 'Num'){
							  $sort = " ".$sort_field." desc";
						  }else{
							  $sort = " ".$sort_field." asc";
						  }
					  }
/********************************************************************************/
					  if($selectcate<>''&&$selectcate<>'全部'){	
						  //$sql="select * from ls_news where cate='".$selectcate."' order by Num desc ";
						  $sql="select * from ls_functioncates, ls_news where ls_functioncates.cateName = ls_news.cate  and ls_functioncates.functionName='博客分类' and cate='".$selectcate."' ". $searhprostr." order by ls_news.Num desc";
					  }else{	
						  //$sql="select * from ls_news where cate='news' order by Num desc ";
						  $sql="select * from ls_functioncates, ls_news where ls_functioncates.cateName = ls_news.cate  and ls_functioncates.functionName='博客分类' ". $searhprostr." order by ls_news.Num desc";
					  }

						  $result=$opendb->query($sql);
					  
					  /********************************************************************************/
					  // 获取总数据量
					  
					  $row = mysqli_num_rows($result);
					  $amount = $row;
					  
					  // 记算总共有多少页
					  if( $amount ){
						 if( $amount < $PageSize ){ $page_count = 1; }			   //如果总数据量小于$PageSize，那么只有一页
						 if( $amount % $PageSize ){								  //取总数据量除以每页数的余数
							 $page_count = (int)($amount / $PageSize) + 1;		   //如果有余数，则页数等于总数据量除以每页数的结果取整再加一
						 }else{
							 $page_count = $amount / $PageSize;					  //如果没有余数，则页数等于总数据量除以每页数的结果
						 }
					  }
					  else{
						 $page_count = 0;
					  }
					  
					  // 翻页链接
					  $page_string = '';
						  
					  if( $page == 1 ){
						 $page_string .= '首页 | 上一页 |';
					  }
					  else{
						 $page_string .= '<a href=?selectcate='.$selectcate.'&page=1&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?selectcate='.$selectcate.'&page='.($page-1).'&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
					  }
					  if( ($page == $page_count) || ($page_count == 0) ){
						 $page_string .= ' 下一页 | 尾页';
					  }
					  else{
						 $page_string .= ' <a href=?selectcate='.$selectcate.'&page='.($page+1).'&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?selectcate='.$selectcate.'&page='.$page_count.'&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">尾页</font></u></a>';
					  }
						   $page_string .= " &nbsp;&nbsp;页次：<font color='#FF0000'><b>".$page."</b></font>/<b>".$page_count."</b>页";
						   $page_string .= " &nbsp;&nbsp;<b>".$PageSize."</b>个每页";
						   
					  $ls_msg2="博客管理 >> ".($selectcate==''?'全部':$selectcate)." 博客";

?>
					
				
				<table border="0" width="98%" align="center">
						<tr>
							<td><?php echo $ls_msg2; ?></td>
							<td align="right">共 <b><?php echo $row; ?></b>条</td>
				  </tr>
					 </table>
					 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
						<tr bgcolor="#f0f0ee" height="37">
							<td align="center"  width="30"></td>
							<td align="center" width="30">编号</td>
							<td align="center" width="266">标题</td>
							<td align="center" width="113"><a href='?selectcate=<?=$selectcate?>&sort_field=newsDate'>日期</a></td>
		          			<td align="center" width="144">类别</td>
							<td align="center" width="36"><a href='?selectcate=<?=$selectcate?>&sort_field=Num'>序号</a></td>
							<td align="center" colspan="3">操作</td>
							<td align="center" width="36">允许</td>
						</tr>
						<?php
							$news_sql=$sql." limit ". ($page-1<0?0:$page-1)*$PageSize .",".$PageSize." ";
							$news_query=$opendb->query($news_sql);

							$i=1;
							while($news_rows=mysqli_fetch_assoc($news_query))
							{ ?>
								
							<tr bgcolor='#f9f9f9'height='47'
						onMouseOver=
							 	this.style.backgroundColor='#e5e5e5' 
							onMouseOut=
							 	this.style.backgroundColor='#f9f9f9' 
							>
								<td align='center'>
									<input name='select_id<?=$i?>' type='checkbox' onclick=\"unselectall()" id="select_id" value='<?=$news_rows['ID']?>'>
								</td>
						  	<td style='padding-left:10px;'>
						  <?=$i?>
						  	</td>
						  	<td style='padding-left:10px;'>
						  <?=$news_rows['newsTitle']?>
						  	</td>
						  	<td style='padding-left:10px;'>
						  <?=$news_rows['newsDate']?>
						  	</td>
						  	<td style='padding-left:10px;'>
						  <?=$news_rows['cate']?>
						  	</td>
						  	<td style='padding-left:10px;'>
						  <?=$news_rows['Num']?>
						  	</td>
						  	<td align='center'   width='25'> 
									<a href='modiblog.php?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&searchproductName=<?=$searchproductName?>' title='编辑'><img src='images/b_edit.png' border='0'></a>
							  </td>
							  	<td align='center'   width='25'> 
									<a href='?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=view&cate=<?=$news_rows['cate']?>&searchproductName=<?=$searchproductName?>' title='预览'><img src='images/b_ie.png' border='0'></a>
							  </td>
								<td align='center'  width='25'> 
									<a href='?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=del&searchproductName=<?=$searchproductName?>' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>
							  </td>
								<td align='center'>
					  
							 <?php if($news_rows['enable']==1)
								{ ?>
									<a href='?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=unenable&searchproductName=<?=$searchproductName?>' title='显示'><img src='images/enable.gif' border='0'></a>
							<?php }
							  if($news_rows['enable']==0)
								{ ?>
									<a href='?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=enable&searchproductName=<?=$searchproductName?>' title='不显示'><img src='images/unenable.gif' border='0'></a>
								<?php } ?>
														
								</td>
						  </tr>
						  
						<?php  $i++;
						 } ?>
							<tr bgcolor="#f0f0ee">
						  <td colspan='10' align='center' height='25'>
						  <?=$page_string?>
						  </td>
						  </tr>
						
					 
					</table>
					<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
					<tr >
							<td width="93%" style="padding-left:6px;">
							<input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
							 所有
							 <button name="submit" type='submit' value='删除'>删除</button>
							<input name="Action" type="hidden" id="Action" value="blogDel">
							
							
								</td>
							<td width="7%" align="right" style="padding-left:6px;"><div align="center"><span style="border-bottom:1px solid #FFF;"><img src="images/shao.gif" alt="" />&nbsp;<a href="addblog.php?selectcate=<?=$selectcate?>"><u>添加</u></a></span></div></td>
						</tr>
					</table>
               </form>
				 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee"> <tr >
							<td width="82%" style="padding-left:6px;"> <form name="searcharticle" method="Post" action="?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>" >
				  <div align="right"  ><span style="padding-left:6px;">
			      <input type="text" name="searchproductName" size="16" maxlength="50"  value="" />
			      <input type='submit'    value="查询" style="height:24px;"    />
			      </span> <span style="padding-left:26px;">
			      <input name="gopage" id="gopage" type="text" size="3" />
			      页
<input type='submit'    value="GO"  style="height:24px;"   />
			      </span>
			      </div>
				</form><br/></td>
			</tr></table>
					
				</td>
			</tr>
	</table>
 </body>
</html>