<!--                                                                  -->
<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">Album Count Report</xsl:with-param>
    </xsl:call-template>

    <xsl:call-template name="displayCriteria" />
    <xsl:if test="IsSubmit &gt; 0">
      <xsl:call-template name="displayResults" />
      <xsl:call-template name="displayTotals" />
    </xsl:if>
  </xsl:template>


  <xsl:template name="displayCriteria" >
    <fieldset>
    <form action="/support/reports" method="get">
      <input type="hidden" name="c" value="{/Root/Cmd}" />
      <table>
        <tr>
          <th>Client</th>
          <th>Client Type</th>
          <th>Album Status</th>
          <th></th>
        </tr>

        <tr>

          <xsl:call-template name="listField" >
            <xsl:with-param name="name">client</xsl:with-param>
            <xsl:with-param name="value" select = "Params/client" />
            <xsl:with-param name="empty_label">All</xsl:with-param>
            <xsl:with-param name="options" >
              <xsl:for-each select="Clients/Client" >
                <option name="{ClientID}"><xsl:value-of select="ClientName" /></option>
              </xsl:for-each>
            </xsl:with-param>
          </xsl:call-template>

          <xsl:call-template name="listField" >
            <xsl:with-param name="name">clientType</xsl:with-param>
            <xsl:with-param name="value" select = "Params/client" />
            <xsl:with-param name="empty_label">All</xsl:with-param>
            <xsl:with-param name="options" >
              <option name="1">DA</option>
              <option name="2">RPS</option>
              <option name="4">Label</option>
              <option name="8">Distribution</option>
            </xsl:with-param>
          </xsl:call-template>

          <xsl:call-template name="listField" >
            <xsl:with-param name="name">status</xsl:with-param>
            <xsl:with-param name="value" select = "Params/status" />
            <xsl:with-param name="empty_label">All</xsl:with-param>
            <xsl:with-param name="options" >
              <option name="1">Active</option>
              <option name="0">Inactive</option>
            </xsl:with-param>
          </xsl:call-template>

          <td>
            <xsl:call-template name="submitButton" >
              <xsl:with-param name="name">submit</xsl:with-param>
              <xsl:with-param name="label">Search</xsl:with-param>
            </xsl:call-template>
          </td>
        </tr>
      </table>
    </form>
    </fieldset>
  </xsl:template>

  <xsl:template name="displayResults" >

    <fieldset>

      <xsl:call-template name="collectionList" >
        <xsl:with-param name="columns" >
          <Column align="left" field="client">Client</Column>
          <Column align="left" field="client_id">Client ID</Column>
          <Column align="left" field="album_count">Album Count</Column>
          <Column align="left" field="track_count">Track Count</Column>
          <Column align="left" field="average">Tracks / Album</Column>
        </xsl:with-param>
        <xsl:with-param name="keyField">album_id</xsl:with-param>
      </xsl:call-template>

    </fieldset>
  </xsl:template>

  <xsl:template name="displayTotals" >
    <table>
      <tr>
        <td>Clients: </td><td><xsl:value-of select="format-number(count(/Root/Collection/List/Item), '###,###')" /></td>
      </tr>
      <tr>
        <td>Albums: </td><td><xsl:value-of select="format-number(sum(/Root/Collection/List/Item/album_count), '###,###')" /></td>
      </tr>
      <tr>
        <td>Tracks: </td><td><xsl:value-of select="format-number(sum(/Root/Collection/List/Item/track_count), '###,###')" /></td>
      </tr>
    </table>
  </xsl:template>

</xsl:stylesheet>
