<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <xsl:template name="trackerUpload">
        <script src="/production/javascript/validateUpload.js?t={$now}" type="text/javascript"></script>
        <form name="uploadForm" action="/bookpub/tracker" method="post" enctype="multipart/form-data">
            <input type="hidden" name="c" value="upload" />
            <xsl:call-template name="uiFileUploader">
                <xsl:with-param name="name" select="'fileUpload'"/>
                <xsl:with-param name="id" select="'fileUpload'"/>
                <xsl:with-param name="type" select="'instant'"/>
                <xsl:with-param name="buttonContent" select="'Upload Sales File'"/>
            </xsl:call-template>
            <span id="ERRORfileUpload" class="Form-error"></span>
        </form>
    </xsl:template>

    <xsl:template name="trackerNewFiles">
        <div class="Tracker-files-new">
            <div class="ControlsHeader">
                <h3 class="ControlsHeader-text">New Files</h3>
                <xsl:if test="Access/bookpub/tracker/upload = 1">
                    <div>
                        <xsl:call-template name="trackerUpload" />
                    </div>
                </xsl:if>
            </div>

            <xsl:choose>
                <xsl:when test="Files/NewFiles/NewFile">

                    <table class="Table Table-with-highlight">
                        <thead>
                            <tr class="Table-row Table-row-header">
                                <th class="Table-col Tracker-col-service">Service</th>
                                <th class="Table-col Tracker-col-file-name">File Name</th>
                                <th class="Table-col">Errors</th>
                                <th class="Table-col Table-col-shrink">Received</th>
                                <th class="Table-col Table-col-shrink">Status</th>
                                <th class="Table-col">Notes</th>
                                <xsl:if test="/Root/Access/bookpub/tracker/delete">
                                    <th class="Table-col Table-col-icon">Delete</th>
                                </xsl:if>
                            </tr>
                        </thead>
                        <tbody>
                            <xsl:for-each select="Files/NewFiles/NewFile">
                                <tr class="Table-row Table-row-data">
                                    <td class="Table-col Tracker-col-service">
                                        <xsl:choose>
                                            <xsl:when test="ServiceID = 0 and FileStatus = 1"></xsl:when>
                                            <xsl:otherwise><xsl:value-of select="ServiceName" /></xsl:otherwise>
                                        </xsl:choose>
                                    </td>
                                    <td class="Table-col Tracker-col-file-name">
                                        <a class="js-tooltip">
                                            <xsl:if test="/Root/Access/bookpub/tracker/saveas = 1">
                                                <xsl:attribute name="href">/bookpub/tracker?c=saveas&amp;file=<xsl:value-of select="FileID" />&amp;period=<xsl:value-of select="/Root/Period/PeriodID" /></xsl:attribute>
                                            </xsl:if>
                                            <xsl:if test="/Root/User/AccessLevel = 1 and VersionNum != 0">
                                                <xsl:attribute name="title">Importer Version: <xsl:value-of select="VersionNum" /></xsl:attribute>
                                            </xsl:if>
                                            <xsl:value-of select="PrettyFileName" />
                                        </a>
                                    </td>
                                    <td class="Table-col">
                                        <xsl:if test="FileStatus = 3 and Errors != ''">
                                            <xsl:value-of select="Errors" />
                                        </xsl:if>
                                    </td>
                                    <td class="Table-col">
                                        <xsl:value-of select="DateCreated" />
                                    </td>
                                    <xsl:if test="/Root/Access/bookpub/tracker/import">
                                        <td class="Table-col">
                                            <xsl:call-template name="uiFileStatus">
                                                <xsl:with-param name="status">
                                                    <xsl:choose>
                                                        <xsl:when test="FileStatus = '2'">processing</xsl:when>
                                                        <xsl:when test="FileStatus = '6'">in_queue</xsl:when>
                                                        <xsl:otherwise>invalid</xsl:otherwise>
                                                    </xsl:choose>
                                                </xsl:with-param>
                                                <xsl:with-param name="showProcessingStatus" select="/Root/User/AccessLevel &lt; 3" />
                                            </xsl:call-template>
                                        </td>
                                    </xsl:if>
                                    <td class="Table-col Table-col-icon">
                                        <xsl:if test="FileStatus = 3">
                                            <a class="js-tooltip">
                                                <xsl:attribute name="href">/bookpub/tracker?c=notes&amp;page=<xsl:value-of select="$currentPage" />&amp;file=<xsl:value-of select="FileID" />&amp;period=<xsl:value-of select="/Root/Period/PeriodID"/></xsl:attribute>
                                                <xsl:choose>
                                                    <xsl:when test="Notes = ''">
                                                        <xsl:attribute name="title">Add Note</xsl:attribute>
                                                        <xsl:call-template name="icon">
                                                            <xsl:with-param name="type" select="'note'" />
                                                            <xsl:with-param name="role" select="'action'" />
                                                        </xsl:call-template>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <xsl:attribute name="title"><xsl:value-of select="Notes" /></xsl:attribute>
                                                        <xsl:value-of select="substring(Notes,1,3)" />
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </a>
                                        </xsl:if>
                                    </td>

                                    <xsl:if test="/Root/Access/bookpub/tracker/delete">
                                        <td class="Table-col Table-col-icon">
                                            <xsl:variable name="apos">'</xsl:variable>
                                            <xsl:variable name="escaped">"</xsl:variable>
                                            <a title="Delete File" class="js-tooltip">
                                                <xsl:attribute name="href">javascript:confirmDeleteFile('<xsl:value-of select="translate(PrettyFileName,$apos,$escaped)" />',<xsl:value-of select="FileID" />,<xsl:value-of select="$currentPage" />,0,0)</xsl:attribute>
                                                <xsl:call-template name="icon">
                                                    <xsl:with-param name="type" select="'delete'" />
                                                    <xsl:with-param name="role" select="'action'" />
                                                </xsl:call-template>
                                            </a>
                                        </td>
                                    </xsl:if>

                                </tr>
                            </xsl:for-each>
                        </tbody>
                    </table>
                </xsl:when>
                <xsl:otherwise>
                    <div class="Table-empty-results">
                        <p>No new files exist for this period.</p>
                    </div>
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>
</xsl:stylesheet>
