
<%
		/************************************************************@@
		 * Program Name	: report_regist.jsp
		 * Description		: /보고자/내문서함/임시보고함/보고자료 변경
		 * Author				: 강원중
		 * Create Date		: 2004-11-06
		 * History				:
		@@************************************************************/
%>

<%@ page contentType="text/html; charset=UTF-8"
		 import="java.net.URLEncoder"
		 import="kr.co.kihyun.beans.user.HttpSSOLogin" import="java.net.*"
		 import="kr.co.kihyun.util.MUtil" import="kr.co.kihyun.lang.MString"
		 import="kr.co.kihyun.lang.Encoder" import="kr.co.kihyun.lang.MInteger"
		 import="kr.co.kihyun.lang.MLong"
		 import="kr.co.kihyun.text.html.ServletUtil"
		 import="kr.co.kihyun.moumi.Moumi"
		 import="kr.co.kihyun.moumi.report.MReport"
		 import="kr.co.kihyun.moumi.report.stat.StaticMReport"
		 import="kr.co.kihyun.moumi.doc.table.MTable"
		 import="kr.co.kihyun.moumi.doc.table.item.MItem"
		 import="kr.co.kihyun.moumi.report.MReportData"
		 import="kr.co.kihyun.beans.totsys.doc.Doc"
		 import="kr.co.kihyun.beans.totsys.report.Report"
		 import="kr.co.kihyun.beans.totsys.report.ReportView"
		 import="kr.co.kihyun.beans.totsys.report.tot.TotReportModifyer"
		 import="javax.jdo.PersistenceManager"
         import="javax.jdo.Transaction"
		 import="kr.co.kihyun.beans.entity.util.*"
		 import="kr.co.kihyun.beans.entity.*"%>

<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>

<%		PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
        Transaction tx = pm.currentTransaction();
		try {
			/********** session내의 userId **********/
			String usID = HttpSSOLogin.getLoginID(request);
			String dtID = HttpSSOLogin.getDeptID(request);
			String dpName = HttpSSOLogin.getDeptName(request);

			String savePath = Moumi.getRepoPerRoot().getPath() + "/fileUpload";//// 업로드된 파일의 임시 저장 경로

			/********* Parameter *********/
			Long reportID = MLong.parseLong(request.getParameter("reportID"));
			int rowCount = MInteger.parseInt(request.getParameter("rowCount"), 1);
			int delRowNum = MInteger.parseInt(request.getParameter("delRowNum"), 1);
			String modifyMode = clearXSS(request.getParameter("modifyMode"), "");

			TotReport totReport = pm.getObjectById(TotReport.class, reportID);

			boolean isEndDate = (new Doc()).isEndDate(totReport.getSlaveTotDoc().getId());  //하위 집계로 내린 문서가 종료 됐나..?

			int sendReportCount = new Report().getSendCount(totReport.getSlaveTotDoc().getId());
			if (sendReportCount < 1) {
				out.println("<SCRIPT language='Javascript'> \n");
				out.println("alert('보고된 자료가 없습니다.\\n이전 페이지로 이동합니다.')");
				out.println("</SCRIPT>");
				out.println(ServletUtil.getJavaScript("history.go(-1);"));
				return;
			}

			/********* report *********/
			TotReportModifyer totReportModifyManager = new TotReportModifyer(request, totReport.getSlaveTotDoc(), dtID, rowCount);

			String docName = totReportModifyManager.getDocName();
			int tableType = totReportModifyManager.getTableType();
			rowCount = totReportModifyManager.getRowCount();
			String insertForm = totReportModifyManager.getInsertForm();
			String baseInsertForm = totReportModifyManager.getInsertForm();
			String putValScript = totReportModifyManager.getPutValScript();
			String changeAllScript = totReportModifyManager.getChangeAllScript();
			String inDataJavaScript = totReportModifyManager.getInDataJavaScript();

			////////////////////////////////// 동적표에서만 사용 //////////////////////////////////
			String addJavaScript = "";
			String hiddenData = "";
			if (tableType == MTable.DYNA) {
				addJavaScript = totReportModifyManager.getAddJavaScript();
				hiddenData = totReportModifyManager.getHiddenData();
			}

			session.setAttribute("modifySuccTargetURI", "/totsys/repoper/mydocbox/tempbox/report_view.jsp?reportID=" + reportID);
%>

<HTML>
	<HEAD>
		<TITLE><%=Moumi.getTitle()%></TITLE>
		<link rel="stylesheet" href="/totsys/common/css/text.css"
			  type="text/css">
		<script src="/totsys/common/js/rollover.js"></script>
		<script src='/totsys/common/js/checkNum.js'></script>
		<script src="/totsys/common/js/util.js"></script>
		<script src="/totsys/common/js/calendar.js"></script>
		<script src="/totsys/common/js/drag.js"></script>
		<script src="/totsys/common/js/popup.js"></script>
		<script language="javascript">
			<%= putValScript%>
			function changeAll(){
			<%= changeAllScript%>
			}

			function insertData(){
			<%= inDataJavaScript.toString()%>
			}

			/********** userfile list와 serverfile list를 배열로 저장 **********/
			function viewFrm(num) {
				name = "fileUp"+num;
				eval(name + ".style.visibility = \"visible\";" );
				eval(name + ".style.display    = \"block\";" );
				dform.upFile.focus();
			}

			function viewNote(){
				var width = 600;
				var height = 435;
				var leftpos = (screen.width - width) / 2; 
				var toppos = (screen.height - height) / 2; 	
				window.open("/totsys/common/web/note/popup_note.jsp?docID=<%=totReport.getTotDoc().getId()%>","","width="+width+", height="+height+", toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left= "+ leftpos +" ,top= "+ toppos);
			}

			function deptCheck(){
				var url = '/totsys/common/web/dept_check/popup_reportsend.jsp?deptID=<%= dtID%>';
				var target = 'deptCheck';
				var width = 372;
				var height = 221;
				var align = 'center';
				var valign = 'middle';
				var scroll = 'no';
				var resize = 'no';				

				var farwindow = null;
				farwindow = getOpener(url, target, width, height, align, valign, scroll, resize);				
				farwindow.focus();
			}

			function totApply(){
				totApplyForm.submit();												
			}

		</script>


		<%if (tableType == MTable.DYNA) {%>
		<script language="javascript">
			//동적 표에서만 사용
			function insertData(){
			<%= inDataJavaScript%>
			}

			function lineAdd(){
			<%= addJavaScript%>
				modifyForm.rowCount.value='<%= (rowCount + 1)%>';
				modifyForm.modifyMode.value='addRow';
				modifyForm.submit();	
			}

			function lineDel(){
				var tmp = document.modifyForm.delRowNum.value;
				if(tmp == ''){
					alert('삭제할 라인을 입력하세요!');
					modifyForm.delRowNum.focus();
					return;
				}else if(isNaN(tmp)){
					alert('숫자를 입력하세요!');
					document.modifyForm.delRowNum.value = '';
					modifyForm.delRowNum.focus();
					return;
				}else if(1 > parseInt(tmp)){
					alert('1이상의 값을 입력 하시기 바랍니다.');
					document.modifyForm.delRowNum.value = '';
					modifyForm.delRowNum.focus();
					return;
				}else if(parseInt(tmp) > <%= rowCount%>){
					alert('현재보여진 라인보다 작은값 입력!');
					document.modifyForm.delRowNum.value = '';
					modifyForm.delRowNum.focus();
					return;
				}

			<%= addJavaScript%>
				modifyForm.rowCount.value='<%= (rowCount - 1)%>';
				modifyForm.modifyMode.value='delRow';
				modifyForm.submit();
			}

			function checkReport(){				
				if(1 > dform.rowCount.value){
					alert("보고해야할 자료가 존재하지 않습니다.");
					return;
				}
				openPopup('./popup_dept_check.jsp?deptID=<%= dtID%>', '350', '290', 'no');
			}

		</script>
		<%}%>


	</HEAD>

	<body style='' BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0"
		  MARGINWIDTH="0" MARGINHEIGHT="0" onload="insertData();">
		<table width="100%" height="70" border="0" cellpadding="0"
			   cellspacing="0">
			<jsp:include page="/totsys/common/inc/repoper/top/top.jsp" flush="true" />
			<tr>
				<td nowrap width="75">&nbsp;</td>
				<td valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td>
								<table width="100%" height="50" border="0" cellpadding="0"
									   cellspacing="0" background="images/title_bg.jpg">
									<tr>
										<td width="141"><img src="images/sub_title.jpg"></td>
										<td width="283"><img src="images/s_title_report_modify.jpg"></td>
										<!------------------------------- sub menu start ------------------------------->
										<jsp:include page="/totsys/common/inc/repoper/mydocbox/submenu.jsp" flush="true">
											<jsp:param name="prss" value="<%= TotReportProcess.TEMP%>" />
										</jsp:include>
										<!------------------------------- sub menu end ------------------------------->
									</tr>
								</table>
							</td>
						</tr>
						<!----  topbar  버튼 시작---->
						<tr>
							<td height="31" background="images/topbar_bg.jpg">
								<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0">
									<tr>
										<td nowrap width="12">&nbsp;</td>
										<td width="537">
											<a href="./report_list.jsp">
												<img src="images/bt_rep_list.gif" border="0">
											</a>
										</td>
										<td align="right">
											<table border="0" cellspacing="0" cellpadding="0">
												<tr>
													<td>
														<a href="#" onclick="viewNote();">
															<img src="images/bt_proposal.gif" border="0">
														</a>
													</td>
													<td width="5">&nbsp;</td>
													<td>
														<a href="#" onclick="viewFrm(1);">
															<img src="images/bt_fileadd.gif" border="0">
														</a>
													</td>
													<td width="5">&nbsp;</td>
													<td>&nbsp;</td>
												</tr>
											</table>
										</td>
										<td nowrap width="12">&nbsp;</td>
									</tr>
								</table>
							</td>
						</tr>
						<!----  topbar  버튼 끝---->
						<tr>
							<!---- 내용---->
							<td height="31" valign="top">
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr height="4">
										<td height="4" bgcolor="#9579C4" colspan="4"></td>
									</tr>
									<tr height="10">
										<td height="10"></td>
										<td height="10"></td>
										<td height="10"></td>
										<td height="10"></td>
									</tr>
									<!------------------------------- 공지사항 목록 시작 ------------------------------->
									<jsp:include page="/totsys/common/inc/board/doc/list.jsp" flush="true">
										<jsp:param name="docID" value="<%= totReport.getTotDoc().getId()%>" />
									</jsp:include>
									<!------------------------------- 공지사항 목록 끝 ------------------------------->
									<tr height="10">
										<td height="10"></td>
										<td height="10"></td>
										<td height="10"></td>
										<td height="10"></td>
									</tr>
									<tr>
										<td colspan="4" valign="top">
											<table width="100%" border="0" cellspacing="0" cellpadding="0">
												<!---- 문서내용 시작 ---->
												<tr>
													<td width="149" height="34">
														<img src="images/s_doc_contents.gif" width=149 height=34>
													</td>
													<td width="2418" colspan="3">&nbsp;</td>
												</tr>
												<tr height="1">
													<td height="1" colspan="4" bgcolor="D9D9D9"></td>
												</tr>
												<tr>
													<td height="50" colspan="4" valign="top" style="padding-left: 25; padding-right: 25; padding-bottom: 15; padding-top: 15;">
														<table width="100%" border="0" cellspacing="0" cellpadding="0">
															<tr height="6">
																<td width="6">
																	<img src="images/doct_tleft.jpg" width="6" height="6">
																</td>
																<td background="images/doct_tcenter.jpg"></td>
																<td width="6">
																	<img src="images/doct_tright.jpg" width="6" height="6">
																</td>
															</tr>
															<tr>
																<td background="images/doct_cleft.jpg">&nbsp;</td>
																<td valign="top">
																	<table width="100%" border="0" cellspacing="0" cellpadding="0">
																		<tr>
																			<td valign="top">
																				<table width="100%" border="0" cellspacing="0" cellpadding="0">
																					<!----  문서명 ---->
																					<tr>
																						<td width="81">
																							<img src="images/doc_title_name.gif" width="81" height="39">
																						</td>
																						<td bgcolor="F8F8F8" class="doc_title"><%= docName%></td>
																					</tr>
																					<tr height="1">
																						<td colspan="2">
																							<table width="100%" height="1" border="0" cellpadding="0" cellspacing="0">
																								<tr>
																									<td width="12" bgcolor="F8F8F8"></td>
																									<td height="1" background="images/doctitle_dot.gif">
																										<img src="spacer.gif" width="1" height="1">
																									</td>
																									<td width="12" bgcolor="F8F8F8"></td>
																								</tr>
																							</table>
																						</td>
																					</tr>
																				</table>
																			</td>
																		</tr>
																		<tr>
																			<td valign="top" bgcolor="F8F8F8" style="padding-top: 25; padding-bottom: 25; padding-left: 25; padding-right: 25;">
																				<form name="dform" method="post"
																					  action="/servlet/kr.co.kihyun.beans.totsys.report.HttpReportModifyer"
																					  enctype="multipart/form-data">
																					<input type="hidden" name="comment" value="<%= totReport.getNote()%>">
																					<input type="hidden" name="reportID" value="<%= reportID%>">
																					<input type="hidden" name="rowCount" value="<%= rowCount%>">
																					<input type="hidden" name="inForm" value='<%= URLEncoder.encode(baseInsertForm, "UTF-8")%>'>
																					<input type="hidden" name="tableType" value="<%= tableType%>">
																					<!---- 행추가, 행삭제 시작 ---->
																					<table width="100%" border="0" cellspacing="0" cellpadding="0">
																						<tr>
																							<td nowrap height="20"></td>
																						</tr>
																						<tr>
																							<td>
																								<!-------------------------------------------- 보고 폼 시작 -------------------------------------------->
																								<% out.println(insertForm);%>
																								<!-------------------------------------------- 보고 폼 끝   -------------------------------------------->
																							</td>
																						</tr>
																						<tr>
																							<td nowrap height="10" align="center"></td>
																						</tr>
																						<tr>
																							<td align="center">
																								<%if (changeAllScript.length() > 0) {%>
																								<img style="cursor: hand;" onClick='changeAll();changeAll();changeAll();changeAll();' src="images/bt_cal.gif" border="0">
																								<%}%>
																							</td>
																						</tr>
																						<tr>
																							<td><!-- 파일 첨부 시작 -->
																								<div id='fileUp1' style='visibility: hidden; display: none'>
																									<table width="100%" border="0" cellspacing="3" cellpadding="3">
																										<!---- 첨부파일 찾아보기 ---->
																										<tr height="1" valign="top">
																											<td height="1" colspan="3" bgcolor="cccccc"></td>
																										</tr>
																										<!---- 파일 찾아보기 ---->
																										<tr>
																											<td height="30" colspan="2" style="padding-left: 10;"">
																												<b><font color="#FF6600">+&nbsp;</font>첨부파일 :</b>
																												<input type=file size="72" name="upFile" class="inputtxt">
																											</td>
																										</tr>
																										<!---- 기존파일 / 첨부파일 삭제 ---->
																										<tr>
																											<%
																											for (String fileName : totReport.getAttachments().keySet()) {
																											%>
																											<td width="433" height="30" style="padding-left: 10;"">
																												<b><font color="#FF6600">+&nbsp;</font>기존파일 :</b>&nbsp;
																												<a href="/servlet/kr.co.kihyun.text.html.HttpViewer?saveAs=<%= URLEncoder.encode(fileName, "UTF-8") %>&fileName=<%= fileName %>&reportID=<%= totReport.getId() %>" target="hiddenIframe">
																													<%= fileName %>
																												</a>
																											</td>
																											<td width="677" style="padding-left: 10;">
																												<input type=checkbox name=dropfile value=1>첨부파일 삭제</td>
																											<%
																											}
																											%>
																										</tr>
																										<tr>
																											<!---- 메세지 ---->
																										<tr>
																											<td colspan="2" style="padding-left: 20;">
																												<img src="images/user_list_icon.gif" align="absmiddle">
																												<font color="#FF6600">첨부 파일을 다시 등록하시면 기존 파일은 삭제됩니다.</font>
																											</td>
																										</tr>
																										<tr height="1" valign="top">
																											<td height="1" colspan="3" bgcolor="cccccc"></td>
																										</tr>
																									</table>
																								</div>
																								<!-- 파일 첨부 끝 -->
																							</td>
																							<!-- dform end -->
																						</tr>
																						<tr height="1">
																							<td height="1" bgcolor="cccccc"></td>
																						</tr>
																						<tr>
																							<td height="37" align="center">
																								<table border="0" cellspacing="0" cellpadding="0">
																									<tr>
																										<td>
																											<a href="#" onClick="deptCheck();">
																												<img src="images/bt_reportsend.gif" border="0">
																											</a>
																										</td>
																										<td width="10">&nbsp;</td>
																										<td>
																											<img style="cursor: hand;" onclick="dform.reset();" src="images/bt_data_del.gif" border="0">
																										</td>
																										<td width="10">&nbsp;</td>
																										<td>
																											<a href="#" onClick='history.back();'>
																												<img src="images/bt_cancel2.gif" border="0">
																											</a>
																										</td>
																									</tr>
																									<form name="totApplyForm" method="post" action="./report_modify.jsp">
																										<input type="hidden" name="reportID" value="<%= reportID%>">
																										<input type="hidden" name="rowCount" value="<%= rowCount%>">
																										<input type="hidden" name="delRowNum" value="<%= delRowNum%>">
																										<input type="hidden" name="modifyMode" value="<%= modifyMode%>">
																									</form>
																								</table>
																							</td>
																						</tr>
																					</table>
																				</form>
																			</td>
																		</tr>
																	</table>
																</td>
																<td background="images/doct_cright.jpg">&nbsp;</td>
															</tr>
															<tr HEIGHT=7>
																<td height="7">
																	<img src="images/doct_bleft.jpg" WIDTH=6 HEIGHT=7>
																</td>
																<td height="7" background="images/doct_bcenter.jpg"></td>
																<td height="7">
																	<img src="images/doct_bright.jpg" WIDTH=6 HEIGHT=7>
																</td>
															</tr>
														</table>
													</td>
													<!---- 문서내용 끝---->
												</tr>
												<tr height="1">
													<td height="1" colspan="4" bgcolor="D9D9D9"></td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td colspan="3" align="center" valign="top">&nbsp;</td>
									</tr>
								</table>
							</td>
						</tr>
						<!----  bottom bar  버튼 시작 ---->
						<tr>
							<td height="31" valign="top">
								<table width="100%" height="36" border="0" cellpadding="0" cellspacing="0">
									<tr>
										<td nowrap width="12" background="images/bottombar_bg.jpg">&nbsp;</td>
										<td valign="top" background="images/bottombar_bg.jpg" style="padding-top: 6;">
											<a href="./report_list.jsp">
												<img src="images/bt_rep_list.gif" border="0">
											</a>
										</td>
										<td align="right" valign="top" background="images/bottombar_bg.jpg" style="padding-top: 6;">&nbsp;</td>
										<td nowrap width="12" background="images/bottombar_bg.jpg">&nbsp;</td>
									</tr>
								</table>
							</td>
						</tr>
						<!----  bottom bar  버튼 끝 ---->
					</table>
				</td>
				<td nowrap width="75">&nbsp;</td>
			</tr>
		</table>
                <iframe name="hiddenIframe" width="0" height="0" style="display: none;"></iframe>
	</BODY>
</HTML>
<%
		} catch (Exception ex) {
			ex.printStackTrace();
			out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/servlet/kr.co.kihyun.beans.user.HttpSSOLogin?mode=logout';"));
		} finally {
            if(tx.isActive())
            tx.rollback();
			pm.close();
		}
%>
