bug 2278 - fix results pagination in auth_finder
[koha_fer] / opac / opac-detail.pl
index 91aa87d..76429f4 100755 (executable)
@@ -28,6 +28,7 @@ use C4::Serials;    #uses getsubscriptionfrom biblionumber
 use C4::Output;
 use C4::Biblio;
 use C4::Items;
+use C4::Circulation;
 use C4::Tags qw(get_tags);
 use C4::Dates qw/format_date/;
 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn);
@@ -77,7 +78,7 @@ if (C4::Context->preference('hidelostitems')) {
 my $dat = &GetBiblioData($biblionumber);
 
 if (!$dat) {
-    print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
+    print $query->redirect("/cgi-bin/koha/errors/404.pl");
     exit;
 }
 my $imgdir = getitemtypeimagesrc();
@@ -93,8 +94,7 @@ my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}
 
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
-my @subscriptions       =
-  GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
+my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
 my @subs;
 $dat->{'serial'}=1 if $subscriptionsnumber;
 foreach my $subscription (@subscriptions) {
@@ -118,7 +118,10 @@ if (C4::Context->preference("RequestOnOpac")) {
     $RequestOnOpac = 1;
 }
 
+my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber ) );
+
 my $norequests = 1;
+my $branches = GetBranches();
 my %itemfields;
 for my $itm (@items) {
      $norequests = 0 && $norequests
@@ -139,29 +142,52 @@ for my $itm (@items) {
        $itemfields{ccode} = 1 if($itm->{ccode});
        $itemfields{enumchron} = 1 if($itm->{enumchron});
        $itemfields{copynumber} = 1 if($itm->{copynumber});
+       $itemfields{itemnotes} = 1 if($itm->{itemnotes});
+
+     # walk through the item-level authorised values and populate some images
+     my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
+     # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
+
+     if ( $itm->{'itemlost'} ) {
+         my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
+         $itm->{'lostimageurl'}   = $lostimageinfo->{ 'imageurl' };
+         $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
+     }
+
+    
+     my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
+     if ( $transfertwhen ne '' ) {
+        $itm->{transfertwhen} = format_date($transfertwhen);
+        $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
+        $itm->{transfertto}   = $branches->{$transfertto}{branchname};
+     }
 }
 
 ## get notes and subjects from MARC record
-    my $dbh              = C4::Context->dbh;
-    my $marcflavour      = C4::Context->preference("marcflavour");
-    my $record           = GetMarcBiblio($biblionumber);
-    my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
-    my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
-    my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
-    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
-    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
+my $dbh              = C4::Context->dbh;
+my $marcflavour      = C4::Context->preference("marcflavour");
+my $record           = GetMarcBiblio($biblionumber);
+my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
+my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
+my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
+my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
+my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
+my $subtitle         = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
 
     $template->param(
-        MARCNOTES   => $marcnotesarray,
-        MARCSUBJCTS => $marcsubjctsarray,
-        MARCAUTHORS => $marcauthorsarray,
-        MARCSERIES  => $marcseriesarray,
-        MARCURLS    => $marcurlsarray,
-               norequests => $norequests,
-               RequestOnOpac=>$RequestOnOpac,
-               itemdata_ccode => $itemfields{ccode},
-               itemdata_enumchron => $itemfields{enumchron},
-               itemdata_copynumber => $itemfields{copynumber},
+                     MARCNOTES               => $marcnotesarray,
+                     MARCSUBJCTS             => $marcsubjctsarray,
+                     MARCAUTHORS             => $marcauthorsarray,
+                     MARCSERIES              => $marcseriesarray,
+                     MARCURLS                => $marcurlsarray,
+                     norequests              => $norequests,
+                     RequestOnOpac           => $RequestOnOpac,
+                     itemdata_ccode          => $itemfields{ccode},
+                     itemdata_enumchron      => $itemfields{enumchron},
+                     itemdata_copynumber     => $itemfields{copynumber},
+                     itemdata_itemnotes          => $itemfields{itemnotes},
+                     authorised_value_images => $biblio_authorised_value_images,
+                     subtitle                => $subtitle,
     );
 
 foreach ( keys %{$dat} ) {
@@ -181,15 +207,17 @@ $template->param(
 my $reviews = getreviews( $biblionumber, 1 );
 my $loggedincommenter;
 foreach ( @$reviews ) {
-    my $borrower_number_review = $_->{borrowernumber};
-    my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
+    my $borrowerData   = GetMember($_->{borrowernumber},'borrowernumber');
     # setting some borrower info into this hash
     $_->{title}     = $borrowerData->{'title'};
     $_->{surname}   = $borrowerData->{'surname'};
     $_->{firstname} = $borrowerData->{'firstname'};
-    $_->{userid} = $borrowerData->{'userid'};
+    $_->{userid}    = $borrowerData->{'userid'};
     $_->{datereviewed} = format_date($_->{datereviewed});
-    if($borrowerData->{'borrowernumber'} eq $borrowernumber){ $loggedincommenter = 1; }
+    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
+               $_->{your_comment} = 1;
+               $loggedincommenter = 1;
+       }
 }
 
 
@@ -204,23 +232,29 @@ $template->param(
     subscriptions       => \@subs,
     subscriptionsnumber => $subscriptionsnumber,
     reviews             => $reviews,
-    loggedincommenter => $loggedincommenter
+    loggedincommenter   => $loggedincommenter
 );
 
+sub isbn_cleanup ($) {
+       my $isbn=shift;
+       if (
+               $isbn =~ /\b(\d{13})\b/ or
+               $isbn =~ /\b(\d{10})\b/ or 
+               $isbn =~ /\b(\d{9}X)\b/i
+       ) {
+               return $1;
+       }
+       return undef;
+}
+
 # XISBN Stuff
 my $xisbn=$dat->{'isbn'};
 $xisbn =~ /(\d*[X]*)/;
 $template->param(amazonisbn => $1);            # FIXME: so it is OK if the ISBN = 'XXXXX' ?
-my ($clean, $amazonisbn);
-$amazonisbn = $1;
+my ($clean,$clean2);
 # these might be overkill, but they are better than the regexp above.
-if (
-       $amazonisbn =~ /\b(\d{13})\b/ or
-       $amazonisbn =~ /\b(\d{10})\b/ or 
-       $amazonisbn =~ /\b(\d{9}X)\b/i
-) {
-       $clean = $1;
-       $template->param(clean_isbn => $1);
+if ($clean = isbn_cleanup($xisbn)){
+       $template->param(clean_isbn => $clean);
 }
 
 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
@@ -266,7 +300,6 @@ $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
 my ($starting_cn_sort, $starting_homebranch, $starting_location);
 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
 $sth_get_cn_sort->execute($starting_itemnumber);
-my $branches = GetBranches();
 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
     $starting_cn_sort = $result->{'cn_sort'};
     $starting_homebranch->{code} = $result->{'homebranch'};
@@ -287,7 +320,11 @@ while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
     $sth_get_biblio->execute($this_item->{biblionumber});
     while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
         $this_item->{'title'} = $this_biblio->{'title'};
-        $this_item->{'isbn'} = $this_biblio->{'isbn'};
+               if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
+               $this_item->{'isbn'} = $clean2;
+               } else { 
+                       $this_item->{'isbn'} = $this_biblio->{'isbn'};
+               }
     }
     unshift @previous_items, $this_item;
 }
@@ -301,7 +338,11 @@ while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
     $sth_get_biblio->execute($this_item->{biblionumber});
     while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
         $this_item->{'title'} = $this_biblio->{'title'};
-        $this_item->{'isbn'} = $this_biblio->{'isbn'};
+               if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
+               $this_item->{'isbn'} = $clean2;
+               } else { 
+                       $this_item->{'isbn'} = $this_biblio->{'isbn'};
+               }
     }
     push @next_items, $this_item;
 }
@@ -349,7 +390,7 @@ if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->pref
                TagsShowOnDetail => $tag_quantity,
                TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
        );
-       $template->param(TagLoop => get_tags({biblionumber=>$biblionumber,
+       $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
                                                                'sort'=>'-weight', limit=>$tag_quantity}));
 }