3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
24 use C4
::Dates qw
/format_date/;
26 use C4
::Serials
; #uses getsubscriptionfrom biblionumber
35 use C4
::XISBN
qw(get_xisbns get_biblionumber_from_isbn);
36 use C4
::External
::Amazon
;
37 use C4
::Search
; # enabled_staff_search_views
38 use C4
::VirtualShelves
;
41 # use Smart::Comments;
43 my $query = CGI
->new();
44 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
46 template_name
=> "catalogue/detail.tmpl",
50 flagsrequired
=> { catalogue
=> 1 },
54 my $biblionumber = $query->param('biblionumber');
55 my $fw = GetFrameworkCode
($biblionumber);
57 ## get notes and subjects from MARC record
58 my $marcflavour = C4
::Context
->preference("marcflavour");
59 my $record = GetMarcBiblio
($biblionumber);
61 # XSLT processing of some stuff
62 if (C4
::Context
->preference("XSLTDetailsDisplay") ) {
63 $template->param('XSLTDetailsDisplay' =>'1',
64 'XSLTBloc' => XSLTParse4Display
($biblionumber, $record, 'Detail','intranet') );
67 # some useful variables for enhanced content;
68 # in each case, we're grabbing the first value we find in
69 # the record and normalizing it
70 my $upc = GetNormalizedUPC
($record,$marcflavour);
71 my $ean = GetNormalizedEAN
($record,$marcflavour);
72 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
73 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
76 normalized_upc
=> $upc,
77 normalized_ean
=> $ean,
78 normalized_oclc
=> $oclc,
79 normalized_isbn
=> $isbn,
82 unless (defined($record)) {
83 print $query->redirect("/cgi-bin/koha/errors/404.pl");
87 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
88 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
89 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
90 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
91 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
92 my $subtitle = GetRecordValue
('subtitle', $record, $fw);
94 # Get Branches, Itemtypes and Locations
95 my $branches = GetBranches
();
96 my $itemtypes = GetItemTypes
();
97 my $dbh = C4
::Context
->dbh;
99 # change back when ive fixed request.pl
100 my @items = &GetItemsInfo
( $biblionumber, 'intra' );
101 my $dat = &GetBiblioData
($biblionumber);
103 #coping with subscriptions
104 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
105 my @subscriptions = GetSubscriptions
( $dat->{title
}, $dat->{issn
}, $biblionumber );
107 $dat->{'serial'}=1 if $subscriptionsnumber;
108 foreach my $subscription (@subscriptions) {
110 my $serials_to_display;
111 $cell{subscriptionid
} = $subscription->{subscriptionid
};
112 $cell{subscriptionnotes
} = $subscription->{notes
};
113 $cell{branchcode
} = $subscription->{branchcode
};
114 $cell{branchname
} = GetBranchName
($subscription->{branchcode
});
115 $cell{hasalert
} = $subscription->{hasalert
};
116 #get the three latest serials.
117 $serials_to_display = $subscription->{staffdisplaycount
};
118 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
119 $cell{staffdisplaycount
} = $serials_to_display;
120 $cell{latestserials
} =
121 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
125 if ( defined $dat->{'itemtype'} ) {
126 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
128 $dat->{'count'} = scalar @items;
129 my $shelflocations = GetKohaAuthorisedValues
('items.location', $fw);
130 my $collections = GetKohaAuthorisedValues
('items.ccode' , $fw);
131 my (@itemloop, %itemfields);
133 my $authvalcode_items_itemlost = GetAuthValCode
('items.itemlost',$fw);
134 my $authvalcode_items_damaged = GetAuthValCode
('items.damaged', $fw);
135 foreach my $item (@items) {
137 # can place holds defaults to yes
138 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
140 # format some item fields for display
141 if ( defined $item->{'publictype'} ) {
142 $item->{ $item->{'publictype'} } = 1;
144 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
147 foreach (qw(datedue datelastseen onloan)) {
148 $item->{$_} = format_date
($item->{$_});
150 # item damaged, lost, withdrawn loops
151 $item->{itemlostloop
} = GetAuthorisedValues
($authvalcode_items_itemlost, $item->{itemlost
}) if $authvalcode_items_itemlost;
152 if ($item->{damaged
}) {
153 $item->{itemdamagedloop
} = GetAuthorisedValues
($authvalcode_items_damaged, $item->{damaged
}) if $authvalcode_items_damaged;
155 #get shelf location and collection code description if they are authorised value.
156 my $shelfcode = $item->{'location'};
157 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
158 my $ccode = $item->{'ccode'};
159 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
160 foreach (qw(ccode enumchron copynumber uri)) {
161 $itemfields{$_} = 1 if ( $item->{$_} );
165 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber
($item->{itemnumber
});
166 my $ItemBorrowerReserveInfo = GetMemberDetails
( $reservedfor, 0);
168 if (C4
::Context
->preference('HidePatronName')){
169 $item->{'hidepatronname'} = 1;
172 if ( defined $reservedate ) {
173 $item->{backgroundcolor
} = 'reserved';
174 $item->{reservedate
} = format_date
($reservedate);
175 $item->{ReservedForBorrowernumber
} = $reservedfor;
176 $item->{ReservedForSurname
} = $ItemBorrowerReserveInfo->{'surname'};
177 $item->{ReservedForFirstname
} = $ItemBorrowerReserveInfo->{'firstname'};
178 $item->{ExpectedAtLibrary
} = $branches->{$expectedAt}{branchname
};
179 $item->{cardnumber
} = $ItemBorrowerReserveInfo->{'cardnumber'};
182 # Check the transit status
183 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
184 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
185 $item->{transfertwhen
} = format_date
($transfertwhen);
186 $item->{transfertfrom
} = $branches->{$transfertfrom}{branchname
};
187 $item->{transfertto
} = $branches->{$transfertto}{branchname
};
188 $item->{nocancel
} = 1;
191 # FIXME: move this to a pm, check waiting status for holds
192 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
193 $sth2->execute($item->{ReservedForBorrowernumber
},$item->{itemnumber
});
194 while (my $wait_hashref = $sth2->fetchrow_hashref) {
195 $item->{waitingdate
} = format_date
($wait_hashref->{waitingdate
});
198 push @itemloop, $item;
201 $template->param( norequests
=> $norequests );
203 MARCNOTES
=> $marcnotesarray,
204 MARCSUBJCTS
=> $marcsubjctsarray,
205 MARCAUTHORS
=> $marcauthorsarray,
206 MARCSERIES
=> $marcseriesarray,
207 MARCURLS
=> $marcurlsarray,
208 subtitle
=> $subtitle,
209 itemdata_ccode
=> $itemfields{ccode
},
210 itemdata_enumchron
=> $itemfields{enumchron
},
211 itemdata_uri
=> $itemfields{uri
},
212 itemdata_copynumber
=> $itemfields{copynumber
},
213 volinfo
=> $itemfields{enumchron
} || $dat->{'serial'} ,
214 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
215 C4
::Search
::enabled_staff_search_views
,
218 my @results = ( $dat, );
219 foreach ( keys %{$dat} ) {
220 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
223 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
224 # method query not found?!?!
227 itemloop
=> \
@itemloop,
228 biblionumber
=> $biblionumber,
230 subscriptions
=> \
@subs,
231 subscriptionsnumber
=> $subscriptionsnumber,
232 subscriptiontitle
=> $dat->{title
},
235 # $debug and $template->param(debug_display => 1);
239 if (C4
::Context
->preference("virtualshelves") ) {
240 $template->param( 'GetShelves' => GetBibliosShelves
( $biblionumber ) );
244 if (C4
::Context
->preference("FRBRizeEditions")==1) {
247 XISBNS
=> get_xisbns
($isbn)
250 if ($@
) { warn "XISBN Failed $@"; }
252 if ( C4
::Context
->preference("AmazonEnabled") == 1 ) {
253 $template->param( AmazonTld
=> get_amazon_tld
() );
254 my $amazon_reviews = C4
::Context
->preference("AmazonReviews");
255 my $amazon_similars = C4
::Context
->preference("AmazonSimilarItems");
257 if ( $amazon_reviews ) {
258 $template->param( AmazonReviews
=> 1 );
259 push( @services, 'EditorialReview' );
261 if ( $amazon_similars ) {
262 $template->param( AmazonSimilarItems
=> 1 );
263 push( @services, 'Similarities' );
265 my $amazon_details = &get_amazon_details
( $isbn, $record, $marcflavour, \
@services );
266 if ( $amazon_similars ) {
267 my $similar_products_exist;
268 my @similar_products;
269 for my $similar_product (@
{$amazon_details->{Items
}->{Item
}->[0]->{SimilarProducts
}->{SimilarProduct
}}) {
270 # do we have any of these isbns in our collection?
271 my $similar_biblionumbers = get_biblionumber_from_isbn
($similar_product->{ASIN
});
272 # verify that there is at least one similar item
273 if (scalar(@
$similar_biblionumbers)){
274 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
275 push @similar_products, +{ similar_biblionumbers
=> $similar_biblionumbers, title
=> $similar_product->{Title
}, ASIN
=> $similar_product->{ASIN
} };
278 $template->param( AmazonSimilarItems
=> $similar_products_exist );
279 $template->param( AMAZON_SIMILAR_PRODUCTS
=> \
@similar_products );
281 if ( $amazon_reviews ) {
282 my $item = $amazon_details->{Items
}->{Item
}->[0];
283 my $editorial_reviews = \@
{ $item->{EditorialReviews
}->{EditorialReview
} };
284 #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}};
285 #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{AverageRating} || 0;
286 #$template->param( amazon_average_rating => $average_rating * 20 );
287 #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
288 $template->param( AMAZON_EDITORIAL_REVIEWS
=> $editorial_reviews );
293 if (C4
::Context
->preference('OPACBaseURL')){
294 $template->param( OpacUrl
=> C4
::Context
->preference('OPACBaseURL') );
297 output_html_with_http_headers
$query, $cookie, $template->output;