<%@page import="com.capgemini.framework.common.StringHelper" %>
<%@page import="com.capgemini.reports.database.HibernateUtil" %>
<%@page import="com.capgemini.reports.database.manager.MngSchedulingCriteriaVal" %>
<%@page import="java.util.List" %>
<%! final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("com.capgemini.scheduling_criteria.jsp"); %>
<%
    /* This part requests in the DB all the criteria relative to a report, whose uid is pass as URL parameter. */
    String theJsCriteriaArray = StringHelper.EMPTY;
    String theErrorMessage = StringHelper.EMPTY;
    String theReportId = request.getParameter("reportId");

    try {
        StringBuilder theJsCode = new StringBuilder();
        int theLineCount = 0;
        List<MngSchedulingCriteriaVal.SchedulingCriteriaValue> theReportCriteriaList = new MngSchedulingCriteriaVal().searchFunctional(Long.valueOf(theReportId));

        for (MngSchedulingCriteriaVal.SchedulingCriteriaValue currentCriteria : theReportCriteriaList) {
            if (currentCriteria != null) {
                String theName = StringHelper.toHtml(currentCriteria.getName());
                String theValue = StringHelper.toHtml(currentCriteria.getValue());
                theJsCode.append("\tcriteriaArray[").append(theLineCount).append("] = new Array();\n");
                theJsCode.append("\tcriteriaArray[").append(theLineCount).append("]['name'] = '").append(theName).append("';\n");
                theJsCode.append("\tcriteriaArray[").append(theLineCount).append("]['value'] = '").append(theValue == null || theValue.isEmpty() || "null".equals(theValue) ? "-" : theValue).append("';\n");
                theLineCount++;
            }
        }

        theJsCriteriaArray = theJsCode.toString();
    }
    catch (Exception e) {
        log.error("Impossible d'afficher les crit�res: " + e.getMessage());
    }
%>
<!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"/>

    <title>Crit&egrave;res du rapport et de la planification </title>
    <link rel="stylesheet" href="/kurt-web/css/kurt-style-frame.css">
    <script src="/kurt-web/js/criteria.js"></script>
    <script>
        var criteriaArray = new Array();
        <%= theJsCriteriaArray %>
    </script>
</head>
<body>

<center>
    <div align="center">
        <table cellspacing="0" cellpadding="1" border="0" width="95%" style="border:1px solid #9EC8DE">
            <tr>
                <th class="reportTable">Nom</th>
                <th class="reportTable">Valeur</th>
            </tr>
            <script>
                DisplayTable();
            </script>
        </table>
        <%= theErrorMessage %>
    </div>
</center>
</body>
</html>