<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ 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.docEngine.*" %>
<%@ page import="net.sz600.weboffice.*" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.fckeditor.*"%>
<%//@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<%@ include file="/sessionInfo.jsp"%>
<%@ include file="/docEngine/docEngineSession.jsp"%>
<%
  String strLevel = "../../";
%>
<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">
	<script type="text/javascript">
		function FCKeditor_OnComplete(editorInstance) {
			window.status = editorInstance.Description;
		}
		

	</script>
	<script type="text/javascript" src="<%=strLevel%>share/ckeditor/ckeditor.js"></script>
	<script language="javascript" src="../../share/js/commonTool.js"></script>
	<script language="javascript" src="../../share/js/annexTool.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 XXFL = SzConvert.toZeroStr(request.getParameter("XXFL"));
    String sTable_type = "SZKC_CPFL";
%>
<%
    SzData szData = null;
    SzDataInfo szDataInfo = null;

    String sOPERATOR = request.getParameter("OPERATOR");
    String sKEY =  SzConvert.toZeroStr(request.getParameter("KEY"));
    int iKey = SzConvert.toInt(sKEY);
    
    //2015-01增加锁定判断
    if (iKey > 0) {
    	if (SzEditLock.getInstance().isLocking("docEngine", moduleId, iKey)) {
    		sOPERATOR = "detail";    	
    	} else if (sNavigator_SESSION.equals("MSIE") || sNavigator_SESSION.equals("CHROME")) {
    		SzEditLock.getInstance().lock(session, "docEngine", moduleId, iKey); 
    	}
    }
    
    String sReadonly = "";
    boolean bReadonly = false;
    if (sOPERATOR.equals("detail")) {
        sReadonly = "readonly";
        bReadonly = true;
    }
    

    
    //读取数据
    WdyqDocInfo wdyqDocInfo = null;
    WdyqDoc wdyqDoc = new WdyqDoc(moduleId);
    if (iKey > 0) {
        wdyqDocInfo = (WdyqDocInfo)wdyqDoc.getInfoByKey(iKey);
        //增加阅读记录
        if (docEngineInfo.getHasReadRecord().equals("1")) {
            wdyqDoc.read(iKey, sBMMC_SESSION, iDLID_SESSION, sDLXM_SESSION);
        }             
    }
    if (wdyqDocInfo == null) {
        wdyqDocInfo = new WdyqDocInfo();
        wdyqDocInfo.setXXSJ(SzDateHelp.getTimeStr());
        wdyqDocInfo.setXXDLXM(szLoginInfo_SESSION.getDLXM());
        wdyqDocInfo.setXXBMID(iBMID_SESSION);
        wdyqDocInfo.setXXDLID(szLoginInfo_SESSION.getDLID());
        wdyqDocInfo.setXXBMMC(sBMMC_SESSION);
        wdyqDocInfo.setXXFL(Integer.valueOf(XXFL));
        //默认分类XXFL
        String sXXFL = SzConvert.toZeroStr(request.getParameter("XXFL"));
        wdyqDocInfo.setXXFL(Integer.parseInt(sXXFL));
    } else {
    }

%>
<% if (docEngineInfo.getEditor().equals("html")) {%>
<script language="javascript">
  function LoadContent1() {
     window_onresize();
     var vUrl = "http://<%=sServer_SESSION%>:<%=sPort_SESSION%><%=sContext_SESSION%>/share/editor/load.jsp?tablename=<%=readDocEngineXml.getInfoTable(moduleId)%>&KEY=<%=sKEY%>";
     tbContentElement.LoadURL(vUrl);
  }
</script>
<body >
<% } else {%>
<body >
<% } %>
<!-----上面的工具栏------>
<form name="formUpdate" method="post"  ENCTYPE="multipart/form-data">
  <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="XXID" value="<%=wdyqDocInfo.getXXID()%>">
  <input type="hidden" name="XXBY1" value="<%=wdyqDocInfo.getXXBY1()%>">
  <input type="hidden" name="XXDLID" value="<%=wdyqDocInfo.getXXDLID()%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="RecordID" value="">  
  <% if (docEngineInfo.getEditor().equals("html")) {%>
   <!-- <input type="hidden" name="XXNR">   -->
  <% } %>
<%@ include file="/docEngine/title.jsp"%>
<table width="100%">
  <tr>
    <td>
    <% 
      if (!bReadonly) {
   		if (docEngineInfo.getModulePopedom().equals("2") && sType.equals("1")) {
   			//上报
   			out.println(SzPageHelp.button("上报","javascript:FormSave1(formUpdate, 'control.jsp');"));
   		} else if (docEngineInfo.getModulePopedom().equals("2") && sType.equals("2")) {
   			out.println(SzPageHelp.button("发布","javascript:FormSave2(formUpdate, 'control.jsp');"));   			
   		} else {
   			out.println(SzPageHelp.saveButton());
   		}
      }
    %>
      <%=SzPageHelp.backButton()%>
      <% out.println(SzEditLock.getInstance().getLockInfo(session, "docEngine", moduleId, iKey)); %>
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
<%
	String addIDStr = "";
    //获取能管理的分类ID
    //取得本人能管理的所有模块ID
    String sCond = "FLGSID=" + szCOMPANY_SESSION;
    String strFLID_Manager = "0";
    if (!isBarManager_SESSION && docEngineInfo.getModulePopedom().equals("1")) {
        WdyqType wdyqType = new WdyqType(moduleId);
        //最后一个参数为false时，表示管理权限和添加权限同时存在时，保留管理权限。
        strFLID_Manager = SzConvert.toZeroStr(wdyqType.getAddFLID(iDLID_SESSION,false));
        sCond += " AND FLID in ( " + strFLID_Manager + ")";
        //截取可管理的文件夹ID
        addIDStr = strFLID_Manager.substring(0,strFLID_Manager.indexOf(",-1,"));
    } else if (docEngineInfo.getModulePopedom().equals("0")) {
    	//个人资料
    	sCond += " AND FLDLID=" + szDLID_SESSION + "";
    } else if (docEngineInfo.getModulePopedom().equals("2")) {
    	sCond += " AND 1=1";
    }
%>
<%
String isCan = "";
if (!docEngineInfo.getTypeName().equals("")) { %>
  <tr>
    <td class="tdClassTitle">分类</td>
    <td colspan="3">
    	<%
    	String selectStr = SzPageHelp.idSelectTree(readDocEngineXml.getTypeTable(moduleId),"FLID","FLMC","FLBH", sCond, "XXFL", wdyqDocInfo.getXXFL(), "txtClass2");
    	if(!isBarManager_SESSION){
    		if(wdyqDocInfo.getXXFL()!=0){
    			isCan = (","+addIDStr+",").indexOf(","+wdyqDocInfo.getXXFL()+",")<0?"":"disabled=\"disabled\"";
    		}else{
	    		String idStrs = "";
			if (selectStr.indexOf("</option>")>=0 && selectStr.indexOf("<option")>=0)  {
				idStrs = selectStr.substring(selectStr.indexOf("<option"),selectStr.indexOf("</option>"));
			}
			if (idStrs.lastIndexOf("\"")>=0 && idStrs.indexOf("\"")+1>=0)  {
	    			idStrs = idStrs.substring(idStrs.indexOf("\"")+1,idStrs.lastIndexOf("\""));
			}
	    		isCan = (","+addIDStr+",").indexOf(","+idStrs+",")<0?"":"disabled=\"disabled\"";

    		}
    		
    		if(docEngineInfo.getHasAnnex().equals("1")){
    			selectStr = selectStr.replaceAll("<select","<select onpropertychange=\"javascript:checkCanAdd(this,'"+addIDStr+"','btnFJ',true)\"");
    		}else{
    			selectStr = selectStr.replaceAll("<select","<select onpropertychange=\"javascript:checkCanAdd(this,'"+addIDStr+"','btnFJ',false)\"");
    		}
    	}
    	%>
      <%=selectStr%>
    </td>
  </tr>
<% } %>  
  <tr>
    <td class="tdClassTitle">标题</td>
    <td colspan="3"><input type="text" name="XXBT" class="txtClass2" value="<%=wdyqDocInfo.getXXBT()%>" <%=sReadonly%> >
    <font color="red">*</font>
    </td>
  </tr>
  <tr>
    <td class="tdClassTitle">归档号</td>
    <td colspan="3"><input type="text" name="XXBY2" class="txtClass2" value="<%=wdyqDocInfo.getXXBY2()%>" <%=sReadonly%> ></td>
  </tr>  
  <% if (!docEngineInfo.getEditor().equals("html")) {%>
  <tr>
    <td class="tdClassTitle">内容</td>
    <td colspan="3">
      <textarea name="XXNR" class="areaClass2" <%=sReadonly%> ><%=wdyqDocInfo.getXXNR()%></textarea>
    </td>
  </tr>
  <% } %>
  <tr>
    <td class="tdClassTitle">发布时间</td>
    <td><input type="text" name="XXSJ" class="txtClass1" value="<%=wdyqDocInfo.getXXSJ()%>" readonly>
    </td>
    <td class="tdClassTitle">推荐标志</td>
    <td>
      <input type="checkbox" name="XXZD"  value="1" <% if(wdyqDocInfo.getXXZD() == 1) {%>checked<% } %>>
      &nbsp;&nbsp;精华标志&nbsp;
      <input type="checkbox" name="XXJH"  value="1" <% if(wdyqDocInfo.getXXJH() == 1) {%>checked<% } %>>
    </td>
  </tr>

  <tr>
    <td class="tdClassTitle">发布部门</td>
    <td><input type="text" name="XXBMMC" class="txtClass1" value="<%=wdyqDocInfo.getXXBMMC()%>" readonly></td>
    <td class="tdClassTitle">发布人员</td>
    <td><input type="text" name="XXDLXM" class="txtClass1" value="<%=wdyqDocInfo.getXXDLXM()%>" readonly>
    </td>
  </tr>
  <% if (docEngineInfo.getAlert().equals("1")) { %>
  <tr>
    <td class="tdClassTitle">提醒配置</td>
    <td colspan="3">
      <input type="checkbox" name="Alert"  value="1">是否需要提醒能查看通知的人
      <% if (ReadOaConfig.getAlert_button().indexOf("sms") >=0) { %>
      <input type="checkbox" name="AlertSms"  value="1">是否需要手机提醒
      <% } %>
      <% if (ReadOaConfig.getAlert_button().indexOf("weixin") >=0) { %>      
      <input type="checkbox" name="AlertWeixin"  value="1">是否需要微信提醒
			<% } %>      
    </td>
  </tr> 
  <% } %>
    <input type="hidden" name="XXCKBM" class="txtClass1" value="<%=wdyqDocInfo.getXXCKBM()%>" readonly>
    <input type="hidden" name="XXCKDL" class="txtClass1" value="<%=wdyqDocInfo.getXXCKDL()%>" readonly>

  <% if (docEngineInfo.getModulePopedom().equals("1") && docEngineInfo.getHasDepartLimit().equals("1")) {%>
  <tr>
    <td class="tdClassTitle">指定可查看的<br>部门
    <% if (!bReadonly) {%>
      <input <%=isCan %> id="btnFJ1" type="button" name="btnSelect" class="btnClassShort" value="选择" OnClick="javascript:OpenWin24('formUpdate.XXCKBM','formUpdate.XXCKBMMC');">
    <% } %>
    </td>
    <td colspan="3">
      <textarea name="XXCKBMMC" class="areaClass2" readonly><%=wdyqDocInfo.getXXCKBMMC()%></textarea>
    </td>
  </tr>
  <% } %>
  <% if (docEngineInfo.getModulePopedom().equals("1") && docEngineInfo.getHasUserLimit().equals("1")) {%>
  <tr>
    <td class="tdClassTitle">指定可查看的<br>人员
    <% if (!bReadonly) {%>
      <input <%=isCan %> id="btnFJ2" type="button" name="btnSelect" class="btnClassShort" value="选择" OnClick="javascript:OpenWin14('formUpdate.XXCKDL','formUpdate.XXCKDLXM', 'all');">
    <% } %>
    </td>
    <td colspan="3">
      <textarea name="XXCKDLXM" class="areaClass2" readonly><%=wdyqDocInfo.getXXCKDLXM()%></textarea>
    </td>
  </tr>
  <% } %>
  <% if (docEngineInfo.getModulePopedom().equals("1") && docEngineInfo.getAnnexHasUserLimit().equals("1")&&docEngineInfo.getHasAnnex().equals("1")
		  ) {%>
  <tr>
    <td class="tdClassTitle">附件可查看的<br>人员
  	<input type="hidden" name="XXFJCKDLID" value="<%=wdyqDocInfo.getXXFJCKDLID()%>">
    <% if (!bReadonly) {%>
      <input <%=isCan %> id="btnFJ3" type="button" name="btnSelect" class="btnClassShort" value="选择" OnClick="javascript:OpenWin14('formUpdate.XXFJCKDLID','formUpdate.XXFJCKDLXM', 'all');">
    <% } %>
    </td>
    <td colspan="3">
      <textarea name="XXFJCKDLXM" class="areaClass2" readonly><%=wdyqDocInfo.getXXFJCKDLXM()%></textarea>
    </td>
  </tr>
  <% } %>
	<% if (docEngineInfo.getHasAnnex().equals("1")) {%>
  <tr>
    <td class="tdClassTitle">附件</td>
    <td colspan="3"><%//=SzPageHelp.updateAnnex(readDocEngineXml.getAnnexTable(moduleId), sKEY)%>
    <%=SzPageHelp.updateAnnexNew2(readDocEngineXml.getAnnexTable(moduleId), sKEY, strLevel_SESSION)%>
    </td>
  </tr>
	<% } %>  
</table>


<% if (docEngineInfo.getEditor().equals("html")) {%>
<table width="750" border="0" cellpadding="1" cellspacing="0">
  <tr>
    <td>
      <%//@ include file="/share/editor/edit.jsp"%>
      <%
      /*
			FCKeditor fckEditor = new FCKeditor(request, "XXNR");
			fckEditor.setHeight("400");
			fckEditor.setWidth("650");
			fckEditor.setValue(wdyqDocInfo.getXXNR());
			out.println(fckEditor);
			*/
		%>   
			<textarea id="XXNR" name="XXNR"><%=wdyqDocInfo.getXXNR()%></textarea>    
    </td>
  </tr>
</table>
	<script type="text/javascript">
    CKEDITOR.replace( 'XXNR');
   </script>
<%
	}
%>
</form>
<% 
	if ((docEngineInfo.getEditor().equals(".doc")
			|| docEngineInfo.getEditor().equals(".xls")
			|| docEngineInfo.getEditor().equals(".ppt"))
			&& sNavigator_SESSION.equals("MSIE")) {
		
		String FileType   = docEngineInfo.getEditor();
		String ModuleType = "docEngine";
		int    ModuleID   = SzConvert.toInt( moduleId );
		
	    //取得RecordID
	    OfficeRecordID officeRecordID = new OfficeRecordID();
	    String RecordID  = officeRecordID.loadRecordID(ModuleType,ModuleID,Integer.parseInt(sKEY));	
		//out.println("	RecordID=========" + RecordID);
%>

<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=1">
      </iframe>
    </td>
  </tr>
</table>
<% } else if (!sNavigator_SESSION.equals("MSIE")) {
	OfficeRecordID officeRecordID = new OfficeRecordID();
	String sFileLink = officeRecordID.getFileLink("docEngine", SzConvert.toInt( moduleId ), SzConvert.toInt(sKEY), docEngineInfo.getEditor());
	
	out.println("<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">");
	out.println("<tr><td><font color='red'>提示：</font>您使用的不是IE浏览器,word、excel、ppt不能在线编辑。</td></tr>");
	if (!sFileLink.equals("")) {
  		out.println("<tr><td>" + sFileLink + "</td></tr>");
	}	
	out.println("</td></tr></table>");
	 
   }
%>
<!-- 检查是否有归档 
--找到moduleName,formName,infoID

-->
<% 
  //2015-03增加：
  if ( (moduleId.equals("99910") || moduleId.equals("23")) && !sKEY.equals("0")) { 
		LcPigonhole pigonhole = new LcPigonhole();
		out.println(pigonhole.printPigonholeDetail(moduleId, Integer.parseInt(sKEY)));
  } 
%>
<!-----这里包含要提交的内容--->
<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%>">
</form>

<script language="javascript">
  //上
  function FormSave1(formName, url) {
    formName.XXBY1.value = "0";
    FormSave(formName, url);
  }
  //发布
  function FormSave2(formName, url) {
    formName.XXBY1.value = "1";
    FormSave(formName, url);
  }


  function FormSave(formName, url) {
    //检查是否可以保存
    if (!notSpace(formName.XXBT, "标题")) {
      return false;
    }
    <% if (docEngineInfo.getEditor().equals("html")) {%>
       /*
       formName.XXNR.value=tbContentElement.DocumentHTML;
       if (formName.XXNR.value == "undefined") {
         formName.XXNR.value = "";
       }
       */
    <% } %>
    
    <% if (docEngineInfo.getEditor().equals(".doc")
			|| docEngineInfo.getEditor().equals(".xls")
			|| docEngineInfo.getEditor().equals(".ppt")) { %>    

    formName.RecordID.value = webOffice.webform.RecordID.value;   
    //保存为html 
    webOffice.webform.saveHtml.click();
    //保存历史版本
    webOffice.webform.saveVersion.click(); 
    //保存为Img
    //webOffice.webform.saveImg.click();
    webOffice.webform.save.click();
    
    
    //webOffice.webform.WebOffice.WebSaveAsHtml();
    //webOffice.WebSaveAsHtml();
 
    <% } %>
    //2012-01-11增加
    //vBeforeFrameHtmlUnload = false;
    document.getElementById("divLine").style.display = "block";        
    formName.action = url;
    formName.submit();
  }
</script>
<script language="javascript">
  //弹出窗口，选择人员。这里特定是流程里某个步骤的选择人员。
  function PrintWin(moduleName, formName, key) {
    var vUrl = "../../share/formEngine2/detail_win.jsp?moduleName=" + moduleName 
             + "&formName=" + formName 
             + "&from=22&OPERATOR=detail&KEY=" + key;
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=900px;dialogHeight=550px");
  }
  
  function checkCanAdd(obj,idStr,btnId,hasAnnex){
  	var allId = idStr.split(",");
  	var selectValue = obj.value;
  	var len = allId.length;
  	var canAdd = true;
  	for(var i = 0;i<len;i++){
  		if(allId[i]==selectValue){
  			canAdd = false;
  			break;
 		}
  	}
  	if(canAdd){
  		document.getElementById(btnId+"1").disabled="";
  		document.getElementById(btnId+"2").disabled="";
  		if(hasAnnex){
  			document.getElementById(btnId+"3").disabled="";
  		}
  	}else{
  		document.getElementById(btnId+"1").disabled="disabled";
  		document.getElementById("XXCKBMMC").value = "";
  		document.getElementById("XXCKBM").value = "";
  		document.getElementById(btnId+"2").disabled="disabled";
  		document.getElementById("XXCKDLXM").value = "";
  		document.getElementById("XXCKDL").value = "";
  		if(hasAnnex){
	  		document.getElementById(btnId+"3").disabled="disabled";
	  		document.getElementById("XXFJCKDLXM").value = "";
	  		document.getElementById("XXFJCKDLID").value = "";
  		}
  	}
  }


		//页面解除锁定
	window.onbeforeunload = function() {

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

		  AJAX(vUrl, "", false);
	}  

</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>
