<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ 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.weboffice.*" %>
<%@ include file="/sessionInfo.jsp"%>
<% 
  String strLevel = "../../"; 
%> 
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=strLevel%>share/ckeditor/ckeditor.js"></script>
</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 sPFORM = SzConvert.toZeroStr(request.getParameter("PFORM"));
	//上上级
	String sType2  = SzConvert.toZeroStr(request.getParameter("type2"));	//关联的ID
	String sPKEY2  = SzConvert.toZeroStr(request.getParameter("PKEY2"));	//主表单信息ID
	String sPFORM2 = SzConvert.toZeroStr(request.getParameter("PFORM2"));	//主表单ID
	
    String sOPERATOR = "detail";
	
    String sKEY =  SzConvert.toZeroStr(request.getParameter("KEY"));
    
    int iFormID = SzConvert.toInt(request.getParameter("FormID"));
    //取得表单的信息
    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;
    }   
    BdFormControl bdFormControl = new BdFormControl();
    //取得关联的名称
    String sTriggerName = bdFormControl.getTriggerName(moduleName, formName);
  	//根据名称取得关联的条件控件
    String sRelateObject = bdFormControl.getRelateObject(sTriggerName);
    
    
    
    String sHTML = "";    
	BdValueControl bdValueControl = new BdValueControl(moduleName, formName);	
	sHTML = bdValueControl.getHTML();
	String sTable = bdValueControl.getTableName();
	String sFieldID = bdValueControl.getKeyField();
	
	//获取附件名
	String sTableAnnex = bdValueControl.getTableAnnex();
	String sEditor    = bdValueControl.getEditor();
	String sWeboffice = bdValueControl.getWebOffice();
	String sTemplateSelect = bdValueControl.getTemplateSelect();
	String printTemp = bdValueControl.getPrintTemp();
	String printTempRelate = bdValueControl.getPrintTempRelate();
	//是否有流程，由关联决定
	BdRelateForm bdRelateForm = new BdRelateForm();
	//boolean hasFlow   = bdValueControl.getHasFlow();
	boolean hasFlow = bdRelateForm.hasFlow(sType);
	
	boolean hasAnnex  = false;
	if (!sTableAnnex.equals("")) {
		hasAnnex = true;
	}
	
%>
<%
    SzData szData = null;
    SzDataInfo szDataInfo = null;

    String sReadonly = "";
    boolean bReadonly = false;
    if (sOPERATOR.startsWith("detail")) {
        sReadonly = "readonly";
        bReadonly = true;
    }
    if (sOPERATOR.equals("detailPass")) {
    	LcFlowControl.readPass(iFormID, iDLID_SESSION, Integer.parseInt(sKEY));
        sReadonly = "readonly";
        bReadonly = true;    	
    }
    //读取数据
	String value_str[] = null;
    if (!sKEY.equals("0")) {
    	value_str = (String[])bdValueControl.getInfoByKey(Integer.parseInt(sKEY));
    }
    
    //检查是否有权利办理，如果没有就进入待办列表中
    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, SzConvert.toInt(sKEY), iDLID_SESSION);
    	}
    }        
%>
<%    
    //流程相关
    //根据已经有的信息ID，读取流程ID
    LcFlowControl lcFlowControl = new LcFlowControl();
    //取得流程权限信息
    LcFlowPopedomInfo lcFlowPopedomInfo = lcFlowControl.getFlowPopedomInfo(iFormID, Integer.parseInt(sKEY));
    
    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;
	}
	boolean isTransact = false;
	if (sOPERATOR.startsWith("transact")) {
		isTransact = true;	
	}
	
	//EditType //// 0 显示  1 起草 2 批改 3 审核
	String sEditType = "0";
	if (sOPERATOR.startsWith("add") || (sOPERATOR.startsWith("update") && hasFlow)) {
		sEditType = "1";
	} else if (sOPERATOR.startsWith("update") && !hasFlow) {
		sEditType = "2";
	} else if (sOPERATOR.startsWith("transact")) {
		sEditType = "3";
	} 	
%>

<% if (!sEditor.equals("")) {%>
<script language="javascript">
  function LoadContent1() {
     window_onresize();
     var vUrl = "http://<%=sServer_SESSION%>:<%=sPort_SESSION%><%=sContext_SESSION%>/share/formEngine2/load.jsp?FormID=<%=iFormID%>&KEY=<%=sKEY%>";
     tbContentElement.LoadURL(vUrl);
  }
</script>
<body onload="javascript:LoadContent1();">
<% } else {%>
<body>
<% } %>

<!-----上面的工具栏------>
<% if (hasAnnex) { %>
<form name="formUpdate" method="post" ENCTYPE="multipart/form-data">
<% } else { %>
<form name="formUpdate" method="post">
<% } %>
  <!---使用流程的时候需要使用--->
  <input type="hidden" name="LCID_FLOW" value="0">
  <input type="hidden" name="BZID_FLOW" value="0">
  <input type="hidden" name="BZRYID_FLOW" value="0">  
  <input type="hidden" name="RYBLYJ_FLOW" value="">
  <input type="hidden" name="RYBLTP_FLOW" value="">   
  
  <input type="hidden" name="PFORM" value="<%=sPFORM%>">
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">
  <input type="hidden" name="type2" value="<%=sType2%>">
  <input type="hidden" name="PKEY2" value="<%=sPKEY2%>">  
  <input type="hidden" name="PFORM2" value="<%=sPFORM2%>"> 
    
  <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="szContent" value=""> 
  <input type="hidden" name="RecordID" value="">    
  <input type="hidden" name="TriggerName" value="<%= sTriggerName%>">
  <input type="hidden" name="RelateObject" value="<%= sRelateObject%>">  
  <input type="hidden" name="hasFlow" value="<%=hasFlow %>">
  <input type="hidden" name="hiddenSave" value="not">
<%@ include file="title.jsp"%>
<table width="100%">
  <tr>
    <td>
      <% out.println( SzPageHelp.closeButton() );%>     
      <% out.println( SzPageHelp.button("操作日志","javascript:LogWin();") ); %>
    </td>
  </tr>
</table>

<!-- 传阅反馈信息 -->
<% if (sOPERATOR.startsWith("detailPass")) { %>
<% } %>

<!-- 显示当前表单的名称 -->
<br><b><%=bdFormControl.getFormDesc(moduleName, formName) %></b>
<!-----信息维护------>
<div id="divForm">
<%=sHTML %>
</div>
<!-- 附件 -->
<% if (!sTableAnnex.equals("")) { %>
<table width="650" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0"> 
  <tr> 
    <td class="tdClassTitle">附件</td> 
    <td><%=SzPageHelp.annex(sTableAnnex, sKEY, bReadonly)%></td> 
  </tr> 
</table> 
<% } %>
</form>
<% if (!sEditor.equals("")) {%>

<table width="750" border="0" cellpadding="1" cellspacing="0">
  <tr>
    <td>
      <%//@ include file="/share/editor/edit.jsp"%>
      <%
		szData = new SzData();
	  szData.setTableInfo(sTable, sFieldID, sEditor);
	  szDataInfo = (SzDataInfo)szData.getInfoByKey(Integer.parseInt(sKEY));		
	  String sValue = "";
	  if (szDataInfo != null) {
	        sValue = szDataInfo.getName();
	  }	      
		%>  
		 <textarea id="szContent" name="szContent"><%=sValue %></textarea>       
    </td>
  </tr>
</table>
	<script type="text/javascript">
    CKEDITOR.replace( 'szContent');
   </script>

<% } %>
<% 
   session.setAttribute("SzModuleType", "");
   session.setAttribute("SzModuleID", "");
   session.setAttribute("SzInfoID", "");
   if (!sWeboffice.equals("")) {
		
		String FileType   = sWeboffice;
		String ModuleType = "formEngine";
		int    ModuleID   = iFormID;
		
	    //取得RecordID
	    OfficeRecordID officeRecordID = new OfficeRecordID();
	    String RecordID  = officeRecordID.loadRecordID(ModuleType,ModuleID,Integer.parseInt(sKEY));
	    session.setAttribute("SzModuleType", ModuleType);
	    session.setAttribute("SzModuleID", Integer.toString(ModuleID));
	    session.setAttribute("SzInfoID", sKEY);
%>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr>
    <td>
      <iframe id="webOffice" width="100%" height="1380" 
              frameborder="0"
              src="../../share/weboffice/DocumentEdit.jsp?FileType=<%=FileType%>&ModuleType=<%=ModuleType %>&ModuleID=<%=ModuleID %>&RecordID=<%=RecordID%>&EditType=<%=sEditType%>&Template=<%=sTemplateSelect%>">
      </iframe>
    </td>
  </tr>
</table>
<% } %>
<%

	if (!sOPERATOR.equals("add")) {
		//out.println(bdRelateForm.relateFatherList(SzConvert.toInt(sPFORM), sType, iFormID, SzConvert.toInt(sKEY)));
		out.println(bdRelateForm.relateChildList(iFormID, SzConvert.toInt(sKEY)));
		//out.println(bdRelateForm.relateBrotherList(SzConvert.toInt(sPFORM), SzConvert.toInt(sPKEY), sType));
	}

%>
 
<!-----这里包含要提交的内容--->
<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%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="type2" value="<%=sType2%>">
  <input type="hidden" name="PKEY2" value="<%=sPKEY2%>">  
  <input type="hidden" name="PFORM2" value="<%=sPFORM2%>">   
</form>

<script language="javascript" src="../../share/js/commonTool.js"></script>
<%=bdValueControl.updateJs(Integer.parseInt(sKEY), session, sOPERATOR, canModifyForm)%>
<%=bdValueControl.detailJs(Integer.parseInt(sKEY), sOPERATOR, canModifyForm)%>
<%=LcFlowControl.fieldPopedom(iFormID, iFlowID, Integer.parseInt(sKEY), canModifyForm, isTransact) %>
<%=bdValueControl.saveCheckJs()%>
<script language="javascript">

  function FormSave(formName, url, vOPERATOR) {
	if (!FormCheck(formName)) {
		return false;
	}
    //保存前把流程ID、流程步骤ID、表单ID、信息ID等写到信息里面
    //流程相关
    <% if (hasFlow) {%>
    formName.LCID_FLOW.value = flowDraft.formList.LCID.value;
    formName.RYBLYJ_FLOW.value = flowDraft.formList.RYBLYJ.value;
    formName.RYBLTP_FLOW.value = flowDraft.formList.selectSignature.value;
    <% } %>	
    <% if (!sEditor.equals("")) {%>
    formName.szContent.value=tbContentElement.DocumentHTML;
    <% } %>	
    <% if (!sWeboffice.equals("")) { %>    
    //weboffice
    formName.RecordID.value = webOffice.webform.RecordID.value;
    webOffice.webform.save.click(); 
    <% } %>
        
    if (vOPERATOR != "") {
    	formName.OPERATOR.value = vOPERATOR;
    }
    //alert(formName.OPERATOR.value);
    
    formName.action = url;
    formName.submit();      
  }   
  
  
  function FormSaveConfirm(formName, url, vOPERATOR) {
	if (!FormCheck(formName)) {
		return false;
	}
    //保存前把流程ID、流程步骤ID、表单ID、信息ID等写到信息里面
    //流程相关
    formName.LCID_FLOW.value = flowDraft.formList.LCID.value;
    formName.BZRYID_FLOW.value = ValueOfCheck(flowDraft.formList.BZRYID);
    formName.RYBLYJ_FLOW.value = flowDraft.formList.RYBLYJ.value;
    formName.RYBLTP_FLOW.value = flowDraft.formList.selectSignature.value;
    
    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 (!sEditor.equals("")) {%>
    	formName.szContent.value=tbContentElement.DocumentHTML;
    	<% } %>	
    	<% if (!sWeboffice.equals("")) { %>    
    	//weboffice
    	formName.RecordID.value = webOffice.webform.RecordID.value;
    	webOffice.webform.save.click(); 
    	<% } %>    
      	formName.action = url;
      	formName.submit();      
    }
  }   
  
  function OpenDetailWin(keyValue,formId) {
    var vUrl = "detail_win.jsp?OPERATOR=detail&KEY=" + keyValue + "&FormID=" + formId;
  	window.open(vUrl,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=800,height=700");  
  }
  function OpenRelateDetailWin(keyValue,formId, pKey, pFormId, relateId) {
    var vUrl = "detail_win.jsp?OPERATOR=detail&KEY=" + keyValue + "&FormID=" + formId + "&PKEY=" + pKey + "&PFORM=" + pFormId + "&type=" + relateId;
  	window.open(vUrl,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=800,height=700");  
  }  
  
  function RelateWin() {     
  	//这里就要取得值
  	var vTriggerName = formUpdate.TriggerName.value;
  	var oObject = formUpdate.RelateObject.value;
  	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");
	
  }
  
  function PrintWin() {
    var vUrl = "print.jsp?moduleName=<%=moduleName%>&formName=<%=formName%>&OPERATOR=detail&KEY=<%=sKEY%>";
  	//window.open(vUrl,"","left=20,top=20,width=600,height=600");
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;dialogHeight=550px");
  	//window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;");
  }
  
  function PrintWinWord() {
    var vUrl = "printTemp.jsp?type=0&FormID=<%=iFormID%>&KEY=<%=sKEY%>&printTemp=<%=printTemp%>&printTempRelate=<%=printTempRelate%>";
  	//window.open(vUrl,"","left=20,top=20,width=600,height=600");
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;dialogHeight=550px");
  	//window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;");
  }
  
  function PrintWinWordRelate() {
    var vUrl = "printTemp.jsp?type=1&FormID=<%=iFormID%>&KEY=<%=sKEY%>&printTemp=<%=printTemp%>&printTempRelate=<%=printTempRelate%>&PKEY=<%=sPKEY%>&PFORM=<%=sPFORM%>";
  	//window.open(vUrl,"","left=20,top=20,width=600,height=600");
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;dialogHeight=550px");
  	//window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;");
  }  
  function LogWin() {
    var vUrl = "../../share/other/logList.jsp?LogType=FORM&ModuleID=<%=iFormID%>&InfoID=<%=sKEY%>";
  	window.open(vUrl,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=800,height=700");  
  }    
    
  //这里做退回、跳签需要传递的参数：流程ID，操作类型
  function transactWin(vFlowID, vOPERATOR) {
    var vUrl = "../../flow/flow/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");  
  }  
  
  function transactSubmit() {
	formUpdate.RYBLYJ_FLOW.value = flowDraft.formList.RYBLYJ.value;
	formUpdate.RYBLTP_FLOW.value = flowDraft.formList.selectSignature.value;  
	<% if (!sEditor.equals("")) {%>
		formUpdate.szContent.value=tbContentElement.DocumentHTML;
	<% } %>	
	<% if (!sWeboffice.equals("")) { %>    
    	//weboffice
    	formUpdate.RecordID.value = webOffice.webform.RecordID.value;
    	webOffice.webform.save.click(); 
	<% } %> 	
    <% if (hasAnnex) { %>		  
	formUpdate.action = "control2.jsp";
	<% } else {%>
	formUpdate.action = "relate_control.jsp";
	<% } %>
	formUpdate.submit();  
  }
  
  //document.all.['flowDraft'].style.height = vHeight;  
  var vRelateObject = formUpdate.RelateObject.value;
  var vOPERATOR = formUpdate.OPERATOR.value;
  //添加的时候自动执行,
  if (vOPERATOR == "add" && vRelateObject != "") {
  	RelateWin();
  }
</script>
</body>
<%
	out.println(SzPageHelp.calendarFrame2());
	out.println(SzPageHelp.calendar2Frame2());
%>

