<%@ page import="ro.emid.common.utils.MenuConstants" %>
<%@ page import="ro.emid.common.utils.UserUtils" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ taglib prefix="emid" tagdir="/WEB-INF/tags" %>

<%
    String jsp = (String) request.getAttribute("__jsp");
    if( jsp == null){
        response.sendRedirect( request.getContextPath() + request.getContextPath() +  ".default");
        return;
    }
%>

<%! private static boolean in(String value, String... values) {
    if (value == null) return false;
    if (values == null || value.length() == 0) return false;
    for (String s : values) {
        if (s != null && s.equals(value)) return true;
    }
    return false;
}%>

<%
    User user = SessionUtils.getUserLogat(session);
    String selectedSubTab = "";
    String action = request.getParameter("action");

    if(in(action, "home")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_HOME;

    }else if(in(action, "show-users", "view-user", "edit-user")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_UTILIZATORI;

    }else if(in(action, "show-nomenclator-instalatii", "sync-bdi-history")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_NOM_BDI;

    }else if(in(action, "show-nomenclator", "save-nomenclator")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_NOM_GEN;

    }else if(in(action, "show-volum-instalatii")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_VOLUM_INST;

    }else if(in(action, "show-sesiuni")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_SESIUNI_RAPORTARE;

    }else if(in(action, "show-ads")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_CONSTANTA_AD;

    }else if(in(action, "properties")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_PROPRIETATI;

    }else if(in(action, "showSetValue")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_SEMNALIZARI;

    }else if(in(action, "showUpdateCategoriiScreen")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_CE_NIVELE_TENS;

    }else if(in(action, "alocare-centre-ded")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_CE_DISPECERI;

    }else if(in(action, "sync-ac-manager", "sync-ac-history")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_SYNC_AC_MANAGER;

    }else if(in(action, "admin-messages")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_MESAJE;

    }else if(in(action, "showLogs")) {
        selectedSubTab = MenuConstants.ADMINISTRARE.LINK_LOGURI;
    }
%>


<!DOCTYPE html>
<html>
<head>
    <title>EMID / Admin - [<%=AppProperties.getInstance().getVersion()%>]</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <%@include file="layout/includes-emid.jspf"%>

    <link rel="stylesheet" type="text/css" href="<%=AppConstants.WEB_RESOURCE_PATH%>/styles/admin.css?<%=AppProperties.getInstance().getVersion()%>">
    <script type="text/javascript"  src="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/admin-layout.js?<%=AppProperties.getInstance().getVersion()%>"></script>

    <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery(".menu a").click(function(){
                jQuery(this).parent().addClass("selected");
            });
        });
    </script>
</head>
<body>

<%@include file="layout/header-emid.jspf" %>
<table width="100%" id="page" border="0">
    <tr><td  width="180" valign="top">
        <ul class="menu">
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_HOME)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=home">Home</a>
            </li>
            <% if ( UserUtils.hasAdmRightUtilizatori(user) ){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_UTILIZATORI)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=show-users">Utilizatori</a>
            </li>
            <% }  if (UserUtils.hasAdmRightNomenclatoareBdi(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_NOM_BDI)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=show-nomenclator-instalatii">Nomenclatoare BDI</a>
            </li>
            <% }  if (UserUtils.hasAdmRightNomenclatoareGenerale(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_NOM_GEN)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=show-nomenclator"><nobr>Nomenclatoare generale</nobr></a>
            </li>
            <% }  if (UserUtils.hasAdmRightVolumInstalatii(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_VOLUM_INST)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=show-volum-instalatii">Volumul de instalaţii</a>
            </li>
            <% }  if (UserUtils.hasAdmRightSesiuniRaportare(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_SESIUNI_RAPORTARE)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=show-sesiuni">Sesiuni raportare</a>
            </li>
            <% }  if (UserUtils.hasAdmRightConstantaAD(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_CONSTANTA_AD)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=show-ads">Constanta AD</a>
            </li>
            <% }  if (UserUtils.hasAdmRightProprietati(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_PROPRIETATI)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=properties">Proprietăţi</a>
            </li>
            <% }  if (UserUtils.hasAdmRightSemnalizari(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_SEMNALIZARI)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=showSetValue">Semnalizări</a>
            </li>
            <% }  if (UserUtils.hasAdmRightCeNiveleTensiune(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_CE_NIVELE_TENS)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=showUpdateCategoriiScreen">CE / Nivele tensiune</a>
            </li>
            <% } if (UserUtils.hasAdmRightCeDispeceri(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_CE_DISPECERI)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=alocare-centre-ded">CE / Dispeceri</a>
            </li>
            <% } if (UserUtils.hasAdmRightSyncAcManager(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_SYNC_AC_MANAGER)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=sync-ac-manager">Sincronizare AC</a>
            </li>
            <% } if (UserUtils.hasAdmRightMessage(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_MESAJE)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=admin-messages">Mesaje</a>
            </li>
            <% }  if (UserUtils.hasAdmRightLoguri(user)){ %>
            <li <%=selectedSubTab.equals(MenuConstants.ADMINISTRARE.LINK_LOGURI)?"class=\"selected\"":""%>>
                <a href="<%=AppConstants.APP_NAME%>?action=showLogs">Jurnal audit</a>
            </li>
            <% } %>
        </ul>
    </td>
    <td valign="top" id="contentu">
        <emid:messages/>
        <jsp:include page="<%=jsp%>"/>
    </td>
    </tr>
</table>

</body>
</html>