fix calls to get_template_and_user in label-item-search.pl
[koha.git] / C4 / XSLT.pm
index d6cdcfa..3c781d2 100644 (file)
@@ -22,6 +22,7 @@ use C4::Branch;
 use C4::Items;
 use C4::Koha;
 use C4::Biblio;
+use C4::Circulation;
 use XML::LibXML;
 use XML::LibXSLT;
 
@@ -56,7 +57,12 @@ sub transformMARCXML4XSLT {
     my $biblio = GetBiblioData($biblionumber);
     my $frameworkcode = GetFrameworkCode($biblionumber);
     my $tagslib = &GetMarcStructure(1,$frameworkcode);
-    my @fields = $record->fields();
+    my @fields;
+    # FIXME: wish there was a better way to handle exceptions
+    eval {
+        @fields = $record->fields();
+    };
+    if ($@) { warn "PROBLEM WITH RECORD"; next; }
     my $list_of_authvalues = getAuthorisedValues4MARCSubfields($frameworkcode);
     for my $authvalue (@$list_of_authvalues) {
         for my $field ( $record->field($authvalue->{tagfield}) ) {
@@ -101,13 +107,12 @@ sub getAuthorisedValues4MARCSubfields {
 }
 
 sub XSLTParse4Display {
-    my ($biblionumber,$type) = @_;
+    my ($biblionumber,$xslfile) = @_;
     # grab the XML, run it through our stylesheet, push it out to the browser
     my $record = transformMARCXML4XSLT($biblionumber);
     my $itemsxml  = buildKohaItemsNamespace($biblionumber);
     my $xmlrecord = $record->as_xml();
     $xmlrecord =~ s/\<\/record\>/$itemsxml\<\/record\>/;
-    my $xslfile = C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPAC$type.xsl";
     my $parser = XML::LibXML->new();
     # don't die when you find &, >, etc
     $parser->recover_silently(1);
@@ -128,12 +133,17 @@ sub buildKohaItemsNamespace {
     my $xml;
     for my $item (@items) {
         my $status;
-        if ( $item->{notforloan} == -1 || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged}) {
+        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
+        if ( $item->{notforloan} == -1 || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged} ||
+             ($transfertwhen ne '') || $item->{itemnotforloan} ) {
             if ( $item->{notforloan} == -1) {
                 $status = "On order";
+            } 
+            if ( $item->{itemnotforloan} ) {
+                $status = "Not for loan";
             }
             if ($item->{onloan}) {
-                $status = "On loan";
+                $status = "Checked out";
             }
             if ( $item->{wthdrawn}) {
                 $status = "Withdrawn";
@@ -144,6 +154,9 @@ sub buildKohaItemsNamespace {
             if ($item->{damaged}) {
                 $status = "Damaged"; 
             }
+            if ($transfertwhen ne '') {
+                $status = 'In transit';
+            }
         } else {
             $status = "available";
         }