<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.ArrayList" %>
<%@ 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.*" %>
<%@ page import="net.sz600.online.*" %>
<%@ include file="/sessionInfo.jsp"%>

<html>
<head>
<title></title>
<META http-equiv=Content-Type content="text/html; charset=gbk">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<SCRIPT src="../share/js/ftiens4_online.js"></SCRIPT>
</head>
<body onload="javascript:this.focus();">
<%
	//获取提交的参数
	String sType = SzConvert.toZeroStr(request.getParameter("type"));
	if (sType.equals("0")) {
%>
<%@ include file="/online/title.jsp"%>
<%		
	} else {
%>
<%@ include file="/online/title2.jsp"%>
<%		
	} 
%>

<%

    //读取部门
    SzUserHelp szUserHelp = new SzUserHelp();
    Iterator iter = szUserHelp.getDepartStaticList(szCOMPANY_SESSION).iterator();
    SzDepartInfo szDepartInfo = new SzDepartInfo();

    //取得员工
    Map mapUser = SzUserHelp.getUserStaticMap();
		int iOnlineCount = OlUserSession.getInstance().getOnLineUser().size();
		int iAllCount = SzUserHelp.getLoginStaticMap().size();        
    ArrayList arrayList = null;
    Iterator iterUser = null;
    SzUserHelpInfo info = null;

    String sUserInfo = "";
    int i = 0;
    boolean flag = true;
    String sPicture = OlUserSession.getInstance().alertCountInfo(iDLID_SESSION);
%>
<table width=100% border="0" cellpadding=0 cellspacing=0>
<form action="">
  <tr>
    <td align="center" width="33"></td>
    <td width="751" colspan="2" align="left" height="25">
	  <div id='divAlert'><%=sPicture %>&nbsp;总人数[<%=iAllCount%>],在线人数[<%=iOnlineCount %>]</div> 
    </td>
  </tr>
  <tr>
    <td align="center" width="33">
    <td width="751" colspan="2" align="left"><p align="left">
      <!--名字，连接，定位的页面，图片---->
<%
    String sBMBH = "";
	String sBMBH_TOP = "";
    String sBMBH_SJ = "";
    String sBMMC = "";
    int iBMID = 0;
    
    //增加判断用户是否在线
    boolean isOnline = false;
    sPicture = "";
    
    //用来保部门的编号
    ArrayList<String> BHlist = new ArrayList<String>();
    int size = 0;	//BHlist.size();
    String BHStr = "";	
    String openUrl = "../images/share/dirOpen1.gif";
    String closeUrl = "../images/share/dirClose1.gif";

    while (flag) {
        if (iter.hasNext()) {
            szDepartInfo = (SzDepartInfo)iter.next();
            iBMID = szDepartInfo.getBMID();
            sBMBH = szDepartInfo.getBMBH();
            sBMBH_SJ = SzConvert.toZeroStr(SzLevelNumber.getParentNumber(sBMBH));
            sBMMC = szDepartInfo.getBMMC();
           
            size = BHlist.size();
            for(int j = 0;j<size;j++){
            	BHStr = BHlist.get(j);
            	if(sBMBH.length()>BHStr.length()&&sBMBH.startsWith(BHStr)){
            		out.println("<input type=\"hidden\" name=\"div"+BHStr+"\" value=\""+sBMBH+"\"/>");
            		//System.out.println(BHStr+":"+sBMBH);
            	}
            }
            //将部门编号存入BHlist
            BHlist.add(sBMBH);
            //System.out.println("ldiv"+sBMBH);
%>
		<div id="ldiv<%=sBMBH %>"><%=SzLevelNumber.getLevelSpace(sBMBH)%>
		     <img class="img2" src='<%=openUrl %>' border='0' style="cursor:hand;" id="imgOpen<%=sBMBH %>" OnClick="javascript:ClickDepart('<%=openUrl %>','<%=closeUrl %>','<%=sBMBH %>');"><b><%=sBMMC %></b>
        <div id="<%=sBMBH%>" align="left"> 
<%
        } else {
            flag = false;
            iBMID = 0;
            sBMBH = "0";
        } //if else ends
        //根据部门ID读取下面的员工
        //arrayList = (ArrayList)mapUser.get(new Integer(iBMID));
        arrayList = (ArrayList)mapUser.get(new String(szCOMPANY_SESSION + "-" + iBMID));
        if (arrayList == null) {
           out.println("</div id=\"" + sBMBH + "\"></div>");
           continue;
        }
        iterUser = arrayList.iterator();
        while (iterUser.hasNext()) {
            info = (SzUserHelpInfo)iterUser.next();
            sUserInfo = info.getUserInfo();
            
            //判断用户是否在线
            isOnline = OlUserSession.getInstance().isOnline(info.getDLID());
            if (isOnline) {
              sPicture = "" + OlMessageControl.IMAGE_PATH + "/online_i2.gif";
	    	} else {
              sPicture = "" + OlMessageControl.IMAGE_PATH + "/online_o.gif";
            }

            i++;
            //out.println(sUserInfo + "<BR>");
%>
<div>
<a href="javascript:SendMessageWin('<%=info.getDLID()%>')" onfocus="javascript:blur();">
            &nbsp;&nbsp;<%=SzLevelNumber.getLevelSpace(sBMBH)%><img class="img2" src="../<%=sPicture %>" border="0" ><%=sUserInfo%>
</a>
</div>
<%
        }
        
        if (sBMBH.length() == SzLevelNumber.I_NUMBER_LEN) {
        	sBMBH_TOP = sBMBH;
        }
        //if (!sBMBH_TOP.equals("") && sBMBH_TOP.length() > SzLevelNumber.I_NUMBER_LEN) {
        out.println("</div id=\"" + sBMBH + "\"></div>");
        //}

    } //while (flag) ends
    mapUser = null;
    arrayList = null;
%>
<SCRIPT>
    //initializeDocument();
    //发送信息
    function SendMessageWin(vJSDLID) {
		var vUrl = "message/send.jsp?OPERATOR=send&JSDLID=" + vJSDLID;
    	window.open(vUrl,"","status=yes,height=500,width=600,top=100,left=100");    
  	}        
	//查看信息
    function ReceiveMessageWin(vJSID) {
    	var vUrl = "message/receive.jsp?refresh=true&OPERATOR=receive&KEY=" + vJSID;
	  	childWin = window.open(vUrl,"","status=yes,height=500,width=600,top=100,left=100");  
    }  	
</SCRIPT>
    </td>
  </tr>
  </form>
</table>
<script language="javascript">
	//var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	//2011-11-04修改
	var xmlhttp = null; 
	if   (window.XMLHttpRequest)   {   //   Mozilla,   Safari,...   
       		xmlhttp =new XMLHttpRequest();               
        }  else if(window.ActiveXObject)   {   //   IE    
		xmlhttp =new ActiveXObject("Microsoft.XMLHTTP");    
        }   
	var checkresult=null; 
	var vOnlineCount_OLD = "<%=iOnlineCount %>";

	function CheckMessage() { 
		xmlhttp.open("POST", "message/refresh_action.jsp", false); 
		//xmlhttp.onreadystatechange = updatePage; 
		xmlhttp.send(null); 

		var response = xmlhttp.responseText;
		var vCount = "0";
		var vFirst = "0";
		var vOnlineCount = "0";
		var vAllCount = "0";
		var v1 = response.indexOf("SzOnlineCountBegin");
		var v2 = response.indexOf("SzOnlineCountEnd");
		
		if (v1 >=0 && v2>v1) {
			vOnlineCount = response.substring(v1 + 18, v2);
			if (vOnlineCount != vOnlineCount_OLD) {
				document.location.reload();
			}			
		}
		
		var v3 = response.indexOf("SzAllCountBegin");
		var v4 = response.indexOf("SzAllCountEnd");
		if (v3 >=0 && v4>v3) {
			vAllCount = response.substring(v3 + 15, v4);
		}
				
		var vIndex = response.indexOf("SzMessageYes");		
		if (vIndex >=0) {
			var vIndex1 = response.indexOf("SzFirstJSID");
			var vIndex2 = response.indexOf("SzEnd");
		    vCount = response.substring(vIndex + 12, vIndex1);
		    vFirst = response.substring(vIndex1 + 11, vIndex2);
		    divAlert.innerHTML 
		    	   =  ""
    	           + "<a href='#' OnClick='javascript:ReceiveMessageWin(" + vFirst + ")'>"
    	           + "<img class='img2' border='0' src='../images/share/online_m.gif'>"
    	           + "</a>"		    	   
				   + "未收信息[<b>" + vCount + "</b>]";
		} else {
		    divAlert.innerHTML = "<img class='img2' border='0' src='../images/share/online_i.gif'>未收信息[0]";
		}
		divAlert.innerHTML += " 总人数[" + vAllCount + "],在线人数[" + vOnlineCount + "]";
		xmlhttp.abort();
	} 
	
	window.setInterval('CheckMessage()',5000);
	
	function ClickDepart(openUrl,closeUrl,BMBH) {
		var oDiv = document.getElementById(BMBH);
		if (oDiv.style.display == "none") {
			oDiv.style.display = "";
			document.getElementById("imgOpen" + BMBH).src = openUrl;
			showLowerDiv("div",BMBH,"");
		} else {
			oDiv.style.display = "none";
			document.getElementById("imgOpen" + BMBH).src = closeUrl;
			showLowerDiv("div",BMBH,"none");
		}
	}
	function showLowerDiv(divPrefix,divBH,display){
		var divGroup = document.getElementsByName(divPrefix+divBH);
		var size = divGroup.length;	//下级的个数
		var value = "";				//记录遍历当前的级divBH
		var divBHlen = divBH.length;
		var showStr = "";		//记录本级的display
		var lateShowStr = "";	//记录上一级的display
		var lateDiv = divBH;	//记录上一级的divBH
		var nonediv = "";		//记录隐藏的divBH
		var isNull = true;		//隐藏的divBH上否为""
		for(var i = 0;i < size;i++){
			value = divGroup[i].value;
			if(display=="none"){	//隐藏所有下级部门
				document.getElementById("ldiv"+value).style.display = "none";
			}else{	//遍历所有下级部门层
				lateDiv = value.substr(0,value.length-3);
				lateShowStr = document.getElementById(lateDiv).style.display;
				showStr = document.getElementById(value).style.display;
				if(lateShowStr=="none"){	//这个条件意思如：ldiv001001与001的显示一致
					continue;
				}else{
					//判断当前级是不是记录下来的隐藏级的子级，是的话不显示
					if(nonediv!=""&&nonediv==value.substr(0,nonediv.length)){
						continue;
					}else{
						nonediv = "";
						document.getElementById("ldiv"+value).style.display = "";
					}
					//判断当前级的div是不是隐藏的，是的话记录下来
					if(nonediv==""&&showStr=="none"){
						nonediv = value;
					}
				}
			}
		}
	}
</script>

</body>

