<%@page import="br.com.centralit.citcorpore.bean.EmpregadoDTO"%>
<%@page import="br.com.centralit.citcorpore.bean.UsuarioDTO"%>
<%@page import="br.com.citframework.util.UtilStrings"%>
<%@page import="br.com.centralit.citcorpore.util.CitCorporeConstantes"%>
<%@page import="br.com.centralit.citcorpore.util.WebUtil"%>
<%@page import="br.com.centralit.citcorpore.util.ParametroUtil"%>
<%@page import="br.com.centralit.citcorpore.util.Enumerados.ParametroSistema"%>
<%@page import="br.com.centralit.citcorpore.util.Enumerados.SimNao" %>

<%@ include file="/WEB-INF/templates/taglibs.jsp"%>

<% if (request.getParameter("iframe") == null || !request.getParameter("iframe").equalsIgnoreCase("true")) {
		String urlAtual = request.getServletPath();
		String portalTelaInicio = ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.LOGIN_PORTAL, "N");
		String habilitaNovoPortal = ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.HABILITAR_NOVO_PORTAL, "S");

		String nameUser = null;
		String emailUser = null;
		StringBuilder finalNameUser = new StringBuilder();
		String acessoCitsmart = null;
		if(WebUtil.getUsuario(request) != null) {
			nameUser = WebUtil.getUsuario(request).getNomeUsuario();
			emailUser = WebUtil.getUsuario(request).getEmail();
			acessoCitsmart = WebUtil.getUsuario(request).getAcessoCitsmart();

			if(nameUser != null){
				String[] array = new String[15];
				int index;
	
				if(nameUser.contains(" ")){
					int cont = 0;
	
					nameUser = nameUser.trim();
					array = nameUser.split(" ");
					index = array.length;
	
					for(String nome : array){
						if(cont == 0){
							finalNameUser.append(nome.toUpperCase() + " ");
							cont++;
						}else{
							if(cont == index-1){
								finalNameUser.append(" " + nome.toUpperCase());
							}else{
								if(nome.length() > 3){
									finalNameUser.append(nome.substring(0, 1).toUpperCase() + ". ");
								}
								cont++;
							}
						}
					}
				}else{
					finalNameUser.append(nameUser.toUpperCase());
				}
			}
		}
	%>
	<header id="header">
		<div id="header-inner" class="clearfix">
			<div id="logo">
				<% if(urlAtual.equalsIgnoreCase("/pages/portal/portal.jsp")) { %>
				<a href="${ctx}/pages/portal/portal.load">
					<img id="logo-img" alt="CITSMart" src="${ctx}/imagens/logo/logo-header.png"/>
				</a>
				<% } else { %>
				<a href="${ctx}/pages/index/index.load">
					<img id="logo-img" alt="CITSMart" src="${ctx}/imagens/logo/logo-header.png"/>
				</a>
				<% } %>
			</div><!-- #logo -->
	
			<div id="header-toolbar" class="clearfix">
				<ul class="clearfix">
					<!-- // #### INICIO #### -->
					<%
					if (urlAtual.equalsIgnoreCase("/pages/smartPortal/smartPortal.jsp") || urlAtual.equalsIgnoreCase("/pages/portal/portal.jsp")) { %>
						<%
						if ("S".equalsIgnoreCase(acessoCitsmart) || "Y".equalsIgnoreCase(acessoCitsmart)) {
						%>
						<li>
							<a 
								href="${ctx}/pages/index/index.load"><i class="material-icons">home</i> <fmt:message key="portal.acessarSistema"/></a>
						</li>
					<%
						}
					} else {
					%>
						<% 
						if ("S".equalsIgnoreCase(portalTelaInicio) || "Y".equalsIgnoreCase(portalTelaInicio)) { 
							if ("S".equalsIgnoreCase(habilitaNovoPortal) || "Y".equalsIgnoreCase(habilitaNovoPortal)) {
						%>
							<li>
								<a 
									href="${ctx}/pages/smartPortal/smartPortal.load"><i class="material-icons">home</i> <fmt:message key="cronograma.inicio"/></a>
							</li>
							<%
							} else {
							%>
							<li>
								<a 
									href="${ctx}/pages/portal/portal.load"><i class="material-icons">home</i> <fmt:message key="cronograma.inicio"/></a>
							</li>
							<%
							}
							%>
						<%
						} else {
						%>
						<li>
							<a 
								href="${ctx}/pages/index/index.load"><i class="material-icons">home</i> <fmt:message key="cronograma.inicio"/></a>
						</li>
						<%
						}
						%>
					<%
					}
					%>
					<!-- // #### INICIO #### -->
	
					<!-- // #### ASTERISK #### -->
					<%
					String ativaBotaoTelefonia = ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.SERVASTERISKATIVAR, "N");
					if (ativaBotaoTelefonia.equalsIgnoreCase("N")){
						ativaBotaoTelefonia = ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.ATIVAR_WEBSERVICE_TELEFONIA, "N");
					}
					if (ativaBotaoTelefonia.equals("S")) {
					%>
					<li>
						<a 
							href="javascript:abreRamalTelefone();"><i class="material-icons">headset_mic</i> <fmt:message key="asterisk.atendimento"/></a>
					</li>
					<%
					}
					%>
					<!-- // #### ASTERISK #### -->

					<!-- // #### SUPORTE #### -->
					<%
					String configuracaoTelefoneTelaLogin = ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.CONFIGURACAO_TELEFONE_SUPORTE_TELA_LOGIN, "");
					String configuracaoEmailSuporteTelaLogin = ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.CONFIGURACAO_EMAIL_SUPORTE_TELA_LOGIN, "");
					boolean existsConfiguracaoTelefoneTelaLogin = !UtilStrings.isNullOrEmpty(configuracaoTelefoneTelaLogin),
							existsConfiguracaoEmailSuporteTelaLogin = !UtilStrings.isNullOrEmpty(configuracaoEmailSuporteTelaLogin);
	
					if(existsConfiguracaoTelefoneTelaLogin || existsConfiguracaoEmailSuporteTelaLogin) {
					%>
					<li id="header-toolbar-support" class="dropdown">
						<a 
							href="javascript:;" 
							data-toggle="dropdown"><i class="material-icons">call</i> <fmt:message key="citcorpore.comum.suporte"/> <span class="caret"></span></a>
						<ul class="dropdown-menu pull-right">
							<%
							if(existsConfiguracaoTelefoneTelaLogin) {
								String[] telefones = configuracaoTelefoneTelaLogin.split(";"); 
								for(String telefone : telefones) {
							%>
							<li>
								<a href="javascript:;">
									<i class="material-icons">phone_iphone</i> <%= telefone %>
								</a>
							</li>
							<%
								}
							}

							if(existsConfiguracaoEmailSuporteTelaLogin) {
								String[] emails = configuracaoEmailSuporteTelaLogin.split(";"); 
								for(String email : emails) {
							%>
							<li>
								<a href="mailto:<%=email %>?Subject=[<fmt:message key="citcorpore.comum.suporte"/>]">
									<i class="material-icons">email</i> <%= email %>
								</a>
							</li>
							<%
								}
							}
							%>
						</ul>
					</li>
					<%
					}
					%>
					<!-- // #### SUPORTE #### -->
	
					<!-- // #### AJUDA #### -->
					<li id="header-toolbar-help" class="dropdown">
						<a 
							href="javascript:;" 
							data-toggle="dropdown"><i class="material-icons">help</i> <fmt:message key="citcorpore.comum.ajuda"/> <span class="caret"></span></a>
						<ul class="dropdown-menu pull-right">
							<li class="dropdown">
								<a 
									href="/cithelp/index.html" 
									target="blank"><i class="material-icons">import_contacts</i> <fmt:message key="citcorpore.comum.guiaUsuario"/></a>
							</li>
							<li>
								<a 
									href="#citsmart-sobre-modal" 
									data-toggle="modal" 
									data-target="#citsmart-sobre-modal"><i class="material-icons">info</i> <fmt:message key="citcorpore.comum.sobre"/></a>
							</li>
						</ul>
					</li>
					<!-- // #### AJUDA #### -->
	
					<!-- // #### CONTA #### -->
					<li class="account dropdown">
						<a 
							href="javascript:;"
							data-toggle="dropdown"><i class="material-icons">lock</i> <%= finalNameUser %></span> <span class="caret"></span></a>
	
						<ul class="dropdown-menu pull-right">
							<li class="account-profile">
								<div class="account-profile-container clearfix">
									<div class="account-profile-img">
										<i class="material-icons">account_circle</i>
									</div><!-- .account-profile-img -->

									<div class="account-profile-content">
										<strong>
											<%=UtilStrings.nullToVazio(nameUser)%>
										</strong>
										<p>
											<%=UtilStrings.nullToVazio(emailUser)%>
										</p>

										<div>
											<a  
												href="${ctx}/pages/alterarSenha/alterarSenha.load">
												<i class="material-icons material-icon-inline md-18">mode_edit</i> <fmt:message key="usuario.alterarSenha"/>
											</a>
										</div>
									</div><!-- .account-profile-content -->
								</div><!-- .account-profile-container -->
							</li>

							<li class="account-items">
								<div class="clearfix">
									<a 
										href="${ctx}/pages/empregado/empregado.load"
										class="btn btn-default pull-left">
										<i class="material-icons material-icon-inline md-18">settings</i> <span><fmt:message key="citcorpore.comum.configuracoes"/></a></span>
									
									<a 
										href="${ctx}/pages/login/login.load?logout=yes" 
										class="btn btn-default pull-right" >
											<i class="material-icons material-icon-inline md-18">power_settings_new</i> <span><fmt:message key="citcorpore.comum.sair"/></span>
										</a>
								</div>
							</li>
						</ul>
					</li>
					<!-- // #### CONTA #### -->
				</ul>
			</div><!-- #header-toolbar -->
		</div><!-- #header-inner -->
	</header>
<div id="citsmart-sobre-modal" class="modal hide fade wd-560">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3 class="modal-title"><fmt:message key="citcorpore.comum.sobre"/></h3>
			</div><!-- .modal-header -->
		
			<div class="modal-body">
				<cit:sobreCitsmart></cit:sobreCitsmart>
			</div><!-- .modal-body -->
		</div><!-- .modal-content -->
	</div><!-- .modal-dialog -->
</div><!-- #citsmart-sobre-modal -->
<% } %>