<%@ 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.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.*" %>
<%//@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<%@ include file="/sessionInfo.jsp"%>
<%
	String moduleNameRelate = SzConvert.toSpaceStr(request.getParameter("moduleNameRelate"));
	String formNameRelate = SzConvert.toSpaceStr(request.getParameter("formNameRelate"));
	String sKEYRelate = SzConvert.toSpaceStr(request.getParameter("KEYRelate"));
  //取关联的设置 
	BdViewRelate bdViewRelate = new BdViewRelate();
	String sPath_str[][] = bdViewRelate.getViewRelatePath(request);
	String currentViewRelate[] = bdViewRelate.getCurrentViewRelate();
	String moduleName = currentViewRelate[5];
	String formName = currentViewRelate[6];

	String sRelateCond = bdViewRelate.getRelateCond(sKEYRelate);

	int iLen_Path = 0;
	if (sPath_str != null) {
	  iLen_Path = sPath_str.length;
	}	
%>



<script language="javascript">
  var vTabClass = "";
  function TabMouseOver(v) {
        vTabClass = v.className;
	v.className = "tab_12";
  }
  function TabMouseOut(v) {	
	v.className = vTabClass;
  }
</script>
<%
    //获取提交的参数
    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"));
    //取得表单的信息
		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;
    }   
    
    //2010-2-21
    BdPopedom bdPopedom = new BdPopedom();        
    String strDenyField = bdPopedom.getDenyField(iFormID, 0, iDLID_SESSION);
    String strDenyField2 = bdPopedom.getDenyField(iFormID, SzConvert.toInt(sKEY), iDLID_SESSION);
    bdPopedom.read(iFormID, SzConvert.toInt(sKEY), iDLID_SESSION);
    
    BdFormControl bdFormControl = new BdFormControl();
    //取得关联的名称
    BdTrigger bdTrigger = new BdTrigger();
    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 assistant = bdValueControl.getAssistant();
	String sTableAnnex = bdValueControl.getTableAnnex();
	String sEditor    = bdValueControl.getEditor();
	String sWeboffice = bdValueControl.getWebOffice();
	String sTemplateSelect = bdValueControl.getTemplateSelect();
	String printTemp = bdValueControl.getPrintTemp();
	String printTempRelate = bdValueControl.getPrintTempRelate();
	String allograph = bdValueControl.getAllograph();
	//System.out.println("allograph==" + allograph);
	
	boolean hasFlow   = bdValueControl.getHasFlow();
	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));
    }
    String loginID2 = SzConvert.toSpaceStr(bdValueControl.getLoginID2(value_str));
    String loginName2 = SzConvert.toSpaceStr(bdValueControl.getLoginName2(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, SzConvert.toInt(sKEY), iDLID_SESSION);
    		
    		//2011-07-12 该文设置为已读
    		lcFlowControl.readTransact(iFormID, SzConvert.toInt(sKEY), iDLID_SESSION);    		
    	}
    }   
%>
<%    
    //流程相关
    //根据已经有的信息ID，读取流程ID
    LcFlowControl lcFlowControl = new LcFlowControl();
    //取得流程权限信息
    LcFlowPopedomInfo lcFlowPopedomInfo = lcFlowControl.getFlowPopedomInfo(iFormID, Integer.parseInt(sKEY), 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;
	}
	boolean isTransact = false;
	if (sOPERATOR.startsWith("transact")) {
		isTransact = true;	
	}
	if (sOPERATOR.equals("updateWin")) {
		hasSend = false;
		isLastStep = false;
		canSend = false;
		canFinish = false;
		canDeny = false;
		canUntread = false;
		canSkip = false;
		
		canDraftSave = true;
		canDraftSend = false;
		canTransactSave = false;
		isTransact = false;
	}
	
	//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";
	} 

%>
<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">
<% if (!sEditor.equals("")) {%>
<script language="javascript">
  function LoadContent1() {
     this.focus();
     window_onresize();
     var vUrl = "http://<%=sServer_SESSION%>:<%=sPort_SESSION%><%=sContext_SESSION%>/share/formEngine2/load.jsp?FormID=<%=iFormID%>&KEY=<%=sKEY%>";
     tbContentElement.LoadURL(vUrl);
  }
</script>
<script type="text/javascript" src="<%=strLevel_SESSION%>share/ckeditor/ckeditor.js"></script>
</head>
<body onload="javascript:this.focus();" >
<% } else {%>
</head>
<body onload="javascript:this.focus();" >
<% } %>

<!-----上面的工具栏------>
<% if (hasAnnex) { %>
<form name="formUpdate" method="post" ENCTYPE="multipart/form-data">
<% } else { %>
<form name="formUpdate" method="post">
<% } %>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<% if (iLen_Path >0) { %>
  <tr>
    <td height="35">  
      <table border=0 cellpadding=0 cellspacing=0 height="30">  
        <tr align="center"> 

             <td class="line_01"></td>
<%
  for (int i_title =0; i_title<iLen_Path; i_title++) {
	if (sPath_str[i_title][0].equals("")) {
		continue;
	}
	if (sPath_str[i_title][4].equals("2") && !isBarManager_SESSION) {
		continue;
	}
%>
	      <td valign="bottom" class="<%=sPath_str[i_title][1]%>1"></td>  
	      <td class="<%=sPath_str[i_title][1]%>2" OnMouseOver="javascript:TabMouseOver(this);" OnMouseOut="javascript:TabMouseOut(this);"> 
	        <a href="<%=sPath_str[i_title][0]%>"><%=sPath_str[i_title][2]%></a>
              </td>  
              <td valign="bottom" class="<%=sPath_str[i_title][1]%>3"></td>
<%
  }
%>
              <td class="line_02"></td>
              <td class="line_03"></td>
        </tr>  
      </table>  
    </td>  
  </tr>
<% } %>
</table>
  <!---使用流程的时候需要使用--->
  <input type="hidden" name="LCID_FLOW" value="0">
  <input type="hidden" name="BZID_FLOW" value="0">
  <input type="hidden" name="BZXH_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="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="OPERATOR_SOURCE" value="<%=sOPERATOR%>">
  <input type="hidden" name="KEY" value="<%=sKEY%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="from" value="<%=from%>">
  <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 %>">
  <input type="hidden" name="hiddenSave" value="not">

  <input type="hidden" name="moduleNameRelate" value="<%=moduleNameRelate%>">
  <input type="hidden" name="formNameRelate" value="<%=formNameRelate%>">
  <input type="hidden" name="moduleName" value="<%=moduleName%>">
  <input type="hidden" name="formName" value="<%=formName%>">  
  <input type="hidden" name="KEYRelate" value="<%=sKEYRelate%>">  
  
<table width="100%">
  <tr>
    <td> 
      <%    
      out.println( SzPageHelp.button("返回", "FormSubmit(formUpdate, 'index.jsp?FormID=" + iFormID + "')") );
      %>         
    </td>
  </tr>
</table>

<% if (allograph.startsWith("1")) { %>
<table width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0"> 
  <tr> 
    <td width="100">所属人员</td> 
    <td><input type="hidden" name="SZOA_BDDLID" class="txtClass" value="<%=loginID2%>">
        <input type="text" name="SZOA_BDDLXM" class="txtClass" value="<%=loginName2%>" readonly>
        <input type="button" value="选择" class="btnClassShort" onClick="javascript:OpenWin12('formUpdate.SZOA_BDDLID', 'formUpdate.SZOA_BDDLXM');">
    </td> 
  </tr> 
</table> 
<% } %>
 

<!-----信息维护------>
<div id="divForm">
<%=sHTML %>
</div>
<!-- 附件 -->
<% if (!sTableAnnex.equals("")) { %>
<table width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0"> 
  <tr> 
    <td class="tdClassTitle"><b>附件</b></td>  
    <td colspan="3">
    <%
    if (bReadonly) {
    	out.println(SzPageHelp.detailAnnexNew2(sTableAnnex, sKEY, strLevel_SESSION));
    } else {
    	out.println(SzPageHelp.updateAnnexNew2(sTableAnnex, sKEY, strLevel_SESSION));
    }
    %>
    </td> 
  </tr> 
</table> 
<% } %>
<% 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();
	  }	      
      /*
			FCKeditor fckEditor = new FCKeditor(request, "szContent");
			fckEditor.setHeight("400");
			fckEditor.setWidth("750");

			fckEditor.setValue(sValue);		    
			out.println(fckEditor);
			*/
		%>  
		 <textarea id="szContent" name="szContent"><%=sValue %></textarea>       
    </td>
  </tr>
</table>
	<script type="text/javascript">
    CKEDITOR.replace( 'szContent');
   </script>
<% } %>
</form>
<% if (hasFlow && !sOPERATOR.startsWith("updateWin") ) { 
	 //而且不是发文的传阅
	 if (!formName.equals("document2") || !moduleName.equals("document_new.xml") || !sOPERATOR.startsWith("detailPass")) {
%>
<!--流程相关 包含流程的frame页面 -->
<iframe id="flowDraft" src="../../flow/flow/draft.jsp?assistant=<%=assistant%>&type=<%=iFlowID%>&FormID=<%=iFormID%>&InfoID=<%=sKEY%>&OPERATOR=<%=sOPERATOR%>" frameborder="0" scrolling="auto" width="750"></iframe>
<%
	 }
  } 
%>

<% 
	
  if (!sWeboffice.equals("") && ((";" + assistant + ";").indexOf(";5;") >=0)) {
	  session.setAttribute("SzModuleType", "");
	  session.setAttribute("SzModuleID", "");
	  session.setAttribute("SzInfoID", "");
	   
		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?InfoID=<%=sKEY%>&FileType=<%=FileType%>&ModuleType=<%=ModuleType %>&ModuleID=<%=ModuleID %>&RecordID=<%=RecordID%>&EditType=<%=sEditType%>&Template=<%=sTemplateSelect%>">
      </iframe>
    </td>
  </tr>
</table>
<% }  else { %>
      <iframe id="webOffice" width="0" height="0" 
              frameborder="0">
      </iframe>

<% } %>


<!-----这里包含要提交的内容--->
<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%>"> 
</form>

<script language="javascript" src="../../../share/js/commonTool.js"></script>
<script language="javascript" src="../../../share/js/formTool.js"></script>
<%=bdValueControl.detailCheckJs()%>
<%=bdValueControl.updateJs(Integer.parseInt(sKEY), session, sOPERATOR, canModifyForm, strDenyField, strDenyField2)%>
<%=bdValueControl.detailJs(Integer.parseInt(sKEY), sOPERATOR, canModifyForm)%>
<%=LcFlowControl.fieldPopedom(iFormID, iFlowID, Integer.parseInt(sKEY), canModifyForm, isTransact) %>
<%=bdValueControl.saveCheckJs()%>
<script language="javascript">
  <% if (sReadonly.equals("readonly")) {%>
    hideAll(formUpdate.btnSelect);
    hideAll(formUpdate.pop1);
  <% } %>

  function OfficeDetailWin(vKey) {
    //hideOperatorWin("div");
    var vRecordId = formUpdate.RecordID.value;
    var vUrl = "documentEdit.jsp?OPERATOR=<%=sOPERATOR%>&WebOffice=<%=sWeboffice%>&FormID=<%=iFormID%>&KEY=" + vKey + "&RecordId=" + vRecordId;
  	//window.open(vUrl,"","left=20,top=20,width=600,height=600");
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=950px;dialogHeight=800px");
  }   
  //document.all.['flowDraft'].style.height = vHeight;  
  
</script>
<div id="divLine" class="divLine" align="center" style="position:absolute;width:450;height:150px;left:150px;top:150px;padding:60px 0 0 0; margin:0px;overflow:auto;overflow:hidden;display:none; background-color:#dbdbdb;">
	<img src="<%=strSkin_SESSION%>/bar.gif">
</div><!---------------------------------------------------------------20120112 ting----------------------------------------->

</body>
<%
out.println(SzPageHelp.calendarFrame2());
out.println(SzPageHelp.calendar2Frame2());
%>

