<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="cn.js.fan.security.*"%>
<%@ page import="cn.js.fan.util.*"%>
<%@ page import="java.util.*"%>
<%@ page import="cn.js.fan.web.*"%>
<%@ page import="cn.js.fan.module.cms.*"%>
<%@ page import="cn.js.fan.module.cms.plugin.*"%>
<%@ page import="cn.js.fan.module.cms.plugin.base.*"%>
<%@ page import="cn.js.fan.module.pvg.*"%>
<%@ page import="java.util.Calendar" %>
<%@ page import="cn.js.fan.db.Paginator"%>
<%@ taglib uri="/WEB-INF/tlds/LabelTag.tld" prefix="lt" %>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="common.css" rel="stylesheet" type="text/css">
<link href="cms/default.css" rel="stylesheet" type="text/css">
<%@ include file="inc/nocache.jsp"%>
<jsp:useBean id="strutil" scope="page" class="cn.js.fan.util.StrUtil"/>
<jsp:useBean id="docmanager" scope="page" class="cn.js.fan.module.cms.DocumentMgr"/>
<jsp:useBean id="dir" scope="page" class="cn.js.fan.module.cms.Directory"/>
<%
String dir_code = ParamUtil.get(request, "dir_code");
String dir_name = ParamUtil.get(request, "dir_name");
int id = 0;

Privilege privilege = new Privilege();

String correct_result = SkinUtil.LoadString(request,"info_op_success");
Document doc = null;
Document template = null;
Leaf leaf = dir.getLeaf(dir_code);
String strtemplateId = ParamUtil.get(request, "templateId");
int templateId = Document.NOTEMPLATE;
if (!strtemplateId.trim().equals("")) {
	if (StrUtil.isNumeric(strtemplateId))
		templateId = Integer.parseInt(strtemplateId);
}
if (templateId==Document.NOTEMPLATE) {
	templateId = leaf.getTemplateId();
}

if (templateId!=Document.NOTEMPLATE) {
	template = docmanager.getDocument(templateId);
}
String op = ParamUtil.get(request, "op");
String action = ParamUtil.get(request, "action");
if (op.equals("add")) {
	LeafPriv lp = new LeafPriv();
	lp.setDirCode(dir_code);
	if (!lp.canUserAppend(privilege.getUser(request))) {
		out.print(StrUtil.Alert(privilege.MSG_INVALID));
		return;
	}

	if (action.equals("selTemplate")){
		int tid = ParamUtil.getInt(request, "templateId");
		template = docmanager.getDocument(tid);
	}
}
if (op.equals("edit")) {
	try {
		id = ParamUtil.getInt(request, "id");
		doc = docmanager.getDocument(id);
		dir_code = doc.getDirCode();

		LeafPriv lp = new LeafPriv(doc.getDirCode());
		if (!lp.canUserModify(privilege.getUser(request))) {
			out.print(StrUtil.makeErrMsg(privilege.MSG_INVALID));
			return;
		}
		
		if (action.equals("selTemplate")) {
			int tid = ParamUtil.getInt(request, "templateId");
			doc.setTemplateId(tid);
			doc.updateTemplateId();
		}
		if (doc!=null) {
			template = doc.getTemplate();
		}
	} catch (ErrMsgException e) {
		out.print(strutil.makeErrMsg(e.getMessage(),"red", "green"));
		return;
	}
	
	if (action.equals("changeAttachOrders")) {
		int attachId = ParamUtil.getInt(request, "attachId");
		String direction = ParamUtil.get(request, "direction");
		// 取得第一页的内容
		DocContent dc = new DocContent();
		dc = dc.getDocContent(id, 1);
		dc.moveAttachment(attachId, direction);		
	}
}
if (op.equals("editarticle")) {
	op = "edit";
	try {
		doc = docmanager.getDocumentByCode(request, dir_code, privilege);
		dir_code = doc.getDirCode();

		LeafPriv lp = new LeafPriv();
		lp.setDirCode(doc.getDirCode());
		if (!lp.canUserModify(privilege.getUser(request))) {
			out.print(StrUtil.makeErrMsg(privilege.MSG_INVALID));
			return;
		}
		
	} catch (ErrMsgException e) {
		out.print(strutil.makeErrMsg(e.getMessage(),"red", "green"));
		return;
	}
}

if (doc!=null) {
	id = doc.getID();
	Leaf lfn = new Leaf();
	lfn = lfn.getLeaf(doc.getDirCode());
	dir_name = lfn.getName();
}
%>
<title><%=doc!=null?doc.getTitle():""%></title>
<style type="text/css">
<!--
td {  font-family: "Arial", "Helvetica", "sans-serif"; font-size: 14px; font-style: normal; line-height: 150%; font-weight: normal}
.style2 {color: #FF3300}
.STYLE3 {font-weight: bold}
-->
</style>
<script language=JavaScript src='scripts/formpost.js'></script>
<script language="JavaScript">
<!--
<%
if (doc!=null) {
	out.println("var id=" + doc.getID() + ";");
}
%>
	var op = "<%=op%>";

	function SubmitWithFileDdxc() {
		addform.webedit.isDdxc = 1;
		if (document.addform.title.value.length == 0) {
			alert("<lt:Label res="res.label.webedit" key="input_artical_title"/>");
			document.addform.title.focus();			
			return false;
		}
		loadDataToWebeditCtrl(addform, addform.webedit);
		addform.webedit.MTUpload();
		// 因为Upload()中启用了线程的，所以函数在执行后，会立即反回，使得下句中得不到ReturnMessage的值
		// 原因是此时服务器的返回信息还没收到
		// alert("ReturnMessage=" + addform.webedit.ReturnMessage);
	}

	function SubmitWithFileThread() {
		if (document.addform.title.value.length == 0) {
			alert("<lt:Label res="res.label.webedit" key="input_artical_title"/>");
			document.addform.title.focus();			
			return false;
		}
		loadDataToWebeditCtrl(addform, addform.webedit);
		addform.webedit.Upload();
		// 因为Upload()中启用了线程的，所以函数在执行后，会立即反回，使得下句中得不到ReturnMessage的值
		// 原因是此时服务器的返回信息还没收到
		// alert("ReturnMessage=" + addform.webedit.ReturnMessage);
	}

	function SubmitWithFile(){
		if (document.addform.title.value.length == 0) {
			alert("<lt:Label res="res.label.webedit" key="input_artical_title"/>");
			document.addform.title.focus();			
			return false;
		}
		loadDataToWebeditCtrl(addform, addform.webedit);
		addform.webedit.UploadArticle();
		if (addform.webedit.ReturnMessage == "<%=correct_result%>")
			doAfter(true);
		else
			doAfter(false);
	}
	
	function SubmitWithoutFile() {
		if (document.addform.title.value.length == 0) {
			alert("<lt:Label res="res.label.webedit" key="input_artical_title"/>");
			document.addform.title.focus();	
			return false;
		}

		addform.isuploadfile.value = "false";
		loadDataToWebeditCtrl(addform, addform.webedit);
		addform.webedit.UploadMode = 0;
		addform.webedit.UploadArticle();
		addform.isuploadfile.value = "true";
		if (addform.webedit.ReturnMessage == "<%=correct_result%>")
			doAfter(true);
		else
			doAfter(false);		
	}

	function ClearAll() {
		document.addform.title.value=""
		oEdit1.putHTML(" ");
	}
	
	var action = "<%=action%>";
	function doAfter(isSucceed) {
		if (isSucceed) {
			if (op=="edit")
			{
				if (confirm("<%=correct_result%> <lt:Label res="res.label.webedit" key="fckwebedit_msg_resfresh"/>")) {
					// 此处一定要reload，否则会导致再点击上传（连同文件）时，因为images已被更改，而content中路径未变，从而下载不到，导到最终会丢失			
					// 以前未注意到此问题，可能是因为再点击上传时，获取的图片在服务器端虽然已丢失，但是缓存中可能还有的原因
					// 也可能是因为在编辑文件时，编辑完了并未重新刷新页面，content中的图片还是来源的位置（来源自别的服务器），所以依然能够上传，但是只要此时再一刷新，再连续上传两次，问题就会出现
					if (action=="selTemplate")
						window.location.href = "fwebedit.jsp?op=edit&id=<%=id%>&dir_code=<%=StrUtil.UrlEncode(dir_code)%>";
					else
						window.location.reload(true); 
					}
			}
			else {
				alert("<%=correct_result%>");
		    }
		}
		else {
			alert(addform.webedit.ReturnMessage);
		}
	}
	
function showvote(isshow)
{
	if (addform.isvote.checked)
	{
		addform.vote.style.display = "";
	}
	else
	{
		addform.vote.style.display = "none";		
	}
}

function selTemplate(id)
{
	if (addform.templateId.value!=id) {
		addform.templateId.value = id;
		// 此处注意当模式对话框的路径在admin下时，退出后本页路径好象被改为admin了
<%if (doc!=null) {%>
		window.location.href="../fwebedit.jsp?op=edit&action=selTemplate&id=<%=id%>&dir_code=<%=StrUtil.UrlEncode(dir_code)%>&dir_name=<%=StrUtil.UrlEncode(dir_name)%>&templateId=" + id;
<%}else{%>
		if (id!=-1)
			window.location.href="../fwebedit.jsp?op=add&action=selTemplate&dir_code=<%=StrUtil.UrlEncode(dir_code)%>&dir_name=<%=StrUtil.UrlEncode(dir_name)%>&templateId=" + id;		
<%}%>
	}
}

// 编辑文件
function editdoc(doc_id, file_id)
{
	addform.redmoonoffice.AddField("doc_id", doc_id);
	addform.redmoonoffice.AddField("file_id", file_id);
	addform.redmoonoffice.Open("http://<%=Global.server%>:<%=Global.port%>/<%=Global.virtualPath%>/word_get.jsp?doc_id=" + doc_id + "&file_id=" + file_id);
}

// 控件完成上传后，调用Operate()
function OfficeOperate() {
	// alert(addform.redmoonoffice.ReturnMessage);
}
//-->
</script>
<script language=JavaScript src='scripts/language/schi/editor_lang.js'></script>
<%
if (request.getHeader("User-Agent").indexOf("MSIE")!=-1){
	out.println("<script language=JavaScript src='scripts/editor.js'></script>");
}
else{
	out.println("<script language=JavaScript src='scripts/moz/editor.js'></script>");
}
%>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<TABLE width="98%" BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0>
  <TR valign="top" bgcolor="#FFFFFF">
    <TD width="" height="430" colspan="2" style="background-attachment: fixed; background-image: url(images/bg_bottom.jpg); background-repeat: no-repeat">
          <TABLE cellSpacing=0 cellPadding=0 width="100%">
            <TBODY>
              <TR>
                <TD width="83%" class=head>
				<%
				if (op.equals("add")) {%>
					<lt:Label res="res.label.webedit" key="add_content_to"/>--<a href="cms/document_list_m.jsp?dir_code=<%=StrUtil.UrlEncode(dir_code)%>&dir_name=<%=StrUtil.UrlEncode(dir_name)%>"><%=dir_name%></a>
				<%}else{%>
					<%=SkinUtil.LoadString(request,"op_modify")%>--
					<%
					Leaf dlf = new Leaf();
					if (doc!=null) {
						dlf = dlf.getLeaf(doc.getDirCode());
					}
					if (doc!=null && dlf.getType()==2) {%>
						<a href="cms/document_list_m.jsp?dir_code=<%=StrUtil.UrlEncode(dir_code)%>&dir_name=<%=StrUtil.UrlEncode(dir_name)%>"><%=dlf.getName()%></a>
					<%}else{%>
						<%=dir_name%>
					<%}%>
					(<%=doc.getDirCode()%>)
				<%}%></TD>
                <TD width="17%" class=head><a href="fckwebedit.jsp?op=<%=op%>&id=<%=id%>&dir_code=<%=StrUtil.UrlEncode(dir_code)%>&dir_name=<%=dir_name%>">FCKEditor</a></TD>
              </TR>
            </TBODY>
          </TABLE>
	<form name="addform" action="/admin/fwebedit_do.jsp" method="post">
          <table border="0" cellspacing="1" width="100%" cellpadding="2" align="center">
            <tr align="center" bgcolor="#F2F2F2">
              <td height="20" colspan=2 align=center><b><%=doc!=null?doc.getTitle():""%>
                <input type="hidden" name=isuploadfile value="true">
              </b>&nbsp;
			  <input type="hidden" name=id value="<%=doc!=null?""+doc.getID():""%>">
<%=doc!=null?"(id:"+doc.getID()+")":""%>	<%if (doc!=null) {%>
( <a href="cms/comment_m.jsp?doc_id=<%=doc.getID()%>"><lt:Label res="res.label.webedit" key="mgr_comment"/></a> )
<%}%></td>
            </tr>
            <tr>
              <td colspan="2" align="left" valign="middle" bgcolor="#FFFFFF" class="unnamed2">
<%
// 如果是加入新文章
if (doc==null) {			  
	PluginMgr pm = new PluginMgr();
	PluginUnit pu = pm.getPluginUnitOfDir(dir_code);
	if (pu!=null) {
		IPluginUI ipu = pu.getUI(request);
		IPluginViewAddDocument pv = ipu.getViewAddDocument(dir_code);
		out.print(pu.getName(request) + ":&nbsp;" + pv.render(UIAddDocument.POS_TITLE) + "<BR>");
		out.print(pv.render(UIAddDocument.POS_FORM_ELEMENT) + "<BR>");
	}
}
else {
	PluginMgr pm = new PluginMgr();
	PluginUnit pu = pm.getPluginUnitOfDir(dir_code);
	if (pu!=null) {
		IPluginUI ipu = pu.getUI(request);
		IPluginViewEditDocument pv = ipu.getViewEditDocument(doc);
		out.print(pu.getName(request) + ":&nbsp;" + pv.render(UIAddDocument.POS_TITLE) + "<BR>");
		out.print(pv.render(UIAddDocument.POS_FORM_ELEMENT) + "<BR>");
	}
}
%>			  </td>
            </tr>
            <tr>
              <td align="left" class="unnamed2" valign="middle"><lt:Label res="res.label.webedit" key="author"/></td>
              <td bgcolor="#F2F2F2"><input name="author" id="author" type="TEXT" size=30 maxlength=100 style="background-color:ffffff;color:000000;border: 1 double" value="<%=doc!=null?doc.getAuthor():privilege.getUser(request)%>">
			  <input type="hidden" name="op" value="<%=op%>"></td>
            </tr>
            <tr>
              <td align="left" class="unnamed2" valign="middle"><lt:Label res="res.label.webedit" key="topic"/></td>
              <td width="92%" bgcolor="#FFFFFF">
                  <input name="title" id=me type="TEXT" size=50 maxlength=100 style="background-color:ffffff;color:000000;border: 1 double" value="<%=doc!=null?doc.getTitle():""%>">                  
                  <span class="unnamed2"><font color="#FF0000">＊</font></span>			  </td>
            </tr>
            <tr bgcolor="#F2F2F2">
              <td align="left" class="unnamed2" valign="middle"><lt:Label res="res.label.webedit" key="key_words"/></td>
              <td bgcolor="#F2F2F2"><input name="keywords" id=keywords type="TEXT" size=30 maxlength=100 style="background-color:ffffff;color:000000;border: 1 double" value="<%=StrUtil.getNullStr(doc==null?dir_code:doc.getKeywords())%>">
                <lt:Label res="res.label.webedit" key="divide"/>
                <span class="unnamed2">
                <%
			String strRelateChecked = "";
			if (doc!=null && doc.getIsRelateShow())
				strRelateChecked = "checked";
			%>
&nbsp;&nbsp;<lt:Label res="res.label.webedit" key="relative_artical"/>
<input type="checkbox" name="isRelateShow" value="1" <%=strRelateChecked%>>
<lt:Label res="res.label.webedit" key="display"/></span></td>
            </tr>
            <tr align="left">
              <td align="left" valign="middle" class="unnamed2"><lt:Label res="res.label.webedit" key="comments"/></td>
              <td valign="middle" class="unnamed2"><%
			String strChecked = "";
			if (doc!=null) {
				if (doc.getCanComment())
					strChecked = "checked";
			}
			else
				strChecked = "checked";
			%>
              <input type="checkbox" name="canComment" value="1" <%=strChecked%>>
<lt:Label res="res.label.webedit" key="enable"/>
<%if (doc!=null) {%>
[<a href="cms/comment_m.jsp?doc_id=<%=doc.getID()%>"><lt:Label res="res.label.webedit" key="mgr_comment"/></a>]
<%}%>
&nbsp;
<%if (doc!=null) {%>
<input type="checkbox" name="isHome" value="<%=doc.getIsHome()?"false":"true"%>" <%=doc.getIsHome()?"checked":""%>>
<%}else{%>
<input type="checkbox" name="isHome" value="true" checked>
<%}%>
<lt:Label res="res.label.webedit" key="to_home"/>
<%
LeafPriv lp = new LeafPriv(dir_code);
if (lp.canUserExamine(privilege.getUser(request))) {
%>
	&nbsp;&nbsp;&nbsp;&nbsp;<span class="style2"><lt:Label res="res.label.webedit" key="check"/></span>	<select name="examine">
	  <option value="0"><lt:Label res="res.label.webedit" key="has_not_checked"/></option>
	  <option value="1"><lt:Label res="res.label.webedit" key="has_not_passed"/></option>
	  <option value="2"><lt:Label res="res.label.webedit" key="has_passed"/></option>
	</select>
	<%if (doc!=null) {%>
		<script>
		addform.examine.value = "<%=doc.getExamine()%>";
		</script>
	<%}%>
<%}else{%>
	<input type="hidden" name="examine" value="<%=(doc!=null)?""+doc.getExamine():"0"%>">
<%}%>
<%
String checknew = "";
if (doc!=null && doc.getIsNew()==1)
	checknew = "checked";
%>
<input type="checkbox" name="isNew" value="1" <%=checknew%>>
<img src="images/i_new.gif" width="18" height="7"></td>
            </tr>
            <tr align="left" bgcolor="#F2F2F2">
              <td colspan="2" valign="middle" class="unnamed2">
			  <%if (doc!=null) {%>
				  <script>
				  var bcode = "<%=doc.getDirCode()%>";
				  </script>
				  <lt:Label res="res.label.webedit" key="sort"/>
				  <%
				  if (leaf.getType()==leaf.TYPE_DOCUMENT) {
					out.print("<input name=dir_code type=hidden value='" + doc.getDirCode() + "'>" + leaf.getName());
				  }else{
				  %>
					<select name="dir_code" onChange="if(this.options[this.selectedIndex].value=='not'){alert(this.options[this.selectedIndex].text+' <lt:Label res="res.label.webedit" key="can_not_be_selected"/>'); this.value=bcode; return false;}">
						  <option value="not" selected><lt:Label res="res.label.webedit" key="select_sort"/></option>
					<%
					Leaf lf = dir.getLeaf("root");
					DirectoryView dv = new DirectoryView(lf);
					dv.ShowDirectoryAsOptions(out, lf, lf.getLayer());
					%>
					</select>
						<script>
						addform.dir_code.value = "<%=doc.getDirCode()%>";
						</script>
						&nbsp;( <span class="style3"><lt:Label res="res.label.webedit" key="blue"/></span><lt:Label res="res.label.webedit" key="can_be_selected"/> )
				  <%}%>
				<%}else{%>
					<input type=hidden name="dir_code" value="<%=dir_code%>">
				<%}%>			  </td>
            </tr>
            <tr align="left" bgcolor="#F2F2F2">
              <td colspan="2" valign="middle" class="unnamed2"><lt:Label res="res.label.webedit" key="template_ID"/>&nbsp;
			    <%
			  if (doc!=null)
			  	templateId = doc.getTemplateId();
			  %>
                <input name="templateId" class="singleboarder" value="<%=templateId%>" size=3 readonly>
&nbsp;<a href="javascript:showModalDialog('cms/doc_template_select_frame.jsp',window.self,'dialogWidth:680px;dialogHeight:480px;status:no;help:no;')"><lt:Label res="res.label.webedit" key="select_template"/></a> <span id=templateInfo>
<%if (doc!=null && doc.getTemplateId()!=doc.NOTEMPLATE) {%>
<a target=_blank href="cms/doc_template_show.jsp?id=<%=doc.getTemplateId()%>"><lt:Label res="res.label.webedit" key="browse_template"/></a>
<a href="javascript:oEdit1.putHTML(divTemplate.innerHTML)"><lt:Label res="res.label.webedit" key="re_aplication_template"/></a>
<a href="javascript:window.location.href='fwebedit.jsp?op=edit&action=selTemplate&id=<%=id%>&dir_code=<%=StrUtil.UrlEncode(dir_code)%>&dir_name=<%=StrUtil.UrlEncode(dir_name)%>&templateId=-1'"><lt:Label res="res.label.webedit" key="cancle_template"/></a>
<%}else{%> 
<a href="#" onClick="if (addform.templateId.value!=-1) window.open('cms/doc_template_show.jsp?id=' + addform.templateId.value); else alert('<lt:Label res="res.label.webedit" key="not_choose_template"/>')"><lt:Label res="res.label.webedit" key="browse_template"/></a>
&nbsp;<a href="#" onClick="addform.templateId.value='-1';oEdit1.putHTML(' ')"><lt:Label res="res.label.webedit" key="cancle_template"/></a>
<%}%>
</span></td>
            </tr>
            <tr bgcolor="#F2F2F2">
              <td align="right" class="unnamed2" valign="middle">
			  <script>
			  var vp = "";
			  </script>
		<%
		String display="none",ischecked="false", isreadonly = "";
		if (doc!=null) {
			if (doc.getType()==1) {
				display = "";
				ischecked = "checked disabled";
				isreadonly = "readonly";
				%>
				<script>
				var voteoption = "<%=doc.getVoteOption()%>";
				var votes = voteoption.split("|");
				var len = votes.length;
				for (var i=0; i<len; i++) {
					if (vp=="")
						vp = votes[i];
					else
						vp += "\r\n" + votes[i];
				}
				</script>
			<%}
		}%>
					  <input type="checkbox" name="isvote" value="1" onClick="showvote()" <%=ischecked%>>
              <lt:Label res="res.label.webedit" key="vote"/></td>
              <td valign="middle"><textarea <%=isreadonly%> style="display:<%=display%>" cols="60" name="vote" rows="8" wrap="VIRTUAL" title="SkinUtil.LoadString(request,"res.label.webedit","input_vote_choose")">
			  </textarea>
			  <script>
  				addform.vote.value = vp;
			  </script>
<lt:Label res="res.label.webedit" key="per_choose"/>&nbsp;&nbsp;<lt:Label res="res.label.webedit" key="editing_can_not_be_vote"/></td>
            </tr>
            <tr align="center">
              <td colspan="2" valign="top" bgcolor="#F2F2F2" class="unnamed2">

<pre id="idTemporary" name="idTemporary" style="display:none">
<%
if (!op.equals("add")) {
%>
<%=strutil.HTMLEncode(strutil.getNullString(doc.getContent(1)))%>
<%}%>
</pre>

<pre id="divTemplate" name="divTemplate" style="display:none">
<%if (template!=null) {%>
	<%=template.getContent(1)%>
<%}%>
</pre>

 <script>
		var oEdit1 = new InnovaEditor("oEdit1");
		oEdit1.width="100%";
		oEdit1.height="500";

		oEdit1.features=["FullScreen","Preview","Print","Search","SpellCheck",
					"Cut","Copy","Paste","PasteWord","PasteText","|","Undo","Redo","|",
					"ForeColor","BackColor","|","Bookmark","Hyperlink",
					"HTMLFullSource","HTMLSource","XHTMLFullSource",
					"XHTMLSource","BRK","Numbering","Bullets","|","Indent","Outdent","LTR","RTL","|","Image","Flash","Media","|","InternalLink","CustomObject","|",
					"Table","Guidelines","Absolute","|","Characters","Line",
					"Form","Clean","ClearAll","BRK",
					"StyleAndFormatting","TextFormatting","ListFormatting","BoxFormatting",
					"ParagraphFormatting","CssText","Styles","|",
					"Paragraph","FontName","FontSize","|",
					"Bold","Italic",
					"Underline","Strikethrough","|","Superscript","Subscript","|",
					"JustifyLeft","JustifyCenter","JustifyRight","JustifyFull"]; 
<%if (templateId!=-1 && doc==null) {%>	
	oEdit1.RENDER(document.getElementById("divTemplate").innerHTML);
<%}else{%>
	oEdit1.RENDER(document.getElementById("idTemporary").innerHTML);
<%}%>
</script>             </td>
            </tr>
            <tr>
              <td width="8%" align="right" bgcolor="#FFFFFF"><lt:Label res="res.label.webedit" key="notice"/></td>
              <td bgcolor="#FFFFFF">
			  <lt:Label res="res.label.webedit" key="enter_can_use"/>Shift+Enter			  </td>
            </tr>
            <tr>
              <td height="25" colspan=2 align="center" bgcolor="#FFFFFF"><table width="50%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#6BC731" bgcolor="#D6D7DE">
                <tr>
                  <td align="center" bgcolor="#F7F3F7"><strong>OfficeEdit&nbsp;<lt:Label res="res.label.webedit" key="webedit_info"/></strong></td>
                </tr>
                <tr>
                  <td align="center" bgcolor="#DBEED9"><object id="redmoonoffice" classid="CLSID:D01B1EDF-E803-46FB-B4DC-90F585BC7EEE" 
codebase="<%=request.getContextPath()%>/activex/rmoffice.cab#version=2,0,0,1" width="316" height="43" viewastext="viewastext">
                      <param name="Encode" value="utf-8" />
                      <param name="BackColor" value="0000ff00" />
                      <param name="Server" value="<%=Global.server%>" />
                      <param name="Port" value="<%=Global.port%>" />
                      <!--设置是否自动上传-->
                      <param name="isAutoUpload" value="1" />
                      <!--设置文件大小不超过1M-->
                      <param name="MaxSize" value="1024000" />
                      <!--设置自动上传前出现提示对话框-->
                      <param name="isConfirmUpload" value="1" />
                      <!--设置IE状态栏是否显示信息-->
                      <param name="isShowStatus" value="0" />
                      <param name="PostScript" value="<%=Global.virtualPath%>/word_upload.jsp" />
                    </object>
                      <input name="remsg" type="button" onclick='alert(addform.redmoonoffice.ReturnMessage)' value="<%=SkinUtil.LoadString(request,"res.label.webedit","view_info_after_upload")%>" />
                      <table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                          <td height="5"></td>
                        </tr>
                      </table>                  </td>
                </tr>
              </table>
			    <br>
			    <%
			  if (doc!=null) {
				  Vector attachments = doc.getAttachments(1);
				  Iterator ir = attachments.iterator();
				  while (ir.hasNext()) {
				  	Attachment am = (Attachment) ir.next(); %>
					<table width="98%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="7%" align="center"><img src=images/attach.gif width="17" height="17"></td>
                        <td width="93%">&nbsp;
                          <input name="attach_name<%=am.getId()%>" value="<%=am.getName()%>" size="30">
&nbsp;<a href="javascript:changeAttachName('<%=am.getId()%>', '<%=doc.getID()%>', '<%="attach_name"+am.getId()%>')"><lt:Label res="res.label.webedit" key="modify"/></a>                        &nbsp;<a href="javascript:delAttach('<%=am.getId()%>', '<%=doc.getID()%>')"><%=SkinUtil.LoadString(request,"op_del")%></a>&nbsp;&nbsp;<a target=_blank href="<%=am.getVisualPath() + "/" + am.getDiskName()%>"><lt:Label res="res.label.webedit" key="view"/></a>&nbsp;<a href="?op=edit&dir_code=<%=StrUtil.UrlEncode(doc.getDirCode())%>&id=<%=doc.getID()%>&action=changeAttachOrders&direction=up&attachId=<%=am.getId()%>"><img src="images/arrow_up.gif" alt="<lt:Label res="res.label.webedit" key="up"/>" width="16" height="20" border="0" align="absmiddle"></a>&nbsp;<a href="?op=edit&dir_code=<%=StrUtil.UrlEncode(doc.getDirCode())%>&id=<%=doc.getID()%>&action=changeAttachOrders&direction=down&attachId=<%=am.getId()%>"><img src="images/arrow_down.gif" alt="<lt:Label res="res.label.webedit" key="down"/>" width="16" height="20" border="0" align="absmiddle"></a>
&nbsp;
<%if (am.getFileExt().equals("doc") || am.getFileExt().equals("xls")) {%>
<input name="button" type="button" class="singleboarder" onClick="javascript:editdoc(<%=doc.getID()%>, <%=am.getId()%>)" value="<%=SkinUtil.LoadString(request,"op_edit")%>" />
<%}%></td>
                      </tr>
                    </table>
			  <%}
			  }
			  %>			  </td>
            </tr>
            <tr>
              <td height="153" colspan=2 align=center bgcolor="#FFFFFF">
			  <table  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
                <tr>
                  <td bgcolor="#FFFFFF"><%
Calendar cal = Calendar.getInstance();
String year = "" + (cal.get(cal.YEAR));
String month = "" + (cal.get(cal.MONTH) + 1);
String filepath = "upfile/webeditimg/" + year + "/" + month;
%><object classid="CLSID:DE757F80-F499-48D5-BF39-90BC8BA54D8C" codebase="<%=request.getContextPath()%>/activex/webedit.cab#version=6,0,2,1" width=400 height=280 align="middle" id="webedit">
                      <param name="Encode" value="utf-8">
					  <param name="MaxSize" value="<%=Global.MaxSize%>"> <!--上传字节-->
 					  <param name="ForeColor" value="(255,255,255)">
                      <param name="BgColor" value="(107,154,206)">
                      <param name="ForeColorBar" value="(255,255,255)">
                      <param name="BgColorBar" value="(0,0,255)">
                      <param name="ForeColorBarPre" value="(0,0,0)">
                      <param name="BgColorBarPre" value="(200,200,200)">
                      <param name="FilePath" value="<%=filepath%>">
                      <param name="Relative" value="1">
                      <!--上传后的文件需放在服务器上的路径-->
                      <param name="Server" value="<%=request.getServerName()%>">
                      <param name="Port" value="<%=request.getServerPort()%>">
                      <param name="VirtualPath" value="<%=Global.virtualPath%>">
                      <param name="PostScript" value="<%=Global.virtualPath%>/fwebedit_do.jsp">
                      <param name="PostScriptDdxc" value="<%=Global.virtualPath%>/ddxc.jsp">
                      <param name="SegmentLen" value="204800">
					  <param name="InternetFlag" value="<%=Global.internetFlag%>">
                    </object>					</td>
                </tr>
              </table>              </td>
            </tr>
            <tr>
              <td height="30" colspan=2 align=center bgcolor="#FFFFFF">
			  <%
			  String action2 = "";
			  if (op.equals("add"))
			  	action2 = SkinUtil.LoadString(request,"op_add");
			  else
			  	action2 = SkinUtil.LoadString(request,"op_modify");
			  %>
			  <%if (templateId==-1) {%>
              <input name="cmdok2" type="button" class="singleboarder" value="<%=action2%>(<%=SkinUtil.LoadString(request,"res.label.webedit","duan_dian_upload")%>)" onClick="return SubmitWithFileDdxc()">
              <%}
			  if (templateId==-1) {%>
              <input name="cmdok3" type="button" class="singleboarder" value="<%=action2%>(<%=SkinUtil.LoadString(request,"res.label.webedit","per_thread")%>)" onClick="return SubmitWithFileThread()">
              <%}
			  if (templateId==-1) {%>
			  <input name="cmdok" type="button" class="singleboarder" value=" <%=action2%> " onClick="return SubmitWithFile()">
			  <%}%>
&nbsp;
<input name="notuploadfile" type="button" class="singleboarder" value="<%=action2%>(<%=SkinUtil.LoadString(request,"res.label.webedit","not_upload_file")%>)" onClick="return SubmitWithoutFile()">
&nbsp;
      <input name="cmdcancel" type="button" class="singleboarder" onClick="ClearAll()" value="<%=SkinUtil.LoadString(request,"res.label.webedit","clear")%>">
      <br>
&nbsp;<br>
      <%if (op.equals("edit")) {%>
	  <input name="editbtn" type="button" class="singleboarder" onClick="location.href='doc_abstract.jsp?id=<%=doc.getID()%>'" value=" <%=SkinUtil.LoadString(request,"res.label.webedit","abstract")%> ">
	  <%}%>
&nbsp;
<input name="remsg" type="button" class="singleboarder" onClick='alert(webedit.ReturnMessage)' value="<%=SkinUtil.LoadString(request,"res.label.webedit","return_info")%>">
&nbsp;
      <%if (op.equals("edit")) {
	  		String viewPage = "doc_show.jsp";
			PluginMgr pm = new PluginMgr();
			PluginUnit pu = pm.getPluginUnitOfDir(dir_code);
			if (pu!=null) {
				IPluginUI ipu = pu.getUI(request);
				viewPage = ipu.getViewPage();
			}
	  %>
<input name="remsg" type="button" class="singleboarder" onClick='window.open("<%=viewPage%>?id=<%=id%>")' value="<%=SkinUtil.LoadString(request,"res.label.webedit","browse")%>"> </td>
	  <%}%>
            </tr>
        </table>
    </form>
		<table width="100%"  border="0">
          <tr>
            <td align="center">
			<%if (doc!=null) {
				int pageNum = 1;
			%>
			<lt:Label res="res.label.webedit" key="artical_sum"/><%=doc.getPageCount()%><lt:Label res="res.label.webedit" key="pages"/>&nbsp;&nbsp;<lt:Label res="res.label.webedit" key="page"/>
            <%
					int pagesize = 1;
					int total = DocContent.getContentCount(doc.getID());
					int curpage,totalpages;
					Paginator paginator = new Paginator(request, total, pagesize);
					// 设置当前页数和总页数
					totalpages = paginator.getTotalPages();
					curpage	= paginator.getCurrentPage();
					if (totalpages==0)
					{
						curpage = 1;
						totalpages = 1;
					}
					
					String querystr = "op=edit&doc_id=" + id;
					out.print(paginator.getCurPageBlock("doc_editpage.jsp?"+querystr));
					%>
            <%if (op.equals("edit")) {
						if (doc.getPageCount()!=pageNum) {					
					%>
&nbsp;<a href="doc_editpage.jsp?op=add&action=insertafter&doc_id=<%=doc.getID()%>&afterpage=<%=pageNum%>"><lt:Label res="res.label.webedit" key="insert_after_current_page"/></a>
<%	}
					}%>
&nbsp;<a href="doc_editpage.jsp?op=add&doc_id=<%=doc.getID()%>"><lt:Label res="res.label.webedit" key="add_page"/></a>
<%}%>		
			</td>
          </tr>
          <tr>
            <form name="form3" action="?" method="post"><td align="center">
			<input name="newname" type="hidden">
			</td></form>
          </tr>
        </table>
	</TD>
  </TR>
</TABLE>

<iframe id="hideframe" name="hideframe" src="fwebedit_do.jsp" width=0 height=0></iframe>
</body>
<script>
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

function changeAttachName(attach_id, doc_id, nm) {
	var obj = findObj(nm);
	// document.frames.hideframe.location.href = "fwebedit_do.jsp?op=changeattachname&page_num=1&doc_id=" + doc_id + "&attach_id=" + attach_id + "&newname=" + obj.value
	form3.action = "fwebedit_do.jsp?op=changeattachname&page_num=1&doc_id=" + doc_id + "&attach_id=" + attach_id;
	form3.newname.value = obj.value;
	form3.submit();
}

function delAttach(attach_id, doc_id) {
	if (!window.confirm("<lt:Label res="res.label.webedit" key="del_confirm"/>")) {
		return;
	}
	document.frames.hideframe.location.href = "fwebedit_do.jsp?op=delAttach&page_num=1&doc_id=" + doc_id + "&attach_id=" + attach_id
}
</script>
</html>