package jeus_jspwork._moniter._search;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.List;
import org.kldp.ebmsh.moniter.persistant.SearchResult;
import java.util.ArrayList;
import java.util.Calendar;
import org.kldp.ebmsh.moniter.persistant.EbmsMoniterManager;

public final class _500_messageSearchView_5fjsp extends jeus.servlet.jsp2.runtime.HttpJspBase
    implements jeus.servlet.jsp2.runtime.JspSourceDependent {

  private static java.util.Vector _jspx_dependants;

  public java.util.List getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html; charset=euc-kr");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");

	List searchResultList = new ArrayList();
	long searchResultCount = 0;
	int currentPage = 1;
	int perPageContentCount = 10;
	String parameter = "";
	
	String searchType = request.getParameter("searchType");
	
	if( searchType != null ) {
		if( searchType.equals("documentId") ) {
	// DocumentId로 검색
	String documentId = request.getParameter("documentId");
	
	String pageStr = request.getParameter("page");
	
	if( pageStr != null )
		currentPage = Integer.parseInt(pageStr);
	
		parameter = "searchType=" + searchType + "&documentId=" + documentId;
		
		EbmsMoniterManager bizboxMoniterManager = new EbmsMoniterManager();
		
		searchResultList = bizboxMoniterManager.searchReceiveMessagesByDocumentId(documentId, currentPage);
		searchResultCount = bizboxMoniterManager.searchReceiveMessageCountByDocumentId(documentId);
	}
	else if( searchType.equals("messageId") ) {
		// MessageId로 검색
		String messageId = request.getParameter("messageId");
		
		String pageStr = request.getParameter("page");
		
		if( pageStr != null )
			currentPage = Integer.parseInt(pageStr);
			
			parameter = "searchType=" + searchType + "&messageId=" + messageId;
			
			EbmsMoniterManager bizboxMoniterManager = new EbmsMoniterManager();
			
			SearchResult searchResult = null;
			
			searchResult = bizboxMoniterManager.searchReceiveMessageByMessageId(messageId);
			
			if( searchResult != null ) {
				searchResultList.add(searchResult);
				
				searchResultCount = 1;
			}
		}
		else if( searchType.equals("period") ) {
			// Period로 검색
			int startYear = Integer.parseInt(request.getParameter("startYear"));
			int startMonth = Integer.parseInt(request.getParameter("startMonth"));
			int startDay = Integer.parseInt(request.getParameter("startDay"));
			
			int endYear = Integer.parseInt(request.getParameter("endYear"));
			int endMonth = Integer.parseInt(request.getParameter("endMonth"));
			int endDay = Integer.parseInt(request.getParameter("endDay"));
				
			String pageStr = request.getParameter("page");
			
			if( pageStr != null )
				currentPage = Integer.parseInt(pageStr);
				
			parameter = "searchType=" + searchType + "&startYear=" + startYear + "&startMonth=" + startMonth + "&startDay=" + startDay + "&endYear=" + endYear + "&endMonth=" + endMonth + "&endDay=" + endDay;		
				
			Calendar startCalendar = Calendar.getInstance();
			Calendar endCalendar = Calendar.getInstance();
			
			startCalendar.set(startYear, startMonth-1, startDay);
			endCalendar.set(endYear, endMonth-1, endDay);
			
			EbmsMoniterManager bizboxMoniterDAO = new EbmsMoniterManager();
			searchResultList = bizboxMoniterDAO.searchReceiveMessagesByPeriod(startCalendar.getTimeInMillis(), endCalendar.getTimeInMillis(), currentPage);
			searchResultCount = bizboxMoniterDAO.searchReceiveMessageCountByPeriod(startCalendar.getTimeInMillis(), endCalendar.getTimeInMillis());
		}
	}

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<!--검색-->\r\n");
      out.write("<table width=\"100%\" height=\"45\" border=\"0\" cellpadding=\"0\"\r\n");
      out.write("\tcellspacing=\"1\" bgcolor=\"CECECF\">\r\n");
      out.write("\t<tr>\r\n");
      out.write("\t\t<td bgcolor=\"F8F8F8\">\r\n");
      out.write("\t\t\t<form action=\"messageSearch.jsp\" style=\"margin:0px;padding:0px;\"\r\n");
      out.write("\t\t\t\tname=\"searchForm\">\r\n");
      out.write("\t\t\t\t<select class=\"selectBox\" name=\"searchType\"\r\n");
      out.write("\t\t\t\t\tOnChange=\"conditionChanged(this);\" style=\"margin-left:10px\">\r\n");
      out.write("\t\t\t\t\t<option value=\"documentId\" selected>\r\n");
      out.write("\t\t\t\t\t\t문서 ID\r\n");
      out.write("\t\t\t\t\t</option>\r\n");
      out.write("\r\n");
      out.write("\t\t\t\t\t<option value=\"messageId\">\r\n");
      out.write("\t\t\t\t\t\t메시지 ID\r\n");
      out.write("\t\t\t\t\t</option>\r\n");
      out.write("\r\n");
      out.write("\t\t\t\t\t<option value=\"period\">\r\n");
      out.write("\t\t\t\t\t\t기간\r\n");
      out.write("\t\t\t\t\t</option>\r\n");
      out.write("\t\t\t\t</select>\r\n");
      out.write("\r\n");
      out.write("\t\t\t\t<span id=\"condition_detail\"\r\n");
      out.write("\t\t\t\t\tstyle=\"text-align:center; vertical-align:middle; width:620px\">\r\n");
      out.write("\t\t\t\t\t<input name=\"documentId\" type=\"text\" size=\"100\" maxlength=\"255\" />\r\n");
      out.write("\t\t\t\t</span>\r\n");
      out.write("\r\n");
      out.write("\t\t\t\t<span align=\"right\" style=\"vertical-align:middle; margin-left:10px\">\r\n");
      out.write("\t\t\t\t\t<img src=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/btn_search.gif\" width=\"79\"\r\n");
      out.write("\t\t\t\t\t\theight=\"24\" onClick=\"searchForm.submit();\"> </span>\r\n");
      out.write("\t\t\t</form>\r\n");
      out.write("\t\t</td>\r\n");
      out.write("\t</tr>\r\n");
      out.write("</table>\r\n");
      out.write("<!--/검색-->\r\n");
      out.write("\r\n");
      out.write("<br>\r\n");
      out.write("<table width=\"100%\" height=\"39\" border=\"0\" cellpadding=\"0\"\r\n");
      out.write("\tcellspacing=\"0\">\r\n");
      out.write("\t<tr>\r\n");
      out.write("\t\t<td background=\"sub/search_bg.gif\"\r\n");
      out.write("\t\t\tstyle=\"PADDING-RIGHT: 10px; PADDING-LEFT: 10px;\">\r\n");
      out.write("\t\t\t검색어가\r\n");
      out.write("\t\t\t<span class=\"style1\">");
      out.print(searchResultCount);
      out.write(" </span>개 검색되었습니다.\r\n");
      out.write("\t\t</td>\r\n");
      out.write("\t</tr>\r\n");
      out.write("</table>\r\n");
      out.write("\r\n");
      out.write("<br>\r\n");
      out.write("<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\"\r\n");
      out.write("\tcellspacing=\"0\">\r\n");
      out.write("\t<tbody>\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td width=\"15%\" height=\"30\" align=\"center\"\r\n");
      out.write("\t\t\t\tbackground=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/td_bg.gif\">\r\n");
      out.write("\t\t\t\t문서ID\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"27%\" align=\"center\"\r\n");
      out.write("\t\t\t\tbackground=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/td_bg.gif\">\r\n");
      out.write("\t\t\t\t메세지ID\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"16%\" align=\"center\"\r\n");
      out.write("\t\t\t\tbackground=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/td_bg.gif\">\r\n");
      out.write("\t\t\t\t받은시간\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"22%\" align=\"center\"\r\n");
      out.write("\t\t\t\tbackground=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/td_bg.gif\">\r\n");
      out.write("\t\t\t\t메세지 처리상태\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"20%\" align=\"center\"\r\n");
      out.write("\t\t\t\tbackground=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/td_bg.gif\">\r\n");
      out.write("\t\t\t\t어플리케이션 처리상태\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\r\n");
      out.write("\t\t");

		if (searchResultList == null || searchResultList.isEmpty()) {
		
      out.write("\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td colspan=\"5\" style=\"text-align:center\">\r\n");
      out.write("\t\t\t\t검색 결과가 없습니다.\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td colspan=\"5\" align=\"center\" bgcolor=\"#f0f0f0\"></td>\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\t\t");

				} else {
				int searchResultSize = searchResultList.size();

				for (int i = 0; i < searchResultSize; i++) {
					SearchResult searchResult = (SearchResult) searchResultList
					.get(i);
		
      out.write("\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td height=\"20\" align=\"center\">\r\n");
      out.write("\t\t\t\t");

							String documentId = searchResult.getDocumentId();

							if (documentId == null) {
				
      out.write("\r\n");
      out.write("\t\t\t\t<a\r\n");
      out.write("\t\t\t\t\thref=\"messageInfo.jsp?ocumentId=&messageId=");
      out.print(searchResult.getMessageId());
      out.write("\" />-</a>\r\n");
      out.write("\t\t\t\t");

				} else {
				
      out.write("\r\n");
      out.write("\t\t\t\t<a\r\n");
      out.write("\t\t\t\t\thref=\"messageInfo.jsp?documentId=");
      out.print(searchResult.getDocumentId());
      out.write("&messageId=");
      out.print(searchResult.getMessageId());
      out.write("\" />");
      out.print(documentId);
      out.write("\r\n");
      out.write("\t\t\t\t</a>\r\n");
      out.write("\t\t\t\t");

				}
				
      out.write("\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"27%\" align=\"center\">\r\n");
      out.write("\t\t\t\t");
      out.print(searchResult.getMessageId());
      out.write("\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"16%\" align=\"center\">\r\n");
      out.write("\t\t\t\t");
      out.print(searchResult.getReceiveTime());
      out.write("\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"22%\" align=\"center\">\r\n");
      out.write("\t\t\t\t");
      out.print( searchResult.getEbxmlMessageStatus() );
      out.write("\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"20%\" align=\"center\">\r\n");
      out.write("\t\t\t\t");
      out.print( searchResult.getBsiMessageStatus() );
      out.write("\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td colspan=\"5\" align=\"center\" bgcolor=\"#f0f0f0\"></td>\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\t\t");

			}
			}
		
      out.write("\r\n");
      out.write("\r\n");
      out.write("\t\t<!-- <tr>\r\n");
      out.write("\t\t\t<td height=\"20\" align=\"center\">\r\n");
      out.write("\t\t\t\tㅇㅇ\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"27%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"16%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"22%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"20%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td colspan=\"5\" align=\"center\" bgcolor=\"#f0f0f0\"></td>\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td height=\"20\" align=\"center\">\r\n");
      out.write("\t\t\t\tㅇㅇ\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"27%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"16%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"22%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<td width=\"20%\" align=\"center\">\r\n");
      out.write("\t\t\t\t&nbsp;\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t</tr> \r\n");
      out.write("\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<td height=\"1\" colspan=\"5\"></td>\r\n");
      out.write("\t\t</tr>-->\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<!-- start of : 리스트 -->\r\n");
      out.write("\t\t\t<td colspan=\"5\" valign=\"top\">\r\n");
      out.write("\t\t\t\t<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" border=\"0\">\r\n");
      out.write("\t\t\t\t\t<tr>\r\n");
      out.write("\t\t\t\t\t\t<td bgcolor=\"#f0f0f0\" height=\"1\"></td>\r\n");
      out.write("\t\t\t\t\t</tr>\r\n");
      out.write("\t\t\t\t</table>\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<!-- end of : 리스트 -->\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\t\t<tr>\r\n");
      out.write("\t\t\t<!-- start of : 리스트  보기-->\r\n");
      out.write("\t\t\t<td height=\"50\" colspan=\"5\" align=\"middle\">\r\n");
      out.write("\t\t\t\t<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("\t\t\t\t\t<tr>\r\n");
      out.write("\t\t\t\t\t\t<td>\r\n");
      out.write("\t\t\t\t\t\t\t<div align=\"center\">\r\n");
      out.write("\t\t\t\t\t\t\t\t");

									int totalPageCount = (int) (searchResultCount / perPageContentCount) + 1;
									int startPage = ((currentPage - 1) / 5) * 5 + 1;
									int endPage = startPage + 4;

									if (endPage > totalPageCount)
										endPage = totalPageCount;

									// Prev button
									if (currentPage <= 5) {
								
      out.write("\r\n");
      out.write("\t\t\t\t\t\t\t\t");

										} else {
										int prePage = startPage - 5;
										String preLinkPath = "messageSearch.jsp?" + parameter
										+ "&page=" + prePage;
								
      out.write("\r\n");
      out.write("\t\t\t\t\t\t\t\t<a href=\"");
      out.print(preLinkPath);
      out.write("\"><img\r\n");
      out.write("\t\t\t\t\t\t\t\t\t\tsrc=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/page_list_butn04_01.gif\"\r\n");
      out.write("\t\t\t\t\t\t\t\t\t\twidth=\"16\" height=\"12\" border=\"0\"> </a>\r\n");
      out.write("\t\t\t\t\t\t\t\t");

									}

									// Page button
									for (int i = startPage; i <= endPage; i++) {
										String numberLinkPath = "messageSearch.jsp?" + parameter
										+ "&page=" + i;

										if (i != startPage)
											out.println(" | ");

										if (i == currentPage) {
								
      out.write("\r\n");
      out.write("\t\t\t\t\t\t\t\t<b>");
      out.print(i);
      out.write(" </b>\r\n");
      out.write("\t\t\t\t\t\t\t\t");

								} else {
								
      out.write("\r\n");
      out.write("\t\t\t\t\t\t\t\t<a href=\"");
      out.print(numberLinkPath);
      out.write('"');
      out.write('>');
      out.print(i);
      out.write(" </a>\r\n");
      out.write("\t\t\t\t\t\t\t\t");

									}
									}

									// Next button
									if (startPage > totalPageCount - 5) {
								
      out.write("\r\n");
      out.write("\t\t\t\t\t\t\t\t");

										} else {
										int nextPage = startPage + 5;
										String nextLinkPath = "messageSearch.jsp?" + "page=" + nextPage
										+ "&" + parameter;
								
      out.write("\r\n");
      out.write("\t\t\t\t\t\t\t\t<a href=\"");
      out.print(nextLinkPath);
      out.write("\"><img\r\n");
      out.write("\t\t\t\t\t\t\t\t\t\tsrc=\"");
      out.print( request.getContextPath() );
      out.write("/image/search/page_list_butn04_04.gif\"\r\n");
      out.write("\t\t\t\t\t\t\t\t\t\twidth=\"16\" height=\"12\" border=\"0\"> </a>\r\n");
      out.write("\t\t\t\t\t\t\t\t");

								}
								
      out.write("\r\n");
      out.write("\t\t\t\t\t\t\t</div>\r\n");
      out.write("\t\t\t\t\t\t</td>\r\n");
      out.write("\t\t\t\t\t</tr>\r\n");
      out.write("\t\t\t\t</table>\r\n");
      out.write("\t\t\t</td>\r\n");
      out.write("\t\t\t<!-- end of : 리스트  보기-->\r\n");
      out.write("\t\t</tr>\r\n");
      out.write("\t</tbody>\r\n");
      out.write("</table>\r\n");
      out.write("<p>\r\n");
      out.write("\t&nbsp;\r\n");
      out.write("</p>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
