
<%
/************************************************************@@
  * Program Name	: tot_report_regist.jsp
  * Description		: /보고자/내문서함/임시보고함/보고자료 변경
  * Author			: 강원중
  * Create Date		: 2004-11-06
  * History			: - 연계문서의 자료입력사항 수정 못하게 막음 . 풀기 위해선 body의 onLoad 삭제 해주면 됨.
@@************************************************************/
%>

<%@ page contentType="text/html; charset=UTF-8"
	import="java.net.URLEncoder"
	import="kr.co.kihyun.beans.user.HttpSSOLogin" import="java.net.*"
	import="java.util.Date" import="java.text.SimpleDateFormat"
	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);

	/********* Parameter *********/
	Long reportID = MLong.parseLong(request.getParameter("reportID"));
	int rowCount = MInteger.parseInt(request.getParameter("rowCount"), 1);
	int repoState = MInteger.parseInt(request.getParameter("repoState"), 0);
	int delRowNum = MInteger.parseInt(request.getParameter("delRowNum"), 1);
	String modifyMode = clearXSS(request.getParameter("modifyMode"),"");
	String tables = MString.checkNull( Encoder.toJava(request.getParameter("tables")) );
	String tableRows =  MString.checkNull( Encoder.toJava(request.getParameter("tableRows")) );

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

	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(-2);"));
		return;
	}

	if(!new Doc().isEndDate(totReport.getSlaveTotDoc().getId())){
	    out.println("<SCRIPT language='Javascript'> \n");
		out.println("if(confirm('집계가 "+new SimpleDateFormat("yyyy'년 'MM'월 'dd'일'").format(totReport.getSlaveTotDoc().getEndDate())+" 까지입니다. "+sendReportCount+"개 부서가 제출하였습니다.\\n\\n제출받은 자료를 상위부서로 제출하기 위하여 집계합니다.\\n\\n계속 진행하시겠습니까?')){}else{history.go(-2)}");
		out.println("</SCRIPT>");
	}

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

	String docName = totReportModifyManager.getDocName();
	int tableType = totReportModifyManager.getTableType();
	String tableTypes = totReportModifyManager.getTableTypes();
	rowCount = totReportModifyManager.getRowCount();
	String insertForm = totReportModifyManager.getInsertForm();
	String baseInsertForm = totReportModifyManager.getInsertForm();
	String putValScript = totReportModifyManager.getPutValScript();
	String changeAllScript = totReportModifyManager.getChangeAllScript();
	String inDataJavaScript = totReportModifyManager.getInDataJavaScript();
	if(tableRows.equals("") || tableRows==null){
		tableRows = totReportModifyManager.getTableRows();
	}

	if(tableRows.equals("") || tableRows==null){
			tableRows = tableTypes.replaceAll("0","1");
	}

	// table들 중 하나라도 동적인 표가 존재한다면 tableType를 동적표로 바꾸어 준다.
	if(tableTypes.indexOf("1")==-1){
		tableType = MTable.STATIC;
	}else{
		tableType = MTable.DYNA;
	}

	String addJavaScript = "";
	String hiddenData = "";
	if(tableType == MTable.DYNA){
		addJavaScript = totReportModifyManager.getAddJavaScript();
		hiddenData = totReportModifyManager.getHiddenData();
	}

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

<HTML>
<HEAD>
<TITLE><%=Moumi.getTitle()%></TITLE>
<link rel="stylesheet" href="/totsys/common/css/text.css"
	type="text/css">
<link rel="stylesheet" href="/totsys/common/css/kecttep.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 target = 'deptCheck';
				var width = 372;
				var height = 221;
				var align = 'center';
				var valign = 'middle';
				var scroll = 'no';
				var resize = 'no';

				<%if (changeAllScript.length() > 0) {%>
					changeAll();changeAll();changeAll();changeAll();
				<%}%>

				dform.submit();
			}

		<%if(tableType == MTable.DYNA){%>
			//동적 표에서만 사용
			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 %>&deptName=<%= dpName %>', '350', '290', 'no');
			}

		</script>
<%}%>
</HEAD>

<body style='' BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0"
	MARGINWIDTH="0" MARGINHEIGHT="0" onload="insertData();deptCheck();">
<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="0"></td>
		<td valign="top">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" />
			<tr>
				<td>
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td width="537"><a
							href="/totsys/repoper/mydocbox/returnbox/report_list.jsp"><img
							src="images/bt_doc_list.gif" border="0"></a></td>
						<td align="right">&nbsp;</td>
					</tr>
				</table>
				</td>
			</tr>
			<!----  topbar  버튼 끝---->

			<!--1픽셀 띄우기-->
			<tr>
				<td height="1"></td>
			</tr>

			<!--파란색 밑줄-->
			<tr>
				<td bgcolor="6891cb" height="2"></td>
			</tr>

			<!--1픽셀 띄우기-->
			<tr>
				<td height="20"></td>
			</tr>

			<tr>
				<!---- 내용---->
				<td height="31" valign="top">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td colspan="4" valign="top">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td height="50" colspan="4" 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 valign="top" bgcolor="F8F8F8"
													style="padding-top: 25; padding-bottom: 25; padding-left: 25; padding-right: 25;">
												<!---- 행추가, 행삭제 시작 ---->
												<table width="100%" border="0" cellspacing="0"
													cellpadding="0">
													<tr>
														<td nowrap height="20"></td>
													</tr>
													<tr>
														<td valign="top"
															style="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="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 %>"> <input type="hidden"
															name="tableTypes" value="<%= tableTypes %>"> <input
															type="hidden" name="tableRows" value="<%= tableRows%>">
														<!-------------------------------------------- 보고 폼 시작 -------------------------------------------->
														<%
																							out.println(insertForm);
																							 %> <!-------------------------------------------- 보고 폼 끝   -------------------------------------------->
														</td>
													</tr>

													<tr>
														<td height="15"></td>
													</tr>

													<!--세미타이틀-->
													<tr>
														<td colspan="4">
														<table border="0" width="100%" cellpadding="0"
															cellspacing="0">
															<tr>
																<td style="width: 14"><img src="images/ico_1.gif"></td>
																<td class="kecttep_title" style="padding-left: 5"
																	align="left" width="100%">의견 및 관련자료</td>
																<td>&nbsp;</td>
																<td>&nbsp;</td>
															</tr>
														</table>
														</td>
													</tr>
													<tr>
														<td height="5"></td>
													</tr>

													<tr>
														<td><textarea name="comment"
															style="width: 100%; height: 60;"><%= totReport.getNote() %></textarea>
														</td>
													</tr>
													<tr>
														<td><!-- 파일 첨부 시작 -->
														<div id='fileUp1'>
														<table width="100%" border="0" cellspacing="3"
															cellpadding="3">
															<!---- 첨부파일 찾아보기 ---->
															<!---- 파일 찾아보기 ---->
															<tr>
																<td><input type=file style="width: 100%"
																	name="upFile" class="inputtxt"></td>
															</tr>
														</table>
														</div>
														<!-- 파일 첨부 끝 --></td>
														</form>
														<!-- dform end -->
													</tr>
													<tr>
														<td height="37" align="center">
														<table border="0" cellspacing="0" cellpadding="0">
															<tr>
																<%if (changeAllScript.length() > 0) {%>
																<td><img style="cursor: hand;"
																	onClick='changeAll();changeAll();changeAll();changeAll();'
																	src="images/bt_in_cal.gif" border="0"></td>
																<td width="3"></td>
																<%}%>
																<td><a href="#" onClick="deptCheck();"><img
																	src="images/bt_reportsend.gif" border="0"></a></td>
																<td width="3">&nbsp;</td>
																<td><img style="cursor: hand;"
																	onclick="dform.reset();" src="images/bt_data_del.gif"
																	border="0"></td>
																<td width="3">&nbsp;</td>
																<td><a href="#" onClick='history.back();'><img
																	src="images/bt_cancel2.gif" border="0"></a></td>
															</tr>
														</table>
														</td>
													</tr>
												</table>
												</td>
											</tr>
										</table>
										</td>
										<!---- 문서내용 끝---->
									</tr>
								</table>
								</td>
							</tr>

							<!--파란색 밑줄-->
							<tr>
								<td bgcolor="6891cb" height="2"></td>
							</tr>
							<!--1픽셀 띄우기-->
							<tr>
								<td height="1"></td>
							</tr>

							<!----  bottom bar  버튼 시작 ---->
							<tr>
								<td valign="top">
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
									<tr>
										<td valign="top"><a href="./report_list.jsp"><img
											src="images/bt_doc_list.gif" border="0"></a></td>
										<td align="right">&nbsp;</td>
									</tr>
								</table>
								</td>
							</tr>
							<!----  bottom bar  버튼 끝 ---->
						</table>
						</td>
						<td nowrap width="10">&nbsp;</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</BODY>
<div id="SetWin" style="position: absolute; visibility: hidden; width: 100px; height: 100px; background: silver; border: 1px solid #333333; line-height: 1.4em; padding: 3px 3px"></div>
</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();
}
%>
