/* 
    ETRI IntraPMS Project
    결재/반려/상신취소/삭제를 처리하는 Servlet

    
*/

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import com.etri.groupware.*;
import com.etri.groupware.eda.*;

public class EDAApprovalServlet extends HttpServlet{
	GroupwareControllerInterface groupwareController = null;
	EDAControllerInterface edaController = null;
	Properties pro=null;
	
	
		
	public void init( ServletConfig sc ) throws ServletException{
		super.init(sc);
		
		pro = new Properties();
		pro.put("DriverName","weblogic.jdbc.mssqlserver4.Driver");
		pro.put("DBServer","jdbc:weblogic:mssqlserver4:GWDB@Server:1433");
		pro.put("User","sa");
		pro.put("Password","");
		
		pro.put("OrganizationDBManagerClassName","PandaSoftOrganizationDBManager");
		pro.put("BBSDBManagerClassName","PandaSoftBBSDBManager");
		pro.put("EDADBManagerClassName","PandaSoftEDADBManager");
		pro.put("MailDBManagerClassName","PandaSoftMailDBManager");
		
		try{
			groupwareController = GroupwareController.init( pro );
			System.out.println("그룹웨어 컨트롤러 생성을 마쳤습니다.");
			
			edaController = groupwareController.createEDAController();
			System.out.println("전자결재 컨트롤러 생성도 무사히 마쳤습니다.");	
		}
		catch( Exception e){
			System.out.println( e.toString() );
		}
	}
	
	public void destroy(){
		System.out.println("EDAApprovalServlet Destroy() 호출");
		super.destroy();
		DBConnectionManager.instance.release();
		System.out.println("EDAApprovalServlet Destroy() 완료");
	}
	
/*----------------------------------------------------------------- */
/**
 [메소드이름]: doGet<br>
 [기능]:문서를 결재,반려,삭제,상신취소를 삭제해준다.<br>
 [파라미터]: HttpServletRequest req,HttpServletResponse res<br>
 [호출자] : EDADocumentServlet<br>
 */
/*--------------------------------------------------------------- */		
	public void doGet(HttpServletRequest req,HttpServletResponse res) 
	 throws ServletException,IOException{
	 
	 	HttpSession session = req.getSession(true);
	 	
	 	System.out.println("GET 함수 시작");
		res.setContentType("text/html;charset=edu-kr");
		PrintWriter out = new PrintWriter( new OutputStreamWriter(
		 res.getOutputStream(),"EUC-KR"));
		 
		boolean authentication = false;
	
		String docID;
		int count;
		int position=0;
		int length;
		String docIDs;
		String[] docIDArray;
		String listID;
		String description=null;
		String approvalButton;
		EDAResultStatus result;
		ApprovalDocument document;
		String Search;
		
		String itemSel = null; 
		String docItem = null;
		String initDay = null;
		String startYear = null;
		String startMon = null;
		String startDay = null;
		String stopYear = null;
		String stopMon = null;
		String stopDay = null;
		String personSel = null;
		String docPerson = null;
		String titleSel = null;
		String docTitle = null;
		String commSel = null;
		String docComment = null;
		String andSearch = null;
		int oldCount = 1;		
		
		String id = null;
		String name=null;
		

		if((session.isNew())){
			session.invalidate();
			res.sendRedirect("../Login.html");
		}
		else if(session.getValue("Authentication").equals("true")){
			authentication = true;
			id = (String)session.getValue("Id");
			name = (String)session.getValue("Name");
		}
		else{
			session.invalidate();
			res.sendRedirect("../Login.html");
		}

		docID = req.getParameter("docID");
		docID = new String( docID.getBytes("ISO-8859-1"),"EUC-KR");
		System.out.println("docID: " + docID );
							
		count = Integer.parseInt(req.getParameter("count"));
		System.out.println("count: " + count );
		
		listID = req.getParameter("listID");
		System.out.println("listID : " + listID );
		
		
		
		length = Integer.parseInt(req.getParameter("length"));
		System.out.println("length : " + length);

		docIDs = req.getParameter("docIDS");
		docIDs = new String( docIDs.getBytes("ISO-8859-1"),"EUC-KR");
		System.out.println("docIDs : " + docIDs );
		//문서 번호를 순서 대로 정렬
		StringTokenizer token = new StringTokenizer ( docIDs , "," );
		docIDArray = new String [ length ];
		int loopCount = 0;
		while( token.hasMoreTokens() ){
			docIDArray[ loopCount ] = token.nextToken();
			if( docIDArray[loopCount].equals( docID ) )
				position = loopCount ;
			loopCount ++;
		}
				
		Search = req.getParameter("Search");
		System.out.println("Search"+Search);//debug
		if(Search.equals("YES")){
			oldCount = Integer.parseInt( req.getParameter("oldCount"));

			itemSel = req.getParameter("itemSel");
			docItem = req.getParameter("docItem");
			docItem = new String ( docItem.getBytes("ISO-8859-1"),"EUC-KR");

			initDay = req.getParameter("initDay");
			startYear = req.getParameter("startYear");
			startMon = req.getParameter("startMon");
			startDay = req.getParameter("startDay");

			stopYear = req.getParameter("stopYear");
			stopMon = req.getParameter("stopMon");
			stopDay = req.getParameter("stopDay");

			personSel = req.getParameter("personSel");
			docPerson = req.getParameter("docPerson");
			docPerson = new String ( docPerson.getBytes("ISO-8859-1"),"EUC-KR");

			titleSel = req.getParameter("titleSel");
			docTitle = req.getParameter("docTitle");
			docTitle = new String ( docTitle.getBytes("ISO-8859-1"),"EUC-KR");

			commSel = req.getParameter("commSel");
			docComment = req.getParameter("docComment");
			docComment = new String ( docComment.getBytes("ISO-8859-1"),"EUC-KR");

			andSearch = req.getParameter("andSearch");
		}
		if( listID.equals(Lists.INGBOX)){
			description = req.getParameter("description");
			description = new String( description.getBytes("ISO-8859-1"),"EUC-KR");
			System.out.println("결재의견:"+description);
		}
		
		approvalButton = req.getParameter("Approval");
		approvalButton = new String( approvalButton.getBytes("ISO-8859-1"),"EUC-KR");

		if(authentication){
			out.println("<body text=\"black\" " +
			 "link=\"blue\" vlink=\"black\" alink=\"#FF2020\">");
			out.println("<p align=right><img src=\'../image/우측_기안결재.gif\'></p>");
			try{
				document = edaController.getDocument( docID , name + "(" + id + ")" , Lists.INGBOX );
		
				if( approvalButton.equals("결재")){
					result = edaController.processObtainApproval( document , name + "(" + id + ")" , description );
					if( result.getResultStatus() == EDAResultStatus.SUCCESS){
						System.out.println("결재 로직 시작");
					 	out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
				 	 	 "<b> 결재 완료</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");
						out.println("<p align=\"center\">문서가 정상적으로 결재되었습니다.</p></br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">결재의견</td>");
						out.println("<td width=\"60%\">"+ description + "</td>");
						out.println("</tr>");
						
						out.println("</table></div>");
						out.println("<div align=\"center\">");
						out.println("<table border=\"0\">");
						out.println("<tr>");
						
						if(Search.equals("YES"))
							//검색함 완성 후 수정 요망
							out.println("<td width=\"90\"><a href=\"http:/servlet/EDASearchServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
							 "listID="+ listID + "&count=" + count + "&itemSel="+ itemSel +
							 "&docItem=" + docItem + "&initDay=" + initDay + "&startYear=" +
							 startYear + "&startMon=" + startMon + "&startDay=" + startDay +
							 "&stopYear=" + stopYear + "&stopMon=" + stopMon + "&stopDay=" +
							 stopDay + "&personSel="+ personSel + "&docPerson=" + docPerson +
							 "&titleSel=" + titleSel + "&docTitle=" + docTitle + "&commSel=" +
							 commSel + "&docComment=" + docComment + "&oldCount="+ 
							 oldCount + "&andSearch=" + andSearch + "&doGet=YES\">"+
							 "검색함으로 </a></td>");

						out.println("<td width=\"90\"><a href=\"http:/servlet/EDADocumentBoxServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
						 "listID="+ listID + "&count=" + count + "&doGet=YES\">"+
						 "문서함으로 </a></td>");
						//기존의 문서 배열에서 현재 결재한 문서 제외 
						docIDs = "";
						for( int i = 0 ; i < length ; i ++ )
							if( i != position )
								docIDs = docIDs + docIDArray[i] + ",";

						if( position != 0 )
							out.println("<td width=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position - 1]+
							 "&DocIDS="+docIDs+"&position="+ ( position - 1 )+"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_back.gif\' border=0 alt=\'이전 문서\'></a></td>");
						
						if (position + 1 < length) 
							out.println("<td widtd=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position + 1]+
							 "&DocIDS="+docIDs+"&position="+  position +"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_forward.gif\' border=0 alt=\'다음 문서\'></a></td>");
		
						out.println("</tr></table>");
						
					}
					else{
					 	out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
					 	 "<b> 결재 실패</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");
						out.println("<p align=\"center\">문서 결재에 실패했습니다.</br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">결재의견</td>");
						out.println("<td width=\"60%\">"+ description + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">사    유</td>");
						out.println("<td width=\"60%\">" + result.getReason());
						out.println("</tr>");
						
						out.println("</table></div>");
										
			        		out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
			        		 "count="+count+"&listID="+listID+"&DocID="+docID +"&position="+position+"&length"+length+"&DocIDS="+docIDs+ "&doGet=YES\">"+
		        			 "문서 다시 보기</a></p>");
					}
				}
				else if( approvalButton.equals("반려")){
					System.out.println("반려 Logic시작");//debug
					result = edaController.processReturnApproval( document , name + "(" + id + ")", description );
					if( result.getResultStatus() == EDAResultStatus.SUCCESS){
				 		out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
				 	 	 "<b> 반려 완료</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");
						out.println("<p align=\"center\">문서가 반려되었습니다.</br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");
						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">반려의견</td>");
						out.println("<td width=\"60%\">"+ description + "</td>");
						out.println("</tr>");
					
						out.println("</table></div>");

						out.println("<div align=\"center\">");
						out.println("<table border=\"0\">");
						out.println("<tr>");
						if(Search.equals("YES"))
							//검색함 완성 후 수정
							out.println("<td width=\"90\"><a href=\"http:/servlet/EDASearchServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
							 "listID="+listID + "&count=" + count + "&itemSel="+ itemSel +
							 "&docItem=" + docItem + "&initDay=" + initDay + "&startYear=" +
							 startYear + "&startMon=" + startMon + "&startDay=" + startDay +
							 "&stopYear=" + stopYear + "&stopMon=" + stopMon + "&stopDay=" +
							 stopDay + "&personSel="+ personSel + "&docPerson=" + docPerson +
							 "&titleSel=" + titleSel + "&docTitle=" + docTitle + "&commSel=" +
							 commSel + "&docComment=" + docComment + "&oldCount="+ 
							 oldCount + "&andSearch=" + andSearch + "&doGet=YES\">"+
							 "검색함으로</a></td>");
						 
						out.println("<td width=\"90\"><a href=\"http:/servlet/EDADocumentBoxServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
						 "listID="+ listID + "&count=" + count + "&doGet=YES\">"+
						 "문서함으로</a></td>");
						//기존의 문서 배열에서 반려한 문서 제외
						docIDs = "";
						for( int i = 0 ; i < length ; i ++ )
							if( i != position )
								docIDs = docIDs + docIDArray[i] + ",";

						if( position != 0 )
							out.println("<td width=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position - 1]+
							 "&DocIDS="+docIDs+"&position="+ ( position - 1 )+"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_back.gif\' border=0 alt=\'이전 문서\'></a></td>");
						
						if (position + 1 < length) 
							out.println("<td widtd=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position + 1]+
							 "&DocIDS="+docIDs+"&position="+position+"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_forward.gif\' border=0 alt=\'다음 문서\'></a></td>");
		
						out.println("</tr></table>");
					}
					else{
				 		out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
				 	 	 "<b> 반려 실패</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");
						out.println("<p align=\"center\">문서 반려에 실패했습니다.</br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">반려의견</td>");
						out.println("<td width=\"60%\">"+ description + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">사    유</td>");
						out.println("<td width=\"60%\">" + result.getReason());
						out.println("</tr>");
						
						out.println("</table></div>");
										
			        		out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
			        		"count="+count+"&listID="+listID+"&DocID="+docID +"&position="+ position +"&length="+length+"&DocIDS="+docIDs+ "&doGet=YES\">"+
		        			 "문서 다시 보기</a></p>");
					}
					
				}
				else if( approvalButton.equals("상신취소")){
					System.out.println("상신취소Logic시작");//debug
					result=edaController.processAbortApproval( document , name + "(" + id + ")" );
					if( result.getResultStatus() == EDAResultStatus.SUCCESS){
				 		out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
				 	 	 "<b> 취소 완료</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");
						out.println("<p align=\"center\">문서가 상신취소 되었습니다.</br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
					
						out.println("</table></div>");
						
						out.println("<div align=\"center\">");
						out.println("<table border=\"0\">");
						out.println("<tr>");
						if(Search.equals("YES"))
							//검색함 완성 후 수정
							out.println("<td width=\"90\"><a href=\"http:/servlet/EDASearchServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
							 "listID="+ listID + "&count=" + count + "&itemSel="+ itemSel +
							 "&docItem=" + docItem + "&initDay=" + initDay + "&startYear=" +
							 startYear + "&startMon=" + startMon + "&startDay=" + startDay +
							 "&stopYear=" + stopYear + "&stopMon=" + stopMon + "&stopDay=" +
							 stopDay + "&personSel="+ personSel + "&docPerson=" + docPerson +
							 "&titleSel=" + titleSel + "&docTitle=" + docTitle + "&commSel=" +
							 commSel + "&docComment=" + docComment + "&oldCount="+ 
							 oldCount + "&andSearch=" + andSearch + "&doGet=YES\">"+
							 "검색함으로</a></td>");

						out.println("<td width=\"90\"><a href=\"http:/servlet/EDADocumentBoxServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
						 "listID="+ listID + "&count=" + count +"&doGet=YES\">"+
						 "문서함으로</a></td>");
						//기존의 문서 배열에서 현재 취소 한 문서 제외
						docIDs = "";
						for( int i = 0 ; i < length ; i ++ )
							if( i != position )
								docIDs = docIDs + docIDArray[i] + ",";
						if( position != 0 )
							out.println("<td width=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position - 1]+
							 "&DocIDS="+docIDs+"&position="+ ( position - 1 )+"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_back.gif\' border=0 alt=\'이전 문서\'></a></td>");
						
						if (position + 1 < length) 
							out.println("<td widtd=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position + 1]+
							 "&DocIDS="+docIDs+"&position="+position+"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_forward.gif\' border=0 alt=\'다음 문서\'></a></td>");
		
						out.println("</tr></table>");
										
					}
					else{
				 		out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
				 	 	 "<b> 취소 실패</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");
						out.println("<p align=\"center\">상신 취소에 실패했습니다.</br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">사    유</td>");
						out.println("<td width=\"60%\">" + result.getReason());
						out.println("</tr>");
					
						out.println("</table></div>");
										
		        			out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
		        			 "count="+count+"&listID="+listID+"&DocID="+docID + "&position="+position+"&length="+length+"&DocIDS"+docIDs+"&doGet=YES\">"+
	        			 	 "문서 다시 보기</a></p>");
					}
				}				
				else if( approvalButton.equals("삭제")){
					System.out.println("삭제Logic시작");//debug
					if( listID.equals(Lists.PUBLICBOX))
						result=edaController.deleteLists( docID , listID , Lists.PUBLICUSER );
					else
						result=edaController.deleteLists( docID , listID , name + "(" + id + ")" );
					if( result.getResultStatus() == EDAResultStatus.SUCCESS){
				 		out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
				 	 	 "<b> 삭제 완료</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");

						out.println("<p align=\"center\">문서가 삭제 되었습니다.</br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");

						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
					
						out.println("</table></div>");
						
						out.println("<div align=\"center\">");
						out.println("<table border=\"0\">");
						out.println("<tr>");
						if(Search.equals("YES"))
						//검색 함 완성 후 수정
							out.println("<td width=\"90\"><a href=\"http:/servlet/EDASearchServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
							 "listID="+ listID + "&count=" + count + "&itemSel="+ itemSel +
							 "&docItem=" + docItem + "&initDay=" + initDay + "&startYear=" +
							 startYear + "&startMon=" + startMon + "&startDay=" + startDay +
							 "&stopYear=" + stopYear + "&stopMon=" + stopMon + "&stopDay=" +
							 stopDay + "&personSel="+ personSel + "&docPerson=" + docPerson +
							 "&titleSel=" + titleSel + "&docTitle=" + docTitle + "&commSel=" +
							 commSel + "&docComment=" + docComment + "&oldCount="+ 
							 oldCount + "&andSearch=" + andSearch + "&doGet=YES\">"+
							 "검색함으로</a></td>");
							
						out.println("<td width=\"90\"><a href=\"http:/servlet/EDADocumentBoxServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
						 "listID="+ listID + "&count=" + count +"&doGet=YES\">"+
				 		 "문서함으로</a></td>");
						//기존의 문서 배열에서 현재 삭제한 문서 제외
						docIDs = "";
						for( int i = 0 ; i < length ; i ++ )
							if( i != position )
								docIDs = docIDs + docIDArray[i] + ",";
						if( position != 0 )
							out.println("<td width=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position - 1]+
							 "&DocIDS="+docIDs+"&position="+ ( position - 1 )+"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_back.gif\' border=0 alt=\'이전 문서\'></a></td>");
						
						if (position + 1 < length) 
							out.println("<td widtd=\"90\"><p align=center><a href=\"http:/servlet/EDADocumentServlet?count="
							 +count+"&listID="+listID+"&DocID="+docIDArray[position + 1]+
							 "&DocIDS="+docIDs+"&position="+position+"&length=" + (length-1) +
							 "&Search="+Search+"&oldCount="+oldCount+"&itemSel="+itemSel+"&docItem="+
							 docItem+"&initDay="+initDay+"&startYear="+startYear+"&startMon="+startMon+
							 "&startDay="+startDay+"&stopYear="+stopYear+"&stopMon="+stopMon+"&stopDay="+
							 stopDay+"&personSel="+personSel+"&docPerson="+docPerson+"&titleSel="+titleSel+
							 "&docTitle="+docTitle+"&commSel="+commSel+"&docComment="+docComment+"&andSearch="+
							 andSearch+"\"><img src=\'/image/BBS_forward.gif\' border=0 alt=\'다음 문서\'></a></td>");
		
						out.println("</tr></table>");
				 		 
					}
					else{
				 		out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
				 	 	 "<b> 삭제 실패</b></font></p>");
						out.println("<p align=\"center\"><hr width=\"80%\"><br>");
						out.println("<p align=\"center\">문서 삭제에 실패했습니다.</br>");
						out.println("<div align=\"center\">");
						out.println("<table width=\"80%\">");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">제    목</td>");
						out.println("<td width=\"60%\">"+ document.gettitle() + "</td>");
						out.println("</tr>");
						
						out.println("<tr>");
						out.println("<td width=\"20%\">문서번호</td>");
						out.println("<td width=\"60%\">"+ docID + "</td>");
						out.println("</tr>");
					
						out.println("<tr>");
						out.println("<td width=\"20%\">사    유</td>");
						out.println("<td width=\"60%\">" + result.getReason());
						out.println("</tr>");
					
						out.println("</table></div>");
										
			        		out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
			        		 "count="+count+"&listID="+listID+"&DocID="+docID + "&position="+position+"&length="+length+"&DocIDS"+docIDs+"&doGet=YES\">"+
		        		 	 "문서 다시 보기</a></p>");
					}
				}
				else {
					out.println("선택이 잘못되었습니다.<br>");
					out.println("다시 문서를 확인 한 후 작업하여 주세요.<br>");
					out.println("<td><a href=\'javascript:history.go(-1)\'> "+
		    		 	"문서 다시 보기</a></td>");
					if(Search.equals("YES"))
						//검색함 완성 후 수정
						out.println("<p><a href=\"http:/servlet/EDASearchServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
						 "listID="+ listID + "&count=" + count + "&itemSel="+ itemSel +
						 "&docItem=" + docItem + "&initDay=" + initDay + "&startYear=" +
						 startYear + "&startMon=" + startMon + "&startDay=" + startDay +
						 "&stopYear=" + stopYear + "&stopMon=" + stopMon + "&stopDay=" +
						 stopDay + "&personSel="+ personSel + "&docPerson=" + docPerson +
						 "&titleSel=" + titleSel + "&docTitle=" + docTitle + "&commSel=" +
						 commSel + "&docComment=" + docComment + "&oldCount="+ 
						 oldCount + "&andSearch=" + andSearch + "&doGet=YES\">"+
						 "검색함으로 돌아가기</a>");
			    	 
					out.println("<p><a href=\"http:/servlet/EDADocumentBoxServlet?"+/*여기서 부터 debug*/ "id="+id+"&name="+name+"&"+
					 "listID="+ listID + "&count=" + count + "&doGet=YES\">"+
					 "문서함으로 돌아가기</a></p>");
				}	
				
			}catch ( Exception e ){
			
				if( approvalButton.equals("결재")){
	 				out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
	 	 	 		 "<b> 결재 실패</b></font></p>");
					out.println("<p align=\"center\"><hr width=\"80%\"><br>");
					out.println("<p align=\"center\">문서 결재에 실패했습니다.</br>");
					out.println("<div align=\"center\">");
					out.println("<table width=\"80%\">");
					
					out.println("<tr>");
					out.println("<td width=\"20%\">문서번호</td>");
					out.println("<td width=\"60%\">"+ docID + "</td>");
					out.println("</tr>");
				
					out.println("<tr>");
					out.println("<td width=\"20%\">결재의견</td>");
					out.println("<td width=\"60%\">"+ description + "</td>");
					out.println("</tr>");
				
					out.println("<tr>");
					out.println("<td width=\"20%\">사    유</td>");
					out.println("<td width=\"60%\">" + e.toString());
					out.println("</tr>");
						
					out.println("</table></div>");
									
			        	out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
			        	 "count="+count+"&listID="+listID+"&DocID="+docID + "&position="+position+"&length="+length+"&DocIDS"+docIDs+"&doGet=YES\">"+
		        		 "문서 다시 보기</a></p>");			
		        	}
				else if( approvalButton.equals("반려")){		        
					out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
					 "<b> 반려 실패</b></font></p>");
					out.println("<p align=\"center\"><hr width=\"80%\"><br>");
					out.println("<p align=\"center\">문서 반려에 실패했습니다.</br>");
					out.println("<div align=\"center\">");
					out.println("<table width=\"80%\">");
						
					out.println("<tr>");
					out.println("<td width=\"20%\">문서번호</td>");
					out.println("<td width=\"60%\">"+ docID + "</td>");
					out.println("</tr>");
				
					out.println("<tr>");
					out.println("<td width=\"20%\">반려의견</td>");
					out.println("<td width=\"60%\">"+ description + "</td>");
					out.println("</tr>");
				
					out.println("<tr>");
					out.println("<td width=\"20%\">사    유</td>");
					out.println("<td width=\"60%\">" + e.toString());
					out.println("</tr>");
					
					out.println("</table></div>");
										
			        	out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
			        	 "count="+count+"&listID="+listID+"&DocID="+docID + "&position="+position+"&length="+length+"&DocIDS"+docIDs+"&doGet=YES\">"+
		        		 "문서 다시 보기</a></p>");
				}
				else if( approvalButton.equals("상신취소")){
		 			out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
		 	 		 "<b> 취소 실패</b></font></p>");
					out.println("<p align=\"center\"><hr width=\"80%\"><br>");
					out.println("<p align=\"center\">상신 취소에 실패했습니다.</br>");
					out.println("<div align=\"center\">");
					out.println("<table width=\"80%\">");
					
					out.println("<tr>");
					out.println("<td width=\"20%\">문서번호</td>");
					out.println("<td width=\"60%\">"+ docID + "</td>");
					out.println("</tr>");
					
					out.println("<tr>");
					out.println("<td width=\"20%\">사    유</td>");
					out.println("<td width=\"60%\">" + e.toString());
					out.println("</tr>");
			
					out.println("</table></div>");
									
        				out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
        		 		 "count="+count+"&listID="+listID+"&DocID="+docID +"&position="+position+"&length="+length+"&DocIDS"+docIDs+ "&doGet=YES\">"+
       			  		 "문서 다시 보기</a></p>");
       				}
				else if( approvalButton.equals("삭제")){						
		 			out.println("<p align=\"center\"><font size=\"5\" color=\"gray\" >"+
		 	 		 "<b> 삭제 실패</b></font></p>");
					out.println("<p align=\"center\"><hr width=\"80%\"><br>");
					out.println("<p align=\"center\">문서 삭제에 실패했습니다.</br>");
					out.println("<div align=\"center\">");
					out.println("<table width=\"80%\">");
				
					out.println("<tr>");
					out.println("<td width=\"20%\">문서번호</td>");
					out.println("<td width=\"60%\">"+ docID + "</td>");
					out.println("</tr>");
					
					out.println("<tr>");
					out.println("<td width=\"20%\">사    유</td>");
					out.println("<td width=\"60%\">" + e.toString());
					out.println("</tr>");
			
					out.println("</table></div>");
											
        				out.println("<p align=\"center\"><a href=\"http:/servlet/EDADocumentServlet?"+/*여기서 부터는 debug*/ "id=" + id + "&name=" + name + "&"+
        				 "count="+count+"&listID="+listID+"&DocID="+docID +"&position="+position+"&length="+length+"&DocIDS"+docIDs+ "&doGet=YES\">"+
       			 		 "문서 다시 보기</a></p>");
				}		
			}
		}
		else{
			//사용자 인증에 실패했습니다.
			res.sendRedirect("../Login.html");
		}
		out.close();
	}
}