
<?php
/*********************************************************      
 文件说明:         
    功能说明:OMC界面左侧主菜单


    调用关系:调用:header.inc  
             被调用:实现各个功能模块的页面        
    变量说明:
			$OmcTypeNo		在config.inc中定义;
			$myPrivilege	从用户的session中取出

 作者:      
      
修改注释:      
NO.1      
姓名:            
时间:      
修改说明:      
*********************************************************/ 
require("../../inc/header.inc");

$DEBUG = 0;
$pubDb = 'OMC_PUB';
$menuTable='sysMenuConf';
$elementTable='elementExistConf';
$level_1 = $_REQUEST['level_1'];
$OmcTypeNo = (isset($thisOmcType)?$thisOmcType:0);
if($DEBUG) echo "level_1=$level_1<br>";
$level_1 = ($level_1 > 0 ?$level_1 :1);
$myPrivilege = $userInfo['privilege'];
$max_layer=5;
if($selectedLanguage == 'eng'){
	$menuName	= 'name_2';
	$menuRemark	= 'remark_2';
}else{
	$menuName	= 'name_1';
	$menuRemark	= 'remark_1';
}
getSerial();
$tmpSql="SELECT * FROM $elementTable ORDER BY elementNo";
//$tmpResult = @mysqli_query($pubConn,$tmpSql);
$tmpResult = mysqli_query($pubConn,$tmpSql);
echo mysqli_error($pubConn);
while($tmpRow=mysqli_fetch_array($tmpResult)){
	$tmpNum=$tmpRow['elementNo'];
	$elementExistArr[$tmpNum]=$tmpRow['existFlag'];
}

//for($i=0;$i<sizeof($elementExistArr);$i++)
//	echo "<br>$i=$elementExistArr[$i]";

//menuTypeNo level_1 level_2 level_3 level_4 level_5 name_1 name_2 link_1 link_2 privilege remark_1 remark_2 
$menuSql = "SELECT level_1,level_2,level_3,level_4,level_5,$menuName,httpLink,$menuRemark,menuTypeNo 
			FROM $menuTable 
			WHERE  privilege <= '$myPrivilege' AND privilege >= '0'
			AND level_1='$level_1'
			ORDER BY level_1,level_2,level_3,level_4,level_5
			";
if($DEBUG) echo "<br>menuSql = $menuSql";
$menuResult = mysqli_query($pubConn,$menuSql);
echo mysqli_error($pubConn);
$menuRowsNum = mysqli_num_rows($menuResult);

//init menu array
$tmpArrNo=0;
for($i=0;$i< $menuRowsNum;$i++){
	$menuRow=mysqli_fetch_array($menuResult);
	//echo "<br>menuTypeNo=$menuRow[menuTypeNo]";
	if($elementExistArr[$menuRow['menuTypeNo']]!=1)
		continue;
	$menu_arr[$tmpArrNo]=array(0,0,0,0,0,'menuName','menuLink','menuRemak'); //match to $max_layer
	$menu_arr[$tmpArrNo][0]=$menuRow['level_1'];
	$menu_arr[$tmpArrNo][1]=$menuRow['level_2'];
	$menu_arr[$tmpArrNo][2]=$menuRow['level_3'];
	$menu_arr[$tmpArrNo][3]=$menuRow['level_4'];
	$menu_arr[$tmpArrNo][4]=$menuRow['level_5'];
	$menu_arr[$tmpArrNo][$max_layer]=$menuRow[$menuName];
	$menu_arr[$tmpArrNo][$max_layer + 1]=$menuRow['httpLink'];
	$menu_arr[$tmpArrNo][$max_layer + 2]=$menuRow[$menuRemark];
	$tmpArrNo++;
}
$topMenuName=$menu_arr[0][$max_layer];
/*
if($DEBUG){
	echo "<br>menuRowsNum = $menuRowsNum";
	echo "<br>-------------------------------------";
	//显示导入数组的信息
	for($i=0;$i<$menuRowsNum;$i++){
		echo "<br>>";
		for($j=0;$j<$max_layer;$j++){
			if($menu_arr[$i][$j] > 0){
				echo "{$menu_arr[$i][$j]}";
				echo ".";
			}
		}
		echo "-{$menu_arr[$i][$max_layer]}";
		echo "-{$menu_arr[$i][$max_layer+1]}";
		echo "-{$menu_arr[$i][$max_layer+2]}";
	}
}
*/
?>

<base target="contents">
<style type="text/css">
<!--
A:link{ color: #000000}
A:visited {color: #000000}
A:hover   {color: #000000; background:#AAFFFF; text-decoration: underline;}
A:active  {color: #000000; background:#FFFF80;}
.parent	  {}
.child	  {}
-->
</style>

<!-- OMC Sever's timezone must is GMT0-->
<script LANGUAGE="JavaScript" language="JavaScript1.2">
var server_timestamp=<?php echo mktime(); ?>;
var timeoffset=<?php echo date("Z"); ?>;
server_timestamp=server_timestamp+timeoffset;
var now = new Date();
var client_timestamp = now.getTime() / 1000;
var diff_seconds = server_timestamp - client_timestamp;



function show_id(web_id)
{
	document.page_num.p_num.value =" # "+web_id;
}

</script>

</head>
<!--
<body onLoad="clock();initIt();">
<body topmargin="0" leftmargin="0" onLoad="clock();expandAll();" style="background-color:transparent;overflow:hidden;overflow-x:hidden;overflow-y:scroll;">

-->
<body topmargin="0" leftmargin="0" onLoad="expandAll();" style="background-color:transparent;overflow:auto;overflow-x:hidden;overflow-y:auto;">




<script LANGUAGE="JavaScript" type="text/javascript">
<!--
<!--检测浏览器的名称与版本2-->
var NS = (document.layers) ? 1 : 0;
var IE=((navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>=3))?1:0;
<!--window.document.write("<br>NS="+NS+",IE="+IE);-->
var bV=parseInt(navigator.appVersion);
DOM=(!document.layers && !document.all && bV>=4) ? true : false; // A hack to guess if the browser supports the DOM
capable = (NS || IE || DOM) ? true : false;
//function expandIt(){return}
//function expandAll(){return}
//-->
</script>

<script language="JavaScript1.2" type="text/javascript">
<!--
isExpanded = false;
ishide = true;

function getIndex(ID) 
{
	ind = null;
	for (i=0; i<document.layers.length; i++) 
	{
		whichID = document.layers[i];
		if (whichID.id == ID) 
		{
			ind = i;
			break;
		}
	}
	return ind;
}

function arrange() 
{
	nextY = document.layers[firstInd].pageY + document.layers[firstInd].document.height;
	for (i=firstInd+1; i<document.layers.length; i++) 
	{
		whichID = document.layers[i];
		if (whichID.visibility != "hide") 
		{
			whichID.pageY = nextY;
			nextY += whichID.document.height;
		}
	}
}
function hideOrExpend()
{
	isExpanded = !isExpanded;
	if(!isExpanded)
		expandAll();
	else
		initIt();
}
function EleId2ImgId(eleId)
{
	var len=eleId.length;
	var ID = eleId.substring(0,len-5);
	var imgId = "Img" + ID;
	return imgId;
}

function initIt()
{
	if (NS) 
	{
		for (i=0; i<document.layers.length; i++) 
		{
			whichID = document.layers[i];
			if (whichID.id.indexOf("Child") != -1) whichID.visibility = "hide";
		}
		arrange();
	}	
	else
	{
		if(IE)
			tempColl = document.all.tags("DIV");
		if(DOM)
			tempColl = document.getElementsByTagName("DIV");
		for (i=0; i<tempColl.length; i++) 
		{
			if (tempColl[i].className == "child")
			{
				tempColl[i].style.display = "none";
				var eleId = tempColl[i].id;
				var imgId = EleId2ImgId(eleId);
				whichIm = document.getElementById(imgId);
				whichIm.src = "../../images/midplus.gif";
			}
		}
	}
}

function expandIt(ID) 
{
	if (!capable) return;
	if (IE) 
	{	
		expandIE(ID);
	} 
	else if(NS) 
	{
		expandNS(ID);
	} 
	else if(DOM) 
	{
		expandDOM(ID);
	}
}

function expandNS(ID) 
{
	whichEl = eval("document." + ID + "Child");
	whichIm = eval("document." + ID + "Parent.document.images['imEx']");
	if (whichEl.visibility == "hide") 
	{
		whichEl.visibility = "show";
		whichIm.src = "../../images/midminus.gif";
	} 
	else 
	{
		whichEl.visibility = "hide";
		whichIm.src = "../../images/midplus.gif";
	}
	arrange();
}

function expandIE(ID) 
{
	whichEl = eval(ID + "Child");
	whichIm = eval("Img" + ID);
	
	if (whichEl.style.display == "none") 
	{
		whichEl.style.display = "block";
		whichIm.src = "../../images/midminus.gif";
	} 
	else 
	{
		whichEl.style.display = "none";
		whichIm.src = "../../images/midplus.gif";
	}
	window.event.cancelBubble = true ;
}

function expandDOM(ID) 
{
	whichEl = document.getElementById(ID + "Child");
	whichIm = document.getElementById("Img"+ID);	
	if (whichEl.style.display == "none")
	{
		whichEl.style.display = "";
		whichIm.src = "../../images/midminus.gif";
	} 
	else 
	{
		whichEl.style.display = "none";
		whichIm.src = "../../images/midplus.gif";
	}
}

function expandAll() 
{
	// Brian Birtles 7-Jun-00 : This fn might be unnecessary (for phpMyAdmin).
	// My changes are certainly untested.
	newSrc = (isExpanded) ? "../../images/midplus.gif" : "../../images/midminus.gif";
	
	if (NS) 
	{
		// TR-02-01-99: Don't need that
		// document.images["imEx"].src = newSrc;
		for (i=firstInd; i<document.layers.length; i++) 
		{
			whichID = document.layers[i];
			if (whichID.id.indexOf("Parent") != -1) 
			{
				whichID.document.images["imEx"].src = newSrc;
			}
			if (whichID.id.indexOf("Child") != -1) 
			{
				whichID.visibility = (isExpanded) ? "hide" : "show";
			}
		}	
		arrange();
		if (isExpanded) scrollTo(0,document.layers[firstInd].pageY);
	} 	
	else  
	{
		if(IE)
		{
			divColl = document.all.tags("DIV");
			imColl = document.images.item("imEx");
		}
		if(DOM)
		{
			divColl = document.getElementsByTagName("DIV");
			imColl = document.getElementsByName("imEx");			
		}
		for (i=0; i<divColl.length; i++) 
		{
			if (divColl[i].className == "child") 
			{
				divColl[i].style.display = (isExpanded) ? "none" : "";
			}
		}
		for (i=0; i<imColl.length; i++) 
		{
			imColl[i].src = newSrc;
		}
	}	
	//isExpanded = !isExpanded;
}

//-->
</script>



<?php
/*************************************下面是顺序存储菜单程序***************************************/ 
$level_num=$max_layer;
$show_level='';
$bgnLevelNo=1;
if($DEBUG) echo "<table><tr><td>menuId</td><td>bgnNum</td><td>endNum</td></tr>";
for($i=0 ; $i < sizeof($menu_arr); $i++)  //从上到下 ---> 级
{  
	$tree_menu[$i]=array(0,'',0,0);
	$menu_temp='';
	$div_bgn_num=0;
	$div_end_num=0;
	$menu_id='';
	for($id=0;$id<$max_layer;$id++){
		if($menu_arr[$i][$id] > 0){
			if($id > 0){
				$menu_id = $menu_id.'_'.$menu_arr[$i][$id];
			}else{
				$menu_id = $menu_arr[$i][$id];
			}
		}else{
			break;
		}
	}
	
	$show_name = $menu_arr[$i][$level_num];
	
	$num=1;
	while($menu_arr[$i][$num] > 0){
		$num++;
	}   

	$show_level = $menu_arr[$i][$num - 1].'.';
	$lastLevelNo=$num - 1;
	$show = "<a href=\"{$menu_arr[$i][$max_layer+1]}\" title=\"$show_name\">".$show_name."</a>";
	
	//$show = "<a href=\"{$menu_arr[$i][$max_layer+1]}\" title=\"{$menu_arr[$i][$max_layer+2]}\">".'&nbsp;'.$show_name."</a>";			 
	$show_1 = "<img align=\"absBottom\" border=\"0\" src=\"../../images/midplus.gif\" ID=\"ImgT"."$menu_id\" NAME=\"imEx\">$show";
	$show_2 = "<img align=absBottom border=0 src=../../images/midblk.gif>$show";
	$show_3 = "<img align=absBottom border=0 src=../../images/line.gif>";
	$show_4 = "<img align=absBottom border=0 src=../../images/lastblk.gif>$show";
	$show_5 = "<img align=absBottom border=0 src=../../images/blank.gif>";
	
	$menu_temp.="\n<nobr>";
	for($j=$bgnLevelNo;$j < $level_num; $j++){  //从左到右 ---> 层
		if($menu_arr[$i][$j] > 0){ //如果该节点大于零	                 
			//如果下面有树枝或页子与本节点（树枝或叶子）相连，即下面有兄弟节点
			if($menu_arr[$i+1][$j] > $menu_arr[$i][$j] ){
				//如果是树枝
				if($menu_arr[$i][$j+1] > 0){ 		  
					$menu_temp.="$show_3";  //show_3
				//否则是叶子
				}else{  
					$menu_temp.="$show_2";  //show_2
				}
			}else{
				//如果下面的节点号不大于本节点号
				if($menu_arr[$i][$j+1] > 0){ //如果本节点不是叶子
					$is_line =0;   //标志位，用于标志同一树枝下面是否还有分支，或是直接连在本枝上的叶子。
					
					//顺着上一层目录，向下查找
					for($p=$i+1;$p < sizeof($menu_arr) && $menu_arr[$p][$j-1] == $menu_arr[$i][$j-1];$p++){ 
						if($menu_arr[$p][$j] > $menu_arr[$i][$j]){  //找到了！！！
							$is_line = 1;
							break;
						}
					} 
					  
					if($is_line == 1){  
						//下面还有分支，或是直接连在本枝上的叶子
						$menu_temp.= "$show_3";  //show_3
					}else{  
						//同一树枝下没有分支，或是连在本枝上的叶子
						$menu_temp.= "$show_5";  //show_5
					}
				}else{ 
					//本节点是叶子
					if($menu_arr[$i+1][$j+1] > 0){  
						//本节点有分叉，即有起点在本节点的子树
						$menu_temp.= "$show_1";  //show_1
						$div_bgn_num++;
					}else{
						$menu_temp.= "$show_4";   //show_4
						//本节点是树枝最末一片页子
						for($k=$bgnLevelNo;$k < $level_num;$k++){
							if($menu_arr[$i+1][$k] == 0){
								$div_end_num = $j - $k + 1;
								break;
							}
						}
						//if($menu_arr[$i][$bgnLevelNo] != $menu_arr[$i+1][$bgnLevelNo] 
						//	|| $menu_arr[$i+1][$bgnLevelNo] == 0){
						//	$div_end_num = $j - $bgnLevelNo;
						//}
						if($div_end_num == 0){
							$div_end_num = 1;
						}
						if($DEBUG) echo "<tr><td>$j / $k</td><td> $div_bgn_num </td><td> $div_end_num</td></tr>";
						for($k=($i-1);$k >= $bgnLevelNo;$k--){
							if($menu_arr[$k][$j-1] == $menu_arr[$i][$j-1] && $menu_arr[$k][$j] > 0){//同一个父节点
								if($tree_menu[$k][3] > 2){
									$tree_menu[$k][3] --;
									if($DEBUG) echo "<tr><td>$j / $k</td><td> {$tree_menu[$k][2]} </td><td> {$tree_menu[$k][3]}</td></tr>";
								}
							}else{
								break;
							}
						}
					}
				}
			} //end  else of if($menu_arr[$i+1][$j] > $menu_arr[$i][$j] ) 
		} //end if($menu_arr[$i][$j] > 0)
	} //end for($j=0;$j < $level_num;$j++)
	$menu_temp.="</nobr><br>";
	$tree_menu[$i][0]=$menu_id;
	$tree_menu[$i][1]=$menu_temp;
	$tree_menu[$i][2]=$div_bgn_num;
	$tree_menu[$i][3]=$div_end_num;
	if($DEBUG) echo "<tr bgcolor=#e6e6e6><td>$menu_id </td><td> $div_bgn_num </td><td> $div_end_num</td></tr>";
} //end  for($i=0 ; $i < sizeof($menu_arr); $i++)
if($DEBUG) echo "</table>";
//echo "<br>menu_num = $i";
/*************************************下面是顺序显示菜单程序***************************************/ 


echo "<a href=\"../contents/default.php?level_1=$level_1\" onClick=\"hideOrExpend();return true;\"><b><u>>> $topMenuName</u></b></a>";
for($i=0;$i<=sizeof($tree_menu);$i++){
	$menu_id		= $tree_menu[$i][0];
	$menu_content	= $tree_menu[$i][1];
	$div_bgn_num	= $tree_menu[$i][2];
	$div_end_num	= $tree_menu[$i][3];
	if($div_bgn_num > 0){
		echo "\n <div ID=\"T"."$menu_id"."Parent\" onClick=\"expandIt('T".$menu_id."'); return false;\" CLASS=\"parent\">";
		echo "$menu_content";
		echo "\n </div>";
		echo "\n <div ID=\"T"."$menu_id"."Child\" CLASS=\"child\">";
	}else{
		echo "$menu_content";
	}

	for($j=0;$j<$div_end_num;$j++){
		echo "\n </div>";
	}
}


//echo "<br>i=$i";

//鼠标形状
//小手: style="cursor:hand" 
//左箭头: style="cursor:w-resize"
?>

</body>

</html>


