<%@page import="com.capgemini.framework.common.SettingsHelper" %>
<%@page import="com.capgemini.framework.common.activedirectory.ActiveDirectory" %>
<%@page import="com.capgemini.framework.teamcenter.exceptions.KurtException" %>
<%@page import="com.capgemini.reports.database.javabean.DbUser.UserData" %>
<%@page import="java.net.InetAddress" %>
<%! final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("com.capgemini.index.jsp"); %>
<%
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);

    String rawUserLogin = request.getRemoteUser();

    // Useful for debug:
    log.trace("Request:            =" + request.toString());
    log.trace("Request: Auth Type  =" + request.getAuthType());
    log.trace("Request: HeaderNames=" + request.getHeaderNames().toString());
    log.trace("Request: isSecure   =" + request.isSecure());
    log.trace("Raw userName        =" + rawUserLogin);


    // Obtain user data (if the header's login is valid)
    UserData userData;
    try {
        userData = ActiveDirectory.obtainUserData(rawUserLogin);
    } catch (KurtException e) {
        // Failed to authenticate the user, defaulting to Guest
        log.debug("Could not authenticate the user: " + (rawUserLogin == null ? "null" : rawUserLogin), e);
        userData = ActiveDirectory.getGuestUser();
    }

    // Tag for developer mode
    String theDevModeInfo = "";
    boolean isDevMode = SettingsHelper.isDevMode();
    boolean isValMode = SettingsHelper.isValMode();
    if (isDevMode) {
        theDevModeInfo = " - <B style='color:#36C227;'>Mode DEV actif</B>";
    }
    if (isValMode) {
        theDevModeInfo = theDevModeInfo + " - <B style='color:#36C227;'>Mode VAL actif</B>";
    }

    // Tag for URL to the current teamcenter target server
    String theTeamcenterURL;
    if (isValMode || isDevMode) {
        theTeamcenterURL = " - " + SettingsHelper.getPropertyWithDefaultValue("teamcenter.url", "Unknown");
    } else {
        theTeamcenterURL = "";
    }
%>

<!DOCTYPE html>
<html>
<head>

    <!-- Disable client browser cache -->
    <meta http-equiv="cache-control" content="no-cache"/>
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/>
    <meta http-equiv="pragma" content="no-cache"/>

    <!-- Load specific script in IE8 for JSON support -->
    <!--[if lt IE 9]>
    <script src="/kurt-web/js/json2.js" type="text/javascript"></script>
    <![endif]-->

    <title>G&eacute;n&eacute;rateur de rapports Teamcenter</title>

    <link rel="stylesheet" type="text/css" href="css/kurt-style.css"/>
    <link rel="stylesheet" type="text/css" href="css/dialog.css"/>
    <script language="JavaScript" src="/kurt-web/js/dialog_box.js"></script>
    <script language="JavaScript" src="/kurt-web/js/kurt-common-submit.js"></script>
    <script language="JavaScript" src="/kurt-web/js/index.js"></script>
    <meta http-equiv="imagetoolbar" content="no">
    <meta name="charset" content="iso-8859-1">

</head>

<body onresize="pageResize()" onload="pageResize()">

<div id="topBarImg" width="100%"></div>
<div id="snecmaImg"></div>
<div id="titleImg"></div>

<div id="actionLeftBar">
    <div id="actionLeftBarTitle">Utilisateur :</div>
    <a class="actionLeftBarActionBack">
        <img src="ihm/ico-user.png" border="0" height="16" width="16" align="left" hspace="6"><%=userData.getLogin()%>
    </a>

    <% if (isDevMode){ %>
    <!-- Enable visualization of email address only for DEV mode -->
    <a class="actionLeftBarActionBack">
        <img src="ihm/ico-email.png" border="0" height="16" width="16" align="left" hspace="6"><a
            HREF='mailto:<%=userData.getEmail()%>'><%=userData.getFirstName()%> <%=userData.getSurname()%>
    </a>
    </a>
    <% } %>

    <% if(userData.isAdmin()){%>
    <a class="actionLeftBarActionBack"><img src="ihm/ico-admin.png" border="0" height="16" width="16" align="left"
                                            hspace="6">Admin</a>
    <% } %>

    <div id="actionLeftBarTitle">Actions :</div>
    <% if (isDevMode){ %>
    <!--  Enable direct access to all reports only for DEV mode -->
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R01" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 01</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R03&dataValues=EidFrUN5hLofXA" target="subFrame"
       class="actionLeftBarActionBack"><img src="ihm/ico-report.png" border="0" height="16" width="16" align="left"
                                            hspace="6">Rapport 03</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R07" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 07</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R10" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 10</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R11" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 11</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R13" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 13</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R15&dataValues=EidFrUN5hLofXA" target="subFrame"
       class="actionLeftBarActionBack"><img src="ihm/ico-report.png" border="0" height="16" width="16" align="left"
                                            hspace="6">Rapport 15</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R16" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 16</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R17&dataValues=rfQFrUNvhLofXA" target="subFrame"
       class="actionLeftBarActionBack"><img src="ihm/ico-report.png" border="0" height="16" width="16" align="left"
                                            hspace="6">Rapport 17</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R19&dataValues=jWWVqJLehLofXA" target="subFrame"
       class="actionLeftBarActionBack"><img src="ihm/ico-report.png" border="0" height="16" width="16" align="left"
                                            hspace="6">Rapport 19</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R20" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 20</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R21" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 21</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R22&dataValues=EidFrUN5hLofXA" target="subFrame"
       class="actionLeftBarActionBack"><img src="ihm/ico-report.png" border="0" height="16" width="16" align="left"
                                            hspace="6">Rapport 22</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R23" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 23</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R24" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 24</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R25" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 25</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R26" target="subFrame" class="actionLeftBarActionBack"><img
        src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 26</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R27" target="subFrame" class="actionLeftBarActionBack"><img
        src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 27</a>
    <a href="frames/submitNewReport.jsp?rd_id=REPORT_R28" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-report.png" border="0" height="16" width="16" align="left" hspace="6">Rapport 28</a>
    <% } %>
    <a href="frames/my_reports.jsp" target="subFrame" class="actionLeftBarActionBack"><img src="ihm/ico-report.png"
                                                                                           border="0" height="16"
                                                                                           width="16" align="left"
                                                                                           hspace="6">Mes rapports</a>
    <% if (isDevMode){ %>
    <!-- Enable access to memory monitoring only for DEV mode -->
    <a href="frames/mem_monitoring.jsp" target="subFrame" class="actionLeftBarActionBack"><img src="ihm/ico-admin.png"
                                                                                               border="0" height="16"
                                                                                               width="16" align="left"
                                                                                               hspace="6">Suivi m&eacute;moire</a>
    <% } %>

    <% if(userData.isAdmin() || isDevMode){ %>
    <!-- Enable Administrative tools only for ADMIN use -->
    <div id="actionLeftBarTitle">Administration :</div>
    <% if (isDevMode) { %>
    <a href="http://localhost:9990/console/App.html" class="actionLeftBarActionBack"><img src="ihm/ico-jboss.png"
                                                                                          border="0" height="16"
                                                                                          width="16" align="left"
                                                                                          hspace="6">Interface JBoss</a>
    <% } %>
    <a href="frames/running_reports.jsp" target="subFrame" class="actionLeftBarActionBack"><img src="ihm/ico-queued.png"
                                                                                                border="0" height="16"
                                                                                                width="16" align="left"
                                                                                                hspace="6">Rapports en
        cours</a>
    <a href="queueReader" target="subFrame" class="actionLeftBarActionBack"><img src="ihm/ico-queued.png" border="0"
                                                                                 height="16" width="16" align="left"
                                                                                 hspace="6">Etat des queues</a>
    <a href="frames/statistics_per_report.jsp" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-stats.png" border="0" height="16" width="16" align="left" hspace="6">Statistiques par
        rapport</a>
    <a href="frames/statistics_per_user.jsp" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/ico-stats.png" border="0" height="16" width="16" align="left" hspace="6">Statistiques par
        utilisateur</a>
    <a href="schedulingReader?reportCode=TOUS" target="subFrame" class="actionLeftBarActionBack"><img
            src="ihm/calendar_planification.png" border="0" height="16" width="16" align="left" hspace="6">Planification
        des rapports</a>
    <% } %>

</div>

<table cellspacing="0" cellpadding="0" border="0" width="100%">
    <tr height="12">
        <td width="250" rowspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td width="25" rowspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td>
            <script>
                // Create dynamically the corresponding IFRAME depending on the URL argument
                var currentReport_with_comments = parseURL("rd_id", "report_r01").toLowerCase(); // May contain comments appended by '_' like : 'REPORT_R19_Document'
                var currentReport = currentReport_with_comments.split('_').slice(0, 2).join('_'); // Removes everything after the second '_' (including it) -> 'REPORT_R19'

                // Forward all URL arguments to IFRAME
                var currentUrlArgs = "";
                var currentUrl = window.location.href;
                var argPos = currentUrl.indexOf('?');
                if (argPos > 0) {
                    currentUrlArgs = currentUrl.substring(argPos);
                }
                document.write('<iframe style="height:800px;" src="frames/submitNewReport.jsp' + currentUrlArgs + '" id="subFrame" name="subFrame" frameborder="0"></iframe>');
            </script>
        </td>
    </tr>
</table>

<div id="footer">G&eacute;n&eacute;rateur de rapports Teamcenter -
    <b>${project.version}</b> <%= theDevModeInfo %> <%= theTeamcenterURL %> <%= InetAddress.getLocalHost().getHostName() %>
    - Capgemini
</div>

</body>
</html>