<?php 
/*********************************************************      
 程序说明：         
    功能说明：本程序将数据表中的分级目录，按树状菜单的形式显示出来，
              类似于windows资源管理器的效果。

    调用关系：调用: header.inc     
              被调用:      
 
    变量说明：$language_type是公共变量在config.inc文件定义

     返回值：无

 作者：      
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/     
require("../../inc/header.inc");
$DEBUG=0;
$pubDb='OMC_PUB';
$sysConfTable = 'sysConf';
$sysInfoTable = 'sysInfo';
$sysIdArr	= explode('_',$sysId);
$sysTypeNo	= $sysIdArr[0];
$sysNo		= $sysIdArr[1];
$subSysNo	= $sysIdArr[2];
if($DEBUG) echo "<br>sysTypeNo = $sysTypeNo";
if($DEBUG) echo "<br>sysNo = $sysNo";
if($DEBUG) echo "<br>subSysNo = $subSysNo";
if($DEBUG) echo "<br>selectedDPC = $selectedDPC";
if($DEBUG) echo "<br>selectedSysId = $selectedSysId";

//产生菜单时，所依据的表名
$objDb		= 'OBJ_'.$sysTypeNo;
$confTable  = 'paramConf';

//所链接的页面
$targetPage = 'paramConf_down_main.php';

//----------------------
//选择语言版本
if($language == 'eng'){
	$showName = name_2; //语种2	
}else{
	$showName = name_1; //语种1
}
//-----------------------

echo"<base target=\"r_r_main\">";

//------------------------------------------------------------------------
//下面列出该菜单依赖的字段名，用逗号隔开

//**如果需要添加可显示的层数，以按相同格式更改$levelList和$levelNum

//**例如：$levelList = "level_0,level_1,level_2,level_3,level_4.menu_6,menu_7,menu_8,menu_9,level_10.......level_n";
//**      并将$levelNum = n+1;

$levelList = "level_1,level_2,level_3,level_4,level_5,level_6,level_7,level_8,level_9,level_10";
$levelNum  = 10;
//------------------------------------------------------------------------

if($subSysNo == '99'){
	$isSysParam=1;
}else{
	$isSysParam=0;
}
?>
<script LANGUAGE="JavaScript">  
	function selectSubSys(){      
		var base_url,url_add,url; 
		base_url='<?php echo"paramConf_down.php?sysId=$sysId&selectedDPC=$selectedDPC&selectedSysId=";?>';
		url_add=document.selectForm.selectedSysId.options[document.selectForm.selectedSysId.selectedIndex].value;      
		url=base_url+url_add;
		window.parent.location=url;      
	}   
</script>

<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<?php
adjust_head_small_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";
?>
<FORM METHOD=POST name=selectForm>
<table border="1" width="100% cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"  >
  <tr>
    <td bgcolor="#E6E6E6"><nobr>
    <?php
	//echo "$sysNo,$subSysNo<br>";
	if(($sysNo == '99') || ($subSysNo == '99')){
		if($sysNo == '99'){
			$paramType = 2;
			if($sysTypeNo[0] == '2'){
				if($sysTypeNo == '222' || $sysTypeNo == '223'|| $sysTypeNo == '260'){
					$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
							FROM $sysInfoTable,$sysConfTable 
							WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
							AND $sysInfoTable.sysTypeNo = '$sysTypeNo' AND sysNo!='8' AND sysNo!='11' AND DPC='$selectedDPC'
							";
				}else{
					$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
							FROM $sysInfoTable,$sysConfTable 
							WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
							AND $sysInfoTable.sysTypeNo = '$sysTypeNo' AND sysNo='9' AND DPC='$selectedDPC'
							";
				}
			}else{
				$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
						FROM $sysInfoTable,$sysConfTable 
						WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
						AND $sysInfoTable.sysTypeNo = '$sysTypeNo'
						";
			}
		}else{
			$paramType = 1;
			$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
					FROM $sysInfoTable,$sysConfTable 
					WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
					AND $sysInfoTable.sysTypeNo = '$sysTypeNo'
					AND sysNo = '$sysNo'
					";
		}
		if($DEBUG) echo "sysIdSql(1) = $sysIdSql<br>";
		$result = mysqli_query($pubConn,$sysIdSql);
		echo mysqli_error($pubConn);
		$rowsNum=mysqli_num_rows($result);
		$rows=mysqli_fetch_array($result);
		$sysTypeName=$rows[sysTypeName];
		if($rowsNum < 1){
			echo "&nbsp;</td></tr></table>Can not find Any system be installed.<br>";
			exit();
		}
		if($sysNo == '99'){
			echo "<b>$sysTypeName"."_pub</b>";
		}else{
			echo "<b>$sysTypeName"."_$sysNo"."_pub</b>";
		}
		echo "&nbsp;&nbsp;&nbsp;Select:&nbsp;";
		echo "<select name=\"selectedSysId\"  size=\"1\" onChange=\"javascript:selectSubSys()\">";
		if($selectedSysId == -1){
			echo "<option value=\"-1\" selected>----</option>";
		}else{
			echo "<option value=\"-1\" >----</option>";
		}
		do{
			$tmpSysId	=$rows[sysTypeNo].'_'.$rows[sysNo].'_'.$rows[subSysNo];
			$tmpSysName	=$rows[sysTypeName].'_'.$rows[sysNo].'_'.$rows[subSysNo];
			$tmpAlias	=$rows[sysAlias];
			if($tmpSysId == $selectedSysId){
				$selectedStr='selected';
			}else{
				$selectedStr='';
			}
			if(strlen($tmpAlias) > 0){
				echo "<option value=\"$tmpSysId\" $selectedStr>$tmpSysName [$tmpAlias]</option>";
			}else{
				echo "<option value=\"$tmpSysId\" $selectedStr>$tmpSysName</option>";
			}
		}while($rows=mysqli_fetch_array($result));
		echo "</select>";
	}else{
		if ( ('222' == $sysTypeNo) || ('223' == $sysTypeNo) )  //MTP3 OR SCCP)
			$paramType = 2;
		else
			$paramType = 0;
	
		$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
						FROM $sysInfoTable,$sysConfTable 
						WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
						AND $sysInfoTable.sysTypeNo = '$sysTypeNo'
						AND sysNo = '$sysNo'
						AND subSysNo = '$subSysNo'
						";
		if($DEBUG) echo "sysIdSql(2) = $sysIdSql<br>";
		$result = mysqli_query($pubConn,$sysIdSql);
		echo mysqli_error($pubConn);
		$rowsNum=mysqli_num_rows($result);
		$rows=mysqli_fetch_array($result);
		$sysTypeName=$rows[sysTypeName];
		if($rowsNum < 1){
			echo "&nbsp;</td></tr></table>Can not find this system.<br>";
			exit();
		}
		echo "<b>$sysTypeName"._."$sysNo"._."$subSysNo</b>";
		$sysAlias=$rows[sysAlias];
		if(strlen($sysAlias)){
			echo "&nbsp;&nbsp;&nbsp;[$sysAlias]";
		}
	}	
  ?>
  </nobr></td>
  </tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr><td ><img src="../../images/line.gif"></td></tr>
<?php
     
/************************从数据库取出菜单结构的数据，并按顺序导入到数组中**************************/  
/*
if($sysTypeNo == 120 || $sysTypeNo == 130 || $sysTypeNo == 140){
	$bgnLevelNo=5;//1.1.7.2.* or 1.1.6.2.*
}else{
*/
	$bgnLevelNo=1;
/*
}
*/
$treeMenuSql = "SELECT * FROM $confTable 
			WHERE paramType ='$paramType' AND operType >'0' AND operType !='4'
			ORDER BY ".$levelList
			; 
if($DEBUG) echo "<br>$treeMenuSql";
$treeMenuResult = mysqli_query($pubConn,$treeMenuSql);
echo mysqli_error($pubConn);
$n=0;
while($treeMenuRows = @mysqli_fetch_array($treeMenuResult)){
	//从第i层开始划分层次，第i层之前不参与显示算法
	for($i=$bgnLevelNo; $i<=$levelNum; $i++){
		$levelId = 'level_'.$i;
		$treeMenuArr[$n][$i-1]=$treeMenuRows[$levelId];
	}
	$treeMenuArr[$n][$levelNum]=$treeMenuRows[$showName];
	$treeMenuArr[$n][$levelNum+1]=$treeMenuRows[keyId];
	$treeMenuArr[$n][$levelNum+2]=$treeMenuRows[paramType];
	$n++;
}

/*************************************下面是顺序显示菜单程序***************************************/ 

for($i=0 ; $i < sizeof($treeMenuArr); $i++){  //从上到下 ---> 级
	$objName = $treeMenuArr[$i][$levelNum];
	$objKeyId= $treeMenuArr[$i][$levelNum+1]; 
   
	$num=$bgnLevelNo;
	while($treeMenuArr[$i][$num] > 0){
		$num++;
	}
	$lastLevelNum = $treeMenuArr[$i][$num - 1].'.';
	$isSysParam = $treeMenuArr[$i][$levelNum+2]; 
	$leaf_show = "<a href=\"$targetPage?isKnot=0&objKeyId=$objKeyId&sysId=$sysId&selectedSysId=$selectedSysId&selectedDPC=$selectedDPC\">".$lastLevelNum.'&nbsp;'.$objName."</a></nobr>";
	$knot_show = "<a href=\"$targetPage?isKnot=1&objKeyId=$objKeyId&sysId=$sysId&selectedSysId=$selectedSysId&selectedDPC=$selectedDPC\">".$lastLevelNum.'&nbsp;'.$objName."</a></nobr>";
		 
	$show_1 = "\n<img align=absBottom border=0 src=../../images/midminus.gif><img align=absBottom border=0 src=../../images/open.gif>$knot_show";
	if($isSysParam > 0){
		$show_2 = "\n<img align=absBottom border=0 src=../../images/midblk.gif><img align=absBottom border=0 src=../../images/page.gif> $leaf_show";       
		$show_4 = "\n<img align=absBottom border=0 src=../../images/lastblk.gif><img align=absBottom border=0 src=../../images/page.gif> $leaf_show";
	}else{
		$show_2 = "\n<img align=absBottom border=0 src=../../images/midblk.gif><img align=absBottom border=0 src=../../images/page.gif> $leaf_show";  
		$show_4 = "\n<img align=absBottom border=0 src=../../images/lastblk.gif><img align=absBottom border=0 src=../../images/page.gif> $leaf_show";
	}
	$show_3 = "\n<img align=absBottom border=0 src=../../images/line.gif>";
	$show_5 = "\n<img align=absBottom border=0 src=../../images/blank.gif>";
	echo"<tr ><td valign=middle>";
	echo "<nobr>";
	for($j=0; $j < $levelNum;$j++){  //从左到右 ---> 层
		if($treeMenuArr[$i][$j] > 0){ //如果该节点大于零
			if($treeMenuArr[$i+1][$j] > $treeMenuArr[$i][$j] ){ //如果下面有树枝或页子与本节点（树枝或叶子）相连，即下面有兄弟节点
				if($treeMenuArr[$i][$j+1] > 0){ //如果是树枝		  
					echo "$show_3";  //show_3
				}else{//叶子 
					echo "$show_2";  //show_2
				}
			}else{//如果下面的节点号不大于本节点号
				if($treeMenuArr[$i][$j+1] > 0){ //如果本节点不是叶子
					$is_line =0;   //标志位，用于标志同一树枝下面是否还有分支，或是直接连在本枝上的叶子。
					//顺着上一层目录，向下查找
					for($p=$i+1;$p < sizeof($treeMenuArr) && $treeMenuArr[$p][$j-1] == $treeMenuArr[$i][$j-1];$p++){ 
						if($treeMenuArr[$p][$j] > $treeMenuArr[$i][$j]){  //找到了！！！
							$is_line = 1;
							break;
						}
					} 
					if($is_line == 1){  //下面还有分支，或是直接连在本枝上的叶子
						echo "$show_3";  //show_3
					}else{//同一树枝下没有分支，或是连在本枝上的叶子
						echo "$show_5";  //show_5
					}    
				}else{ //本节点是叶子
					if($treeMenuArr[$i+1][$j+1] > 0){  //本节点有分叉，即有起点在本节点的子树
						echo "$show_1";  //show_1
					}else{//本节点是该树枝上最末一片页子
						echo "$show_4";   //show_4
					}
				}
			}  //end  else of if($treeMenuArr[$i+1][$j] > $treeMenuArr[$i][$j] ) 
		}  //end if($treeMenuArr[$i][$j] > 0)
	}    //end for($j=0;$j < $levelNum;$j++)
	echo"</nobr></td></tr>";
}//end  for($i=0 ; $i < sizeof($treeMenuArr); $i++)
?>
</table>
</FORM>
<?php
adjust_content_tail("down");
?>
</body>
</html>
