/* 
    IntraPMS Project
    부서 발령을 위한 프레임 셋을 가진 html페이지 제공하는 서블릿

    
*/
import java.io.*;
import java.lang.*;

import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

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

public class DepartmentChangeServlet extends HttpServlet
{
	GroupwareControllerInterface groupwareController=null;
	BBSControllerInterface bbsController = null;
	ResultStatus bbsResultStatus = null;
	Properties pro=null;	

	public void init ( ServletConfig config ) throws ServletException 
	{
		super.init ( config ) ;
				
		//그룹웨어 컨트롤러를 생성한다.
		//먼저 프라퍼티를 생성한다.
		pro = new Properties();
		//DB매너저 구현 클래스 이름 설정
		pro.put("OrganizationDBManagerClassName", "PandaSoftOrganizationDBManager");
		pro.put("BBSDBManagerClassName", "PandaSoftBBSDBManager");
		pro.put("EDADBManagerClassName", "PandaSoftEDADBManager");
		pro.put("MailDBManagerClassName", "PandaSoftMailDBManger");
		
		try {
			groupwareController = GroupwareController.init( pro );
			System.out.println("그룹웨어 컨트롤러 생성을 마쳤습니다.");
			
			//게시판 관리 컨트롤러를 가져온다.
			bbsController = groupwareController.createBBSController();
			System.out.println("게시판 컨트롤러 생성도 무사히 마쳤습니다.");
			System.out.println ( "Groupware ShowMenuServlet init () Call..........." ) ;					
		}
		catch(Exception e) { }

	}

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

	/*----------------------------------------------------------------- */
	/**
	[메소드이름]: doGet<br>
	[기능]: 부서 발령하기에서 사원의 현재 상태를 보여준다.<br>
	[파라미터]: HttpServletRequest request, HttpServletResponse response<br>
	[호출자] : 사용자<br>
	*/
	/*--------------------------------------------------------------- */		
	public void doGet ( 
						HttpServletRequest	request , 
						HttpServletResponse	response
																				) throws ServletException, IOException {
		PrintWriter out ;
			
		// ContentType을 text/html로 set한다.
		response.setContentType("text/html;charset=euc-kr") ;
														
		// response의 Writer를 얻는다.
		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 ( true );
		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");   
		}

		System.out.println ( "메뉴 보여주기 서블릿의 response에 대한 프린트라이터가 생성되었습니다." ) ;

		// 넘겨받은 사원의 id를 저장한다.
		String id = request.getParameter ( "id" ) ;
		//kind = new String ( kind.getBytes ( "ISO-8859-1" ) , "EUC-KR" ) ;
		// 넘겨받은 사원의 부서를 저장한다.
		String department = request.getParameter ( "department" ) ;
		//name = new String ( name.getBytes("ISO-8859-1") , "EUC-KR" ) ;
		// 넘겨받은 사원의 팀을 저장한다.
		String team = request.getParameter ( "team" ) ;
		//kind = new String ( kind.getBytes ( "ISO-8859-1" ) , "EUC-KR" ) ;
		// 넘겨받은 사원의 직급을 저장한다.
		String orders = request.getParameter ( "orders" ) ;
		//name = new String ( name.getBytes("ISO-8859-1") , "EUC-KR" ) ;
		
		out.println ( "<html>" ) ;
		out.println ( "<head>" ) ;
		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 ( "<title>발령하고자 하는 부서를 선택하세요~~~~</title>" ) ;
		out.println ( "<script language=\"javascript\">" ) ;
		out.println ( "function ok( a, b, c ) {" ) ;
		out.println ( "	var department = arguments[0];" ) ;
		out.println ( "	var team = arguments[1];" ) ;
		out.println ( "	var orders = arguments[2];" ) ;
		out.println ( "	opener.result( department, team, orders );" ) ;
		out.println ( "   self.close(); " ) ;
		out.println ( "}" ) ;
		out.println ( "function can() { self.close();}" ) ;
		out.println ( "</script>" ) ;
		out.println ( "<frameset rows=\"1*\" cols=\"40%, 30%, 30%\" border=\"0\">" ) ;
		out.println ( "    <frame name=\"left\" src=\"/servlet/ShowDepartmentChangeServlet\" scrolling=\"auto\" marginwidth=\"0\" marginheight=\"14\">" ) ;
		out.println ( "    <frame name=\"center\" src=\"/servlet/DepartmentChangeCenterServlet?id=" + id 
			+ "&department=" + department
			+ "&team=" + team
			+ "&orders=" + orders
			+ "\" scrolling=\"auto\" marginwidth=\"0\" marginheight=\"14\">" ) ;
		out.println ( "    <frame name=\"right\" src=\"/DepartmentChangeRight.html\" scrolling=\"auto\" marginwidth=\"0\" marginheight=\"14\">" ) ;
		out.println ( "    <noframes>    <body bgcolor=\"white\" text=\"black\" link=\"blue\" vlink=\"purple\" alink=\"red\">" ) ;
		out.println ( "    <p>이 페이지를 보려면, 프레임을 볼 수 있는 브라우저가 필요합니다.</p>" ) ;
		out.println ( "</body></noframes></frameset>" ) ;
	
		out.println ( "</html>" ) ;
		
		out.close ( ) ;
	}
}