/* 
    IntraPMS Project
    부서 등록,검색폼 제공 서블릿

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

import java.util.*;

import java.sql.DriverManager ;
import java.sql.Connection ;
import java.sql.Statement ;
import java.sql.ResultSet ;
import java.sql.SQLException ;

import com.etri.groupware.*;
import com.etri.groupware.organization.*;

public class AddSearchDepartmentServlet extends HttpServlet
{
	GroupwareControllerInterface gc = null ;
	OrganizationManagementControllerInterface  omc = null ;
	Properties myPro = null ;
	
	public void init ( ServletConfig config ) throws ServletException {
		super.init ( config ) ;
		System.out.println ( "AddSearchDepartmentServlet init () Call..........." ) ;
		
		// 그룹웨어 컨트롤러를 생성한다.
		// 먼저 프라퍼티를 생성한다.
		myPro = new Properties ( ) ;
		// DB매니저 구현 클래스 이름 설정
		myPro.put ( "OrganizationDBManagerClassName" , "PandaSoftOrganizationDBManager" ) ;
		myPro.put ( "BBSDBManagerClassName" , "PandaSoftBBSDBManager" ) ;
		myPro.put ( "EDADBManagerClassName" , "PandaSoftEDADBManager" ) ;
		myPro.put ( "MailDBManagerClassName" , "PandaSoftMailDBManager" ) ;
		////////////////////////////////////////
		System.out.println ( "부서 추가와 검색 서블릿의 POST에서 프라퍼티 설정을 무사히 마쳤습니다." ) ;
		
		try {
			gc = GroupwareController.init ( myPro ) ;
			/////////////////////////////////////////////////
			System.out.println ( "부서 추가와 검색 서블릿의 POST에서 사용할 그룹웨어 컨트롤러 생성을 무사히 마쳤습니다." ) ;
			
			// 조직도 관리 컨트롤러를 가져온다.
			omc = gc.createOrganizationManagementController ( ) ;
			///////////////////////////////////////////////////////////
			System.out.println ( "부서 추가와 검색 서블릿의 POST에서 사용할 조직도 관리 컨트롤러 생성도 무사히 마쳤습니다." ) ;
		} catch ( Exception e ) { }
	}

	public void destroy ( ) {
		super.destroy() ;
		DBConnectionManager.instance.release() ;
		System.out.println ( "AddSearchDepartmentServlet destroy () Call..........." ) ;
	}

	/*----------------------------------------------------------------- */
	/**
	[메소드이름]: doGet<br>
	[기능]: 부서 등록또는 부서 검색의 html폼을 제공한다.<br>
	[파라미터]: HttpServletRequest request, HttpServletResponse response<br>
	[호출자] : 사용자<br>
	*/
	/*--------------------------------------------------------------- */	
	public void doGet (
													HttpServletRequest request ,
													HttpServletResponse response ) throws ServletException , IOException
	{
		PrintWriter out ;
		String head = " 팬더 소프트 " ;
		// Set content type and other response header fields first
		response.setContentType ( "text/html;charset=euc-kr" ) ;
		// then write the data of the response
		out = new PrintWriter ( new OutputStreamWriter ( response.getOutputStream ( ) , "EUC-KR" ) ) ;
		
		// 세션 확인 부분 - 인증되지 않은 사용자의 경우 Login.html 로 되돌려 보낸다.
		String authenKind = null ;
		String authenId = null ;
		String authenName = null ;
		String authenLoginStatus = null;
		
		HttpSession session = request.getSession ();
		authenLoginStatus =  (String)session.getValue("Authentication");
		
		if( (authenLoginStatus == null) || ( !(authenLoginStatus.equals("true")) ) ){
			// 인증되지 않은 사용자의 세션을 무효화 시킨다.
			session.invalidate();
			// 인증되지 않은 사용자를 Loing.html로 돌려 보낸다.
			response.sendRedirect("../Login.html");
		} else {
			// 인증된 사용자의 사용자 종류, 아이디, 이름을 얻는다.
			authenKind = (String)session.getValue("Kind");
			authenId = (String)session.getValue("Id");
			authenName = (String)session.getValue("Name");   
		}

		out.println ( "<html><head><title>" + head + "</title>" ) ;
		out.println ( "<META content=\"text/html; charset=euc-kr\" http-equiv=Content-Type>" ) ;
		out.println ( "<style type=\"text/css\">" ) ;
		out.println ( "BODY {font-size:9pt; color:\"#000000\"; line-height:14px;}" ) ;
		out.println ( "A:Link {font-size:9pt; color:\"#000033\"; line-height:14px; text-decoration:none}" ) ;
		out.println ( "A:Visited {font-size:9pt; color:\"#330033\"; line-height:14px; text-decoration:none}" ) ;
		out.println ( "A:Hover {font-size:9pt; color:\"#0000ff\"; line-height:14px; text-decoration:underline}" ) ;
		out.println ( "td {font-size:9pt;}" ) ;
		out.println ( "td.red {font-size:9pt; color:\"#ff0000\"}" ) ;
		out.println ( "td.black {font-size:9pt; color:\"#000000\"}" ) ;
		out.println ( "td.navy {font-size:9pt; color:\"#000066\"}" ) ;
		out.println ( "td.space {font-size:1pt;}" ) ;
		out.println ( "</style></HEAD>" ) ;		
		out.println ( "<body>" ) ;		
		
		out.println ( "<p align=right><img src=\"/image/우측_관리기능.gif\" alt=\"관리 기능\"></p>" ) ;
			

		if ( request.getParameter ( "add" ) != null ) {
			// 부서 등록 버튼을 눌렀을 경우이다.
			out.println ( "<form><table border=0 hspace=1 width=800 cellpadding=3><tr width=800><td width=340>" ) ;
			out.println ( "<a href=\"/servlet/ShowOrganizationTreeServlet\" target=\"contents\" onClick=\"parent.frames[\'detail\'].location=\'/orgdetail.html\'\">조직관리</a></font>" ) ;
			out.println ( "</td><td width=460 align=right>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?add=add\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depAdd.src='/image/부서등록-1.jpg'\" onMouseOut=\"document.forms[0].depAdd.src='/image/부서등록.jpg'\"><img name=depAdd src=\"/image/부서등록.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?search=search\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depSea.src='/image/부서검색-1.jpg'\" onMouseOut=\"document.forms[0].depSea.src='/image/부서검색.jpg'\"><img name=depSea src=\"/image/부서검색.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?add=add&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temAdd.src='/image/팀등록-1.jpg'\" onMouseOut=\"document.forms[0].temAdd.src='/image/팀등록.jpg'\"><img name=temAdd src=\"/image/팀등록.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?search=search&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temSea.src='/image/팀검색-1.jpg'\" onMouseOut=\"document.forms[0].temSea.src='/image/팀검색.jpg'\"><img name=temSea src=\"/image/팀검색.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?add=add&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offAdd.src='/image/사원등록-1.jpg'\" onMouseOut=\"document.forms[0].offAdd.src='/image/사원등록.jpg'\"><img name=offAdd src=\"/image/사원등록.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?search=search&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offSea.src='/image/사원검색-1.jpg'\" onMouseOut=\"document.forms[0].offSea.src='/image/사원검색.jpg'\"><img name=offSea src=\"/image/사원검색.jpg\"></a>" ) ;
			out.println ( "</td></tr><tr width=800 valign=middle bgcolor=\"#3399ff\"><td colspan=2 width=800><nobr><FONT color=#ffffff>부서 등록하기</nobr></td></tr></table></form>" ) ;
			
			out.println ( "<p><p><p><p>" ) ;
			// 자바 스크립트의 시작입니다.
			out.println ( "<script language=\"JavaScript\">" ) ;
			out.println ( "<!--" ) ;
			out.println ( "	function Check_Form(form)" ) ;
			out.println ( "	{ " ) ;
			out.println ( "     if ( form.name.value.length == 0 )	 alert(\"부서 이름은 필수 항목입니다!!!!\");" ) ;
			out.println ( "	     else form.submit();" ) ;
			out.println ( "	} " ) ;
			out.println ( "	function Back_Click()" ) ;
			out.println ( "	{ " ) ;
			out.println ( "      history.back() ;" ) ;
			out.println ( "	} " ) ;
			out.println ( "//-->" ) ;
			out.println ( "</script>" ) ;
			// 자바 스크립트가 끝나고, HTML 페이지 생성..
			
			out.println ( "<form action=\"/servlet/ShowAllDepartmentServlet\" method=\"GET\"><BR>" ) ;
			out.println ( "<TABLE align=center border=0 cellPadding=2 cellSpacing=1 width=700>" ) ;
			out.println ( "  <TBODY><TR>  " ) ;
			out.println ( "    <TD bgColor=#3399ff><FONT color=#ffffff size=2><B>[ 새로운 부서 등록하기 ]</B></FONT> " ) ;
			out.println ( "  </TD></TR></TBODY></TABLE>" ) ;
			out.println ( "<CENTER><TABLE bgColor=#cccccc border=0 cellPadding=1 cellSpacing=1 width=700>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_red.gif\"><FONT size=2> 부서 이름</FONT></DIV></TD><TD colSpan=3 width=380><FONT face=굴림체><INPUT class=form name=name size=20> </FONT></TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 주요 업무</FONT></DIV></TD><TD colSpan=3 width=380><FONT face=굴림체><INPUT class=form name=weightWork size=40></FONT></TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 전화 번호</FONT></DIV></TD><TD colSpan=3 width=410><FONT face=굴림체><INPUT class=form name=phoneNumber size=20></FONT> </TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 팩스 번호</FONT></DIV></TD><TD colSpan=3 width=410><FONT face=굴림체><INPUT class=form name=faxNumber size=20></FONT> </TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 Web URL</FONT></DIV></TD> <TD colSpan=3 width=380><FONT face=굴림체><INPUT class=form name=webURL size=40></FONT> </TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 설명</FONT></DIV></TD><TD colSpan=3 width=380><FONT face=굴림체><textarea class=form name=departmentExplain rows=4 cols=60></textarea></FONT> </TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD align=right colSpan=4><FONT color=red size=2><IMG src=\"/image/icon_red.gif\"> \"붉은색\"아이콘 항목은 반드시 입력하셔야 합니다. </FONT></TD></TR>" ) ;
			out.println ( "</TABLE></CENTER>" ) ;
			out.println ( "<BR><BR><CENTER><TABLE border=0 cellPadding=2 cellSpacing=1>" ) ;
			out.println ( "  <TR><TD width=680 align=right>" ) ;
			out.println ( "<input type=\"hidden\" name=\"form\" value=\"form\">" ) ;
			out.println ( "<input type=\"hidden\" name=\"page\" value=\"1\">" ) ;		
			out.println ( "<INPUT type=button name=add value=\"등록 하기\" onClick=\"Check_Form(this.form)\">" ) ;
			out.println ( "<INPUT type=reset name=reset value=\"다시 쓰기\">" ) ;
			out.println ( "<INPUT type=button name=back value=\"되돌아 가기\" onClick=\"Back_Click()\">" ) ;
			out.println ( "</TD></TR></TABLE></CENTER></FORM>" ) ;
		      } else if ( request.getParameter ( "search" ) != null ) {
			// 부서 검색 버튼을 눌렀을 경우이다.
			out.println ( "<form><table border=0 hspace=1 width=800 cellpadding=3><tr width=800><td width=340>" ) ;	
			out.println ( "<a href=\"/servlet/ShowOrganizationTreeServlet\" target=\"contents\" onClick=\"parent.frames[\'detail\'].location=\'/orgdetail.html\'\">조직관리</a></font>" ) ;
			out.println ( "</td><td width=460 align=right>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?add=add\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depAdd.src='/image/부서등록-1.jpg'\" onMouseOut=\"document.forms[0].depAdd.src='/image/부서등록.jpg'\"><img name=depAdd src=\"/image/부서등록.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?search=search\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depSea.src='/image/부서검색-1.jpg'\" onMouseOut=\"document.forms[0].depSea.src='/image/부서검색.jpg'\"><img name=depSea src=\"/image/부서검색.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?add=add&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temAdd.src='/image/팀등록-1.jpg'\" onMouseOut=\"document.forms[0].temAdd.src='/image/팀등록.jpg'\"><img name=temAdd src=\"/image/팀등록.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?search=search&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temSea.src='/image/팀검색-1.jpg'\" onMouseOut=\"document.forms[0].temSea.src='/image/팀검색.jpg'\"><img name=temSea src=\"/image/팀검색.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?add=add&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offAdd.src='/image/사원등록-1.jpg'\" onMouseOut=\"document.forms[0].offAdd.src='/image/사원등록.jpg'\"><img name=offAdd src=\"/image/사원등록.jpg\"></a>" ) ;
			out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?search=search&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offSea.src='/image/사원검색-1.jpg'\" onMouseOut=\"document.forms[0].offSea.src='/image/사원검색.jpg'\"><img name=offSea src=\"/image/사원검색.jpg\"></a>" ) ;
			out.println ( "</td></tr><tr width=800 valign=middle bgcolor=\"#3399ff\"><td colspan=2 width=800><nobr><FONT color=#ffffff>부서 검색하기</nobr></td></tr></table></form>" ) ;
		
			out.println ( "<p><p><p><p>" ) ;
			// 자바 스크립트의 시작입니다.
			out.println ( "<script language=\"JavaScript\">" ) ;
			out.println ( "<!--" ) ;
			out.println ( "	function Check_Form(form)" ) ;
			out.println ( "	{ " ) ;
			out.println ( "	    if ( form.name.value.length != 0 )	 form.submit();" ) ;
			out.println ( "	    else if ( form.weightWork.value.length != 0 )	 form.submit();" ) ;
			out.println ( "	    else if ( form.departmentExplain.value.length != 0 )	 form.submit();" ) ;
			out.println ( "	    else alert(\"검색 조건 중에서 하나는 꼭 입력해야 합니다!!!!\");" ) ;
			out.println ( "	} " ) ;			
			out.println ( "	function Back_Click()" ) ;
			out.println ( "	{ " ) ;
			out.println ( "		  history.back(); " ) ;
			out.println ( "	} " ) ;
			out.println ( "//-->" ) ;
			out.println ( "</script>" ) ;
			// 자바 스크립트가 끝나고, HTML 페이지를 생성합니다.
			out.println ( "<form action=\"/servlet/ShowAllDepartmentServlet\" method=\"GET\"><BR>" ) ;
			out.println ( "<TABLE align=center border=0 cellPadding=2 cellSpacing=1 width=700>" ) ;
			out.println ( "  <TBODY>  <TR>" ) ;
			out.println ( "    <TD bgColor=#3399ff><FONT color=#ffffff size=2><B>[ 부서 검색하기 ]</B></FONT> " ) ;
			out.println ( "  </TD></TR></TBODY></TABLE>" ) ;
			out.println ( "<CENTER><TABLE bgColor=#cccccc border=0 cellPadding=1 cellSpacing=1 width=700>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 이름</FONT></DIV></TD><TD colSpan=3 width=380><FONT face=굴림체><INPUT class=form name=name size=20> </FONT></TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 주요 업무</FONT></DIV></TD><TD colSpan=3 width=380><FONT face=굴림체><INPUT class=form name=weightWork size=40></FONT></TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_dot1.gif\"><FONT size=2> 부서 설명</FONT></DIV></TD><TD colSpan=3 width=380><FONT face=굴림체><textarea class=form name=departmentExplain rows=4 cols=60></textarea></FONT> </TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD width=120><DIV align=left><IMG src=\"/image/icon_red.gif\"><FONT size=2> 부서 검색 방법</FONT></DIV></TD><TD align=center colSpan=3 width=410><FONT face=굴림체><input type=\"radio\" name=\"orAnd\" value=\"or\" checked>OR ( 또는 ) 검색<br><input type=\"radio\" name=\"orAnd\" value=\"and\">AND ( 그리고 ) 검색</FONT> </TD></TR>" ) ;
			out.println ( "<TR bgColor=#f7f7f7><TD align=right colSpan=4><FONT color=red size=2><IMG src=\"/image/icon_dot1.gif\"> \"검은색\"아이콘 항목중 반드시 하나는 입력하셔야 합니다. </FONT></TD></TR>" ) ;
			out.println ( "</TABLE></CENTER>" ) ;
			out.println ( "<BR><BR><CENTER><TABLE border=0 cellPadding=2 cellSpacing=1>" ) ;
			out.println ( "  <TR><TD width=680 align=right>" ) ;
			out.println ( "<input type=\"hidden\" name=\"search\" value=\"search\">" ) ;
			out.println ( "<input type=\"hidden\" name=\"first_search\" value=\"first_search\">" ) ;
			out.println ( "<input type=\"hidden\" name=\"phoneNumber\" value=\"null\">" ) ;
			out.println ( "<input type=\"hidden\" name=\"faxNumber\" value=\"null\">" ) ;
			out.println ( "<input type=\"hidden\" name=\"webURL\" value=\"null\">" ) ;
			out.println ( "<input type=\"hidden\" name=\"form\" value=\"form\">" ) ;
			out.println ( "<input type=\"hidden\" name=\"page\" value=\"1\">" ) ;
			out.println ( "<INPUT type=button name=search value=\"검색 하기\" onClick=\"Check_Form(this.form)\">" ) ;
			out.println ( "<INPUT type=reset name=reset value=\"다시 쓰기\">" ) ;
			out.println ( "<INPUT type=button name=back value=\"되돌아 가기\" onClick=\"Back_Click()\">" ) ;
			out.println ( "</TD></TR></TABLE></CENTER></FORM>" ) ;
		}
		out.println ( "</body></html>" ) ;		
		out.close ( ) ;
	}
}