<%@page import="com.capgemini.framework.common.SettingsHelper" %>
<%@page import="com.capgemini.reports.ReportEnum" %>
<%@page import="com.capgemini.reports.database.manager.MngReportType" %>
<%@ page import="org.hibernate.SessionFactory" %>
<%@ page import="com.capgemini.reports.database.HibernateUtil" %>
<%@ page import="org.hibernate.Session" %>
<%! final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("com.capgemini.reports.submitNewReport.jsp"); %>
<%

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);

    String reportNameRaw = request.getParameter("rd_id"); // May contain comments appended by '_' like : 'REPORT_R19_Document'
    if (reportNameRaw == null) {
        reportNameRaw = "REPORT_R01";
    }
    String reportCode = reportNameRaw.split("_")[1]; // Report Code like 'R19'
    ReportEnum reportEnum = ReportEnum.fromCode(reportCode);
    String theReportTitle = reportEnum.getReportTitle();
    boolean authorized = new MngReportType().isAuthorized(reportEnum);
    boolean isDevMode = SettingsHelper.isDevMode();

    String targetTemplate = "template_" + reportCode.toLowerCase() + ".jsp";

    log.trace("reportCode    : " + reportCode);
    log.trace("reportEnum    : " + reportEnum.toString());
    log.trace("TargetTemplate: " + targetTemplate);
    log.trace("isDevMode: " + isDevMode);
%>

<!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]-->

    <%if (isDevMode) {%>
    <!-- Dev mode enabled -->
    <%}%>

    <title><%= theReportTitle %>
    </title>
    <link rel="stylesheet" href="/kurt-web/css/pikaday.css">
    <link rel="stylesheet" href="/kurt-web/css/kurt-style-frame.css">

    <script src="/kurt-web/js/moment.js"></script>
    <script src="/kurt-web/js/pikaday.js"></script>
    <script src="/kurt-web/js/post_form.js"></script>
    <script src="/kurt-web/js/kurt-common-submit.js"></script>

</head>
<body id="body_frame">

<h1><%=reportCode%> - <%= theReportTitle %>
</h1>
<br/>
<br/>
<br/>
<br/>

<%if (!authorized) {%>
<div id="div_message_not_authorized" style="margin-top: 10px;  margin-bottom: 10px; " align=center>
    <p style="display:inline;color:#cc0000;font-size:14px;font-weight:bold;">Ce rapport n'est pas autoris&eacute;</p>
</div>
<% } %>

<center>
    <div align="center">
        <form class="form" id="reportQueryForm" method="post" onsubmit="return false;">
            <%-- Imports the report's template JSP in a form --%>
            <%-- Activates content fields in the report template IF it is authorized for immediate execution --%>
            <jsp:include page="<%=targetTemplate%>">
                <jsp:param name="isUpdateReport" value="false"/>
                <jsp:param name="idReport" value="-1"/>
            </jsp:include>
            <div class="tdFieldTitle" style="text-align: center; display: '';" id="btZone">
                <br/>
                <br/>
                <br/>
                <br/>
                <% if (authorized) { %>
                <button class="formButton" onclick="sendForm('/kurt-web/report_<%=reportCode.toLowerCase()%>/submit')">
                    Lancer le rapport
                </button>
                <% } %>
                <button class="formButton" onclick="closeWindow()">Annuler</button>
            </div>
        </form>
    </div>
</center>
</body>
</html>