Bug 5549 : circ/returns needs to import DateUtils
[koha.git] / C4 / XSLT.pm
old mode 100755 (executable)
new mode 100644 (file)
index 28a70fc..06dfaf4
@@ -29,7 +29,6 @@ use C4::Koha;
 use C4::Biblio;
 use C4::Circulation;
 use C4::Reserves;
-use C4::Output qw//;
 use Encode;
 use XML::LibXML;
 use XML::LibXSLT;
@@ -59,7 +58,7 @@ Replaces codes with authorized values in a MARC::Record object
 
 sub transformMARCXML4XSLT {
     my ($biblionumber, $record) = @_;
-    my $frameworkcode = GetFrameworkCode($biblionumber);
+    my $frameworkcode = GetFrameworkCode($biblionumber) || '';
     my $tagslib = &GetMarcStructure(1,$frameworkcode);
     my @fields;
     # FIXME: wish there was a better way to handle exceptions
@@ -122,12 +121,12 @@ sub getAuthorisedValues4MARCSubfields {
 my $stylesheet;
 
 sub XSLTParse4Display {
-    my ( $biblionumber, $orig_record, $xsl_suffix, $interface, $fixamps ) = @_;
+    my ( $biblionumber, $orig_record, $xsl_suffix, $interface, $fixamps, $hidden_items ) = @_;
     $interface = 'opac' unless $interface;
     # grab the XML, run it through our stylesheet, push it out to the browser
     my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
     #return $record->as_formatted();
-    my $itemsxml  = buildKohaItemsNamespace($biblionumber);
+    my $itemsxml  = buildKohaItemsNamespace($biblionumber, $hidden_items);
     my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
     my $sysxml = "<sysprefs>\n";
     foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow
@@ -160,14 +159,14 @@ sub XSLTParse4Display {
         if ($interface eq 'intranet') {
             $xslfile = C4::Context->config('intrahtdocs') . 
                       '/' . C4::Context->preference("template") . 
-                      '/' . C4::Output::_current_language() .
+                      '/' . C4::Templates::_current_language() .
                       '/xslt/' .
                       C4::Context->preference('marcflavour') .
                       "slim2intranet$xsl_suffix.xsl";
         } else {
             $xslfile = C4::Context->config('opachtdocs') . 
                       '/' . C4::Context->preference("opacthemes") . 
-                      '/' . C4::Output::_current_language() .
+                      '/' . C4::Templates::_current_language() .
                       '/xslt/' .
                       C4::Context->preference('marcflavour') .
                       "slim2OPAC$xsl_suffix.xsl";
@@ -181,8 +180,13 @@ sub XSLTParse4Display {
 }
 
 sub buildKohaItemsNamespace {
-    my ($biblionumber) = @_;
+    my ($biblionumber, $hidden_items) = @_;
+
     my @items = C4::Items::GetItemsInfo($biblionumber);
+    if ($hidden_items && @$hidden_items) {
+        my %hi = map {$_ => 1} @$hidden_items;
+        @items = grep { !$hi{$_->{itemnumber}} } @items;
+    }
     my $branches = GetBranches();
     my $itemtypes = GetItemTypes();
     my $xml = '';
@@ -191,7 +195,7 @@ sub buildKohaItemsNamespace {
 
         my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
 
-       my ( $reservestatus, $reserveitem ) = C4::Reserves::CheckReserves($item->{itemnumber});
+       my ( $reservestatus, $reserveitem, undef ) = C4::Reserves::CheckReserves($item->{itemnumber});
 
         if ( $itemtypes->{ $item->{itype} }->{notforloan} || $item->{notforloan} || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged} || 
              (defined $transfertwhen && $transfertwhen ne '') || $item->{itemnotforloan} || (defined $reservestatus && $reservestatus eq "Waiting") ){ 
@@ -222,7 +226,7 @@ sub buildKohaItemsNamespace {
         } else {
             $status = "available";
         }
-        my $homebranch = xml_escape($branches->{$item->{homebranch}}->{'branchname'});
+        my $homebranch = $item->{homebranch}? xml_escape($branches->{$item->{homebranch}}->{'branchname'}):'';
            my $itemcallnumber = xml_escape($item->{itemcallnumber});
         $xml.= "<item><homebranch>$homebranch</homebranch>".
                "<status>$status</status>".