/* 
    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 ShowOneDepartmentServlet extends HttpServlet
{
	GroupwareControllerInterface gc = null ;
	OrganizationManagementControllerInterface  omc = null ;
	Properties myPro = null ;

	public void init ( ServletConfig config ) throws ServletException {
		super.init ( config ) ;
		System.out.println ( "ShowOneDepartmentServlet 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 ( "부서 상세정보 보여주기 서블릿의 프라퍼티 설정을 무사히 마쳤습니다." ) ;
		
		try {
			gc = GroupwareController.init ( myPro ) ;
			/////////////////////////////////////////////////
			System.out.println ( "부서 상세정보 보여주기 서블릿에서 사용할 그룹웨어 컨트롤러 생성을 무사히 마쳤습니다." ) ;
			
			// 조직도 관리 컨트롤러를 가져온다.
			omc = gc.createOrganizationManagementController ( ) ;
			///////////////////////////////////////////////////////////
			System.out.println ( "부서 상세정보 보여주기 서블릿에서 사용할 조직도 관리 컨트롤러 생성도 무사히 마쳤습니다." ) ;
		} catch ( Exception e ) { }
	}
	
	public void destroy ( ) {
		super.destroy();
		DBConnectionManager.instance.release() ;
		System.out.println ( "ShowOneDepartmentServlet destroy () Call..........." ) ;
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: doGet<br>
	 [기능]: 부서의 상세 정보를 보여준다.<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();
			response.sendRedirect("../Login.html");
		} else {
			authenKind = (String)session.getValue("Kind");
			authenId = (String)session.getValue("Id");
			authenName = (String)session.getValue("Name");   
		}
		/////////////////////////////////////////////

		Department[] allDepartment ;
		Team[] allTeam ;

		// 폼 태그의 변수 값을 얻는다.
		String name = request.getParameter ("property") ;		
		name = new String ( name.getBytes("ISO-8859-1") , "EUC-KR" ) ;	
		
		// 데이타 베이스에서 모든 부서의 내용을 가져온다.
		allDepartment = omc.getAllDepartment ( ) ;
		
		// 데이타 베이스에서 모든 팀의 내용을 가져온다.
		Department htDep = new Department ( ) ;
		htDep.setName ( name ) ;
		allTeam = omc.getAllTeam( htDep ) ;
				
		int index ;
		for ( index=0 ; !(allDepartment[index].getName().equals(name)) ; index++ ) ;	

		out.println ( "<html><head><title>팬더 소프트</title>" ) ;
		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\"></p>" ) ;
				
		out.println ( "<script language=\"JavaScript\">" ) ;
		out.println ( "<!--" ) ;
		out.println ( "	function backClick()" ) ;
		out.println ( "	{ " ) ;
		out.println ( " 	history.back();" ) ;
		out.println ( "	} " ) ;
		out.println ( "//-->" ) ;
		out.println ( "</script>" ) ;

		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>" + allDepartment[index].getName() + "(상세 정보)</nobr></td></tr></table></FORM>" ) ;
		out.println ( "<p><p><p><p>" ) ;
		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=굴림체>" + allDepartment[index].getName() + " <input type=\"hidden\" name=\"name\" value=\"" + allDepartment[index].getName() + "\"></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 value=\"" + allDepartment[index].getWeightWork() + "\"></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 value=\"" + allDepartment[index].getPhoneNumber() + "\"></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 value=\"" + allDepartment[index].getFaxNumber() + "\"></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 value=\"" + allDepartment[index].getWebURL() + "\"></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>" + allDepartment[index].getDepartmentExplain() + "</textarea></FONT> </TD></TR>" ) ;
		out.println ( "</TABLE></CENTER>" ) ;
		out.println ( "<BR><BR><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=submit name=update value=\"변경하기\">" ) ;
		if ( allTeam[0].getName().equals("null") ) {
			out.println ( "<INPUT type=submit name=delete value=\"삭제하기\">" ) ;
		} else {
			out.println ( "<INPUT type=button name=delete value=\"삭제하기\" onClick=\"alert('이 부서에는 팀이 존재합니다.\\n팀을 먼저 삭제해 주십시요!');\">" ) ;
		}
		out.println ( "<INPUT type=button name=back value=\"되돌아 가기\" onClick=\"backClick()\">" ) ;
		out.println ( "</TD></TR></TABLE></CENTER></FORM>" ) ;
		
		out.println ( "</body></html>" ) ;		
		
		out.close ( ) ;
	}
}


			
		