<?php
define('IN_SYS',TRUE);
define('IN_AdminMenu',TRUE);
require './admin_config.php';
require '../config.php';
require '../setup.php';
require("../lib/admin_chk.php");
?>
<?php
$pageTitle="网站信息列表";

$cateTable = "category";
$infoTable = "content";
$CatalogId = trim($_GET["CatalogId"]);

if($CatalogId==""){
	$CatalogId = -1;
}
$mcataid=$CatalogId;
$CatalogId_Color = $CatalogId;
$Action=$_REQUEST["Action"];
$Move_type=trim($_POST["Move_type"]);
$P_ID = $_REQUEST["P_ID"];

if(isset($Action)){
	if(is_array($P_ID) && instr($P_ID,',')==0){
		$P_ID = implode(",",$P_ID);
	}
	switch($Action){
		case $Action=="DODelete":
			$db = mysql_query("select * from ".DB_TablePre.$infoTable." where id in ($P_ID)");
			while($rs = mysql_fetch_array($db)){
				if(isset($rs["pic"])){
					ImgDelpic($rs["pic"],".."); //删除图片
				}
				if(isset($rs["attachments"])){
					ImgDelpic($rs["attachments"],".."); //删除附件
				}
				if(isset($rs["content"])){
					ImgDel(RequestImg($rs["content"]),"","..");
				}
			}
			mysql_query("delete from ".DB_TablePre.$infoTable." where id in ($P_ID)");
			break;
		
		case $Action=="DOUpdate":
			mysql_query("update ".DB_TablePre.$infoTable." set type='$Move_type' where id in ($P_ID)");
		break;
		
		case $Action=="Check_true":
			mysql_query("update ".DB_TablePre.$infoTable." set isRecommend=1 where id in ($P_ID)");
		break;		
		
		case $Action=="Check_false":
			mysql_query("update ".DB_TablePre.$infoTable." set isRecommend=0 where id in ($P_ID)");
		break;

		case $Action=="RefreshTime":
			mysql_query("update ".DB_TablePre.$infoTable." set adate='".date('Y-m-d H:i:s')."' where id in ($P_ID)");
		break;
	}	
	GoLink($ReturnUrl);
}
?><!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex,nofollow" />
<title><?php echo $pageTitle?><?php echo $sysTitle?></title>
<link href="templates/admin.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../lib/jquery/jquery.js"></script>
<script type="text/javascript" src="js/controlPanelMenu.js"></script>
<script type="text/javascript" src="js/commmonAdmin.js"></script></head>
<body>
<?php
include("./admin_header.php")
?>
<div id="containerAdmin" class="wrapper_m">
<div id="sidebarAdmin">
<?php
include("./admin_controlPanelDir.php")
?>
</div>
<div id="contentbarAdmin">
<div class="tips_2"><?php echo adminPageLocation($pageTitle)?></div>
<?php
include("./infoSearch.php");

echo '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td width="80"><strong>网站主分类:</strong></td>';
echo '<td>';
echo '<ul class="showCatalogUI">';
$db = mysql_query("select * from ".DB_TablePre.$cateTable." where CatalogParentId=0 order by SortId asc");
while($rs = mysql_fetch_array($db)){
	echo "<li class=\"ui_1\" title=\"".$rs["title"]."\"><a href='?CatalogId=".$rs["id"]."' style='".Check_color($rs["id"],$CatalogId_Color)."'>".$rs["title"]."</a></li>";
}
echo '</ul>';
echo '</td>';
echo '</tr>';
echo '</table>';
ShowNewsMenu($CatalogId,$cateTable);
?>
<?php
	if($CatalogId==-1){
		NoCheckInfo();
	}else{
	if($CatalogId>0){
		$coll = " type in (".GetSqlSuper($CatalogId,"category").")";
		//$coll = " type = '$CatalogId'";
	}else{
		$coll =  " 1=1";
	}
	$keyword = addslashes($_REQUEST["keyword"]);
    $keyword = str_replace("_","_",$keyword);
    $keyword = str_replace("%","%",$keyword);
	
	if(isset($keyword)){
		$coll .=" and (title like '%".$keyword."%' or content like '%".$keyword."%')"	;
	}
	$order = "isRecommend desc,adate desc";
	$sql = "select * from ".DB_TablePre.$infoTable." where" . $coll ." order by ".$order;	
	//echo $sql;
	$page_size = 20;					 //定义每页显示多少记录
	$num_cnt = @mysql_num_rows(mysql_query($sql)); //获取总记录数
	$page_cnt = ceil($num_cnt/$page_size);  //计算总页数	
	if(isset($_GET["page"])){
		$page = intval($_GET["page"]);
	}else{
		$page = 1;
	}
    if ($page<1){
        $page=1;
	}
    elseif ($page>$page_cnt){
        $page=$page_cnt;
    }
	$query_start = ($page - 1 ) * $page_size;
	$query_sql = $sql." limit $query_start,$page_size";
	
	$query_set = $conn->query($query_sql);
?>
<form name="formListInfo" id="formListInfo" method="post"  action="">
<input type="checkbox" name="P_ID[]" 	value="0" style="display:none;">
<input type="hidden" name="dd" />
<table cellspacing="0" class="adminTableV1">
<tr class="head1">
<td>信息标题</td>
<td width="110">所属类型</td>
<td width="90">作者</td>
<td width="130">发布时间</td>
<td width="90">操作</td>
</tr>
<?php
if($num_cnt==0){
	//echo "暂无记录";
}else{
	while($rs = mysql_fetch_array($conn->res)){
?>
<tr onMouseOver="this.style.backgroundColor='#FFFACA'" onMouseOut="this.style.backgroundColor='#FFFFFF'">
<td class="title1" style="<?php echo Check_color($rs["isRecommend"],true)?>" title="<?php echo $rs["title"]?>"><label class="otherLabel"><input type="checkbox" name="P_ID[]" value="<?php echo $rs["id"]?>"><?php echo killword($rs["title"],21)?><?php if($rs["pic"] !='') {?>&nbsp;<img src="templates/icon_tu.gif" alt="图片"><?php }?><?php if($rs["isRecommend"] == 1) {?><img src="templates/icon_jian.gif" alt="推荐"><?php }?><?php if($rs["isHot"] == 1) {?><img src="templates/icon_re.gif" alt="热门"><?php }?><?php if($rs["isHeadlines"] == 1) {?><img src="templates/icon_tou.gif" alt="头条"><?php }?></label></td>
<td><?php echo GetTitle($rs["type"],$cateTable)?></td>
<td>&nbsp;<?php echo $rs["aAuthor"]?></td>
<td>&nbsp;<?php echo $rs["adate"] ?></td>
<td><a href="infoUpdate.php?id=<?php echo $rs["id"]?>">修改</a>&nbsp;|&nbsp;<a href="?Action=DODelete&P_ID=<?php echo $rs["id"]?>" onClick="return confirm('是否确定删除此信息?\n\n删除后将不可恢复，请谨慎操作!')">删除</a></td>
</tr>
<?php
	}
}
?>
<tr>
<td colspan="5"><?php Controlnews($num_cnt,$page_cnt,$page,$table_style,$font_style); ?></td>
</tr>
</table>
<div class="iListPage">
<input type="button" onClick="selectAll(document.formListInfo)" value="全选" class="btn_4" /> 
<input type="button" onClick="selectOther(document.formListInfo)" value="反选" class="btn_4" />
<input name="ss" type="reset" onClick="javascript:document.formListInfo.reset();" value="重置" class="btn_4"/>
<input name="Action" type="button" id="Action" onClick="ContentDo('DODelete');" value="删除" class="btn_4"/>
<select name="Move_type" size="1"><option value="0">--请选择类别--</option><?php ShowSelect(0,$cateTable,$mcataid,6,true) ?>	</select>
<input name="Action" type="button" id="Action" value="移动" onClick="ContentDo('DOUpdate');" class="btn_4"/>
<input name="check_true" type="button" id="check_true" onClick="ContentDo('Check_true');" value="推荐" class="btn_4"/>
<input name="check_true" type="button" id="check_true" onClick="ContentDo('Check_false');" value="取消推荐" class="btn_4"/>
<input name="RefreshTime" type="button" id="RefreshTime" onClick="ContentDo('RefreshTime');" value="刷新" class="btn_4"/>
</div>
</form>

<?php
}

//级别换成汉字
function convertNumToCC($pNum){
    switch($pNum){
      case 1:$convertNumToCC="一";break;
      case 2:$convertNumToCC="二";break;
      case 3:$convertNumToCC="三";break;
      case 4:$convertNumToCC="四";break;
      case 5:$convertNumToCC="五";break;
      case 6:$convertNumToCC="六";break;
	  case 7:$convertNumToCC="七";break;
	 }
	  return $convertNumToCC;
}

function NoCheckInfo(){
?>
<table cellspacing="1" class="adminTableV1">
<tr class="head1">
<td colspan="2" class="t_l">请选择大分类，对大分类或其子分类中的信息进行操作，您可以进行以下操作:</td>
</tr>
<tr>
<td width="40" class="t_r">1.</td>
<td class="t_l">可以修改已经存在信息的内容。</td>
</tr>
<tr>
<td class="t_r">2.</td>
<td class="t_l">可以删除已经无效的信息。</td>
</tr>
<tr>
<td class="t_r">3.</td>
<td class="t_l">您也可以进入子分类中，对小分类中的信息进行修改</td>
</tr>
<tr>
<td class="t_r">4.</td>
<td class="t_l">信息标题为红色说明该信息已经设置成&ldquo;<font color="#FF0000">推荐</font>”</td>
</tr>
<tr>
<td class="t_r"><strong>注意:</strong></td>
<td class="t_l">删除信息之前，请一定确认信息已经无效，删除之后不可恢复！</td>
</tr>
</table>
<?php
}

//==无限极栏目显示过程==
//==根据栏目的ID号先查询是否存在，存在则用找到的父级目录ID号进行递归查找，==
//==递归查找到了，则再运用递归过来的父目录ID号再查一次是否存在，因为最上一级是0，==
//==0是在数据库中查找不到的。所以调用最多到二级分类，所以在此之前可以先将第一级分类加上去==
//==如此循环递归调用则只传递一个ID号就可以显示所有的栏目项了。==
//==无限极栏目显示函数==
function ShowNewsMenu($CatalogId,$cateTable){
	global $CatalogId_Color;
	$conn = new dbo();
	$sql = "select id,CatalogParentId,title,Mlevel from ".DB_TablePre.$cateTable." where id=".$CatalogId;
	$conn->query($sql);
	$rs_x = @mysql_fetch_array($conn->res);

	if($rs_x){
		$Mlevel=$rs_x["Mlevel"]+1;		
		ShowNewsMenu($rs_x["CatalogParentId"],$cateTable);
		
		$mysql = "select id,CatalogParentId,title,Mlevel from ".DB_TablePre.$cateTable." where CatalogParentId=".$rs_x["id"]." order by SortID asc";
		$conn->query($mysql);
		$xiaquery = $conn->res;
		$rscount = @mysql_num_rows($xiaquery);
		if($rscount>0)
		{
?>
		<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
		  <tr>
			<td width="80"><strong>第<?php echo convertNumToCC($Mlevel)?>级分类:</strong></td>
			<td>
<?php
echo "<ul class=\"showCatalogUI\">";
while($rs = mysql_fetch_array($xiaquery)){
	echo "<li class=\"ui_".$rs["Mlevel"]."\" title=\"".$rs["title"]."\"><a href='?CatalogId=".$rs["id"]."' style='".Check_color($rs["id"],$CatalogId_Color)."'>".$rs["title"]."</a></li>";
}
echo "</ul>";
?>
			</td>
		  </tr>
		</table>
<?php
		}
	}
}
?>
</div>
<div class="clearfix"></div>
</div>
<?php
include("./admin_footer.php")
?>
</body>
</html>