<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ include file="sessionInfo2.jsp"%>
<%
    //获取提交的参数
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    //查询时间段
    String sSearchBegin = SzConvert.strWriteData(request.getParameter("txtSearchBegin"));
    String sSearchEnd = SzConvert.strWriteData(request.getParameter("txtSearchEnd"));

    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
    String sType = SzConvert.toSpaceStr(request.getParameter("type"));
    String sTableName = SzConvert.toSpaceStr(request.getParameter("tablename"));
    String moduleName = SzConvert.strWriteData(request.getParameter("moduleName"));
    String formName = SzConvert.strWriteData(request.getParameter("formName"));
    String fieldName = SzConvert.toZeroStr(request.getParameter("fieldName"));
%>
<form name="formHidden" method="post">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="tablename" value="<%=sTableName%>">
  <input type="hidden" name="moduleName" value="<%=moduleName%>">
  <input type="hidden" name="module" value="<%=moduleName%>">  
  <input type="hidden" name="formName" value="<%=formName%>"> 
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSearchBegin" value="<%=sSearchBegin%>">
  <input type="hidden" name="txtSearchEnd" value="<%=sSearchEnd%>">
</form>
<%
    boolean flag = true;
    String sUrl = "formIndex.jsp";
	String sUrlWin = "";
	BdFormControl formControl = new BdFormControl();
	boolean isFormEngine = formControl.isFormEngine(moduleName);		

		
    BdForm bdForm = new BdForm();
    BdFormFieldInfo bdFormFieldInfo = null;
    ArrayList arrayList = null;
    
    if (sOPERATOR.equals("DeleteModule")) {
        bdForm.deleteXMLModule(moduleName);
    } else if (sOPERATOR.equals("DeleteForm")) {
        bdForm.deleteXMLForm(moduleName, formName);
    } else if (sOPERATOR.equals("XMLModule")) {
    	//增加XML模块
        flag = bdForm.addXMLModule(moduleName);
    } else if (sOPERATOR.equals("NewForm")) {
        flag = bdForm.addXMLForm(moduleName, request);
        sUrlWin = "formEdit.jsp";
    } else if (sOPERATOR.equals("UpdateForm")) {
        flag = bdForm.updateXMLForm(moduleName, request);
    } else if (sOPERATOR.equals("XMLFORM")) {  //编辑界面，提交保存表单
        bdForm.updateXMLForm(moduleName, formName, request);
        sUrlWin = "formEdit2.jsp";        
    } else if (sOPERATOR.equals("XMLFIELD")) {
        bdForm.updateXMLField(moduleName, formName, request);
        sUrl = "formField.jsp";
    } else if (sOPERATOR.equals("XMLFIELD_ONLY")) {
        bdForm.updateXMLField_ONLY(moduleName, formName, request);
        sUrl = "formField.jsp";
    } else if (sOPERATOR.equals("FieldIndex")) {
      bdForm.fieldIndex(moduleName, formName, request);
      sUrl = "formFieldIndex.jsp";   
    } else if (sOPERATOR.equals("AddModule")) {
    	//把真个模块连接加到菜单中
    	flag = bdForm.addSystemModule(moduleName);	
    } else if (sOPERATOR.equals("AddModule2")) {
    	flag = bdForm.addSystemModule(request);    
    } else if (sOPERATOR.equals("AddModuleApp")) {
    	//把真个模块连接加到菜单中    	//2014-06增加
    	flag = bdForm.addSystemModuleApp(moduleName);	
    } else if (sOPERATOR.equals("AddModuleApp2")) {
    	//2014-06增加
    	flag = bdForm.addSystemModuleApp(request);    	    	
    } else if (sOPERATOR.equals("AddFlow")) {
    	flag = bdForm.addFlowForm(moduleName);	
    } else if (sOPERATOR.equals("CopyForm")) {
        flag = bdForm.copyForm(request);
    } else if (sOPERATOR.equals("FieldFormula")) {
    	flag = bdForm.setFieldFormula(moduleName, formName, request);  
        sUrl = "formField.jsp";
    } else if (sOPERATOR.equals("CreateTable")) {
    	flag = bdForm.createTable(moduleName);
    } else if (sOPERATOR.equals("CreateFormTable")) {
    	flag = bdForm.createTable(moduleName, formName);    	
    } else if (sOPERATOR.equals("Initial")) { 
    	flag = bdForm.initial();   
    	sUrl = "module/index.jsp";
    } else if (sOPERATOR.equals("InitialCheck")) { 
    	BdFormCheck bdFormCheck = new BdFormCheck();
    	bdFormCheck.check();
    	flag = true;
    	String sMessage2 = SzOutMessage.getMessage(); 
    	
    	if (!sMessage2.equals("")) {    		
    		out.println(sMessage2);
    		//out.println("<font color='red'>[重要提示]</font><b>系统菜单路径有异常,请通过--系统管理--模块管理修改路径</b>");
    	}
    	sUrl = "module/index.jsp";
    } else if (sOPERATOR.equals("DeleteField")) {
        bdForm.deleteField(moduleName, formName, fieldName);
    } else if (sOPERATOR.equals("DeleteFieldBat")) {
        bdForm.deleteField(moduleName, formName, request);        
    } else if (sOPERATOR.equals("SaveTemplate")) {
        bdForm.saveTemplate(moduleName);
    } else if (sOPERATOR.equals("FormTableCreate") || sOPERATOR.equals("FormTableCheck")) {
    	//执行脚本：重建表或检测表
    	flag = bdForm.createTable(request);
    } else if (sOPERATOR.equals("XMLFIELD_APP")) {
      bdForm.updateXMLField(moduleName, formName, request);
      sUrl = "formApp.jsp";
  	} 
//System.out.println("sOPERATOR=" + sOPERATOR);
    String sMessage = SzOut.getMessage();
//    flag = false;
    if (flag) {
        out.println(SzPageHelp.jsAlert("操作成功"));
        //out.println(SzPageHelp.jsGoUrl(sUrl));
        if (sOPERATOR.equals("DeleteModule")) {
					//模块已经删除，要保证返回的是全部
					out.println("<script language=\"javascript\">");
					out.println("formHidden.module.value=''");
					out.println("</script>");		
        }
        //2011-09-13增加：AddModule:加到菜单中，自动刷新左侧菜单
        if ( sOPERATOR.startsWith("AddModule") && moduleName.equals("simpleform.xml") ) {
					out.println("<script language=\"javascript\">");
					out.println("top.szMenuFrame.location.reload();");
					out.println("</script>");		
				}        
        if (sUrlWin.equals("formEdit.jsp")) {
%>
  <script language="javascript">  
    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');    
    }
    var moduleName = formHidden.moduleName.value;
    var formName = formHidden.formName.value;
    EditUI(moduleName, formName);     
  </script>

<%
					out.println(SzPageHelp.jsFormSubmit("formHidden",sUrl));
        } else if (sUrlWin.equals("formEdit2.jsp")) {
        	//刷新父窗口
        %>
  			<script language="javascript">
  				//var oWindow = window.opener;
  				//oWindow.document.location.reload();
			  </script>
				<%
        	//编辑界面，提交保存表单：回到编辑界面        	
        	out.println(SzPageHelp.jsFormSubmit("formHidden","formEdit.jsp"));
        } else if (sOPERATOR.equals("InitialCheck")) { 
        	//2015-05-06增加检测
        } else {
        	out.println(SzPageHelp.jsFormSubmit("formHidden",sUrl));
        }
    } else {
        out.println(SzPageHelp.jsAlertBack(sMessage));
    }
%>
