<%@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");
        String uri = URLEncoder.encode("report_list.jsp?reportType="+MString.checkNull(reportType)+"&findOption="+MString.checkNull(findOption),"UTF-8")+"&method=GET";

	int wordLengthLimit = 30;

	tx.begin();

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

	if("READY".equals(reportType)){
		Object filterValue = findWord;
		if(findOption != null && findOption.endsWith("Date"))
			filterValue = new SimpleDateFormat("yy-MM-dd").parse(findWord);
//		reports = mUser.getSavedReports(pm, findOption, filterValue);
//		reports = mUser.getUpperDept(pm).getDeptSavedReports(pm, findOption, filterValue);
        //reports = mUser.getUpperDept(pm).getDeptApproveReports(pm, findOption, filterValue);
        reports = mUser.getRecogReports(pm, findOption, filterValue);        
	}else if("COMPLETE".equals(reportType)){
		Object filterValue = findWord;
		if(findOption != null && findOption.endsWith("Date"))
			filterValue = new SimpleDateFormat("yy-MM-dd").parse(findWord);
//		reports = mUser.getSavedReports(pm, findOption, filterValue);
//		reports = mUser.getUpperDept(pm).getDeptSavedReports(pm, findOption, filterValue);
        //reports = mUser.getUpperDept(pm).getDeptApproveReports(pm, findOption, filterValue);
        reports = mUser.getRecogReports(pm, findOption, filterValue);
	}
  /*제출진행일대 데이타 가져옴*/
  /*else{
		Object filterValue = findWord;
		if(findOption != null && findOption.endsWith("Date"))
			filterValue = new SimpleDateFormat("yy-MM-dd").parse(findWord);
		//reports = mUser.getRecogReports(pm, findOption, filterValue);
        reports = mUser.getUpperDept(pm).getDeptApproveReports(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;
        }

	tx.rollback();

	/************ ????? ?????? ???? ************/
	int endPage = 0;
	int pageSize =0 ;
	int currentPage = 0;
	int absolutePage = 0;
	int currentPageSetUp = 0;
	int recordSize = 15;

	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 = Moumi.getMessageBundle().getString("moumi.message.tot_report.recog") + Moumi.getMessageBundle().getString("moumi.message.tot_doc.box");
%>
<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;
            }
		</script>
</HEAD>

<body style='' BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0"
	MARGINWIDTH="0" MARGINHEIGHT="0">
<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="10"></td>
		<td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">

       <jsp:include page="/totsys/common/inc/title/title_approve.jsp" flush="true">
        <jsp:param value='<%= URLEncoder.encode(titleName,"UTF-8")%>' name="title" />
          <jsp:param value='<%= URLEncoder.encode(reportType,"UTF-8")%>' name="reportType" />
        </jsp:include>
            
			<tr>
				<td>
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr  class="toolbar">
						<td>
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td width="500">
								<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; '>&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="2px" class="kecttep_list_table"
							bordercolor="#e3e3e3" width="100%" cellpadding="0"
							cellspacing="0">
							<tr valign="middle">
								<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_report.status")%></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>





                                <%
                                    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/approve/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"
									<%
                                    boolean flag=false;
                                    long temp1=reports.get(index).getTotDoc().getEndDate().getTime();
                                    String temp2=new SimpleDateFormat("yyyy-MM-dd HH").format(reports.get(index).getTotDoc().getEndDate());
                                    String tstr = "??";
                                    if(temp2.indexOf("9999")>-1) flag=true;
                                    if(flag == true) tstr = "";
                                    if(temp1 < nowDate.getTime())
                                    {%>
                                        style="color: red;" <%
                                    }%>>
                                    <%--
									<%= reports.get(index).getTotDoc().getEndDate() == null ? "&nbsp;" : new SimpleDateFormat("yyyy-MM-dd").format(reports.get(index).getTotDoc().getEndDate()) %>
                                --%>
                                        <%= flag==true ? "????????" : temp2 %><%=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")%>
							<%}%>
							<%if(reports.get(index).getSlaveTotDoc() != null){
                                String ttmp="";
                                TotDocProcess tmp=reports.get(index).getSlaveTotDoc().getProcess(pm);
                                if(tmp==TotDocProcess.END) ttmp="END";
                                else if(tmp==TotDocProcess.FORM) ttmp="FROM";
                                else if(tmp==TotDocProcess.REG) ttmp="REG";
                                else if(tmp==TotDocProcess.PRSS) ttmp="PRSS";
                                else if(tmp==TotDocProcess.SUBMIT) ttmp="SUBMIT";
                                else if(tmp==TotDocProcess.END) ttmp="END";
                                else if(tmp==TotDocProcess.CANCEL) ttmp="CANCEL";
                                else if(tmp==TotDocProcess.READ) ttmp="READ";
                                %>
									<br />
									<%-- <a href="/totsys/totper/mydocbox/prssbox/reports/report_list.jsp?docType=<%= ttmp %>&docID=<%= reports.get(index).getSlaveTotDoc().getId() %>&deptID=<%= dtID %>">[<%=TotDocType.SUB_DOC_LIST %>]</a><br> --%>
                                    <a href="javascript:goEndPage('<%=ttmp%>','<%= reports.get(index).getSlaveTotDoc().getId() %>');">[<%=TotDocType.SUB_DOC_LIST %>]</a><br>

							<%}%>
								</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();
}
%>

