<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.organize.*" %>
<%@ include file="/sessionInfo.jsp"%>
<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">
</head>
<%
    //获取提交的参数
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sPKEY = SzConvert.toZeroStr(request.getParameter("PKEY"));
    String sTable_type = "SZKC_CPFL";
%>
<%
    SzData szData = null;
    SzDataInfo szDataInfo = null;

    String sOPERATOR = request.getParameter("OPERATOR");
    String sKEY =  SzConvert.toZeroStr(request.getParameter("KEY"));
    String sReadonly = "";
    boolean bReadonly = false;
    if (sOPERATOR.equals("detail")) {
        sReadonly = "readonly";
        bReadonly = true;
    }
    //读取数据
    SzPopedomInfo szPopedomInfo = null;
    if (!sKEY.equals("0")) {
        SzPopedom szPopedom = new SzPopedom();
        szPopedomInfo = (SzPopedomInfo)szPopedom.getInfoByKey(Integer.parseInt(sKEY));
    }
    if (szPopedomInfo == null) {
        szPopedomInfo = new SzPopedomInfo();
    } else {
    }
    
    String strDLID = "0";
    String strBMID = "0";
    String strZWID = "0";
    if (szPopedomInfo.getQXRYLB() ==0) {
    	strDLID = "0," + szPopedomInfo.getQXRY() + ",0";
    } else if (szPopedomInfo.getQXRYLB() ==1) {
    	strBMID = "0," + szPopedomInfo.getQXRY() + ",0";
    } else if (szPopedomInfo.getQXRYLB() ==2) {
    	strZWID = "0," + szPopedomInfo.getQXRY() + ",0";
    }   
%>

<!-----上面的工具栏------>
<form name="formUpdate" method="post">
  <%@ include file="/share/title.jsp" %>
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
  <input type="hidden" name="KEY" value="<%=sKEY%>">
  <input type="hidden" name="QXID" value="<%=szPopedomInfo.getQXID()%>">
  <input type="hidden" name="type" value="<%=sType%>">
<table width="100%">
  <tr>
    <td>
    <% if (!bReadonly) { %>
      <input type="button" name="btnSave" class="btnClass" value="保存" OnClick="javascript:FormSave(formUpdate, 'control.jsp');">
    <% } %>
      <input type="button" name="btnBack" class="btnClass" value="返回" OnClick="javascript:FormSubmit(formHidden, 'index.jsp');">
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td colspan="2"><b>权限类型:</b>
<%
    int iLen = SzProperties.POPEDOM_NAME_STR.length;
    for (int i=0; i<iLen; i++) {
%>
      <input type="radio" name="chkQXLX" value="<%=SzProperties.POPEDOM_NAME_STR[i][0]%>" <%if (SzProperties.POPEDOM_NAME_STR[i][0].equals("" + szPopedomInfo.getQXLX()) ) { %>checked<% } %> 
			onClick="javascript:CheckQX('<%=SzProperties.POPEDOM_NAME_STR[i][0]%>');";      
      ><%=SzProperties.POPEDOM_NAME_STR[i][1]%>
<%
      if (i % 4 == 3) {
        //out.println("<br>");
      }
    }
%>
    </td>
  </tr>

  <tr>
    <td><b>请选择模块</b><br>
    <!-- [不选择模块表示整个系统] -->
<!----这里列出可以选择的模块---->
<%
    String sMKID_selected = "0," + szPopedomInfo.getQXMK() + ",0";
%>
<%@ include file="/share/organize/module_mult_include.jsp"%>
    </td>

    <td><b>请选择员工</b><br>
<!----这里列出可以选择的用户---->
<%
    String sDLID_selected = strDLID;
%>
<%@ include file="/share/organize/login_mult_include.jsp"%>
    </td>
  </tr>
  <tr>
    <td><b>请选择部门</b><br>
<!----这里列出可以选择的部门---->
<%
    String sBMID_selected = strBMID;
%>
<%@ include file="/share/organize/depart_mult_include.jsp"%>

    </td>
    <td><b>请选择职务名称</b><br>
<!----这里列出可以选择的部门---->
<%
    String sZWID_selected = strZWID;
%>
<%@ include file="/share/organize/post_mult_include.jsp"%>
    </td>
  </tr>

</table>
</form>


<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="type" value="<%=sType%>">
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript" src="../../share/js/selectTool.js"></script>
<script language="javascript">
  function CheckQX(vId) {

			if (formUpdate.chkQXLX[0].checked == true) {
				formUpdate.ModuleSelecting.disabled = true;
				MoveAllOption(formUpdate.ModuleSelected, formUpdate.ModuleSelecting);
				formUpdate.btnToRightM.disabled = true;
				formUpdate.btnToRightM2.disabled = true;
			}	else {
				formUpdate.ModuleSelecting.disabled = false;
				formUpdate.btnToRightM.disabled = false;
				formUpdate.btnToRightM2.disabled = false;
			}		
  }
  
  function FormSave(formName, url) {
    //至少选择一种权限
    var vCheck = NumberOfCheck(formName.chkQXLX);
    if (vCheck == 0) {
      alert("请至少选择一种权限");
      return;
    }
        
    //如果选择了3或者1，就一定要选择模块
    var vValue = ValueOfCheck(formName.chkQXLX) + ",";
    if (vValue.indexOf("1") > -1 || vValue.indexOf("3") > -1) {
       if ( formName.ModuleSelected.length == 0 ) {
         alert("'模块管理员、模块可见'要选择具体的模块");
         return;
       }
    }


    //至少选择人员/部门/职务中的一个
    if ( formName.LoginSelected.length == 0
      && formName.DepartSelected.length == 0
      && formName.PostSelected.length == 0) {
      alert("请至少选择人员、部门、职务中的一个");
      return;
    }
    //选择全部
    SelectAllOption(formName.ModuleSelected);
    SelectAllOption(formName.LoginSelected);
    SelectAllOption(formName.DepartSelected);
    SelectAllOption(formName.PostSelected);

    formName.action = url;
    formName.submit();
  }
</script>
