Revert "Fix the guided report export, bad check of errors(bug #2672)"
[koha.git] / catalogue / detail.pl
index 6913636..d21b8a7 100755 (executable)
@@ -70,8 +70,6 @@ my $subtitle         = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 's
 # Get Branches, Itemtypes and Locations
 my $branches = GetBranches();
 my $itemtypes = GetItemTypes();
-
-# FIXME: move this to a pm, check waiting status for holds
 my $dbh = C4::Context->dbh;
 
 # change back when ive fixed request.pl
@@ -103,6 +101,8 @@ my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
 my $collections    = GetKohaAuthorisedValues('items.ccode'   , $fw);
 my (@itemloop, %itemfields);
 my $norequests = 1;
+my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
+my $authvalcode_items_damaged  = GetAuthValCode('items.damaged', $fw);
 foreach my $item (@items) {
 
     # can place holds defaults to yes
@@ -112,14 +112,16 @@ foreach my $item (@items) {
     if ( defined $item->{'publictype'} ) {
         $item->{ $item->{'publictype'} } = 1;
     }
-    $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
+    $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
+                                               : '';
+
        foreach (qw(datedue datelastseen onloan)) {
                $item->{$_} = format_date($item->{$_});
        }
     # item damaged, lost, withdrawn loops
-    $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
+    $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
     if ($item->{damaged}) {
-        $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
+        $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
     }
     #get shelf location and collection code description if they are authorised value.
     my $shelfcode = $item->{'location'};
@@ -208,8 +210,8 @@ if (C4::Context->preference("FRBRizeEditions")==1) {
 if ( C4::Context->preference("AmazonContent") == 1 ) {
     my $similar_products_exist;
     my $amazon_details = &get_amazon_details( $xisbn, $record, $marcflavour );
-    my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
-    my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
+    my $item_attributes   = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
+    my $customer_reviews  = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
     my @similar_products;
     for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
         # do we have any of these isbns in our collection?
@@ -221,11 +223,11 @@ if ( C4::Context->preference("AmazonContent") == 1 ) {
         }
     }
     my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
-    my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
-    $template->param( AmazonSimilarItems => $similar_products_exist );
-    $template->param( amazon_average_rating => $average_rating * 20);
-    $template->param( AMAZON_CUSTOMER_REVIEWS    => $customer_reviews );
-    $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
-    $template->param( AMAZON_EDITORIAL_REVIEWS    => $editorial_reviews );
+    my $average_rating    =    $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
+    $template->param( AmazonSimilarItems       => $similar_products_exist );
+    $template->param( amazon_average_rating    => $average_rating * 20    );
+    $template->param( AMAZON_CUSTOMER_REVIEWS  => $customer_reviews       );
+    $template->param( AMAZON_SIMILAR_PRODUCTS  => \@similar_products      );
+    $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews      );
 }
 output_html_with_http_headers $query, $cookie, $template->output;