From d51fbca601d9434e400d9c007ac30a11c25ff47e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick=20Capovilla?= <frederick.capovilla@libeo.com>
Date: Fri, 24 Feb 2012 16:17:03 -0500
Subject: [PATCH] XSLT Results template improvement : Use the NOT_LOAN authorised values

Improved the MARC21slim2OPACResults.xsl file to use the authorised values
instead of just showing these items as "unavailable"
---
 C4/XSLT.pm                                         |    7 ++
 .../prog/en/xslt/MARC21slim2OPACResults.xsl        |   78 +++++++++-----------
 2 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index 8bc4000..103bc37 100755
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -184,6 +184,7 @@ sub buildKohaItemsNamespace {
     my @items = C4::Items::GetItemsInfo($biblionumber);
     my $branches = GetBranches();
     my $itemtypes = GetItemTypes();
+    my $not_loan_values = GetKohaAuthorisedValues('items.notforloan', '', 1);
     my $xml = '';
     for my $item (@items) {
         my $status;
@@ -200,6 +201,12 @@ sub buildKohaItemsNamespace {
             if ( $item->{itemnotforloan} > 0 || $item->{notforloan} > 0 || $itemtypes->{ $item->{itype} }->{notforloan} == 1 ) {
                 $status = "reference";
             }
+            if($item->{itemnotforloan} and defined $not_loan_values->{$item->{itemnotforloan}}){
+                $status = $not_loan_values->{$item->{itemnotforloan}};
+            }
+            if($item->{notforloan} and defined $not_loan_values->{$item->{notforloan}}) {
+                $status = $not_loan_values->{$item->{notforloan}};
+            }
             if ($item->{onloan}) {
                 $status = "Checked out";
             }
diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl
index 9c6c307..a92ca2e 100644
--- a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl
+++ b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl
@@ -1023,49 +1023,41 @@
                    </xsl:when>
                    </xsl:choose>
 
-                   <xsl:if test="count(key('item-by-status', 'Checked out'))>0">
-                   <span class="unavailable">
-                       <xsl:text>Checked out (</xsl:text>
-                       <xsl:value-of select="count(key('item-by-status', 'Checked out'))"/>
-                       <xsl:text>). </xsl:text>
-				   </span>
-                   </xsl:if>
-                   <xsl:if test="count(key('item-by-status', 'Withdrawn'))>0">
-                   <span class="unavailable">
-                       <xsl:text>Withdrawn (</xsl:text>
-                       <xsl:value-of select="count(key('item-by-status', 'Withdrawn'))"/>
-                       <xsl:text>). </xsl:text>                   </span>
-				   </xsl:if>
-                    <xsl:if test="$hidelostitems='0' and count(key('item-by-status', 'Lost'))>0">
-                   <span class="unavailable">
-                       <xsl:text>Lost (</xsl:text>
-                       <xsl:value-of select="count(key('item-by-status', 'Lost'))"/>
-                       <xsl:text>). </xsl:text>                   </span>
-				   </xsl:if>
-                    <xsl:if test="count(key('item-by-status', 'Damaged'))>0">
-                   <span class="unavailable">
-                       <xsl:text>Damaged (</xsl:text>
-                       <xsl:value-of select="count(key('item-by-status', 'Damaged'))"/>
-                       <xsl:text>). </xsl:text>                   </span>
-                   </xsl:if>
-                    <xsl:if test="count(key('item-by-status', 'On order'))>0">
-                   <span class="unavailable">
-                       <xsl:text>On order (</xsl:text>
-                       <xsl:value-of select="count(key('item-by-status', 'On order'))"/>
-                       <xsl:text>). </xsl:text>                   </span>
-                   </xsl:if>
-                    <xsl:if test="count(key('item-by-status', 'In transit'))>0">
-                   <span class="unavailable">
-                       <xsl:text>In transit (</xsl:text>
-                       <xsl:value-of select="count(key('item-by-status', 'In transit'))"/>
-                       <xsl:text>). </xsl:text>                   </span>
-                   </xsl:if>
-                    <xsl:if test="count(key('item-by-status', 'Waiting'))>0">
-                   <span class="unavailable">
-                       <xsl:text>On hold (</xsl:text>
-                       <xsl:value-of select="count(key('item-by-status', 'Waiting'))"/>
-                       <xsl:text>). </xsl:text>                   </span>
-                   </xsl:if>
+                   <xsl:for-each select="//items:item[generate-id() = generate-id(key('item-by-status', items:status)[1])]">
+                       <xsl:if test="items:status != 'available' and items:status != 'reference'">
+                       <span class="unavailable">
+                           <xsl:choose>
+                               <xsl:when test="items:status = 'Checked out'">
+                                   <xsl:text>Checked out (</xsl:text>
+                               </xsl:when>
+                               <xsl:when test="items:status = 'Withdrawn'">
+                                   <xsl:text>Withdrawn (</xsl:text>
+                               </xsl:when>
+                               <xsl:when test="$hidelostitems='0' and items:status = 'Lost'">
+                                   <xsl:text>Lost (</xsl:text>
+                               </xsl:when>
+                               <xsl:when test="items:status = 'Damaged'">
+                                   <xsl:text>Damaged (</xsl:text>
+                               </xsl:when>
+                               <xsl:when test="items:status = 'On order'">
+                                   <xsl:text>On order (</xsl:text>
+                               </xsl:when>
+                               <xsl:when test="items:status = 'In transit'">
+                                   <xsl:text>In transit (</xsl:text>
+                               </xsl:when>
+                               <xsl:when test="items:status = 'Waiting'">
+                                   <xsl:text>On hold (</xsl:text>
+                               </xsl:when>
+                               <xsl:otherwise>
+                                   <xsl:value-of select="items:status"/>
+                                   <xsl:text> (</xsl:text>
+                               </xsl:otherwise>
+                           </xsl:choose>
+                           <xsl:value-of select="count(key('item-by-status', items:status))"/>
+                           <xsl:text>). </xsl:text>
+                       </span>
+                       </xsl:if>
+                   </xsl:for-each>
                </span>
     </xsl:template>
 
-- 
1.7.2.5