
<%@page import="java.util.ArrayList"%>
<%@page import="java.net.URLDecoder"%>
<%
/************************************************************@@
  * Program Name	: report_list.jsp
  * Description		: /보고자/내문서함/종료함/보고자료 목록
  * Author			: 기현테크
  * Create Date		: 2010.11.26
  * History			:
@@************************************************************/
%>

<%@ page contentType="text/html; charset=UTF-8"
	import="java.net.URLEncoder" import="java.util.Calendar"
	import="java.util.Date" import="java.util.List"
	import="java.text.SimpleDateFormat"
	import="javax.jdo.PersistenceManager" import="javax.jdo.Transaction"
	import="kr.co.kihyun.beans.entity.*"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.beans.totsys.doc.Doc"
	import="kr.co.kihyun.lang.Encoder" import="kr.co.kihyun.lang.MInteger"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.moumi.Moumi"%>

<%@ 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);

        /********** Parameter **********/
	int strPage  = MInteger.parseInt(request.getParameter("strPage"), 1);
	String findOption = clearXSS(request.getParameter("findOption"),null);
	String findWord = clearXSS(Encoder.toJava(request.getParameter("findWord")),null);
	String reportType = clearXSS(Encoder.toJava(request.getParameter("reportType")),null);
  //String uri = URLEncoder.encode("report_list.jsp?reportType="+MString.checkNull(reportType)+"&findOption="+MString.checkNull(findOption)+"&findWord="+MString.checkNull(findWord), "UTF-8");


        String method = clearXSS(request.getParameter("method"),"");
        if(method.equals("GET")) findWord = URLDecoder.decode(MString.checkNull(request.getParameter("findWord")), "UTF-8");
  
	int wordLengthLimit = 30;

	tx.begin();

	MUser mUser = pm.getObjectById(MUser.class, usID);
        SysAuth sysAuth = mUser.getSysAuth();
      	List<TotReport> reports = null;
	Object filterValue = findWord;

	if(findOption != null && findOption.endsWith("Date"))
		filterValue = new SimpleDateFormat("yy-MM-dd").parse(findWord);


        if("COMP".equals(reportType))
		reports = mUser.getCompReports(pm, findOption, filterValue);
	else if("END".equals(reportType))
		reports = mUser.getUpperDept(pm).getCompReports(pm, findOption, filterValue);
       
		if(findOption != null && findOption.endsWith("Date"))
			filterValue = new SimpleDateFormat("yy-MM-dd").parse(findWord);
		reports = mUser.getRecogReports(pm, findOption, filterValue);



         int count=reports.size();
         List<TotReport> reports2 = new ArrayList<TotReport>();
        if(count>0 && findOption!=null && findOption.equals("totDoc.mUser.name2") && findWord!=null && findWord.length()>1)
        {
            for(int index=0;index<count;index++)
            {
                String tmp=reports.get(index).getUser(pm).getName(pm);
                if(tmp==null) continue;
                if(tmp.indexOf(findWord)>=0) reports2.add(reports.get(index));
            }
            reports=reports2;
            count=reports.size();
        }


	tx.rollback();

       String uri = URLEncoder.encode("report_list.jsp?reportType="+MString.checkNull(reportType)+"&findOption="+MString.checkNull(findOption),"UTF-8")+"&method=GET";
        

	/************ 리스트 페이지 구성 ************/
	int endPage = 0;
	int pageSize =0 ;
	int currentPage = 0;
	int absolutePage = 0;
	int currentPageSetUp = 0;
	int recordSize = 10;

	currentPage=strPage;

	if((reports.size()%recordSize) == 0){
		pageSize = (int)(reports.size()/recordSize);
	}else{
		pageSize = (int)(reports.size()/recordSize)+1;
	}

	currentPageSetUp = (int)(currentPage/10)*10;
	if (currentPage%10 == 0){
		currentPageSetUp-=10;
	}

	Date nowDate = new Date();

	String titleName = URLEncoder.encode(Moumi.getMessageBundle().getString("moumi.message.tot_report.recog") + Moumi.getMessageBundle().getString("moumi.message.tot_doc.box"), "UTF-8");

    String reportName = "";
	if("COMP".equals(reportType))
		reportName = Moumi.getMessageBundle().getString("moumi.message.tot_report.mySubmit") +Moumi.getMessageBundle().getString("moumi.message.tot_doc.doc");
	else if("END".equals(reportType))
		reportName = Moumi.getMessageBundle().getString("moumi.message.tot_report.end") +Moumi.getMessageBundle().getString("moumi.message.tot_doc.doc");

%>

<HTML>
<HEAD>
<TITLE><%=Moumi.getTitle()%></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<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/find.js"></script>
<script src="/totsys/common/js/popup.js"></script>
<script src="/totsys/common/js/mouse.js"></script>
<script>
			function leftAnc(){
				for(var i=1; i<=4; i++){
					top.frames['left'].document.all["link"+i].style.fontWeight="";
				}
				top.frames['left'].link2.style.fontWeight="bold";
			}
		
			function leftIncReload(){
				top.left.incFrame.location.reload();
			}
            function goEndPage(ttmp1,ttmp2)
            {
                var str="/totsys/totper/mydocbox/prssbox/reports/report_list.jsp?docType="+ttmp1+"&docID="+ttmp2+"&deptID=<%= dtID %>";
                parent.topx.menuSelect(1);
                location.href=str;
            }
            function viewNote(docID, userID, deptID){
				var width = 600;
				var height = 350;
				var leftpos = (screen.width - width) / 2;
				var toppos = (screen.height - height) / 2;
				window.open("/totsys/common/web/note/popup_doc_history.jsp?docID="+docID+"&deptID="+deptID+"&userID="+userID,"","width="+width+", height="+height+", toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left= "+ leftpos +" ,top= "+ toppos);
			}



            function changeDam()
            {
                nnn=$("input:checkbox[name=check]:checked").length;
                if(nnn==0) { alert("선택을하신후 담당변경 버튼을 클릭하세요."); return; }

                var res=new Array();
                $("input:checkbox[name=check]:checked").each(function(){
                    res.push($(this).val());
                });
                var height = screen.height;
				var width = screen.width;
				var leftpos = width / 2 - 350;
				var toppos = height / 2 - 350;
                frm=document.damdangForm;
                frm.reportID.value=res;
                frm.action="/totsys/repoper/mydocbox/returnbox/popup_rep_transfer5.jsp";
                frm.target='damdangForm';
                frm.method='post';
                win= window.open('', "damdangForm","width=607, height=541, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + leftpos + ",top=" + toppos);
				win.focus();
                frm.submit();
            }
		</script>
</HEAD>

<body style='' BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0"
	MARGINWIDTH="0" MARGINHEIGHT="0">
         <form name="damdangForm" method="post" >
        <input type="hidden" name="reportID" value="">
        <input type="hidden" name="reportType" value="<%=reportType%>">
        <input type="hidden" name="boxName" value="returnbox">
        <input type="hidden" name="hideUser" value="false">
    </form>
<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>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<%if("TEMP".equals(reportType)){%>
			<jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" />
			<%}else if("RECOG".equals(reportType)){%>
			<jsp:include page="/totsys/common/inc/title/title.jsp" flush="true">
				<jsp:param value="<%= titleName %>" name="title" />
			</jsp:include>
			<%}%>
			<tr>
				<td>
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr valign="top" class="toolbar">
						<td>
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td width="330">
								<form name="findForm" method="post" action="./report_list.jsp"
									onsubmit="return findCheck(this);" style="margin: 0px">
								<select name="findOption" class="inputtxt"
									onchange="showMSG(this.options[this.selectedIndex].value, msg)">
									<option value="totDoc.name"<%= "totDoc.name".equals(findOption) ? " selected" : "" %>><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.doc") %><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.name") %></option>
									<option value="totDoc.executionCode"<%= "totDoc.executionCode".equals(findOption) ? " selected" : "" %>><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.executionCode")%></option>
                                                                        <option value="totDoc.mUser.name"<%= "totDoc.mUser.name".equals(findOption) ? " selected" : "" %>>담당자</option>
                                                                        <option value="totDoc.mUser.name2"<%= "totDoc.mUser.name2".equals(findOption) ? " selected" : "" %>>제출자</option>
								</select> <input name="findWord" value="<%=MString.checkNull(findWord)%>"
									type="text" class="inputtxt" size="30" maxlength="30">
								<input name="reportType"
									value="<%=MString.checkNull(reportType)%>" type="hidden">
								<input type="image" src="/totsys/common/images/bt_search_inquiry.gif"
									border="0" align="middle" style="MARGIN: -3px 0px 0px 0px">
								</form>
								</td>
								<td><span id="msg" class="kecttep_date_search"
									style='display: none; padding-top: 5'>&nbsp;&nbsp;<%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.daySearchForm")%></span></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td width="100%" height="31" valign="top">
						<table border="1px" class="kecttep_list_table"
							bordercolor="#e3e3e3" width="100%" cellpadding="0"
							cellspacing="0">
							<tr valign="middle">
								<td width="130" align="center" nowrap class="kecttep_tdmenu"><%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.executionCode") %></td>
								<td align="center" class="kecttep_tdmenu" rowspan="1"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.doc")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.name")%></td>
								<td width="140" align="center" nowrap class="kecttep_sub_tdmenu"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.request")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.coporation")%></td>
								<td width="97" align="center" nowrap class="kecttep_sub_tdmenu"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.personInCharge")%></td>
								<td width="97" align="center" class="kecttep_tdmenu" rowspan="1"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.submit")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.person")%></td>
								<td width="97" align="center" class="kecttep_tdmenu"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.startDate")%></td>
								<td width="97" align="center" class="kecttep_tdmenu"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.endDate")%></td>
								<td width="97" align="center" nowrap class="kecttep_last_tdmenu"
									rowspan="1"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.remark")%></td>
							</tr>
					<%
                        int index = 0;     //배열에서 값을 꺼내오는 키값
						int nextCount = 0; //

						if(currentPage > 1){
							nextCount = ((currentPage-1)*recordSize);
						}

						tx.begin();

                      	for(int i = 0; (i < recordSize) && ((nextCount+i) < reports.size()); i++){
							index = nextCount+i;
                  	%>

							<tr style="padding-top: 3" valign="middle"
								onmouseover="this.style.backgroundColor='F9F9F9'"
								onmouseout="this.style.backgroundColor='white'" bgColor=#ffffff>

                            <% if(reportType.equals("COMP")) { %>
                                <td nowrap class="kecttep_graytd" height="25" align="center" width="50">
                                <input type="checkbox" name="check" id="checkBox" value=<%= reports.get(index).getId() %>>
                                </td>
                            <% } %>
								<td width="130" align="center" nowrap class="kecttep_graytd" height="25"
									align="center"><%= reports.get(index).getTotDoc().getExecutionCode() %>&nbsp;</td>
                                <%
                                    String name=reports.get(index).getUser(pm).getName(pm);
                                    int tmpb=-1;
                                    String iid=reports.get(index).getUser(pm).getId();
                                    if(iid!=null)
                                    {
                                       if(iid.equals(usID)) tmpb=1;
                                       else tmpb=0;
                                     }
                                    else tmpb=-1;

                                %>

                          <%if(tmpb==1 || tmpb==-1  || sysAuth.equals(SysAuth.SUB_SYSADM) || sysAuth.equals(SysAuth.SYSADM) ||sysAuth.equals(SysAuth.REPOADM)){ %>    <!--제출자아이디와 파라미터로받아온 값 비교 같으면 링크 sysAuth값 5,7,9 이면 링크-->
                            <%--
                            <%if(reports.get(index).getUser(pm).getId().equals(usID) || sysAuth.equals(SysAuth.SUB_SYSADM) || sysAuth.equals(SysAuth.SYSADM) ||sysAuth.equals(SysAuth.REPOADM)){ %>    <!--제출자아이디와 파라미터로받아온 값 비교 같으면 링크 sysAuth값 5,7,9 이면 링크-->
                         --%>
								<td nowrap class="kecttep_graytd">&nbsp;&nbsp;
                                    <a onmouseover="balloon_on('<%= reports.get(index).getTotDoc().getName() %>',this,10,4)"  onmouseout="balloon_off()"
									<%if(reports.get(index).getTotDoc().getEndDate().getTime() < nowDate.getTime()){%>
									style="color: red;" <%}%>
									href="/totsys/repoper/mydocbox/tempbox/report_view.jsp?doctName=<%=reports.get(index).getTotDoc().getName()%>&reportID=<%= reports.get(index).getId() %>&totperInfo=true&reportType=<%=reportType%>&repoadminID=<%=reports.get(index).getCurrentRepoadm() == null ? "" : reports.get(index).getCurrentRepoadm().getId()%>"><%= MString.getEllipsis(reports.get(index).getTotDoc().getName(),wordLengthLimit) %></a>
								</td>
                               <%}else{%>
                               <td onmouseover="balloon_on('<%= reports.get(index).getTotDoc().getName() %>',this,10,4)"  onmouseout="balloon_off()" nowrap class="kecttep_graytd" <%if(reports.get(index).getTotDoc().getEndDate().getTime() < nowDate.getTime()){%>
									style="color: red;" <%}%> >&nbsp;&nbsp; <%= MString.getEllipsis(reports.get(index).getTotDoc().getName(),wordLengthLimit)%> </td> <%} %>
								<td width="140" align="center" nowrap class="kecttep_graytd"><%= reports.get(index).getTotDoc().getDept(pm).getName() %></td>
								<td width="97" align="center" nowrap class="kecttep_graytd"><%= reports.get(index).getTotDoc().getOwnerName(pm) %></td>
                                <%
                                if(name==null && iid==null)
                                {
                                %>
                                <td width="97" align="center" nowrap class="kecttep_graytd">&nbsp;</td>
                                <%
                                } else {
                                %>
                                <td width="97" align="center" nowrap class="kecttep_graytd"><%= name %>(<%=iid %>)</td>
                                <%}%>

                                <%--
                               <td width="97" align="center" nowrap class="kecttep_graytd"><%= name %>(<%=iid %>)</td>
                            --%>








								<td width="97" align="center" nowrap class="kecttep_graytd"><%= reports.get(index).getTotDoc().getStartDate() == null ? "&nbsp;" : new SimpleDateFormat("yyyy-MM-dd").format(reports.get(index).getTotDoc().getStartDate()) %></td>
								<td width="97" align="center" nowrap class="kecttep_graytd"
									 <%
                                    String tmp2=new SimpleDateFormat("yyyy-MM-dd HH").format(reports.get(index).getTotDoc().getEndDate());
                                     String tstr = "시";
                                    if(tmp2.contains("9999-12-30")) tmp2="수동종료";
                                    if(tmp2.equals("수동종료")) tstr = "";
                                    if(!usID.equals(reports.get(index).getUser(pm).getId()))
                                    {%>
                                        style="color: red;" <%
                                    }%>>
                                    <%--
                                    <%= new SimpleDateFormat("yyyy-MM-dd").format(reports.get(index).getTotDoc().getEndDate()) %></td>
                                --%>
                                <%= tmp2 %><%=tstr%>
								</td>
								<td width="97" align="center" nowrap class="kecttep_last_graytd">

							<%if(reports.get(index).getProcess() == TotReportProcess.TEMP){%>
									<%=reports.get(index).getTotDoc().getProcess(pm)%>
								<%if(reports.get(index).getRecog() == Recog.RETURN_RECOG){ %>
									/<br />
									<font color="red"><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.giveBack")%></font>
								<%}%>
							<%}else{%>
									<%=Moumi.getMessageBundle().getString("moumi.message.tot_report.recogWaitDuring")%>
							<%}%>						
							</td>
							</tr>
					<%
						}
						tx.commit();
					%>
						</table>
						</td>
					</tr>

					<tr>
						<td height="15"></td>
					</tr>
					<%if(reports.size() > 0){%>
					<tr style="padding-top: 3" valign="middle">
						<td class="kecttep_board" colspan="10" align="center"><!------------------------------- 페이지수 나오는 부분 시작 ------------------------------->
						<jsp:include page="/totsys/common/inc/board/page.jsp" flush="true">
							<jsp:param name="uri" value="<%= uri %>" />
							<jsp:param name="pageSize" value="<%= pageSize %>" />
							<jsp:param name="currentPage" value="<%= currentPage %>" />
							<jsp:param name="currentPageSetUp"
								value="<%= currentPageSetUp %>" />
                                                        <jsp:param name="findWord" value='<%=URLEncoder.encode(MString.checkNull(findWord),"UTF-8")%>' />
						</jsp:include> <!------------------------------- 페이지수 나오는 부분 끝 ------------------------------->
						</td>
					</tr>
					<%}else{%>
					<tr>
						<td class="kecttep_none_tdmenu" colspan="10" height="25"
							align="center"><%= Moumi.getMessageBundle().getString("moumi.message.tot_report.tempStatus") %>
						<%= Moumi.getMessageBundle().getString("moumi.message.tot_doc.doc") %><%=Moumi.getMessageBundle().getString("moumi.message.tot_report.noOne")%></td>
					</tr>
					<%}%>

					<tr>
						<td height="2"></td>
					</tr>
					<input type="hidden" name="tmpFind"
						value="<%=MString.checkNull(findOption)%>">
					<script>
									if(tmpFind.value == "totDoc.docName"){
										findForm.findOption.selectedIndex=0;
									}else if(tmpFind.value == "totDoc.mDept.name"){
										findForm.findOption.selectedIndex=1;
									}else if(tmpFind.value == "totDoc.mUser.name"){
										findForm.findOption.selectedIndex=2;
									}else if(tmpFind.value == "totDoc.startDate"){
										findForm.findOption.selectedIndex=3;
									}else if(tmpFind.value == "totDoc.repoEndDate"){
										findForm.findOption.selectedIndex=4;
									}else if(tmpFind.value == "totDoc.mUser.name2"){
                                        findForm.findOption.selectedIndex=3;
                                    }
								</script>
				</table>
				</td>
				<td nowrap width="10"></td>
			</tr>
		</table>
		</td>
	</tr>
	<!------------------------------- top menu start ------------------------------->
	<%@ include file="/totsys/common/inc/buttom/buttom.jsp"%>
	<!------------------------------- top menu end ------------------------------->
</table>
</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();
}
%>
