<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.tool.*" %>
<%@ page import="java.util.*" %>
<%@ include file="sessionInfo2.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">
</head>

<%
    BdForm bdForm = new BdForm();
    String XML_str[] = bdForm.getXMLModuleList();
    int iLen = XML_str.length;  
    String sModule = SzConvert.toSpaceStr(request.getParameter("module")); 
    if (!sModule.equals("") && !sModule.endsWith(".xml")) {
    	sModule = sModule + ".xml";
    }
    BdFormControl formControl = new BdFormControl();
		boolean isFormEngine = formControl.isFormEngine(sModule);
		if (!isFormEngine) {
			out.println(SzPageHelp.jsGoUrl("simpleIndex.jsp"));
			return;
		}
	  if (!net.sz600.check.SzHasp.getInstance().checkFormEdit(sModule)) {
		  out.println("<font color='red'>[提示]本授权的版本不能使用表单引擎</font>");
  		return;
  	} 		
%>
<!-----上面的工具栏------>
<%@ include file="title.jsp"%>
<table width="100%">
  <form name="form" method="post" action="formIndex.jsp">
  <input type="hidden" name="OPERATOR" value="">
  <tr>
    <td>
      请选择模块：<%=SzPageHelp.selectArraySubmit(XML_str, XML_str, "module", sModule, "", "simpleform.xml")%>
     <% if (isBarManager_SESSION) { %>        
      输入要新增的模块名称：<input type="text" name="moduleName" size="10" title="可用字母、数字、下划线的组合">
      <input type="button" class="btnClass" value="保存" OnClick="SaveXMLModule();" title="保存要新增的模块名称">           
      <input type="button" class="btnClass120" value="初始化全部" title="重新创建所有表,数据将全部丢失" 
       OnClick="javascript:document.location.href='formControl.jsp?OPERATOR=Initial'" >
	  <input type="button" class="btnClass120" value="检测异常并修复" title="检查丢失的字段和表,自动修复;检查ID的冲突,自动修复,可能要修改系统菜单的路径" 
	   OnClick="javascript:document.location.href='formControl.jsp?OPERATOR=InitialCheck'" >
     <% } %> 
    </td>
  </tr>
  </form>
</table>
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass"
       cellpadding="3" cellspacing="0" align="center">
  <tr class="trClassTitle">
    <td>表单名称</td>
    <td>中文名</td>   
    <!--  
    <td>表格名称</td>
    --> 
    <td>操作</td>
    <td>删除</td>
  </tr>
<%

    Iterator iterForm = null;
    String sFormName = "";
    String formID = "";
    BdFormInfo bdFormInfo = null;
    boolean hasFlow = false;

    String sTableName = "";
    String sTemp = "";
    BdRelateForm bdRelateForm = new BdRelateForm();
		String sRelateButton = "";
		int iCount = 0;
    for (int i=0; i<iLen; i++) {
    	if (!sModule.equals("") && !sModule.equals(XML_str[i])) {
    		continue;
    	}
    	if (!isSystemManager_SESSION && XML_str[i].startsWith("manage.xml") && XML_str[i].equals("simpleform.xml") ) {
    		continue;
    	}
%>
  <tr onMouseOver="javascript:this.className='trMouseOver'" onMouseOut="javascript:this.className='trMouseOut'">
    <td colspan="2"><b>模块名称：</b><%=XML_str[i]%></td>
    <td>
    <% if (isBarManager_SESSION) { %>
      <a href="formUpdate.jsp?moduleName=<%=XML_str[i]%>&OPERATOR=NewForm">增加新表单</a>
      <a href="formControl.jsp?moduleName=<%=XML_str[i]%>&OPERATOR=AddModule">加进菜单</a>
      <a href="formControl.jsp?moduleName=<%=XML_str[i]%>&OPERATOR=AddFlow">加进系统</a>
      <a href="#" OnClick="javascript:ReCreateTable('<%=XML_str[i]%>', '', 'CreateTable');">重新创建表</a>      
      <a href="formControl.jsp?moduleName=<%=XML_str[i]%>&OPERATOR=SaveTemplate">存为模板</a>      
    <% } %>&nbsp;
    </td>
    <td align="center">    
    <% if (isBarManager_SESSION) { %>
      <a href="#" OnClick="DeleteModule('<%=XML_str[i]%>')">删除</a>
    <% } %>      
    </td>
  </tr>
<%
      //根据
      iterForm = bdForm.getFormInfoList(XML_str[i]).iterator();
      while (iterForm != null && iterForm.hasNext()) {
    	bdFormInfo = (BdFormInfo)iterForm.next();  
    	formID = bdFormInfo.getFormId();
        sFormName = bdFormInfo.getFormName();
        hasFlow = false;
        if ( bdFormInfo.getHasFlow().equals("1")) {
        	hasFlow = true;
        }
        sTableName  = bdForm.getTableStr(XML_str[i], sFormName);
        sTemp = "";
        if (bdFormInfo.getDesktop() > 0) {
        	sTemp += "<img width='14' height='14'  src='../../images/share/destop.gif' border='0'>";
        }
        if (bdFormInfo.getToolbar().endsWith(".gif")) {
        	sTemp += "<img width='14' height='14' src='../../images/share/top/" + bdFormInfo.getToolbar() + "' border='0'>";
        }
        sTemp += sFormName;
        
        //检查是否已经设置了关联
        if (bdRelateForm.hasRelateForm(XML_str[i], sFormName)) {
        	sRelateButton = "<font color='red'>下级表单</font>";
        } else {
        	sRelateButton = "下级表单";
        }
%>
  <tr onMouseOver="javascript:this.className='trMouseOver'" onMouseOut="javascript:this.className='trMouseOut'">
    <td>&nbsp;&nbsp;&nbsp;&nbsp;<%=sTemp%></td>
    <td><%=bdFormInfo.getFormDesc()%>&nbsp;</td> 
        <!--    
    <td><%=sTableName%>&nbsp;</td>
         -->
    <td>
    <% if (isBarManager_SESSION) { %>    
      <a href="formUpdate.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>&OPERATOR=UpdateForm">修改</a>

      <%if (!bdFormInfo.getLock().equals("1") ) { %>
      <a href="javascript:EditUI('<%=XML_str[i]%>','<%=sFormName%>');">编辑界面</a>
      <a href="formField.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>">字段属性</a>
      <a href="stat_index.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>">设置统计</a>
      <a href="collect_index.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>">设置汇总</a>
      <% } else { %>
      编辑界面
      字段属性
      <% } %>
      <% if (!hasFlow) { %>    
       【测试】<a href="../../share/formEngine2/index.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>">列表</a>
      <% } else { %>
       【测试】<a href="../../share/formEngine2/index.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>">列表</a>
      <a href="../../share/formEngine2/index_transact.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>">待办</a>  
      <% } %>        
      <br>
      【辅助】
      <%if (!bdFormInfo.getLock().equals("1") ) { %>
      <a href="#" OnClick="javascript:ReCheckTable('<%=XML_str[i]%>', '<%=sFormName%>', 'FormTableCreate');">重建表</a>
      <a href="#" OnClick="javascript:ReCheckTable('<%=XML_str[i]%>', '<%=sFormName%>', 'FormTableCheck');">检测表</a>
      <a href="formControl.jsp?PMKID=5024&moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>&OPERATOR=AddModule">加进菜单</a>
      <% } %>
      表单ID:<%=formID %>&nbsp;      
      【高级】
      <a href="formCopy.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>&OPERATOR=CopyForm">复制到</a>
      <%if (!bdFormInfo.getLock().equals("1") ) { %>
      <a href="other/relateForm_index.jsp?moduleName=<%=XML_str[i]%>&formName=<%=sFormName%>"><%=sRelateButton%></a>
    	<% } %>
			<br>

    <% } %>         
  
    </td>
    <td align="center">
      <%if (!bdFormInfo.getLock().equals("1") && isBarManager_SESSION ) { %>
      <a href="#" onClick="javascript:DeleteForm('<%=XML_str[i]%>','<%=sFormName%>');">删除</a>
      <% } %>    
    </td>
  </tr>
<%
				iCount++;
      }
    }
%>
  <tr onMouseOver="javascript:this.className='trMouseOver'" onMouseOut="javascript:this.className='trMouseOut'" >
    <td colspan="10" class="trClassTitle2"><b>已创建表单数量：<%=iCount%></b></td>
  </tr>
</table>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  //增加一个XML模块配置文件
  function SaveXMLModule() {
    if (form.moduleName.value == "") {
      form.moduleName.focus();
      alert("模块名称不能为空");
      return;
    }
    if (!isLetterOrNumOrLine(form.moduleName.value)) {
      alert("模块名称有不允许的字符");
      form.moduleName.focus();
      return false;
    }    
    form.action = "formControl.jsp";
    form.OPERATOR.value = "XMLModule";
    form.submit();
  }
  
  function EditUI(moduleName, formName) {
  	var url = "formEdit.jsp?moduleName=" + moduleName + "&formName=" + formName;
    window.open(url, '', 'left=20,top=20,scrollbars=yes,resizable=yes,status=yes,width=1100,height=720');
  }
  
  function DeleteModule(vModuleName) {
	var theResponse = window.prompt("请输入删除的密码：");
	if (theResponse == "xiaomutou") {
	  var vUrl = "formControl.jsp?moduleName=" + vModuleName + "&OPERATOR=DeleteModule";
	  document.location.href = vUrl;	  
	} else {
	  alert("密码不正确，不能删除模块");
	}  
  }
  
  function DeleteForm(moduleName, formName) {
  	if (confirm("确定要删除?")) {
  		var vUrl = "formControl.jsp?moduleName=" + moduleName + "&formName=" + formName + "&OPERATOR=DeleteForm";
  		document.location.href = vUrl;  	
  	}
  }
  
  //重新创建表
  function ReCreateTable(moduleName, formName, operator) {
  	var vUrl = "formControl.jsp?moduleName=" + moduleName;
  	if (formName != "") {
		vUrl += "&formName=" + formName;
		
  	}
  	vUrl += "&OPERATOR=" + operator;
  	if (confirm("重新创建表将丢失已录入的数据,是否继续?")) {
		document.location.href = vUrl;
  	}  	
  }
  
  function ReCheckTable(moduleName, formName, operator) {
  	var vUrl = "formCheck.jsp?moduleName=" + moduleName + "&formName=" + formName;
  	vUrl += "&OPERATOR=" + operator;
	document.location.href = vUrl;
  }  
</script>