<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.online.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.weboffice.*" %>
<%@ include file="/sessionInfoWeixin.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<%@ include file="/share/oa_app_title.jsp"%>
 <link href="<%=strLevel_SESSION%>app/images/soarwell_css.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript" src="<%=strLevel_SESSION%>share/js/commonTool.js"></script>
 <script type="text/javascript" src="<%=strLevel_SESSION%>share/js/formTool.js"></script>
 <script type="text/javascript" src="<%=strLevel_SESSION%>app/share/appWinOpen.js"></script> 
</head>
<body>
<%
		
    //获取提交的参数
    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 sOPERATOR = request.getParameter("OPERATOR");
    String sKEY =  SzConvert.toZeroStr(request.getParameter("KEY"));
    String from =  SzConvert.toZeroStr(request.getParameter("from"));
    
    int iFormID = SzConvert.toInt(request.getParameter("FormID"));
    int iInfoID = SzConvert.toInt(sKEY);
    //取得表单的信息
    String moduleName = "";
    String formName = "";
		LcForm lcForm = new LcForm();
		LcFormInfo lcFormInfo = null;    
    if (iFormID == 0) {
    	moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
    	formName = SzConvert.toSpaceStr(request.getParameter("formName")); 
    	//
    	iFormID = lcForm.getKeyByCond(moduleName, formName); 
    } else {
    	lcFormInfo = (LcFormInfo)lcForm.getInfoByKey(iFormID);    
    	if (lcFormInfo != null) {
    		moduleName = lcFormInfo.getBDLJ();
    		formName = lcFormInfo.getBDBY1();  
    	}
    } 
    //System.out.println("moduleName=" + moduleName);
    //System.out.println("formName=" + formName);
    if (moduleName.equals("") || formName.equals("")) {
    	out.println("还没有设置相关表单信息！");
    	return;
    }   
    //2015-01增加锁定判断
    if (iInfoID > 0) {
    	if (SzEditLock.getInstance().isLocking("formEngine", "" + iFormID, iInfoID)) {
    		sOPERATOR = "detail";    	
    	} else if (sNavigator_SESSION.equals("MSIE") || sNavigator_SESSION.equals("CHROME")) {
    		//手机QQ浏览器不锁定
    		SzEditLock.getInstance().lock(session, "formEngine", "" + iFormID, iInfoID); 
    	}
    }
    
    BdFormControl bdFormControl = new BdFormControl();

    //取得关联的名称
    BdTrigger bdTrigger = new BdTrigger();
    String sTriggerName = bdFormControl.getTriggerName(moduleName, formName);  
    
    String sHTML = "";    
	BdValueControl bdValueControl = new BdValueControl(moduleName, formName);	
	sHTML = bdValueControl.getHTML();
	
	//获取附件名
	String sTableAnnex = bdValueControl.getTableAnnex();
	String sEditor    = bdValueControl.getEditor();
	String sWeboffice = bdValueControl.getWebOffice();
	String sTemplateSelect = bdValueControl.getTemplateSelect();
	
	boolean hasFlow   = bdValueControl.getHasFlow();
	boolean hasAnnex  = false;
	if (!sTableAnnex.equals("")) {
		hasAnnex = true;
	}


    String sReadonly = "";
    boolean bReadonly = false;
    if (sOPERATOR.startsWith("detail")) {
        sReadonly = "readonly";
        bReadonly = true;
    }
    if (sOPERATOR.equals("detailPass")) {
    	LcFlowControl.readPass(iFormID, iDLID_SESSION, iInfoID);
        sReadonly = "readonly";
        bReadonly = true;    	
    }
    //读取数据
		String value_str[] = null;
    if (!sKEY.equals("0")) {
    	value_str = (String[])bdValueControl.getInfoByKey(iInfoID);
    	//System.out.println("value_str==aaaa=============" + value_str);
    }    
    String loginID = SzConvert.toSpaceStr(bdValueControl.getLoginID(value_str));
    if (loginID.equals("")) {
    	loginID = Integer.toString(iDLID_SESSION);
    }
    
    //检查是否有权利办理，如果没有就进入待办列表中
    if (sOPERATOR.equals("transact")) {
    	
    	LcFlowControl lcFlowControl = new LcFlowControl();
    	String str_InfoID = lcFlowControl.getTransactInfoID(iFormID, iDLID_SESSION) + ",0"; 
    	//System.out.println(str_InfoID + "==" + sKEY);
    	if (value_str == null || value_str[0] == null || str_InfoID.indexOf(("," + sKEY + ",")) == -1) {
    		//不在待办中，提示已过期
    		out.println(SzPageHelp.jsAlertBack("该文已办理或不存在"));
    		return;
    	} else {
			//读取相关的提醒。
    		OlMessageControl olMessageControl = new OlMessageControl();
    		olMessageControl.readMessage(iFormID, iInfoID, iDLID_SESSION);
    		
    		//2011-07-12 该文设置为已读
    		lcFlowControl.readTransact(iFormID, iInfoID, iDLID_SESSION);    		
    	}
    }     
    
    //2010-2-21
    BdPopedom bdPopedom = new BdPopedom();        
    String strDenyField = bdPopedom.getDenyField(iFormID, 0, iDLID_SESSION);
    String strDenyField2 = bdPopedom.getDenyField(iFormID, iInfoID, iDLID_SESSION); 
   
    //流程相关
    //根据已经有的信息ID，读取流程ID
    LcFlowControl lcFlowControl = new LcFlowControl();
    //取得流程权限信息
    //LcFlowPopedomInfo lcFlowPopedomInfo = lcFlowControl.getFlowPopedomInfo(iFormID, iInfoID);
    LcFlowPopedomInfo lcFlowPopedomInfo = lcFlowControl.getFlowPopedomInfo(iFormID, iInfoID, iDLID_SESSION);
    
    int iFlowID = lcFlowPopedomInfo.getFlowID();
	boolean hasSend = lcFlowPopedomInfo.isHasSend();
	boolean isLastStep = lcFlowPopedomInfo.isLastStep();
	boolean canSend = lcFlowPopedomInfo.isCanSend();  
	boolean canFinish = lcFlowPopedomInfo.isCanFinish();
	boolean canDeny = lcFlowPopedomInfo.isCanDeny();
	boolean canUntread = lcFlowPopedomInfo.isCanUntread();
	boolean canSkip = lcFlowPopedomInfo.isCanSkip();
	boolean canModifyForm = lcFlowPopedomInfo.isCanModifyForm();
	if (bReadonly) {
		canModifyForm = false;
	}
	if (canModifyForm || sOPERATOR.startsWith("add") || sOPERATOR.startsWith("update")) {
		 sReadonly = "";
	} else {
		 sReadonly = "readonly";		
	}
	
	boolean canDraftSave = false;
	boolean canDraftSend = false;
	boolean canTransactSave = false;
	if (hasFlow && !hasSend) {
		canDraftSave = true;
		canDraftSend = true;
	} else if (hasFlow && hasSend) {
		canTransactSave = true;
	} else if (!hasFlow) {
		canDraftSave = true;
	}
	//2015-05-12：当canDraftSend=true时，canSend为false;
	if (canDraftSend) {
		canSend = false;
	}
	boolean isTransact = false;
	if (sOPERATOR.startsWith("transact")) {
		isTransact = true;	
	}
	
	BdFormHelp bdFormHelp = new BdFormHelp();
	String sFromUrl = bdFormHelp.getFromUrl(from);
	
	if (iInfoID > 0) {
  	  SzReadForm szReadForm = new SzReadForm(iFormID); 
  	  szReadForm.read(iInfoID, sBMMC_SESSION, iDLID_SESSION, sDLXM_SESSION);
	}
%>

<% if (hasAnnex) { %>
<form name="formUpdate" id="formUpdate" method="post" ENCTYPE="multipart/form-data">
<% } else { %>
<form name="formUpdate" id="formUpdate" method="post">
<% } %>
<%@ include file="title.jsp"%>
<table width="100%">
  <tr>
    <td>
    <% 
    if (!bReadonly) {
        out.println( LcHelp.saveButton(canDraftSave, hasAnnex, "saveButtonUpdate"));
        out.println( LcHelp.draftSendButton(canDraftSend, hasAnnex)); 
        out.println( LcHelp.transactSaveButton(canTransactSave, hasAnnex, "saveButtonUpdate"));        
        //下面操作只在办理的过程中才会有  

        out.println( LcHelp.sendButton(canSend, hasAnnex));

        out.println( LcHelp.finishButton(canFinish, hasAnnex));
        out.println( LcHelp.denyButton(canDeny, hasAnnex));
        out.println( LcHelp.untreadButton(canUntread, iFlowID ));
        out.println( LcHelp.skipButton(canSkip, iFlowID));
    }
    out.println(bdTrigger.triggerButton(sTriggerName, sOPERATOR, "重新获取", "triggerButton"));
       
    out.println( SzPageHelp.button("返回", "FormSubmit(formUpdate, '" + sFromUrl + "?FormID=" + iFormID + "')") );        
    %>   
    <% out.println(SzEditLock.getInstance().getLockInfo(session, "formEngine", "" + iFormID, iInfoID)); %>	      
    </td>
  </tr>
</table>
<table height="100" width="100%" border="0" cellspacing="3" cellpadding="3" style="border:#D7D7D9 1px solid;">
  
  <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="type" value="<%=sType%>">
  <input type="hidden" name="detailCount" value="0">
  <input type="hidden" name="detailCount1" value="0">
  <input type="hidden" name="detailCount2" value="0">
  <input type="hidden" name="detailCount3" value="0">
  <input type="hidden" name="detailCount4" value="0">  
  <input type="hidden" name="FormID" value="<%=iFormID%>">  
  <input type="hidden" name="loginID" value="<%=loginID%>"> 
  <input type="hidden" name="szContent" value=""> 
  <input type="hidden" name="RecordID" value="">    
  <input type="hidden" name="hasFlow" value="<%=hasFlow %>">
      

<%

	//bdValueControl.getDetailTitleApp();
	//int iKey, HttpSession session, String sOPERATOR, boolean canModifyForm, String strDenyField, String strDenyField2
	out.println(bdValueControl.printAddValueApp(iInfoID, session, sOPERATOR, canModifyForm, strDenyField, strDenyField2));

%>   
<!-- 附件 -->
<%
  if (!sEditor.equals("") && iInfoID>0) {
  	out.println("	<tr>");
  	out.println("	<td height=\"5\" align=\"left\" background=\"../images/line.gif\"></td>");
  	out.println("	</tr>\n"); 
  	out.println("<tr><td><a href='editor.jsp?FormID=" + iFormID + "&KEY=" + iInfoID + "' target='_blank'>编辑器正文</a></td></tr>");
  } 
  if (!sWeboffice.equals("")) {
	OfficeRecordID officeRecordID = new OfficeRecordID();
	String sFileLink = officeRecordID.getFileLink("formEngine", iFormID, iInfoID, sWeboffice);
	if (!sFileLink.equals("")) {
  	out.println("	<tr>");
  	out.println("	<td height=\"5\" align=\"left\" background=\"../images/line.gif\"></td>");
  	out.println("	</tr>\n"); 
  	out.println("<tr><td>office正文：" + sFileLink + "</td></tr>");
	}
  } 
  if (!sTableAnnex.equals("")) {
	out.println("	<tr>");
	out.println("	<td height=\"5\" align=\"left\" background=\"../images/line.gif\"></td>");
	out.println("	</tr>\n"); 
  	out.println("<tr><td>");
    if (bReadonly) {
    	out.println(SzPageHelp.detailAnnexNew2(sTableAnnex, sKEY, strLevel_SESSION));
    } else {
    	out.println(SzPageHelp.updateAnnexNew2(sTableAnnex, sKEY, strLevel_SESSION));
    }
    out.println("<td><tr>");
  } 
%>
</table>
<% 
  if (hasFlow) { 
%>  	
<table height="100" width="100%" border="0" cellspacing="3" cellpadding="3" style="border:#D7D7D9 1px solid;">
  <%@ include file="draft_app.jsp"%>  
</table>
<%
  } 
%>

  
<table width="100%">
  <tr>
    <td>
    <% 
    if (!bReadonly) {
        out.println( LcHelp.saveButton(canDraftSave, hasAnnex, "saveButtonUpdate"));
        out.println( LcHelp.draftSendButton(canDraftSend, hasAnnex)); 
        out.println( LcHelp.transactSaveButton(canTransactSave, hasAnnex, "saveButtonUpdate"));        
        //下面操作只在办理的过程中才会有  
      
        out.println( LcHelp.sendButton(canSend, hasAnnex));
        out.println( LcHelp.finishButton(canFinish, hasAnnex));
        out.println( LcHelp.denyButton(canDeny, hasAnnex));
        out.println( LcHelp.untreadButton(canUntread, iFlowID ));
        out.println( LcHelp.skipButton(canSkip, iFlowID));
    }
        out.println( SzPageHelp.button("返回", "FormSubmit(formUpdate, '" + sFromUrl + "?FormID=" + iFormID + "')") );        
    %>   
	      
    </td>
  </tr>
</table>
</form>
<br> 
<%
	out.println(SzPageHelp.calendarFrame2());
	out.println(SzPageHelp.calendar2Frame2());
%>
<%=bdValueControl.saveCheckJs()%>
<script language="javascript">

  //弹出窗口
  function OpenSelectWinApp(vTableName) {

    var type= "";
    var vUrl = "select_win.jsp";
    vUrl = vUrl + "?tableName=" + vTableName + "&index=-1";
    
    //window.open(vUrl,"_top","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=400px,height=350px");
    //window.showModalDialog(vUrl,window,"status=no;dialogWidth=580px;dialogHeight=350px");
    var vElementTop = getElementTop(window.event.srcElement);
    var vWebHeight = document.body.scrollHeight;    
    DivWinOpen(vUrl, vElementTop, vWebHeight); 

  }  
  function OpenUserSelectWinApp(name) {
    var vUrl = "select_user.jsp?name=" + name;
  	//window.open(vUrl,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=400px,height=430px");
  	//window.showModalDialog(vUrl,window,"status=no;dialogWidth=680px;dialogHeight=450px");  
  	
    var vElementTop = getElementTop(window.event.srcElement);
    var vWebHeight = document.body.scrollHeight;    
    DivWinOpen(vUrl, vElementTop, vWebHeight);  	
  }
  
  function FormSave(formName, url, vOPERATOR) {
		if (!FormCheck(formName)) {
			return false;
		}
		var hasFlow = formName.hasFlow.value;
		if (hasFlow == "true") {
	    formName.BZRYID_FLOW.value = ValueOfCheck(formName.BZRYID); 
		}
    if (vOPERATOR != "") {
    	formName.OPERATOR.value = vOPERATOR;
    }
	    
    formName.action = url;
    formName.submit();      
  }   
  
    
  
  
  function FormSaveConfirm(formName, url, vOPERATOR) {
		formName.BZRYID_FLOW.value = ValueOfCheck(formName.BZRYID); 
		var sOPERATOR_form = formName.OPERATOR.value;
		if (sOPERATOR_form != "add" && sOPERATOR_form != "update") {
			if (formName.RYBLYJ_FLOW.value == "" && formName.KEY.value != "0") {
		  	alert("办理意见不能为空");
    	  return;
    	}
		}
    var vMessage = "";
    if (vOPERATOR == "transact" || vOPERATOR == "send") {
      vMessage = "确定要发送？";
      if (formName.BZRYID_FLOW.value == "0" || formName.BZRYID_FLOW.value == "") {
    	  alert("请至少选择一个办理人员！");
    	  return false;
      } 
      //当multipart/form-data时，request不到后面的值，所以补充了下面      
    } else if (vOPERATOR=="transactFinish") {
      vMessage = "确定要办结？";    
    } else if (vOPERATOR=="transactDeny") {
      vMessage = "确定要否决？";    
    }
  
    if (vOPERATOR != "") {
      formName.OPERATOR.value = vOPERATOR;
    }  
    if (confirm(vMessage)) {
	  if (!FormCheck(formName)) {
		return false;
      }
				
	  formName.action = url;
	  formName.submit();      
    }
  }
  
	//这里做退回、跳签需要传递的参数：流程ID，操作类型
  function transactWin(vFlowID, vOPERATOR) {
    var vUrl = "untread_win.jsp";
    if (vOPERATOR == "transactUntread") {
    
    } else if (vOPERATOR == "transactSkip") {
    
    }
    vUrl += "?OPERATOR=" + vOPERATOR + "&FlowID=" + vFlowID;
    //window.showModalDialog(vUrl,window,"status=no;dialogWidth=680px;dialogHeight=580px");  
    //window.open(vUrl,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=400px,height=450px");
    var vElementTop = getElementTop(window.event.srcElement);
    var vWebHeight = document.body.scrollHeight;    
    DivWinOpen(vUrl, vElementTop, vWebHeight);     
  }  
  
  function transactSubmit() {
		if (!FormCheck(formUpdate)) {
			return false;
		}
		//formUpdate.RYBLYJ_FLOW.value = formUpdate.RYBLYJ.value;
		//formUpdate.RYBLTP_FLOW.value = formUpdate.selectSignature.value;  	
    <% if (hasAnnex) { %>		  
	    formUpdate.action = "control2.jsp";
	  <% } else {%>
	    formUpdate.action = "control.jsp";
	  <% } %>
	  	  
	  formUpdate.submit();  
  }  
  
  function RelateWin(vTriggerName ,oObject) {     
  	var vValue = "";
  	if (oObject != "") {
  		vValue = eval("formUpdate." + oObject + ".value;");
  	}
    var vUrl = "relate_win.jsp?moduleName=<%=moduleName%>&formName=<%=formName%>&triggerName=" + vTriggerName + "&relateValue=" + vValue;
  	window.open(vUrl,"","left=1020,top=1020,width=1,height=1");	
  }   
  //初始化后才能调用AJAX
  <% 
		//自动触发2013-11-20
		out.println(bdTrigger.autoTriggerJs(sTriggerName, sOPERATOR, "triggerButton"));    
    //实现自动编号
  	BdNumberRuler bdNumberRuler = new BdNumberRuler();
  	out.println(bdNumberRuler.autoNumberJs(sOPERATOR,moduleName,formName));
  %> 
  
  //页面解除锁定
	window.onbeforeunload = function() {

		  var moduleType = "formEngine";
		  var moduleId = "<%=iFormID%>";
		  var infoId = formUpdate.KEY.value;
			var vUrl = "../../share/page/edit_unlock_app.jsp?moduleType=" + moduleType + "&moduleId=" + moduleId + "&infoId=" + infoId;

		  AJAX(vUrl, "", false);
	}    


</script>  
<div id="divWinOpenBg"></div>
<div id="divWinOpen">
 <iframe id="frameWinOpen" frameborder="0"  width="100%" height="100%"></iframe>
</div>
</body>
</html>
