Bug 10403: (follow-up) fix test to use vendor created earlier during test
[koha.git] / C4 / XSLT.pm
index dd1967a..d85b048 100644 (file)
@@ -136,6 +136,26 @@ sub getAuthorisedValues4MARCSubfields {
 
 my $stylesheet;
 
+sub _get_best_default_xslt_filename {
+    my ($htdocs, $theme, $lang, $base_xslfile) = @_;
+
+    my @candidates = (
+        "$htdocs/$theme/$lang/xslt/${base_xslfile}", # exact match
+        "$htdocs/$theme/en/xslt/${base_xslfile}",    # if not, preferred theme in English
+        "$htdocs/prog/$lang/xslt/${base_xslfile}",   # if not, 'prog' theme in preferred language
+        "$htdocs/prog/en/xslt/${base_xslfile}",      # otherwise, prog theme in English; should always
+                                                     # exist
+    );
+    my $xslfilename;
+    foreach my $filename (@candidates) {
+        $xslfilename = $filename;
+        if (-f $filename) {
+            last; # we have a winner!
+        }
+    }
+    return $xslfilename;
+}
+
 sub XSLTParse4Display {
     my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_;
     my $xslfilename = C4::Context->preference($xslsyspref);
@@ -165,10 +185,7 @@ sub XSLTParse4Display {
             $xslfile = C4::Context->preference('marcflavour') .
                        "slim2OPACResults.xsl";
         }
-        $xslfilename = "$htdocs/$theme/$lang/xslt/$xslfile";
-        $xslfilename = "$htdocs/$theme/en/xslt/$xslfile" unless ( $lang ne 'en' && -f $xslfilename );
-        $xslfilename = "$htdocs/prog/$lang/xslt/$xslfile" unless ( -f $xslfilename );
-        $xslfilename = "$htdocs/prog/en/xslt/$xslfile" unless ( $lang ne 'en' && -f $xslfilename );
+        $xslfilename = _get_best_default_xslt_filename($htdocs, $theme, $lang, $xslfile);
     }
 
     if ( $xslfilename =~ m/\{langcode\}/ ) {
@@ -221,8 +238,7 @@ sub XSLTParse4Display {
         $stylesheet->{$xslfilename} = $xslt->parse_stylesheet($style_doc);
     }
     my $results      = $stylesheet->{$xslfilename}->transform($source);
-    my $newxmlrecord = $stylesheet->{$xslfilename}->output_as_chars($results);
-    #no need to decode with UTF-8 in header of XSLT templates: BZ 6554
+    my $newxmlrecord = $stylesheet->{$xslfilename}->output_string($results);
     return $newxmlrecord;
 }
 
@@ -250,7 +266,7 @@ sub buildKohaItemsNamespace {
 
         my $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber} );
 
-        if ( $itemtypes->{ $item->{itype} }->{notforloan} || $item->{notforloan} || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged} || 
+        if ( $itemtypes->{ $item->{itype} }->{notforloan} || $item->{notforloan} || $item->{onloan} || $item->{withdrawn} || $item->{itemlost} || $item->{damaged} ||
              (defined $transfertwhen && $transfertwhen ne '') || $item->{itemnotforloan} || (defined $reservestatus && $reservestatus eq "Waiting") ){ 
             if ( $item->{notforloan} < 0) {
                 $status = "On order";
@@ -261,7 +277,7 @@ sub buildKohaItemsNamespace {
             if ($item->{onloan}) {
                 $status = "Checked out";
             }
-            if ( $item->{wthdrawn}) {
+            if ( $item->{withdrawn}) {
                 $status = "Withdrawn";
             }
             if ($item->{itemlost}) {
@@ -280,10 +296,12 @@ sub buildKohaItemsNamespace {
             $status = "available";
         }
         my $homebranch = $item->{homebranch}? xml_escape($branches->{$item->{homebranch}}->{'branchname'}):'';
-        $location = $item->{location}? xml_escape($shelflocations->{$item->{location}}):'';
-        $ccode = $item->{ccode}? xml_escape($ccodes->{$item->{ccode}}):'';
+        my $holdingbranch = $item->{holdingbranch}? xml_escape($branches->{$item->{holdingbranch}}->{'branchname'}):'';
+        $location = $item->{location}? xml_escape($shelflocations->{$item->{location}}||$item->{location}):'';
+        $ccode = $item->{ccode}? xml_escape($ccodes->{$item->{ccode}}||$item->{ccode}):'';
         my $itemcallnumber = xml_escape($item->{itemcallnumber});
         $xml.= "<item><homebranch>$homebranch</homebranch>".
+                "<holdingbranch>$holdingbranch</holdingbranch>".
                 "<location>$location</location>".
                 "<ccode>$ccode</ccode>".
                "<status>$status</status>".