<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:include href="/app/tools/support/templates/layout.xsl" />

<xsl:template name="mainBody" >
    <xsl:call-template name="bodyTitle" >
        <xsl:with-param name="title">DTMV Catalog Import Status</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="listStatus" />
</xsl:template>

<xsl:template name="listStatus" >
    <fieldset>
        <legend>Catalog Import Status</legend>
            <table class="textChart">
                <tr>
                    <th>Client</th>
                    <th>Last Import ID</th>
                    <th>Effective Date</th>
                    <th>Start Time</th>
                    <th>End Time</th>
                    <th>File Count</th>
                    <th>Status</th>
                </tr>
                <xsl:for-each select="StatusList/Status">
                    <xsl:sort select="Client/ClientName" />
                    <xsl:call-template name="statusRow" />
                </xsl:for-each>
            </table>
    </fieldset>
</xsl:template>

<xsl:template name="statusRow" >
    <tr class="row{position() mod 2}">
        <xsl:variable name="linkClientID" select="Client/ClientID" />
        <td><A href="/support/dtmv?c=ci_c&amp;client={$linkClientID}"><xsl:value-of select="Client/ClientName" /></A></td>
        <td><A href="/support/dtmv?c=ci_s&amp;client={$linkClientID}&amp;import={LastImport/CatalogImportID}"><xsl:value-of select="LastImport/CatalogImportID" /></A></td>
        <td><xsl:value-of select="LastImport/Date" /></td>
        <td><xsl:value-of select="LastImport/FetchStartTime" /></td>
        <td>
            <xsl:choose>
                <xsl:when test="LastImport/StatusType = 'done' or LastImport/StatusType = 'error'">
                    <xsl:choose>
                        <xsl:when test="LastImport/ImportEndTime != '00/00/0000 00:00:00 AM'">
                            <xsl:value-of select="LastImport/ImportEndTime" />
                        </xsl:when>
                        <xsl:when test="LastImport/AnalysisEndTime != '00/00/0000 00:00:00 AM'">
                            <xsl:value-of select="LastImport/AnalysisEndTime" />
                        </xsl:when>
                        <xsl:when test="LastImport/StageEndTime != '00/00/0000 00:00:00 AM'">
                            <xsl:value-of select="LastImport/StageEndTime" />
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="LastImport/FetchEndTime" />
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise> - - - </xsl:otherwise>
            </xsl:choose>
        </td>
        <td><xsl:value-of select="LastImport/FileList/File/@size" /></td>
        <td><xsl:value-of select="LastImport/StatusText" /></td>
        <td><A href="/support/dtmv?c=waiting&amp;client={$linkClientID}">View Waiting Files</A></td>
    </tr>
</xsl:template>

</xsl:stylesheet>
