<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.system.SzLevelNumber" %>
<%@ page import="net.sz600.organize.SzModule" %>
<%@ page import="net.sz600.organize.SzModuleInfo" %>
<%@ page import="net.sz600.organize.SzPopedom" %>
<%@ include file="/sessionInfo.jsp"%>
<%
//System.out.println("strSkin_SESSION==" + strSkin_SESSION);
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<SCRIPT src="../share/js/ftiens4_tree_menu.js"></SCRIPT>
<script language="javascript">
	function ClickSecond(number, secondLink) {
		var oImg = document.getElementById("img" +number);
		var oThird = document.getElementsByName("third" + number);
		
		if (oImg.src.indexOf("menu_down2.gif") >=0) {
			//未展开
			oImg.src = "<%=strSkin_SESSION%>/menu/menu_down1.gif";
			if (oThird != null) {
				HiddenThird(oThird, "");		
			} 			
		} else if (oImg.src.indexOf("menu_down1.gif") >=0) {
			//已经展开，要收缩
			oImg.src = "<%=strSkin_SESSION%>/menu/menu_down2.gif";
			if (oThird != null) {
				HiddenThird(oThird, "none");		
			} 				
		} 
		
		if (oImg.src.indexOf("menu_h02.gif") >=0) {
			oImg.src = "<%=strSkin_SESSION%>/menu/menu_h01.gif";
			if (oThird != null) {
				HiddenThird(oThird, "");		
			} 		
		} else if (oImg.src.indexOf("menu_h01.gif") >=0) {
			//已经展开，要收缩
			oImg.src = "<%=strSkin_SESSION%>/menu/menu_h02.gif";
			if (oThird != null) {
				HiddenThird(oThird, "none");		
			} 				
		}
	
	}	
	
	function HiddenThird(oThird, vDispaly) {
		if (oThird != null) {
			var vCount = oThird.length;
			for (var v = 0; v<vCount; v++) {
				//oThird[v].style.display = vDispaly;
				/*
				if (vDispaly == "") {
					if (oThird[v].style.display == "") {
						oThird[v].style.display = "none";
					} else {
						oThird[v].style.display = "";
					}
				} else {
					oThird[v].style.display = vDispaly;
				}
				*/
				if (vDispaly == "") {
					oThird[v].style.display = "";
				} else {
					oThird[v].style.display = "none";
				}
			}
		}
	}
</script>
<style type=text/css>
body{ 
SCROLLBAR-FACE-COLOR: white;
SCROLLBAR-HIGHLIGHT-COLOR: white; 
SCROLLBAR-SHADOW-COLOR: white;
SCROLLBAR-3DLIGHT-COLOR: white;
SCROLLBAR-ARROW-COLOR: #0C0C0C; 
SCROLLBAR-TRACK-COLOR: white; 
SCROLLBAR-DARKSHADOW-COLOR: white  
}

.menuOn1 {
    background-image:  url(<%=strSkin_SESSION%>/menu/menu_bt2.gif);
}
.menuOut1 {
    background-image:  url(<%=strSkin_SESSION%>/menu/menu_bt.gif);
}
	.menu_text_2222 {
		line-height: 40px;
	}
	
	.menu_text2 {
		line-height: 140px;
		background-image:  url(<%=strSkin_SESSION%>/menu/menu02_a1.gif);
	}	
  img { vertical-align:middle;}	
</style>
</head>


<body bgcolor="#F4FEFF">
<%
  //这里是传递进来的一级模块，下面列出二级模块。
  	String sMKBH_TOP = SzConvert.toZeroStr(request.getParameter("MKBH_TOP"));
	//2010-02-06，把sMKBH_TOP存到session；传递link_default
	session.setAttribute("SzMKBH_TOP", sMKBH_TOP);
	String sLink_Default = SzConvert.toSpaceStr(request.getParameter("Link_Default"));
	
  	String hasUrl = SzConvert.toZeroStr(request.getParameter("hasUrl"));
    
	String sLink = "";

	String sBH_DEFAULT = "";
	String sTemp_BH = ""; //这里保存不可使用的上级模块。如果上级模块都不能使用，直接跳过。
	String sManage_BH = ""; //这里保存有栏目管理权限的模块编号。下级可以继承
	boolean isBarManager = false;
	String sCanSee_BH = "";
	boolean isCanSee = false;
	int i = 0;
	int iSize = 0;
	boolean hasChild = false;
	
    //权限
    SzPopedom szPopedom = new SzPopedom();
    //读取数据，2008-01-18改成到treeMap里读取。
    SzModule szModule = new SzModule();
    SzModuleInfo szModuleInfo = null;
    String sBH = sMKBH_TOP;
    String sBH_ROOT = "";
    String sBH_SJ = "";
    
    Iterator iterChild = null;	
    
    //取得传过来的一级
    int iMKID_TOP = szModule.getModuleId(sMKBH_TOP);
    szModuleInfo = (SzModuleInfo)szModule.getModuleInfoByMap(iMKID_TOP);
    if (szModuleInfo == null) {
    	szModuleInfo = new SzModuleInfo(); 
    }
%>
<table width="100%" bgcolor="#F4FEFF" >
  <tr>
    <td align="right">
  <table border="0" cellpadding="0" cellspacing="0" align="center" id="tableMenu1" >
    <tr>
      <td background="<%=strSkin_SESSION%>/menu/menu01_01.gif" width="8" height="8" colspan="2"></td>
      <td background="<%=strSkin_SESSION%>/menu/menu01_02.gif" width="160" height="8" colspan="3"></td>
      <td background="<%=strSkin_SESSION%>/menu/menu01_03.gif" width="8" height="8" colspan="2"></td>
      <td></td>
    </tr>
    <tr>
      <td background="<%=strSkin_SESSION%>/menu/menu02_a1.gif" width="2" height="23"></td>
      <td background="<%=strSkin_SESSION%>/menu/menu02_a2.gif" width="6" height="23"></td>
      <td background="<%=strSkin_SESSION%>/menu/menu02_02.gif" width="160"  valign="top" colspan="3">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=szModuleInfo.getMKMC()%>
      </td>
      <td background="<%=strSkin_SESSION%>/menu/menu02_a3.gif" width="6" height="23"></td>
      <td background="<%=strSkin_SESSION%>/menu/menu02_a4.gif" width="2" height="23"></td>
      <td></td>
    </tr>   
    <tr>
      <td background="<%=strSkin_SESSION%>/menu/menu03_01.gif" width="2" height="23"></td>
      <td height="500" valign="top"  colspan="5">
        <div id='div'  style="position:relative;width:100%;overflow:auto;padding:0px; margin:0px;">
        <table border="0" cellpadding="0" cellspacing="0" valign="top">
          
  <%      
      sBH_ROOT = sBH;
      sTemp_BH = "";
      sManage_BH = "";
      sCanSee_BH = "";
      iterChild =  SzModule.getChildModuleList(sMKBH_TOP, szCOMPANY_SESSION, isSuperManager_SESSION).iterator();
      String sPath_str[][] = null;
      String sTarget = "";
      while (iterChild != null && iterChild.hasNext()) {
		szModuleInfo = (SzModuleInfo)iterChild.next();
		sBH = szModuleInfo.getMKBH();
        //已经设置横向显示的,这里不再显示
        if (szModuleInfo.getMKTZID() >0 && szModuleInfo.getMKTZID() != szModuleInfo.getMKID()) {
      		continue;
        }		  
	  
	    isCanSee = false;
	    if (isSuperManager_SESSION) {
	  	  isCanSee = true;
	    } else {
          //如果上级模块都不能使用，直接跳过。
          if (!sTemp_BH.equals("") && sBH.indexOf(sTemp_BH) == 0) {
              continue;
          }

          //根据编号判断是否是管理员，上级模块是管理员，则可管理所有下级模块
          if (!sManage_BH.equals("") && sBH.indexOf(sManage_BH) == 0) {
              isBarManager = true;
          } else {
              isBarManager = szPopedom.isModuleManager(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());
              if (isBarManager) {
                  sManage_BH = sBH;
              } else {
                  sManage_BH = "";
              }
          }

          //如果上级模块分派了可见权限，则下级可以继承，不需要再判断权限
          if (!sCanSee_BH.equals("") && sBH.indexOf(sCanSee_BH) == 0) {
              isCanSee = true;
          } else {
              if (szModuleInfo.getMKQX() == 3) {
                //系统管理员可见，判断是否系统管理员，该模块有没有设置成可见的权限。
                isCanSee = isSystemManager_SESSION ||
                           szPopedom.isModuleCanSee(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());
                if (isCanSee) {
                    sCanSee_BH = sBH;
                }

              } else if (szModuleInfo.getMKQX() == 2) {
                //模块管理员可见，判断是否模块管理员，该模块有没有设置成可见的权限。
                isCanSee = isBarManager ||
                           szPopedom.isModuleCanSee(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());
                if (isCanSee) {
                    sCanSee_BH = sBH;
                }
              } else if (szModuleInfo.getMKQX() == 1) {
                  isCanSee = isBarManager ||
                  					szPopedom.isModuleCanSee(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());
       						if (isCanSee) {
           					sCanSee_BH = sBH;
       						}                	
              } else {
                //普通模块，判断是否设置可见的权限
                isCanSee = szPopedom.isModuleCanSee(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());
                //这个的目的是保存已经授权的上级模块编号，不是作为本级显示的依据
                if (isCanSee) {
                    sCanSee_BH = sBH;
                }
                isCanSee = true; //这个应该永远是tree
              }
           } //if (!sCanSee_BH.equals("") && sBH.indexOf(sCanSee_BH) == 0) { } else {
	    } //if (isSuperManager_SESSION) {} else {

        if (!isCanSee) {
             //该模块不能使用，该模块直接跳过。
             sTemp_BH = sBH;  //记录不能使用的上级模块
             sCanSee_BH = "";
             continue;
        }
        sTemp_BH = "";    	  
  	  
  	    sBH = szModuleInfo.getMKBH();
  	    sBH_SJ = SzConvert.toZeroStr( SzLevelNumber.getParentNumber(sBH) );
  	    sLink = SzModule.getMenuLink(szModuleInfo.getMKLJDZ(), szModuleInfo.getMKID());
	  
  	 
		if (sBH_DEFAULT.equals("")) {
		  	sBH_DEFAULT = sBH;
	  	}    	
		if (sLink.equals("") && szModuleInfo.getMKTZID() > 0 ) {
			  //取得同组的第一个连接
				sPath_str = SzModule.getSameGroupStr(szModuleInfo.getMKID(), iDLID_SESSION, strLevel_SESSION);
			  if (sPath_str != null) {
				  //sLink = sPath_str[1][0];
					//2012-06-14增加判断.同组中判断是否有权限访问,没有就跳到下一个.
	  			for (int k = 1; k<sPath_str.length; k++ ) {
	    			if (sPath_str[k][4].equals("2") && !isBarManager_SESSION) {
	    				continue;
	    			} 
	    			sLink = sPath_str[k][0];
	    			if (!sLink.equals("")) {
	    				break;
	    			}
	  			}//for ends
	  			
			  }
		 }
  	     if (sLink_Default.equals("")) {
  		    sLink_Default = sLink;
  		    //System.out.println(sLink_Default);
  	     }
  	  
  	     //是否有下级,
  	     hasChild = SzModule.hasChildModule(sBH, szModuleInfo.getMKTZID());
  	    sTarget = szModuleInfo.getMKLJCK();
  	    if (!sTarget.equals("_blank")) {
  		   sTarget = "szMainFrame";
  	    } 
  	  
  	    i ++;
    	  if (hasChild) {
    		  //有下级
    		  //style="background-color:#DFF2FA"
    	  %>
          <tr><td class="menu_text" height="25" colspan="3" style="background-color:#DFF2FA" >
          
          <% if (!sLink.equals("")) { %>
          	<%=SzLevelNumber.getLevelSpace(sBH) %><img src="<%=strSkin_SESSION%>/menu/menu_down1.gif" id="img<%=sBH%>" style="cursor:hand;" border="0" OnClick="javascript:ClickSecond('<%=sBH%>','<%=sLink%>');">
          	<a href="<%=sLink%>" target="<%=sTarget %>" onfocus="javascript:blur();" id="<%=sBH%>" >
            &nbsp;<%=szModuleInfo.getMKMC()%>
            </a>
          <% } else {%>
						<%=SzLevelNumber.getLevelSpace(sBH) %><img src="<%=strSkin_SESSION%>/menu/menu_h01.gif" id="img<%=sBH%>" style="cursor:hand;" border="0" OnClick="javascript:ClickSecond('<%=sBH%>','<%=sLink%>');">
            &nbsp;<%=szModuleInfo.getMKMC()%>
          <% } %>
          </td></tr>
          <tr>
            <td background="<%=strSkin_SESSION%>/menu/menu_line02.gif" width="46" height="1"></td>
            <td background="<%=strSkin_SESSION%>/menu/menu_line03.gif" width="50%" height="1"></td>
            <td background="<%=strSkin_SESSION%>/menu/menu_line04.gif" width="46" height="1"></td>          
          </tr>          
  		  <%
    	  } else {
    		  if (i==1) {
    			  //如果第一个没有下级，就增加点空白行
    				out.println("<tr><td height='5px'></td></tr>");  
    		  }
          %>
                    
          <tr id="third<%=SzLevelNumber.getParentNumber(sBH)%>" name="third<%=SzLevelNumber.getParentNumber(sBH)%>"><td class="menu_text" height="25" colspan="3">
          <% if (!sLink.equals("")) { %><a href="<%=sLink%>" target="<%=sTarget %>" onfocus="javascript:blur();"><% } %>
            <%=SzLevelNumber.getLevelSpace(sBH) %><img src="<%=strSkin_SESSION%>/menu/menu_b01.gif" border="0">
            &nbsp;<%=szModuleInfo.getMKMC()%>
            <% if (!sLink.equals("")) { %></a><% } %>
          </td></tr>      
          <tr id="third<%=SzLevelNumber.getParentNumber(sBH)%>" name="third<%=SzLevelNumber.getParentNumber(sBH)%>">
            <td background="<%=strSkin_SESSION%>/menu/menu_line02.gif" width="46" height="1"></td>
            <td background="<%=strSkin_SESSION%>/menu/menu_line03.gif" width="50%" height="1"></td>
            <td background="<%=strSkin_SESSION%>/menu/menu_line04.gif" width="46" height="1"></td>          
          </tr>              
          <%    		  
    	  }
    	  %>

    	  <%
      }
  %>   
        </table> 
        </div>
      </td>
      <td background="<%=strSkin_SESSION%>/menu/menu03_02.gif" width="2" height="23"></td>
      <td width="11" align="left"> <!-- 左右缩进 -->      
        <img src="<%=strSkin_SESSION%>/menu/menu_b04.gif"  style="cursor:hand;" width="11" height="259" onClick="javascript:ChangeMenuWidth();">
      </td>
    </tr>
    <tr>
      <td background="<%=strSkin_SESSION%>/menu/menu04_01.gif" width="8" height="8" colspan="2"></td>
      <td background="<%=strSkin_SESSION%>/menu/menu04_02.gif" width="160" height="8"" height="8"  colspan="3"></td>
      <td background="<%=strSkin_SESSION%>/menu/menu04_03.gif" width="8" height="8" colspan="2"></td>
      <td></td>
    </tr>                       
  </table> 
  <table border="0" cellpadding="0" cellspacing="0" align="center" width="11" id="tableMenu2" style="display:none;">
    <tr>
      <td width="11" height="540" align="left" valign="middle">       
        <img src="<%=strSkin_SESSION%>/menu/menu_b03.gif" style="cursor:hand;" id="btnChangeMenu" width="11" height="259" onClick="javascript:ChangeMenuWidth();">
      </td>
    </tr>   
  </table>  
    </td>
    
  </tr>
</table>  
<input type="hidden" id="count" value="<%=i%>">
<input type="hidden" id="MKID_TOP" value="<%=iMKID_TOP%>">
<input type="hidden" id="hasUrl" value="<%=hasUrl%>">
<input type="hidden" id="BH_DEFAULT" value="<%=sBH_DEFAULT%>">
<input type="hidden" id="Link_Default" value="<%=sLink_Default%>">

<script language="javascript">
    //菜单缩进-展开按钮的动作：2011-11-03补充
    function ChangeMenuWidth() {

			var o1 = document.getElementById("tableMenu1");
			var o2 = document.getElementById("tableMenu2");
			//2011-11-03修改window.top.pframe为window.top.document.getElementById("pframe")，支持ff,ie,safari
			var opframe = window.top.document.getElementById("pframe");

	    if (opframe.cols == "200,*") {
			opframe.cols="20,*";
			o1.style.display = "none";
			o2.style.display = "";
	    } else {
			opframe.cols="200,*";
			o1.style.display = "";
			o2.style.display = "none";			
	    }	
    }
    
    function ChangeMenuAuto(vType) {
			var o1 = document.getElementById("tableMenu1");
			var o2 = document.getElementById("tableMenu2");
 			//2011-11-03修改window.top.pframe为window.top.document.getElementById("pframe")，支持ff,ie,safari
			var opframe = window.top.document.getElementById("pframe");

		if (vType == "0") { //隐藏
			opframe.cols="10,*";
			//if (o1 != null) {
				o1.style.display = "none";
			//}
			//if (o2 != null) {
				o2.style.display = "";		
			//}
		} else {
			opframe.cols="200,*";
			//if (o1 != null) {
				o1.style.display = "";
			//}
			//if (o2 != null) {
				o2.style.display = "none";					
			//}
		}
    } 
    
    //从顶过来
    function ChangeMenuAutoDesktop(vType) {
			var o1 = document.getElementById("tableMenu1");
			var o2 = document.getElementById("tableMenu2");
 			//2011-11-03修改window.top.pframe为window.top.document.getElementById("pframe")，支持ff,ie,safari
			var opframe = window.top.document.getElementById("pframe");

			if (vType == "0") { //隐藏
				opframe.cols="10,*";
				//if (o1 != null) {
					o1.style.display = "none";
				//}
				//if (o2 != null) {
					o2.style.display = "none";		
				//}
			}
    }        
    
  //重新计算div的大小
  var vHeight = document.body.clientHeight;  
  var divHeight = vHeight - 51;  
  div.style.height = divHeight;
  
  //如果没有二级，自动隐藏  
  var vCount = document.getElementById("count").value;
  var vMKID_TOP = document.getElementById("MKID_TOP").value;
  if (vCount == "0" || vMKID_TOP == "0") {
	  ChangeMenuAuto("0");
	  //增加隐藏缩进按钮的功能
	  document.getElementById("btnChangeMenu").style.display="none";
  } else {
	  ChangeMenuAuto("1");
	  document.getElementById("btnChangeMenu").style.display="";
  }
  
  //如果一级没有url，那这里就显示第一个url
  var hasUrl = document.getElementById("hasUrl").value;
  var oBH_DEFAULT = document.getElementById("BH_DEFAULT");
  var Link_Default = document.getElementById("Link_Default").value;
	//2011-06-27增加undefined的判断；
  if (hasUrl == "undefined" || hasUrl == "" || hasUrl == "0" || hasUrl == "false") {
    if (Link_Default == "" || vMKID_TOP == "0") {
	  	Link_Default = "desktop.jsp";
    }
    top.szMainFrame.document.location.href = Link_Default;    
    //window.top.document.getElementById("szMainFrame").document.location = Link_Default;    
  }

</script>    
</body>
