<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.online.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.weboffice.*" %>
<%
    String sOPENID_WEIXIN = SzConvert.toSpaceStr(request.getParameter("OPENID"));
    if (!sOPENID_WEIXIN.equals("")) {
	//取得用户ID
	com.soarwell.weixin.oa.User user_WEIXIN = new com.soarwell.weixin.oa.User();
	int iDLID_WEIXIN = user_WEIXIN.getBindLoginId(sOPENID_WEIXIN);
	if (iDLID_WEIXIN > 0) {
	  SzLogin szLogin_WEIXIN = new SzLogin();
	  SzLoginInfo szLoginInfo_WEIXIN = (SzLoginInfo)szLogin_WEIXIN.getInfoByKey(iDLID_WEIXIN);

          session.setMaxInactiveInterval(-1);	//设置为永不断线，2010-06-30
          session.setAttribute("SzDLID", Integer.toString(szLoginInfo_WEIXIN .getDLID()));
          session.setAttribute("SzDLZH", szLoginInfo_WEIXIN.getDLZH());
          session.setAttribute("SzDLXM", szLoginInfo_WEIXIN.getDLXM());
          session.setAttribute("SzLoginInfo", szLoginInfo_WEIXIN );
	  ////绑定listener 2008-09-19
	  session.setAttribute(Integer.toString(szLoginInfo_WEIXIN.getDLID()), net.sz600.online.OlUserSession.getInstance());
	}
    }
%>
<%@ include file="/sessionInfoWeixin.jsp"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<title>数飞协同网络办公系统</title>
 <link href="images/soarwell_css.css" rel="stylesheet" type="text/css" />
  <style type="text/css">
	img{vertical-align:middle;} 

    t img { vertical-align:middle;}
    
    
    .btnImg {
      cursor: hand;
    }

    .btnImgOver {
      cursor: hand;
      background:url(<%=strSkin_SESSION%>/top/t_m_over.gif); 
    }
    .btnImgClick {
      cursor: hand;
      background:url(<%=strSkin_SESSION%>/top/t_m_on.gif);
    }    
    
</style> 

<script language="javascript">
  function ChangeImage(obj, img) {
    obj.src = "<%=strSkin_SESSION%>/top2/" + img;
  }
</script>
</head>
<%
	BdValueControl bdValueControl = new  BdValueControl();
	int iCount = 0;
	StringBuffer sb = new StringBuffer("");
	sb.append("<font size='2' color='#F02C56'><b>[");
	if (!sBMMC_SESSION.equals("")) {
	  sb.append(sBMMC_SESSION);
	  sb.append(",");
	}
	sb.append("");
	sb.append(sDLXM_SESSION);
	sb.append("]</b></font>");		
 
%>
<table width="100%" border="0" cellspacing="3" cellpadding="3" style="border:#D7D7D9 1px solid;">
  <tr>
    <td valign="top" colspan="2" >
      <span class="product_name"><%=sb.toString()%></span>
      
      <a href="#" OnClick="javascript:top.location.href='index.jsp';"  onfocus="javascript:blur();">
      <img src="<%=strSkin_SESSION%>/top2/t_desktop.png" width="60" height="26" id="t_relogin" border="0" 
           OnMouseOver="javascript:ChangeImage(this, 't_desktop2.gif');" 
           OnMouseOut="javascript:ChangeImage(this, 't_desktop.png');">           
      </a>
      
      <a href="#" OnClick="javascript:top.location.href='../reloginApp.jsp?DLID=<%=iDLID_SESSION%>';"  onfocus="javascript:blur();">
      <img src="<%=strSkin_SESSION%>/top2/t_relogin.png" width="60" height="26" id="t_relogin" border="0" 
           OnMouseOver="javascript:ChangeImage(this, 't_relogin2.gif');" 
           OnMouseOut="javascript:ChangeImage(this, 't_relogin.png');">
	  </a>


    </td>
  </tr>
  <tr>
    <td colspan="2" height="8" align="left" background="images/line.gif"></td>
  </tr>
<%
  //获得本人可用的第一级菜单

    String sType = SzConvert.toZeroStr(request.getParameter("type")); //分公司信息
    String strType = sType;
    if (strType.equals("0")) {
    	strType = "-4";	
    }

    //权限
    SzPopedomApp szPopedom = new SzPopedomApp();
    //读取数据，2008-01-18改成到treeMap里读取。
    SzModuleApp szModule = new SzModuleApp();
    SzModuleInfo szModuleInfo = new SzModuleInfo();
	Collection collTop = SzModuleApp.getTopLevelModuleList(szCOMPANY_SESSION, isSuperManager_SESSION, szDLID_SESSION, strType);
    Iterator iter = null;
    int iSize = collTop.size();
    iSize = 600 - iSize * 21;
    if (collTop != null) {
    	iter = collTop.iterator();
    }
    //Iterator iter = szModule.getArrayList().iterator();
    String sBH = "";
    String sBH_ROOT = "";
    String sBH_SJ = "";

    String sBH_DEFAULT = "";
	//String sImage_DEFAULT = "t_default.gif";
	String sImage_DEFAULT = "blank.gif";
	String sImage = "";


    String sLink = "";
    String sLinkSecond = "";
    String sTemp_BH = ""; //这里保存不可使用的上级模块。如果上级模块都不能使用，直接跳过。
    String sManage_BH = ""; //这里保存有栏目管理权限的模块编号。下级可以继承
    boolean isBarManager = false;
    String sCanSee_BH = "";
    boolean isCanSee = false;
    int i = 0;
    boolean hasChild = false;
    boolean hasUrl = false;
    while (iter != null && iter.hasNext()) {
        szModuleInfo = (SzModuleInfo)iter.next();
      	sBH = szModuleInfo.getMKBH();

      	//2013-12-13增加超级管理员的判断
		if (isSuperManager_SESSION) {
			isBarManager = true;
			isCanSee = true; //这个应该永远是tree 
		} else {
        	//根据编号判断是否是管理员，上级模块是管理员，则可管理所有下级模块
        	isBarManager = szPopedom.isModuleManager(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());    
            if (szModuleInfo.getMKQX() == 3) {
              //系统管理员可见，判断是否系统管理员，该模块有没有设置成可见的权限。
              isCanSee = isSystemManager_SESSION ||
                       szPopedom.isModuleCanSee(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());
            } else if (szModuleInfo.getMKQX() == 2) {
              //模块管理员可见，判断是否模块管理员，该模块有没有设置成可见的权限。
              isCanSee = isBarManager ||
                       szPopedom.isModuleCanSee(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());
            } else if (szModuleInfo.getMKQX() == 1) {
            	//2013-12-19增加
              //指定人员可见：判断是否模块管理员，该模块有没有设置成可见的权限。
                isCanSee = isBarManager ||
                         szPopedom.isModuleCanSee(szModuleInfo.getMKID(), szLoginInfo_SESSION.getDLID());              
            } else {
            	isCanSee = true; //这个应该永远是tree
          	}
		}


        if (!isCanSee) {
           continue;
        }
		if (sBH_DEFAULT.equals("")) {
			sBH_DEFAULT = sBH;
		}
        sBH_SJ = SzConvert.toZeroStr( SzLevelNumber.getParentNumber(sBH) );
        sLink = SzModuleApp.getMenuLink(szModuleInfo.getMKLJDZ(), szModuleInfo.getMKID());
        sImage = szModuleInfo.getMKTP1();
        if (sImage.equals("")) {
        	sImage = sImage_DEFAULT;
        }
        if (!sLink.equals("")) {
        	hasUrl = true;
        } else {
        	hasUrl = false;
        }
      	//是否有下级,
      	hasChild = SzModuleApp.hasChildModule(sBH, szModuleInfo.getMKTZID());
      	if (!hasChild && !hasUrl) {
      		//没有连接,没有下级的跳过
      		continue;
      	}
        i ++;
        
        if (i>1 && i %2 == 1) {
        	out.println("<tr>");
        	out.println("<td colspan='2' height=\"8\" align=\"left\" background=\"images/line.gif\"></td>");
        	out.println("</tr>");          	
        }
				
        if (i %2 == 1) {
          out.println("<tr>");
				  out.println("<td width='50%' onMouseOver=\"javascript:this.className='trMouseOver'\" onMouseOut=\"javascript:this.className='trMouseOut'\">");
        } else {
        	out.println("<td width='50%' onMouseOver=\"javascript:this.className='trMouseOver'\" onMouseOut=\"javascript:this.className='trMouseOut'\">");
        }
  
		sLinkSecond = "index_second.jsp?MKBH_TOP=" + sBH;
		out.println("<a href=\"" + sLinkSecond + "\" onfocus=\"javascript:blur();\">");
		out.println("<img src=\"" + strSkin_SESSION + "/menu/menu_down1.gif\" id=\"img" + sBH + "\" width=16 style=\"cursor:hand;\" border=\"0\" >&nbsp;");
		out.println("</a>");
		
  	    if (sLink.equals("")) {
  	    	sLink = sLinkSecond;
  	    }
  		out.println("<a href=\"" + sLink + "\" onfocus=\"javascript:blur();\">");
  	    
  	    
  	    out.println("<span class=\"product_name\">");
  	    /*
  	    if (!sImage.equals("blank.gif")) { 
  	  	  out.print("<img src='../images/share2/top/" + sImage + "' width='20' height='35' border='0'>");
  	    } else {  		
  		  out.print("<img src='../images/share2/top/" + sImage + "' width='1' height='35' border='0'>");  		  
  	    }
  	    */
  	    out.println(szModuleInfo.getMKMC());
  	    out.println("</span>");
  	    if (!sLink.equals("")) {
  		  out.println("</a>");
  	    }
  	    

  			if (i %2 == 1) {
  				out.println("</td>");
  			} else if (i %2 == 0) {
  	      out.println("</td>");  	    
  	  	  out.println("</tr>");
  	  	}

   }//while ends  
	 if (i %2 == 0) {
	      out.println("<td></td>");  	    
	  	  out.println("</tr>");
	 }   
   if (i == 1) {
  	 //只有一个一级菜单,自动跳到二级
  	 out.println("<script language='javascript'>");
  	 out.println("document.location.href='" + sLinkSecond + "'");
  	 out.println("</script>");
   }
%>     
  

</table>
