<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Map" %>
<%@ 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.*" %>
<%@ include file="/sessionInfo.jsp"%>
<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_tree2.js"></SCRIPT>
</head>
<body>11
<%
    //多部门，多员工，多职务

    //type=all没有限制，same同一部门，tree树下的子部门
    String type = SzConvert.toSpaceStr(request.getParameter("type"));
    if (type.equals("")) {
        type = "all"; //默认是全部
    }
    String objId = SzConvert.toSpaceStr(request.getParameter("objId"));
    String objName = SzConvert.toSpaceStr(request.getParameter("objName"));
    String objDesc = SzConvert.toSpaceStr(request.getParameter("objDesc"));
    String objDescName = SzConvert.toSpaceStr(request.getParameter("objDescName"));
    String objPostId = SzConvert.toSpaceStr(request.getParameter("objPostId"));
    String objPostName = SzConvert.toSpaceStr(request.getParameter("objPostName"));

    String s = "";

    s = "";
      //+ "<input type='radio' name='DepartSelecting' value='' OnClick='ShowAllLogin2();'>显示全体员工"
      //+ "<input type='radio' name='DepartSelecting' value='0' OnClick='ClickDepart();'>显示没有部门的员工";    
%>
<%@ include file="/share/organize/user_js_include.jsp"%>
<table width="790" align="center" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formSelect" method="post">
  <input type="hidden" name="objId" value="<%=objId%>">
  <input type="hidden" name="objName" value="<%=objName%>">
  <input type="hidden" name="objDesc" value="<%=objDesc%>">
  <input type="hidden" name="objDescName" value="<%=objDescName%>">
  <input type="hidden" name="objPostId" value="<%=objPostId%>">
  <input type="hidden" name="objPostName" value="<%=objPostName%>">
  <tr>
    <td colspan="3" align="center">
      <input type='radio' name='DepartSelecting' value='' OnClick='ShowAllLogin3();'>显示全体员工   
      <input type='radio' name='DepartSelecting' value='0' OnClick='ClickDepart();'>显示没有部门的员工 

      <input type="checkbox" name="depart_checkall" value="1" OnClick="javascript:CheckAll(formSelect, depart_checkall, 'DepartSelected');" >部门全选&nbsp;
      <input type="checkbox" name="login_checkall" value="1" OnClick="javascript:CheckAll(formSelect, login_checkall, 'LoginSelecting');" >人员全选&nbsp;
      <input type="checkbox" name="post_checkall" value="1" OnClick="javascript:CheckAll(formSelect, post_checkall, 'PostSelected');" >职务全选&nbsp;
      <input type="button" name="btnOk" value="确定" OnClick="javascript:FunOk();">
      <input type="button" name="btnClose" value="关闭" OnCLick="javascript:window.close();">
    </td>
  </tr>
  <tr class="trClassTitle">
    <td>部门选择</td>
    <td>人员选择</td>
    <td>职务选择</td>
  </tr>
  <tr>
    <td width="36%" height="350" valign="top"  id="tdDepart"><!----------这里显示部门-------->
<%
	//读取部门
	SzUserHelp szUserHelp = new SzUserHelp();
	//Map map = szUserHelp.getDepartStaticMap();
	Iterator iter = SzUserHelp.getDepartStaticList().iterator();
	SzDepartInfo szDepartInfo = new SzDepartInfo();
	boolean flag = true;

	String sBMMC = "";
	String sBMBH = "";
	String sBMBH_SJ = "";
		
    int iBMID = 0;
    SzDepart szDepart = new SzDepart();
    out.println(szDepart.printFirstLevelDepart());
%> 
    <div id="divDepart"></div>
    </td>
    <!----------这里显示用户-------->
    <td width="44%" valign="top" align="left" id="tdUser">
      &nbsp;
    </td>
    <!----------这里显示职务-------->   
    <td width="20%" valign="top" align="left" id="tdPost">
<%
    Iterator iterPost = SzUserHelp.getPostStaticList().iterator(); 
    SzPostInfo szPostInfo = null;
    while (iterPost.hasNext()) {
    	szPostInfo = (SzPostInfo)iterPost.next();
    	out.println("<input type='checkbox' name='PostSelected' value='" + szPostInfo.getZWID() + "'>");
    	out.println(szPostInfo.getZWMC() + "<br>");
    }
%> 
    </td>    
  </tr>
  </form>
</table>
</body>
<SCRIPT language="javascript" src="../../share/js/commonTool.js"></script>
<SCRIPT language="javascript">
  //根据部门ID，获取部门名称
  function GetDepartName(vBMID) {
    var vBMMC = "";
    for (var i=0; i<departCount_JS; i++) {
      if (departArray_JS[i][0] == vBMID) {
        vBMMC = departArray_JS[i][1];
        break;
      }
    }
    return vBMMC;
  }
  
  function GetPostName(vZWID) {
    var vZWMC = "";
    for (var i=0; i<postCount_JS; i++) {
      if (postArray_JS[i][0] == vZWID) {
        vZWMC = postArray_JS[i][1];
        break;
      }
    }
    return vZWMC;
  }  
  
  //选择部门，显示用户
  function ClickDepart() {
    //员工
    var objId   = formSelect.objId.value;
    var objName = formSelect.objName.value;
    //部门
    var objDesc = formSelect.objDesc.value;
    var objDescName = formSelect.objDescName.value;
    //职务
    var objPostId = formSelect.objPostId.value;
    var objPostName = formSelect.objPostName.value;

    //获取选择的部门
    var vBMID = "0";
    vBMID = ValueOfRadio(formSelect.DepartSelecting);
    /*
    tdUser.innerHTML = "";
    var vHTML = "<table width='100%' border='0'>";
    var j = 0;
    //========显示部门的全体人员========
      //如果选择了部门，或者选择了没有部门的
    for (var i=0; i<userPostCount_JS; i++) {
        //如果是同一个部门的，就放进去
        //因为员工是按照部门排序的，所以这里可以加一个变量，如果已经加完同一部门的，就跳出循环。
        if (userPostArray_JS[i][0] == vBMID) {
          if (j % 2 == 0) {
            vHTML = vHTML + "<tr><td>";
            vHTML = vHTML + "<input type='checkbox' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            //vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td>";
          } else {
            vHTML = vHTML + "<td>";
            vHTML = vHTML + "<input type='checkbox' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            //vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td></tr>";
          }
          j ++;
        } // if == ends
    }//for

    vHTML = vHTML + "</table>"
    tdUser.innerHTML = vHTML;
    */
    //2009-04-15
    var j = 0;
    var oLogin;
    var oLoginName;
    var oTd;
    for (var i=0; i<userPostCount_JS; i++) {
        oLogin = formSelect.LoginSelecting[i];
        oLoginName = document.getElementById("LoginName" + i);
        oTd = document.getElementById("td" + i); 
        if (userPostArray_JS[i][0] == vBMID) {
        	//显示
        	//oLogin.style.display = "";
        	//oLoginName.style.display = "";
        	oTd.style.display = "";
        } else {
			//隐藏
			//oLogin.style.display = "none";
			//oLoginName.style.display = "none";
			oTd.style.display = "none";
        }
    }//for
  }

  //默认显示全部
  //将全体员工放进LoginSelecting
  function ShowAllLogin2() {
    tdUser.innerHTML = "";
    var vHTML = "<table width='100%' border='0'>";
    var j = 0;
    for (var i=0; i<userPostCount_JS; i++) {
        if (j % 2 == 0) {
            vHTML = vHTML + "<tr><td id='td" + i + "'>";
            vHTML = vHTML + "<input type='checkbox' name='LoginSelecting' value='" + i + "'>";
            vHTML = vHTML + "<span id='LoginName" + i + "'>" + userPostArray_JS[i][2] + "</span>" + "&nbsp;";
            //vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td>";
        } else {
            vHTML = vHTML + "<td id='td" + i + "'>";
            vHTML = vHTML + "<input type='checkbox' name='LoginSelecting' value='" + i + "'>" 
            vHTML = vHTML + "<span id='LoginName" + i + "'>" + userPostArray_JS[i][2] + "</span>" + "&nbsp;";
            //vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td></tr>";
        }
        j ++;
    }
    vHTML = vHTML + "</table>"
    tdUser.innerHTML = vHTML;
  }
  
  function ShowAllLogin3() {
    var oLogin;
    var oLoginName;
    var oTd;    
    for (var i=0; i<userPostCount_JS; i++) {
        oLogin = formSelect.LoginSelecting[i];
        oLoginName = document.getElementById("LoginName" + i);
        oTd = document.getElementById("td" + i); 
        oTd.style.display = "";
    }
  }  
 
  
  function ShowAllDepart2(vBMBH_PARENT) {
    divDepart.innerHTML = "";
    var vHTML = "";
    var j = 0;
    var vBMBH_P
    for (var i=0; i<departCount_JS; i++) {
        if (vBMBH_PARENT == "" || departArray_JS[i][2] != null && departArray_JS[i][2].indexOf(vBMBH_PARENT) == 0) {
        	vHTML = vHTML + "<input type='checkbox' name='DepartSelected' value='" + departArray_JS[i][0] + "'>";
        	vHTML = vHTML + "<input type='radio' name='DepartSelecting' value='" + departArray_JS[i][0] + "'  OnClick='ClickDepart();'>";
        	vHTML = vHTML + getLevelSpace(departArray_JS[i][2], <%=SzLevelNumber.I_NUMBER_LEN%>) +  departArray_JS[i][1];
        	vHTML = vHTML + "<BR>";
        } 
    }
    
    divDepart.innerHTML = vHTML;
  }
  
  //选择部门
  function SelectFirstDepart() {
	//alert(formSelect.firstDepartNumber.value);
	//只显示一级下的部门
	var vBMBH_PARENT = formSelect.firstDepartNumber.value;
	ShowAllDepart2(vBMBH_PARENT);
  }  
  
  function getLevelSpace(number, vNumberLen) {
    var vLen = number.length;
    var vCount = vLen / vNumberLen;
    
    var vReturn = "";
    for(var i=1; i<vCount; i++) {
		vReturn += "&nbsp;&nbsp;";
    }
    return vReturn;
  }
</SCRIPT>
<script language="javascript">
  function FunOk() {
    //用户
    var objId   = formSelect.objId.value;
    var objName = formSelect.objName.value;
    //部门
    var objDesc = formSelect.objDesc.value;
    var objDescName = formSelect.objDescName.value;
    //职务
    var objPostId = formSelect.objPostId.value;
    var objPostName = formSelect.objPostName.value;
    
    var vId = "0";
    var vName = "";
    var vDesc = "0";
    var vDescName = "";
    var vPostId = "0";
    var vPostName = "";
    //确定，获取
    var i = 0;
    var j = 0;

    //html
    var vHTML = "";
    var vHTML_depart = "[部门]";
    var vHTML_user = "<br>[员工]";
    var vHTML_post = "<br>[职务]";
    //这里是数组的index
    var vIndex = -1;
    var vLen = 0;
    //选择部门
    var oSelect = formSelect.DepartSelected;
    if (oSelect != null) {
      //获取部门userPostArray_JS
      j = 0;
      vLen = oSelect.length;
      for (i=0; i<vLen; i++) {
        //是否选中？
        if (oSelect[i].checked != true) {
          continue;
        }
        //这个是部门ID
        vIndex = oSelect[i].value;
        vDesc += "," + vIndex;
        //从部门数组里获取部门名称
        if (j==0) {
          vDescName =  GetDepartName(vIndex);
        } else {
          vDescName += "," + GetDepartName(vIndex);
        }
        //增加部门
        j++
      } //for i=0;
    } //if();

    //选择员工
    oSelect = formSelect.LoginSelecting;
    //alert(oSelect.length);
    if (oSelect != null) {
      //获取部门
      j = 0;
      vLen = oSelect.length;
      //当只有一个的时候
      if (vLen == null) {
        vLen = 1;
      }
      for (i=0; i<vLen; i++) {      
        //是否选中？
        if (vLen == 1) {
          //部门下只有一个人员的时候
          if (oSelect.checked != true) {
          	continue;
        	}
        	//这个是员工数组的index
        	vIndex = oSelect.value;        
        } else {
          if (oSelect[i].checked != true) {
          	continue;
        	}
        	//这个是员工数组的index
        	vIndex = oSelect[i].value;
        }
        
        vId += "," + userPostArray_JS[vIndex][1];
        if (j==0) {
          vName = userPostArray_JS[vIndex][2];
        } else {
          vName += "," + userPostArray_JS[vIndex][2];
        }
        j++
      } //for i=0;
    } //if();

    //选择职务
    oSelect = formSelect.PostSelected;
    if (oSelect != null) {
      j = 0;
      vLen = oSelect.length;
      for (i=0; i<vLen; i++) {
        //是否选中？
        if (oSelect[i].checked != true) {
          continue;
        }
        //这个是职务ID
        vIndex = oSelect[i].value;
        vPostId += "," + vIndex;
        //从部门数组里获取部门名称
        if (j==0) {
          vPostName =  GetPostName(vIndex);
        } else {
          vPostName += "," + GetPostName(vIndex);
        }
        //增加部门
        j++
      } //for i=0;
    } //if();

    var oWindow = window.dialogArguments;
    /*
    eval("oWindow.formUpdate.RYDLID1.value ='" + vId + "';");
    eval("oWindow.formUpdate.RYDLXM1.value ='" + vName + "';");
        
    eval("oWindow.formUpdate.RYDLID2.value ='" + vDesc + "';");
    eval("oWindow.formUpdate.RYDLXM2.value ='" + vDescName + "';");

    eval("oWindow.formUpdate.RYDLID3.value ='" + vPostId + "';");
    eval("oWindow.formUpdate.RYDLXM3.value ='" + vPostName + "';");
    */
    eval("oWindow." + objId + ".value ='" + vId + "';");
    eval("oWindow." + objName + ".value ='" + vName + "';");
        
    eval("oWindow." + objDesc + ".value ='" + vDesc + "';");
    eval("oWindow." + objDescName + ".value ='" + vDescName + "';");

    eval("oWindow." + objPostId + ".value ='" + vPostId + "';");
    eval("oWindow." + objPostName + ".value ='" + vPostName + "';");
                  
    window.close();
  }

  ShowAllDepart2("");
  ShowAllLogin2();
  
  //部门全选
  function CheckAll(oFormList, oChkCheckAll, vChkId) {
    var e;
    var vLen = oFormList.elements.length
    for (var i=0; i<vLen; i++) {
      e = oFormList.elements[i];
      if (e.name == vChkId) {
        e.checked = oChkCheckAll.checked;
      }
    }
  }
  

  
  
</script>

