<%@page import="java.util.*, java.text.SimpleDateFormat, fr.gouv.finances.dgfip.xemelios.web.imports.*, fr.gouv.finances.dgfip.utils.Pair,java.sql.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<c:set var="meta" scope="request"><meta http-equiv="refresh" content="30"/></c:set>
<c:set var="codeEcran" scope="request"><bean:message key="imports.codeEcran"/></c:set>
<c:set var="titreEcran" scope="request"><bean:message key="imports.titreEcran"/></c:set>
<%@ include file="/WEB-INF/jsp/include/entete.jsp" %>
<%
    List<Import> imports = (List<Import>)request.getAttribute("imports");
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
%>
<style type="text/css">
    .importTable {
        margin-top: 12px;
        margin-left: 12px;
        border-collapse: collapse;
        background-color: white;
        padding: 1px;
    }
    .right { text-align: right; }
    .center { text-align: center; }
    th.import {
        background-color: #5988E9;
        color: #FFFFFF;
        font-weight: bold;
        font-size: 12px;
        text-align: center;
        border-style: solid;
        border-color: black;
        border-width: 1px;
    }
    td.import {
        font-size: 12px;
        border-style: solid;
        border-color: black;
        border-width: 1px;
    }
    td.new {
        font-size: 12px;
    }
    div#newImport {
        border-style: outset;
        border-width: 1px;
        /* background-color: #97AFE2; */
        width: 719px;
        margin-top: 12px;
        margin-left: 12px;
    }
    div#header-div {
        width: 100%;
        /* background-color: #5988E9; */
        background-image: url("./img/fondTitreEcran.gif");
        background-repeat: no-repeat;
        background-position: top left;
        color: white;
        font-size: 16px;
        font-weight: bold;
        line-height: 23px;
        vertical-align: baseline;
    }
    p { font-size: 12px;}
</style>
<% if(imports!=null && imports.size()>0) { %>
<table width="720px" class="importTable">
    <colgroup>
        <col width="40%"/>
        <col width="20%"/>
        <col width="20%/>"
        <col width="20%/>"
    </colgroup>
    <theader>
        <tr>
            <th class="import"><bean:message key="imports.file"/></th>
            <th class="import"><bean:message key="imports.drop.date"/></th>
            <th class="import"><bean:message key="imports.status"/></th>
            <th class="import"><bean:message key="imports.date.process"/></th>
        </tr>
    </theader>
    <tbody>
        <% for(Import ip:imports) { 
            String color=null;
            switch(ip.getStatus()) {
                case ImportHelper.IMPORT_STATUS_ERROR: { color="#E45555"; break; }
                case ImportHelper.IMPORT_STATUS_PRECISE: { color="#FFFF66"; break; }
                default: { }
            }
        %>
        <tr<%=(color!=null?" style=\"background-color: "+color+";\"":"")%>>
            <td class="import"><% if(ip.getStatus()==ImportHelper.IMPORT_STATUS_PRECISE || ip.getStatus()==ImportHelper.IMPORT_STATUS_ERROR) { %>
                <a href="${pageContext.request.contextPath}/importDetail.do?importId=<%=ip.getImportId()%>"><% } %><%=ip.getFileName()%><% if(ip.getStatus()==ImportHelper.IMPORT_STATUS_PRECISE || ip.getStatus()==ImportHelper.IMPORT_STATUS_ERROR) { %></a><% } %>
            </td>
            <td class="import right"><%=sdf.format(ip.getSubmitDate())%></td>
            <td class="import center"><%=ip.getStrStatus()%></td>
            <td class="import right"><%=(ip.getEndDate()!=null?sdf.format(ip.getEndDate()):"")%></td>
        </tr>
        <% if(ip.getStatus()==ImportHelper.IMPORT_STATUS_ERROR) { %>
        <tr>
            <td colspan="4" class="import" style="background-color: #E45555;"><pre><%=ip.getErrorMessage()%></pre></td>
        </tr>
        <% } } %>
    </tbody>
</table>
<% } %>
<div id="newImport">
    <div id="header-div"><bean:message key="imports.new.import"/></div>
        <form enctype="multipart/form-data" action="${pageContext.request.contextPath}/newImport.do" method="POST">
            <table>
                <tr>
                    <td class="new"><bean:message key="imports.file.to.import"/></td>
                    <td><input type="file" name="theFile" editable="true" class="zoneSaisissable"/></td>
                </tr>
                <tr>
                    <td class="new"><bean:message key="imports.file.type"/></td>
                    <td><select class="zoneSaisissable" name="fileType">
                <% List<Pair> fileTypes = (List<Pair>)request.getAttribute("fileTypes");
                for(Pair fileType:fileTypes) { %>
                    <option value="<%=fileType.key%>"><%=fileType.libelle%></option>
                <% } %>
                    </select></td>
                </tr>
                <tr><td> </td><td><input type="submit" value="<bean:message key="imports.import"/>" class="boutonStandardImpair"/></td></tr>
            </table>
        </form>
    </div>
</div>
<script type="text/javascript">
    <%if(request.getAttribute("message")!=null) { %>
        showDialog('<%=request.getAttribute("message")%>');
    <% } %>
</script>
<%@ include file="/WEB-INF/jsp/include/pied.jsp" %>