/* 
    IntraPMS Project
    메인 화면에 각 기능에 대한 링크를 보여주는 서블릿

    
*/
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 ShowMenuServlet 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 ( ) {
		System.out.println ( "Groupware UserAuthenticationServlet destroy () Call..........." ) ;
		super.destroy();
		DBConnectionManager.instance.release();	
	}

	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: 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 authenDepartment = null ;
		String authenTeam = 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");
			authenDepartment = (String)session.getValue("Department");
			authenTeam = (String)session.getValue("Team");
			authenName = (String)session.getValue("Name");   
		}
		/////////////////////////////////////////////

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

		// 넘겨받은 사원의 kind를 저장한다.
		String kind = request.getParameter ( "kind" ) ;
		// 넘겨받은 사원의 이름을 저장한다.
		String name = request.getParameter ( "name" ) ;
		
		out.println ( "<html>" ) ;
		out.println ( "<head>" ) ;
		out.println ( "<base target=\"contents\">" ) ;
		out.println ( "<title>---- PandaSoft Intranet Groupware ----</title>" ) ;
		out.println ( "		<STYLE type=text/css>P {" ) ;
		out.println ( "	COLOR: white; FONT-FAMILY: 굴림,arial,curier; FONT-SIZE: 9pt; LINE-HEIGHT: 12px" ) ;
		out.println ( "}" ) ;
		out.println ( ":link {" ) ;
		out.println ( "	COLOR: white; TEXT-DECORATION: none" ) ;
		out.println ( "}" ) ;
		out.println ( ":visited {" ) ;
		out.println ( "	COLOR: white; TEXT-DECORATION: none" ) ;
		out.println ( "}:active {	COLOR: white; TEXT-DECORATION: underline" ) ;
		out.println ( "}:hover {	COLOR: white; TEXT-DECORATION: underline" ) ;
		out.println ( "}FONT {	COLOR: black; FONT-SIZE: 9pt; LINE-HEIGHT: 0.7cm; font-face: Arial" ) ;
		out.println ( "}FONT.bb {	COLOR: white; FONT-SIZE: 7pt; font-face: Arial" ) ;
		out.println ( "}FONT.dd {	COLOR: white; FONT-SIZE: 16pt; font-face: Arial}</STYLE>" ) ;
		out.println ( "</head>" ) ;
		out.println ( "<body>" ) ;
		out.println ( "<form><CENTER><TABLE border=0 cellPadding=0 cellSpacing=1><TBODY><TR>" ) ;
		out.println ( "<td bgcolor=white width=550 align=left valign=center><a href=\"/servlet/MainServlet\" target=\"_top\"><img src=\"/image/왼쪽상단.jpg\" border=0 alt=\"처음 페이지로\"><a></td>" ) ;
		
		// 게시판 선택시 게시판트리(content) 와 사용자의 처음 게시판(detail)을 뿌려준다...
		OptionProperty option = bbsController.getPersonalOption( authenId );

		out.println ( "<TD bgcolor=white width=90 align=middle><a href=\"/servlet/BBSTreeServlet\" target=\"contents\" onclick=\"parent.frames['detail'].location='/servlet/BBSFirstServlet'\" onMouseOver=\"document.forms[0].bbs.src='/image/게시판.gif'\" onMouseOut=\"document.forms[0].bbs.src='/image/c_게시판.gif'\"><img name=\"bbs\" border=\"0\" src=\"/image/c_게시판.gif\" alt=\"게시판으로\"><img name=\"t_bbs\" border=\"0\" src=\"/image/t_게시판.gif\" alt=\"게시판으로\"></A></TD> " ) ;	

		// 메일로 링크되는 이미지
		out.println ( "		<TD bgcolor=white width=90 align=middle><a href=\"/servlet/MailInitPageServlet\" target=\"detail\" onclick=\"parent.frames[\'contents\'].location=\'/Mailleft.html\'\" onMouseOver=\"document.forms[0].mail.src='/image/전자우편.gif'\" onMouseOut=\"document.forms[0].mail.src='/image/c_전자우편.gif'\"><img name=\"mail\" border=\"0\" src=\"/image/c_전자우편.gif\" alt=\"전자 우편으로\"><img name=\"t_mail\" border=\"0\" src=\"/image/t_전자우편.gif\" alt=\"전자 우편으로\"></a></TD>" ) ;
		
		/// 전자 결재로 링크되는 이미지
		out.println ( "    <TD bgcolor=white width=90 align=middle><a href=\"/servlet/EDAStartPanelServlet\" target=\"detail\" onclick=\"parent.frames[\'contents\'].location=\'/EDAMainMenu.html\'\" onMouseOver=\"document.forms[0].eda.src='/image/기안결재.gif'\" onMouseOut=\"document.forms[0].eda.src='/image/c_기안결재.gif'\"><img name=\"eda\" border=\"0\" src=\"/image/c_기안결재.gif\" alt=\"전자 결재로\"><img name=\"t_eda\" border=\"0\" src=\"/image/t_기안결재.gif\" alt=\"전자 결재로\"></A></TD> " ) ;
		
		if ( kind.equals("1") ) {
			// 관리자인 경우...
			out.println ( "<TD bgcolor=white width=90 align=middle><a href=\"/servlet/ShowOrganizationTreeServlet\" target=\"contents\" onclick=\"parent.frames[\'detail\'].location=\'/orgdetail.html\'\" onMouseOver=\"document.forms[0].org.src='/image/관리기능.gif'\" onMouseOut=\"document.forms[0].org.src='/image/c_관리기능.gif'\"><img name=\"org\" border=\"0\" src=\"/image/c_관리기능.gif\" alt=\"관리 기능으로\"><img name=\"t_org\" border=\"0\" src=\"/image/t_관리기능.gif\" alt=\"관리 기능으로\"></A></TD>" ) ;
		} else {
			// 일반 사용자인 경우...
			out.println ( "<TD bgcolor=white width=90 align=middle><a href=\"/servlet/PersonInformationServlet\" target=\"detail\" onClick=\"parent.frames[\'contents\'].location=\'/blank.html\'\" onMouseOver=\"document.forms[0].org.src='/image/관리기능.gif'\" onMouseOut=\"document.forms[0].org.src='/image/c_관리기능.gif'\"><img name=\"org\" border=\"0\" src=\"/image/c_관리기능.gif\" alt=\"개인 정보 변경으로\"><img name=\"t_org\" border=\"0\" src=\"/image/t_개인정보.gif\" alt=\"개인 정보 변경으로\"></A></TD>" ) ;
		}
		out.println ( "<TD bgcolor=white width=90 align=middle><a href=\"/servlet/LogInServlet\" target=\"_parent\" onMouseOver=\"document.forms[0].logout.src='/image/로그아웃.gif'\" onMouseOut=\"document.forms[0].logout.src='/image/c_로그아웃.gif'\"><img name=\"logout\" border=\"0\" src=\"/image/c_로그아웃.gif\" alt=\"그룹웨어 나가기\"><img name=\"t_logout\" border=\"0\" src=\"/image/t_로그아웃.gif\" alt=\"그룹 웨어 나가기\"></a></TD>" ) ;
		//if ( kind.equals("1") ) {
		//	out.println ( "<TD bgcolor=white valign=bottom align=right width=100><p><FONT>" + name + "(관리자)</FONT></p></TD>" ) ;
		//} else {
		//	out.println ( "<TD bgcolor=white valign=bottom align=right width=100><p><FONT>" + name + "(사용자)</FONT></p></TD>" ) ;
		//}
		out.println ( "</TR></TBODY></TABLE></CENTER></form></body>" ) ;
		out.println ( "</html>" ) ;
		
		out.close ( ) ;
		}
}