<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:variable name="canEditAlbums">
    <xsl:if test="/Root/Access/rps/catalog/edit or /Root/Access/rps/catalog/da_edit">1</xsl:if>
  </xsl:variable>


  <xsl:template name="catalogMainLayout">
		<div id="catalogMain">
			<xsl:if test="Access/rps/distribution/show and $canEditAlbums = 1">
				<xsl:attribute name="class">withDistribution</xsl:attribute>
			</xsl:if>

			<xsl:call-template name="errorMessageBox">
				<xsl:with-param name="errorMessage" select="Messages/Message/Code" />
			</xsl:call-template>

			<xsl:call-template name="successMessageLarge">
				<xsl:with-param name="successMessage" select="Messages/Message/Code" />
			</xsl:call-template>

			<xsl:choose>
				<xsl:when test="$canEditAlbums = 1">
					<div class="section">
					    <table class="landingPage">
					        <tr>
        						<xsl:call-template name="addSection" />
        						<xsl:call-template name="viewSection" />
        				    </tr>
        				</table>
					</div>
    		        <div class="section landingSearch">
        		        <xsl:call-template name="searchInnerSection" />
        		    </div>
				</xsl:when>
				<xsl:otherwise>
                  <div class="section">
                    <table class="landingPage">
                        <tr>               
                            <td class="landingAdd">
			                    <h2>Search</h2>
                                <xsl:call-template name="searchInnerSection" />
                            </td>
                            <xsl:call-template name="viewSection" />
                        </tr>
                    </table>
                  </div>
				</xsl:otherwise>
			</xsl:choose>

			<xsl:call-template name="recentList" />
			
		</div>
	</xsl:template>


	<xsl:template name="addSection">
		<td class="landingAdd">
			<h2>Add Album</h2>
			<table>
				<tr>
					<td>
						<a href="/rps/catalog?c=edit" title="Add New Album"><img src="/production/images/icons/office/Add-(16x16).gif" width="16" height="16" /></a> <a href="/rps/catalog?c=edit">Add New Album</a>
						<xsl:if test="Access/rps/distribution/show">
							<br /><br />
			        <a href="/rps/distribution" title="Import New Albums"><img src="/production/images/icons/office/Add-(16x16).gif" width="16" height="16" /></a> <a href="/rps/distribution">Import New Albums</a>
		        </xsl:if>
					</td>
				</tr>
			</table>
		</td>
	</xsl:template>


	<xsl:template name="viewSection">
		<td class="landingView">
			<h2>View Albums</h2>
			<table>
				<tr>
					<td>
						<form action="/rps/catalog" method="get">
							<input type="hidden" name="c" value="list" />

							<xsl:choose>
								<xsl:when test="LabelList/Label">
									<label for="labelView">By Label: </label>
									<select name="label" id="labelView">
										<option value="">All Labels</option>
										<xsl:for-each select="LabelList/Label">
											<option value="{LabelID}"><xsl:value-of select="substring(LabelName,1,25)" /><xsl:if test="substring(LabelName,26,1)">...</xsl:if></option>
										</xsl:for-each>
									</select>
									<input type="submit" name="go" value="Go" />
								</xsl:when>
								<xsl:otherwise>
									<a href="/rps/catalog?c=list">All Albums</a>
								</xsl:otherwise>
							</xsl:choose>						
							<span class="subtle">View all albums<xsl:if test="LabelList/Label"> or albums for a specific label</xsl:if>.</span>
						
							<!--
							<xsl:if test="Access/rps/catalog/search_import">
					    	<a href="/rps/catalog?c=search_import">Review Import</a>
					    	<span class="subtle">View all albums included in the last import.</span>
					    </xsl:if>
						  -->

						</form>
					</td>
				</tr>
				<tr>
					<td>
						<xsl:choose>
							<xsl:when test="ClientTypes/ClientType[ClientTypeID = 4]/IsClientTypeFlag = 1">
								<form action="/rps/catalog" method="get">
                  <label for="labelView">By Status: </label>
                  <select name="c" id="labelView">
                    <option value="search_import">Recently Imported</option>
                    <option value="search_no_dr">Not Ready for Distribution</option>
                    <option value="search_no_image"> - Missing Album Art</option>
                    <option value="search_no_audio"> - Missing Audio Files</option>
                    <option value="search_no_metadata"> - Missing/Invalid Metadata</option>
                    <option value="search_dr">Ready but not approved for delivery</option>
                    <option value="search_in_queue">In queue for delivery</option>
                    <option value="search_delivered">Recently Delivered</option>
                  </select>
                  <input type="submit" value="Go" />
                  <span class="subtle">View albums based on distribution status.</span>
								</form>
							</xsl:when>
							<xsl:otherwise>
								<br />
								<a href="?c=search_import">Most Recently Imported Albums</a>
							</xsl:otherwise>
						</xsl:choose>
					</td>
				</tr>
          </table>
		</td>
	</xsl:template>


	<xsl:template name="searchInnerSection">
        <table>
            <tr>
                <td>
                    <form action="/rps/catalog" method="get">
                        <input type="hidden" name="c" value="search" />
                        <label for="albumQuery">Search Catalog: </label> <input type="text" name="Query" id="albumQuery" class="searchField" />
                        <input type="submit" name="go" value="Go" />
                        <br />
                        <span class="subtle">Search by album title, catalog #, product title, UPC, ISRC, artist or track name.</span>
                    </form>
                </td>
            </tr>
        </table>
    </xsl:template>
    

	<xsl:template name="recentList">
		<div class="section">
			<h2>Most Recently Accessed Albums</h2>
			<xsl:if test="RecentlyViewed/Item">
	            <table class="textChart hiOn">
  	                <tr>
    	                <th>Title</th>
      	                <th>Catalog #</th>
						<th>Artist</th>
          	            <xsl:if test="LabelList/Label">
	                        <th>Label</th>
  	                    </xsl:if>
    	                <th class="status">Status</th>
                        <xsl:if test="Access/rps/catalog/edit or Access/rps/catalog/da_edit">
      	                    <th class="editCol">Edit</th>
                        </xsl:if>
        	        </tr>
	                <xsl:for-each select="RecentlyViewed/Item/Album[AlbumID != '']">
      	                <tr class="row{position() mod 2}">
        	                <td>
                	        	<a href="catalog?AlbumID={AlbumID}&amp;c=show"><xsl:value-of select="Title" /><xsl:if test="TitleVersion != ''"> (<xsl:value-of select="TitleVersion" />)</xsl:if></a>
                	        </td>
                  	        <td><xsl:value-of select="CatalogNumber" /></td>
            			    <td><xsl:value-of select="ArtistName" /></td>
                  	        <xsl:if test="/Root/LabelList/Label">
                    	        <xsl:variable name="albumLabelID"><xsl:value-of select="LabelID" /></xsl:variable>
                      	        <td><xsl:value-of select="/Root/LabelList/Label[LabelID = $albumLabelID]/LabelName" /></td>
                            </xsl:if>
              	            <td class="status">
                				<xsl:call-template name="albumStatus">
                					<xsl:with-param name="status" select="Status" />
                				</xsl:call-template>
              	            </td>
            
                            <xsl:if test="/Root/Access/rps/catalog/edit or /Root/Access/rps/catalog/da_edit">
                	          <td class="icon">
                                <a href="catalog?c=edit&amp;AlbumID={AlbumID}" title="Edit">
                                  <img src="/production/images/icons/office/Edit-(16x16).gif" height="16" width="16" />
                                </a>
                              </td>
                            </xsl:if>
      	                </tr>
    	            </xsl:for-each>
      	        </table>
			</xsl:if>
            <xsl:if test="not(RecentlyViewed/Item)">
                <p>No albums exist in your viewing history.</p>
            </xsl:if>
		</div>
    </xsl:template>

</xsl:stylesheet>
