<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="kr.co.kihyun.moumi.MoumiConfig"%>
<%@ page import="kr.co.kihyun.lang.MString"%>
<%@ page import="kr.co.kihyun.lang.Encoder"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.URLDecoder"%>
<%@ page import="kr.co.kihyun.beans.entity.Grade"%>
<%@ page import="kr.co.kihyun.beans.user.HttpSSOLogin"%>
<%@ page import="kr.co.kihyun.beans.user.User"%>
<%@ page import="kr.co.kihyun.lang.MInteger"%>
<%@ page import="org.slf4j.Logger"%>
<%@ page import="org.slf4j.LoggerFactory"%>
<%
	Logger LOG = LoggerFactory.getLogger(this.getClass());
	try{
	    String leftPage="", mainPage;
	    String redirect = URLDecoder.decode(MString.checkNull(request.getParameter("redirect")), "UTF-8");
	    LOG.debug("sessionID: {}", session.getId());

	    if(session.getAttribute("grade").equals(Grade.NULL)){
	        if(HttpSSOLogin.getSysAuth(request) == MoumiConfig.SYSADM){
	            leftPage = "/totsys/common/inc/totper/left/left.jsp";
	            mainPage = MString.isNull(redirect) ? "/totsys/totper/mydocbox/prssbox/doc_list.jsp?docType=PRSS" : redirect;
	        }else{
	            leftPage = "/totsys/common/inc/totper/left/left.jsp";
	            mainPage = MString.isNull(redirect) ? "/totsys/repoper/mydocbox/returnbox/report_list.jsp" : redirect;
	        }
	    }else if(HttpSSOLogin.getSysAuth(request) == MoumiConfig.REPOPER){
	        leftPage = "/totsys/common/inc/totper/left/left.jsp";
	        mainPage = MString.isNull(redirect) ? "/totsys/repoper/mydocbox/returnbox/report_list.jsp" : redirect;
	    }else {
	        leftPage = "/totsys/common/inc/totper/left/left.jsp";
	        //mainPage = MString.isNull(redirect) ? "/totsys/repoper/mydocbox/tempbox/report_list.jsp?reportType=TEMP" : redirect;
	        mainPage = MString.isNull(redirect) ? "/totsys/repoper/mydocbox/returnbox/report_list.jsp" : redirect;
	    }
	    //top, left 로드 후 첫 메뉴에따른 페이지를 로드하므로 수정
	    mainPage = "about:blank";
%>
<!DOCTYPE html>
<html lang="ko">
	<head>
		<meta charset="UTF-8">
		<title><%=MoumiConfig.getTitle()%></title>
		<!-- 페이지 변경시마다 로딩 페이지 블록,팝업창 레이어로,승인상신 무조건팝업,전체화면,폼 확대 -->
		<link rel="stylesheet" type="text/css" href="/totsys/common/css/frame.css">
		<script src="/totsys/common/js/jquery-1.12.4.min.js"></script>
		<script src="/totsys/common/js/main.js"></script>
		<script>
		//topMenu가 left멘뉴를 참조하고 있으므로 순차로딩이 필요함.
		$(document).ready(function(){
			$("#leftMenu").load(function(){
				$("#topMenu").attr("src","/totsys/login/top.jsp");
			});
		});	
		//iframe에서 submit시 발생하는 스크롤이동방지
		$(this).on("scroll",function(e) {
		   parent.scrollTo(0, 0);
		});
		</script>
	</head>
	<body>
	
	<%if(MoumiConfig.isOnTopMenu()){%>
		<header>
			<iframe title="topMenu" id="topMenu" name="topMenu" src="about:blank" style="height:102px"></iframe><!-- knu logo 높이 수정 -->
		</header>
		<section>
			<nav>
				<iframe title="leftMenu" id="leftMenu" name="left" src="<%= leftPage %>"></iframe>
			</nav>
			<article>
				<iframe title="main" id="main" name="main" src="<%= mainPage %>" onload="bindload(this);"></iframe>
			</article>
		</section>
	<%}else{%>
		<header>
			<iframe title="leftMenu" id="leftMenu" name="left" src="<%= leftPage %>"></iframe>
		</header>
		<article>
			<iframe title="main" id="main" name="main" src="<%= mainPage %>" onload="bindload(this);"></iframe>
		</article>
	<%}%>
	</body>
</html>
<%
}catch(Exception ex){
    ex.printStackTrace();
    out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/servlet/kr.co.kihyun.beans.user.HttpSSOLogin?mode=logout';"));
}finally{
}
%>
