<?php 
require_once '../../Config.php';
if (intval ( BLL_Admin::isLogin () ) === 0) {
	header ( 'Location:../index.html' );
	die();
}
$jsonStr="";
?>
<!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/RightFrm.css" />
<script type="text/javascript" src="../jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../Comm.js"></script>
</head>
<body>
<table  border="0" cellpadding="0" cellspacing="1" class="headTable">
  <tr>
    <th width="80%">类别设置</th>
  </tr>
</table>
<table  border="0" cellpadding="0" cellspacing="1" class="listTable">
  <tr>
    <th width="40%">类别名</th>
    <th width="50%">记录数</th>
    <th width="10%">操作</th>
  </tr>
  <tr>
    <td colspan="3" style="color: #ff0000;">根目录</td>
  </tr>
  <?php getList(0); ?>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>
<iframe name="hideframe" width="0" height="0"></iframe>
<script type="text/javascript">
$(function(){
	setTableColor();
	var jsonObj=eval("[<?php echo $jsonStr; ?>]");
	SortInit(jsonObj);
	SortBvtClick();
});
</script>
</body>
</html>
<?php
//获取类别列表
function getList($pid, $indexz = 0, $allList = array(), $isFrist = true) {
	global $jsonStr;
	if ($isFrist) {
		$allList = BLL_LinkSort::getList ( $pid, 'id,pid,sortName,serialNum' );
	}
	if (count ( $allList ) == 0) {
		return;
	}
	$thisList = array_filter ( $allList, create_function ( '$one', "return \$one['pid']==$pid;" ) );
	$nextList = array_filter ( $allList, create_function ( '$one', "return \$one['pid']!=$pid;" ) );
	usort ( $thisList, create_function ( '$a,$b', "if (\$a['serialNum'] == \$b['serialNum']) {return 0;} return (\$a['serialNum'] < \$b['serialNum']) ? -1 : 1;" ) );
	$h = 1;
	foreach ( $thisList as $row ) {
		$tempList = array_filter ( $nextList, create_function ( '$one', "return \$one['pid']==$row[id];" ) );
		$kongGe = "&nbsp;&nbsp;&nbsp;&nbsp;";
		for($i = 0; $i < $indexz; $i ++) {
			$kongGe .= "&nbsp;&nbsp;<img src='../Images/x1.gif' align='absmiddle' />";
		}
		if ($indexz >= 0) {
			if ($h == count ( $thisList )) {
				$kongGe .= "&nbsp;&nbsp;<img src='../Images/x3.gif' align='absmiddle' />";
			} else {
				$kongGe .= "&nbsp;&nbsp;<img src='../Images/x2.gif' align='absmiddle' />";
			}
		}
		echo "<tr id='trId_$row[id]' class='opentr'>\r\n";
		if (count ( $tempList ) > 0) {
			echo "<td colspan='3'>$kongGe <img src='../Images/jian.gif' align='absmiddle' class='shousuo' rel='1' /> $row[sortName]</td>\r\n";
		} else {
			echo "<td>$kongGe <img src='../Images/jian.gif' align='absmiddle' class='shousuo' rel='1' /> $row[sortName]</td>\r\n";
			echo "<td>";
			echo "&nbsp;&nbsp;&nbsp;&nbsp;";
			echo "<a href=\"Link_Add.php?theId=$row[id]\">【新增】</a>";
			echo "&nbsp;&nbsp;&nbsp;&nbsp;";
			echo "记录数：<span style='color:#ff0000;'>" . BLL_Link::getCount ( $row ['id'] ) . "</span> 条";
			echo "</td>\r\n";
			echo "<td class='center'><a href=\"Link_List.php?theId=$row[id]\">【查看】</a></td>\r\n";
		}
		echo "</tr>\r\n";
		if ($row ['id'] != $thisList [0] ['id']) {
			$jsonStr .= ",";
		}
		if (count ( $tempList ) > 0) {
			$jsonStr .= "{'theId':'trId_$row[id]','theList':[";
			getList ( $row ['id'], $indexz + 1, $nextList, false );
			$jsonStr .= "]}";
		} else {
			$jsonStr .= "{'theId':'trId_$row[id]','theList':[]}";
		}
		++ $h;
	}
}
?>