3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Serials; #uses getsubscriptionfrom biblionumber
31 use C4::Tags qw(get_tags);
32 use C4::Dates qw/format_date/;
33 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn);
41 if (C4::Context->preference('BakerTaylorEnabled')) {
42 require C4::External::BakerTaylor;
43 import C4::External::BakerTaylor qw(&image_url &link_url);
48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
50 template_name => "opac-detail.tmpl",
54 flagsrequired => { borrow => 1 },
58 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
59 $template->param( biblionumber => $biblionumber );
60 # XSLT processing of some stuff
61 if (C4::Context->preference("XSLTResultsDisplay") ) {
62 my $newxmlrecord = XSLTParse4Display($biblionumber,C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACDetail.xsl");
63 $template->param('XSLTBloc' => $newxmlrecord);
66 # change back when ive fixed request.pl
67 my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
69 @items = @all_items unless C4::Context->preference('hidelostitems');
71 if (C4::Context->preference('hidelostitems')) {
73 for my $itm (@all_items) {
74 push @items, $itm unless $itm->{itemlost};
77 my $dat = &GetBiblioData($biblionumber);
80 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
83 my $imgdir = getitemtypeimagesrc();
84 my $itemtypes = GetItemTypes();
86 my $itemtype = $dat->{'itemtype'};
88 $dat->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
89 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
91 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
92 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} );
94 #coping with subscriptions
95 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
97 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
99 $dat->{'serial'}=1 if $subscriptionsnumber;
100 foreach my $subscription (@subscriptions) {
102 $cell{subscriptionid} = $subscription->{subscriptionid};
103 $cell{subscriptionnotes} = $subscription->{notes};
104 $cell{branchcode} = $subscription->{branchcode};
105 $cell{hasalert} = $subscription->{hasalert};
106 #get the three latest serials.
107 $cell{latestserials} =
108 GetLatestSerials( $subscription->{subscriptionid}, 3 );
112 $dat->{'count'} = scalar(@items);
114 #adding RequestOnOpac filter to allow or not the display of plce reserve button
115 # FIXME - use me or delete me.
117 if (C4::Context->preference("RequestOnOpac")) {
123 for my $itm (@items) {
124 $norequests = 0 && $norequests
125 if ( (not $itm->{'wthdrawn'} )
126 || (not $itm->{'itemlost'} )
127 || (not $itm->{'itemnotforloan'} )
128 || ($itm->{'itemnumber'} ) );
129 $itm->{ $itm->{'publictype'} } = 1;
130 $itm->{datedue} = format_date($itm->{datedue});
131 $itm->{datelastseen} = format_date($itm->{datelastseen});
133 #get collection code description, too
134 my $ccode= $itm->{'ccode'};
135 $itm->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
136 $itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
137 $itm->{'imageurl'} = $imgdir."/".$itemtypes->{ $itm->{itype} }->{'imageurl'};
138 $itm->{'description'} = $itemtypes->{$itemtype}->{'description'};
139 $itemfields{ccode} = 1 if($itm->{ccode});
140 $itemfields{enumchron} = 1 if($itm->{enumchron});
141 $itemfields{copynumber} = 1 if($itm->{copynumber});
144 ## get notes and subjects from MARC record
145 my $dbh = C4::Context->dbh;
146 my $marcflavour = C4::Context->preference("marcflavour");
147 my $record = GetMarcBiblio($biblionumber);
148 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
149 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
150 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
151 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
152 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
155 MARCNOTES => $marcnotesarray,
156 MARCSUBJCTS => $marcsubjctsarray,
157 MARCAUTHORS => $marcauthorsarray,
158 MARCSERIES => $marcseriesarray,
159 MARCURLS => $marcurlsarray,
160 norequests => $norequests,
161 RequestOnOpac=>$RequestOnOpac,
162 itemdata_ccode => $itemfields{ccode},
163 itemdata_enumchron => $itemfields{enumchron},
164 itemdata_copynumber => $itemfields{copynumber},
167 foreach ( keys %{$dat} ) {
168 $template->param( "$_" => $dat->{$_} . "" );
171 # COinS format FIXME: for books Only
173 my $fmt = substr $record->leader(), 6,2;
175 $fmts->{'am'} = 'book';
176 $coins_format = $fmts->{$fmt};
178 ocoins_format => $coins_format,
181 my $reviews = getreviews( $biblionumber, 1 );
182 my $loggedincommenter;
183 foreach ( @$reviews ) {
184 my $borrowerData = GetMember($_->{borrowernumber},'borrowernumber');
185 # setting some borrower info into this hash
186 $_->{title} = $borrowerData->{'title'};
187 $_->{surname} = $borrowerData->{'surname'};
188 $_->{firstname} = $borrowerData->{'firstname'};
189 $_->{userid} = $borrowerData->{'userid'};
190 $_->{datereviewed} = format_date($_->{datereviewed});
191 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
192 $_->{your_comment} = 1;
193 $loggedincommenter = 1;
198 if(C4::Context->preference("ISBD")) {
199 $template->param(ISBD => 1);
203 ITEM_RESULTS => \@items,
204 subscriptionsnumber => $subscriptionsnumber,
205 biblionumber => $biblionumber,
206 subscriptions => \@subs,
207 subscriptionsnumber => $subscriptionsnumber,
209 loggedincommenter => $loggedincommenter
213 my $xisbn=$dat->{'isbn'};
214 $xisbn =~ /(\d*[X]*)/;
215 $template->param(amazonisbn => $1); # FIXME: so it is OK if the ISBN = 'XXXXX' ?
216 my ($clean, $amazonisbn);
218 # these might be overkill, but they are better than the regexp above.
220 $amazonisbn =~ /\b(\d{13})\b/ or
221 $amazonisbn =~ /\b(\d{10})\b/ or
222 $amazonisbn =~ /\b(\d{9}X)\b/i
225 $template->param(clean_isbn => $1);
228 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
232 XISBNS => get_xisbns($xisbn)
235 if ($@) { warn "XISBN Failed $@"; }
238 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
239 my $similar_products_exist;
240 my $amazon_details = &get_amazon_details( $xisbn );
241 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
242 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
243 for my $one_review (@$customer_reviews) {
244 $one_review->{Date} = format_date($one_review->{Date});
246 my @similar_products;
247 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
248 # do we have any of these isbns in our collection?
249 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
250 # verify that there is at least one similar item
251 $similar_products_exist++ if ${@$similar_biblionumbers}[0];
252 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
254 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
255 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
256 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
257 $template->param( amazon_average_rating => $average_rating * 20);
258 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
259 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
260 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
262 # Shelf Browser Stuff
263 if (C4::Context->preference("OPACShelfBrowser")) {
264 # pick the first itemnumber unless one was selected by the user
265 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
266 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
267 # find the right cn_sort value for this item
268 my ($starting_cn_sort, $starting_homebranch, $starting_location);
269 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
270 $sth_get_cn_sort->execute($starting_itemnumber);
271 my $branches = GetBranches();
272 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
273 $starting_cn_sort = $result->{'cn_sort'};
274 $starting_homebranch->{code} = $result->{'homebranch'};
275 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
276 $starting_location->{code} = $result->{'location'};
277 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
281 ## List of Previous Items
282 # order by cn_sort, which should include everything we need for ordering purposes (though not
283 # for limits, those need to be handled separately
284 my $sth_shelfbrowse_previous = $dbh->prepare("SELECT * FROM items WHERE CONCAT(cn_sort,itemnumber) <= ? AND homebranch=? AND location=? ORDER BY CONCAT(cn_sort,itemnumber) DESC LIMIT 3");
285 $sth_shelfbrowse_previous->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
287 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
288 my $sth_get_biblio = $dbh->prepare("SELECT biblio.*,biblioitems.isbn AS isbn FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber WHERE biblio.biblionumber=?");
289 $sth_get_biblio->execute($this_item->{biblionumber});
290 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
291 $this_item->{'title'} = $this_biblio->{'title'};
292 $this_item->{'isbn'} = $this_biblio->{'isbn'};
294 unshift @previous_items, $this_item;
296 my $throwaway = pop @previous_items;
297 ## List of Next Items
298 my $sth_shelfbrowse_next = $dbh->prepare("SELECT * FROM items WHERE CONCAT(cn_sort,itemnumber) >= ? AND homebranch=? AND location=? ORDER BY CONCAT(cn_sort,itemnumber) ASC LIMIT 3");
299 $sth_shelfbrowse_next->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
301 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
302 my $sth_get_biblio = $dbh->prepare("SELECT biblio.*,biblioitems.isbn AS isbn FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber WHERE biblio.biblionumber=?");
303 $sth_get_biblio->execute($this_item->{biblionumber});
304 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
305 $this_item->{'title'} = $this_biblio->{'title'};
306 $this_item->{'isbn'} = $this_biblio->{'isbn'};
308 push @next_items, $this_item;
311 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
312 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
313 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
316 starting_homebranch => $starting_homebranch->{description},
317 starting_location => $starting_location->{description},
318 shelfbrowser_prev_itemnumber => $previous_items[0]->{itemnumber},
319 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
320 shelfbrowser_prev_biblionumber => $previous_items[0]->{biblionumber},
321 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
322 PREVIOUS_SHELF_BROWSE => \@previous_items,
323 NEXT_SHELF_BROWSE => \@next_items,
327 if (C4::Context->preference("BakerTaylorEnabled")) {
329 BakerTaylorEnabled => 1,
330 BakerTaylorImageURL => &image_url(),
331 BakerTaylorLinkURL => &link_url(),
332 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
334 my ($bt_user, $bt_pass);
336 $bt_user = C4::Context->preference('BakerTaylorUsername') and
337 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
340 BakerTaylorContentURL =>
341 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
342 $bt_user,$bt_pass,$clean)
348 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
351 TagsShowOnDetail => $tag_quantity,
352 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
354 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber,
355 'sort'=>'-weight', limit=>$tag_quantity}));
358 output_html_with_http_headers $query, $cookie, $template->output;