<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="com.csc.library.menu.Menu" %>
<%@ page import="com.csc.library.menu.AdminMenu" %>
<%@ page import="com.csc.library.menu.MenuList"%>
<%@ page import="com.csc.library.menu.TreeMenu" %>
<%@ page import="com.csc.library.menu.*" %>

<%@ page import="com.csc.library.utilities.*"%>
<%@ page import="java.io.File,com.csc.library.util.ManageDocument" %>
<%@ page import="com.csc.library.database.*" %>
<%@ page import="com.csc.library.entry.*" %>
<%@ page import="com.csc.library.session.*" %>

<jsp:useBean id="EMV_PM" class="com.csc.library.system.Task" scope="page" />
<jsp:useBean id="EMV_REPLY" class="com.csc.library.system.Task" scope="page" />
<%

	EMV_PM.setChannel(request,response);
	EMV_REPLY.setChannel(request,response);

	HelpEntry screen_pm= (HelpEntry) EMV_PM.process("HelpEntry","PMINBOXHELP");
	EmvHelpEntry screen_re= (EmvHelpEntry) EMV_REPLY.process("EmvHelpEntry","PMREPLYHELP");
	UProfile uprofile = null;
	if(session != null ) {
		uprofile = (UProfile)session.getAttribute("userprofile");
	}
	if( uprofile == null ){
		return;
	}

	Menu main_menu = new GlobalMenu_STD(uprofile);
	String mainMenu = main_menu.getMenu();

	int mymainmsg=0;
	int myreplymsg=0;
	String filter="userid='"+uprofile.get("employeeid")+"' and flag=0";
	screen_pm.getInquiry().setFilter(filter);
	screen_pm.getInquiry().refresh();

	String filterreply="userid ='"+uprofile.get("employeeid")+"' and flag=0";
	screen_re.getInquiry().setFilter(filterreply);
	screen_re.getInquiry().refresh();

	mymainmsg=screen_pm.getInquiry().recCount();
	myreplymsg=screen_re.getInquiry().recCount();

	ManageDocument manage = new ManageDocument();
	manage.setUProfile( uprofile );
	int newnote = manage.getNewDocument( uprofile.get("employeeid") );

	Menu menu = new AdminMenu(uprofile);

	String imghr=menu.getMenu();
	String myfirstlogin = uprofile.get("loginfirst");
	uprofile.set("loginfirst","0");
	String mydefaultpage = uprofile.get("defaultpage");
%>
<script type='text/javascript' src='/hr/dwr/engine.js'></script>
<script type='text/javascript' src='/hr/dwr/util.js'></script>
<script type='text/javascript' src='/hr/dwr/interface/SearchDWR.js'></script>
<link rel="stylesheet" href="../CSS/jquery.mCustomScrollbar.css">
<script type='text/javascript' src='../JS/jquery.mCustomScrollbar.js'></script>
<link rel="stylesheet" href="../CSS/ADMIN-MENU.css" />
<style>
	#module_menu{
	   padding-top:0px !important;
	   position:fixed !important;
	}
	.container-fluid{
		display:block;
		float:left;
		width:100%;
		height:100%px;
		line-height:50px;
	}
	.module_parent{
		padding-top:8% !important;
	}
	.myscrollmenu{
		position:fixed;
		height: 720px;
		overflow-y:auto;
	}
	.mCSB_scrollTools_vertical{
		right:5px !important;
	}
	@media screen and (max-width: 1366px){
		.module_parent{
			padding-top:5% !important;
		}
		.module_child{
			height:150px !important;
			width:200px !important;
		}
	}

	@media screen and (max-height:780px){
		.myscrollmenu{
			position:fixed;
			height:670px;
		}
	}

	@media screen and (max-height:680px){
		.myscrollmenu{
			position:fixed;
			height:500px;
		}
	}

	@media screen and (max-height:550px){
		.myscrollmenu{
			position:fixed;
			height:350px;
		}
	}
	@media screen and (max-width:1490px){
		.mCSB_scrollTools_vertical{
			right:7px !important;
		}
	}
	@media screen and (max-width:1366px){
		.mCSB_scrollTools_vertical{
			right:10px !important;
		}
	}
</style>
<script language="javascript">
	var click_status="";
	var _errorHandler = function(message) {
		if(message != null ) {
			if (typeof message == "object" && message.name == "Error" && message.description) {
				alert("Error: " + message.description);
			} else if (message.toString().indexOf("0x80040111") == -1) {
					// Ignore NS_ERROR_NOT_AVAILABLE
					//alert(message);
			}
		}
	}
		//dwr.engine.setErrorHandler(function(message) {});
	dwr.engine.setErrorHandler(_errorHandler);
	function checkPM() {
		dwr.engine.beginBatch();
		SearchDWR.searchAll(new Array("PMINBOX","messageid,companyid,senderid","userid = '<%=uprofile.get("employeeid")%>' and flag='0'","messageid","langon"),pm);
		dwr.engine.endBatch({
			async:false
		});

		setTimeout("checkPM();",300000);
	}

	$(document).ready(function(){
		/*var firstlogin = "<%=myfirstlogin%>";
		var defaultpage= "<%=mydefaultpage%>";
		$("#module_menu").css( 'display', 'none' );
		if (firstlogin=="1" && defaultpage=="1"){
			$("#module_menu").css( 'display', 'table' );
		}*/
		$("#emp_INBOX").find(".tools-text").html($("#emp_INBOX").text()+" [<%=newnote%>]");
		$("#emp_PM_INBOX").find(".tools-text").html($("#emp_PM_INBOX").text()+" [<%=mymainmsg+myreplymsg%>]");
		$(".tools-admin").click(function(){
			$("#module_menu").css( 'display', 'table' );
			$('body').css('overflow-y', 'hidden');
		});

	});
</script>

<%
	String lang = uprofile.get("lang").toString();
	int alert_before = Integer.parseInt(StaticConfig.getConfigCompany(uprofile, "SM1003"));
	CscCalendar now = new CscCalendar();
	CscCalendar alert_expiredate = new CscCalendar(uprofile.get("expiredate")).decDate(alert_before);
	CscCalendar expiredate = new CscCalendar(uprofile.get("expiredate"));
	int num_date = 0;
	String msg="";
	if(now.afterEqualsDate(alert_expiredate)){
		num_date = now.diff(expiredate);
		System.out.print(expiredate);
		if(num_date>0 && !uprofile.get("pwdstatus").equals("1")){
			msg += "<li role='separator' class='divider'></li><li><a href='PI_PASSWORD.jsp' style='color:orange;'>";
			if(lang.equalsIgnoreCase("tha")){
				msg +=" รหัสผ่านจะหมดอายุในอีก <label style='color:red;'>"+num_date+"</label> วัน";
			}else{
				msg +=" Password will expired in <label style='color:red;'>"+num_date+"</label> days";
			}
			msg += "</a></li>";
		}
	}
%>
<nav class="navbar navbar-default ">
	<div class="container-fluid">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
				<span class="sr-only">Toggle navigation</span>
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="#"><%=uprofile.get("fullname_noprefix")%></a>
		</div>
		<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
				<%=msg%>
				<li role="separator" class="divider"></li>
				<li><a href="Javascript:changeLang('tha','eng')"><img src="/hr/IMAGES/EMPVIEW/TH.png"></a></li>
				<li role="separator" class="divider"></li>
				<li><a href="Javascript:changeLang('eng','tha')"><img src="/hr/IMAGES/EMPVIEW/EN.png"></a></li>
			</ul>
			<%=imghr%>
			<jsp:include page="../MODULE_SELECT.jsp" flush="true" />
		</div>
	</div>
</nav>