<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzLevelNumber" %>
<%@ page import="net.sz600.organize.SzModule" %>
<%@ page import="net.sz600.organize.SzModuleInfo" %>
<%@ 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 sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sType = SzConvert.toZeroStr(request.getParameter("type"));   
    String FirstMKBH = SzConvert.toZeroStr(request.getParameter("FirstMKBH"));
    String SecondMKBH = SzConvert.toZeroStr(request.getParameter("SecondMKBH"));
%>
<%
    String sOPERATOR = request.getParameter("OPERATOR");
    String sKEY =  SzConvert.toZeroStr(request.getParameter("KEY"));
    //读取数据
    SzModule szModule = new SzModule();
    SzModuleInfo szModuleInfo = null;
    if (!sKEY.equals("0")) {
        szModuleInfo = (SzModuleInfo)szModule.getInfoByKey(Integer.parseInt(sKEY));
    }
    if (szModuleInfo == null) {
        szModuleInfo = new SzModuleInfo();
    }
    String MKBH = SzLevelNumber.getParentNumber(szModuleInfo.getMKBH());
    String sMKBH_CURRENT = szModuleInfo.getMKBH();
%>

<!-----上面的工具栏------>

<form name="formUpdate" method="post">
  <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="MKID" value="<%=szModuleInfo.getMKID()%>">
  <input type="hidden" name="MKBH" value="<%=szModuleInfo.getMKBH()%>">
  <input type="hidden" name="MKTZID" value="<%=szModuleInfo.getMKTZID()%>">
  <input type="hidden" name="MKBH2" value="<%=MKBH%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="FirstMKBH" value="<%=FirstMKBH%>"> 
  <input type="hidden" name="SecondMKBH" value="<%=SecondMKBH%>">    
  <input type="hidden" name="MKSX" value="<%=szModuleInfo.getMKSX()%>" > 
<%@ include file="/share/title.jsp"%>
<table width="100%">
  <tr>
    <td>
      <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(formUpdate, 'index.jsp');">
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="650" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tdClassTitle">模块名称</td>
    <td><input type="text" name="MKMC" class="txtClass1" value="<%=szModuleInfo.getMKMC()%>"></td>
    <td class="tdClassTitle">连接窗口</td>
    <td>
      <input type="radio" name="MKLJCK" value="" <%if (szModuleInfo.getMKLJCK().equals("")) {%> checked <%}%>>默认
      <input type="radio" name="MKLJCK" value="_blank" <%if (szModuleInfo.getMKLJCK().equals("_blank")) {%> checked <%}%>>弹出窗口
    </td>
  </tr>
  <tr>
    <td class="tdClassTitle">模块图片1</td>
    <td><input type="text" name="MKTP1" class="txtClass1" value="<%=szModuleInfo.getMKTP1()%>"></td>

    <td class="tdClassTitle">模块图片2</td>
    <td><input type="text" name="MKTP2" class="txtClass1" value="<%=szModuleInfo.getMKTP2()%>"></td>
  </tr>
  <tr>
    <td class="tdClassTitle">连接地址</td>
    <td colspan="3"><input type="text" name="MKLJDZ" class="txtClass2" value="<%=szModuleInfo.getMKLJDZ()%>"></td>
  </tr>
  <tr>
    <td class="tdClassTitle">模块属性</td>
    <td colspan="3">
      <input type="radio" name="MKQX" value="0" <%if (szModuleInfo.getMKQX() == 0) {%> checked <%}%>>所有人可见
      <input type="radio" name="MKQX" value="1" <%if (szModuleInfo.getMKQX() == 1) {%> checked <%}%>>指定人员可见
      <input type="radio" name="MKQX" value="2" <%if (szModuleInfo.getMKQX() == 2) {%> checked <%}%>>只有模块管理员可见
      <input type="radio" name="MKQX" value="3" <%if (szModuleInfo.getMKQX() == 3) {%> checked <%}%>>只有系统管理员可见
    </td>
  </tr>
  <tr>
    <td class="tdClassTitle">上级模块</td>
    <td colspan="3">
      <select name="MKBH_SJ" class="txtClass2" style="width:300;">
        <option value="">===请选择===</option>
      </select>
      
      <input type="radio" name="topOnly" value="0" checked OnClick="javascript:CheckTopOnly();">全部
      <input type="radio" name="topOnly" value="1" OnClick="javascript:CheckTopOnly();">一级      
      <input type="radio" name="topOnly" value="2" OnClick="javascript:CheckTopOnly();">两级            
    </td>
  </tr>
</table>  
<%
    //Iterator iter = szModule.getArrayList().iterator();
    //
    Iterator iter = szModule.getModuleList().iterator();
    String name_module = "";
%>  
<script language="javascript">
    var moduleArray_JS;
    moduleArray_JS = new Array();
    moduleCount_JS = 0;
<%
	while (iter != null && iter.hasNext()) {
    	szModuleInfo = (SzModuleInfo)iter.next();
    	//只能显示3级。而且已经设置为别人同组的不能作为上级2009-07-10
    	if (szModuleInfo == null) {
    		continue;
    	}
    	if (szModuleInfo.getMKBH().length() > SzLevelNumber.I_NUMBER_LEN * 3) {
    		continue;
    	}
    	if (szModuleInfo.getMKTZID() > 0 && szModuleInfo.getMKTZID() != szModuleInfo.getMKID()) {
    		continue;
    	}
    	
    	name_module = SzLevelNumber.getLevelSpace(szModuleInfo.getMKBH()) + szModuleInfo.getMKMC(); 
    	name_module = name_module.replaceAll("&nbsp;","--");
    	%>
        //部门数组
        moduleArray_JS[moduleCount_JS] = new Array("<%=szModuleInfo.getMKBH()%>","<%=name_module%>");
        moduleCount_JS ++;
<%
	}
%>
	//把数组内容放到select里	
	//vTop ==0全部,1第一级
	function intoSelect(vMKBH, vTop) {
	  //根据需要显示数据
	  
      formUpdate.MKBH_SJ.length = 1;
      for (var i=0; i<moduleCount_JS; i++) {
		if (vTop == "1" && moduleArray_JS[i][0].length ><%=SzLevelNumber.I_NUMBER_LEN%>) {
			continue; 
		}
		if (vTop == "2" && moduleArray_JS[i][0].length ><%=SzLevelNumber.I_NUMBER_LEN * 2%>) {
			continue; 
		}
        formUpdate.MKBH_SJ.options[formUpdate.MKBH_SJ.length]
          	= new Option(moduleArray_JS[i][1], moduleArray_JS[i][0]);      
      }	 
      for (var i=0; i<moduleCount_JS; i++) {
        if (vMKBH == moduleArray_JS[i][0]) {
            formUpdate.MKBH_SJ.options[i + 1].selected = true;
        }      
      }
      
	}
	//如果是修改，这个是默认的上级
	var vMKBH = formUpdate.MKBH2.value;
	if (vMKBH == "" && formUpdate.MKBH.value == "") {
		vMKBH = formUpdate.FirstMKBH.value;
	}
	//显示可以选择的上级
    intoSelect(vMKBH, "0");
    
    function CheckTopOnly() {
      var vCheck = ValueOfRadio(formUpdate.topOnly);
      intoSelect(vMKBH, vCheck);
    }
</script>  
<!-- -----------------列出模块：可设置为同组，条件为： 没有设置同组，最后一级菜单，有设置访问路径-->
<table width="650" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tdClassTitle">设置为同组
    
    <br>(建议不超过6个)
    </td>
    <td>
      <table border="0">
<%
	//条件为： 没有设置同组，最后一级菜单，有设置访问路径
    //读出已经设置为同组的模块
    String str_MKID = "0";
    boolean flag = false;
	//读取数据
	iter = szModule.getModuleList().iterator();
	String check = "";
    while (iter != null && iter.hasNext()) {
        szModuleInfo = (SzModuleInfo)iter.next();
        flag = false;
        check = "";
    	if (szModuleInfo == null) {
    		continue;
    	}
       	if (szModuleInfo.getMKTZID() > 0 && szModuleInfo.getMKTZID() !=  Integer.parseInt(sKEY)) {
    		continue;
    	}    
       	//同一级别或自己的下一级别，其他continue
       	if (szModuleInfo.getMKBH().length() == sMKBH_CURRENT.length() 
       		&& SzLevelNumber.getParentNumber(szModuleInfo.getMKBH()).equals(SzLevelNumber.getParentNumber(sMKBH_CURRENT))
       		|| SzLevelNumber.getParentNumber(szModuleInfo.getMKBH()).equals(sMKBH_CURRENT)) {
       	} else {
       		continue;       		
       	}
       	
       	if (szModuleInfo.getMKTZID() > 0 
       			&& szModuleInfo.getMKTZID() ==  Integer.parseInt(sKEY) ) {
       		flag = true;
       		check = "checked";
       	}

       	
    	//没有设置同组，最后一级菜单，有设置访问路径
    	if (szModuleInfo.getMKTZID() == 0 && szModuleInfo.getMKLJDZ().length() > 0 ) {
    		flag = true;
    	}
    	//2013-12-13：增加禁止将模块管理设置为同组 
     	if (szModuleInfo.getMKID() == 22) {  
     		flag = false;   		
     	}

        if (flag) {
%>  
  <input type="checkbox" name="MKTZID", id="MKTZID" value="<%=szModuleInfo.getMKID()%>" <%=check%> >
<%
		} else {
%>  
  <input type="checkbox" disabled >
<%
			
		}
%>  
  <%=SzLevelNumber.getLevelSpace(szModuleInfo.getMKBH())%><%=szModuleInfo.getMKMC()%><br>
<%
    }
%>
      </table>
    </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="FirstMKBH" value="<%=FirstMKBH%>">
  <input type="hidden" name="SecondMKBH" value="<%=SecondMKBH%>">     
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  //第一个表示对象，form，第二个表示字符串
  function FormSubmit(oFormName, vUrl) {
    oFormName.action = vUrl;
    oFormName.submit();
  }
</script>
<script language="javascript">
  function FormSave(formName, url) {
    //检查是否可以保存
    if (formName.MKMC.value == "") {
      formName.MKMC.focus();
      alert("模块名称不能为空");
      return false;
    }
    //提交
    formName.action = url;
    formName.submit();
  }
</script>
