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::Dates qw/format_date/;
32 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn);
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42 template_name => "opac-detail.tmpl",
46 flagsrequired => { borrow => 1 },
50 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
51 $template->param( biblionumber => $biblionumber );
52 # XSLT processing of some stuff
53 if (C4::Context->preference("XSLTResultsDisplay") ) {
54 my $newxmlrecord = XSLTParse4Display($biblionumber,'Detail');
55 $template->param('XSLTBloc' => $newxmlrecord);
58 # change back when ive fixed request.pl
59 my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
61 @items = @all_items unless C4::Context->preference('hidelostitems');
63 if (C4::Context->preference('hidelostitems')) {
65 for my $itm (@all_items) {
66 push @items, $itm unless $itm->{itemlost};
69 my $dat = &GetBiblioData($biblionumber);
72 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
75 my $imgdir = getitemtypeimagesrc();
76 my $itemtypes = GetItemTypes();
78 my $itemtype = $dat->{'itemtype'};
80 $dat->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
81 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
84 #coping with subscriptions
85 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
87 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
89 $dat->{'serial'}=1 if $subscriptionsnumber;
90 foreach my $subscription (@subscriptions) {
92 $cell{subscriptionid} = $subscription->{subscriptionid};
93 $cell{subscriptionnotes} = $subscription->{notes};
94 $cell{branchcode} = $subscription->{branchcode};
95 $cell{hasalert} = $subscription->{hasalert};
96 #get the three latest serials.
97 $cell{latestserials} =
98 GetLatestSerials( $subscription->{subscriptionid}, 3 );
102 $dat->{'count'} = scalar(@items);
104 #adding RequestOnOpac filter to allow or not the display of plce reserve button
105 # FIXME - use me or delete me.
107 if (C4::Context->preference("RequestOnOpac")) {
113 for my $itm (@items) {
114 $norequests = 0 && $norequests
115 if ( (not $itm->{'wthdrawn'} )
116 || (not $itm->{'itemlost'} )
117 || (not $itm->{'itemnotforloan'} )
118 || ($itm->{'itemnumber'} ) );
119 $itm->{ $itm->{'publictype'} } = 1;
120 $itm->{datedue} = format_date($itm->{datedue});
121 $itm->{datelastseen} = format_date($itm->{datelastseen});
123 #get collection code description, too
124 $itm->{'ccode'} = GetAuthorisedValueDesc('','', $itm->{'ccode'} ,'','','CCODE');
125 $itm->{'location_description'} = GetAuthorisedValueDesc('','', $itm->{'location'} ,'','','LOC');
126 $itm->{'imageurl'} = $imgdir."/".$itemtypes->{ $itm->{itype} }->{'imageurl'};
127 $itm->{'description'} = $itemtypes->{$itemtype}->{'description'};
128 $itemfields{ccode} = 1 if($itm->{ccode});
129 $itemfields{enumchron} = 1 if($itm->{enumchron});
130 $itemfields{copynumber} = 1 if($itm->{copynumber});
133 ## get notes and subjects from MARC record
134 my $dbh = C4::Context->dbh;
135 my $marcflavour = C4::Context->preference("marcflavour");
136 my $record = GetMarcBiblio($biblionumber);
137 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
138 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
139 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
140 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
141 my $marcurlsarray = GetMarcUrls($record,$marcflavour);
144 MARCNOTES => $marcnotesarray,
145 MARCSUBJCTS => $marcsubjctsarray,
146 MARCAUTHORS => $marcauthorsarray,
147 MARCSERIES => $marcseriesarray,
148 MARCURLS => $marcurlsarray,
149 norequests => $norequests,
150 RequestOnOpac=>$RequestOnOpac,
151 itemdata_ccode => $itemfields{ccode},
152 itemdata_enumchron => $itemfields{enumchron},
153 itemdata_copynumber => $itemfields{copynumber},
156 foreach ( keys %{$dat} ) {
157 $template->param( "$_" => $dat->{$_} . "" );
160 # COinS format FIXME: for books Only
162 my $fmt = substr $record->leader(), 6,2;
164 $fmts->{'am'} = 'book';
165 $coins_format = $fmts->{$fmt};
167 ocoins_format => $coins_format,
170 my $reviews = getreviews( $biblionumber, 1 );
171 my $loggedincommenter;
172 foreach ( @$reviews ) {
173 my $borrower_number_review = $_->{borrowernumber};
174 my $borrowerData = GetMember($borrower_number_review,'borrowernumber');
175 # setting some borrower info into this hash
176 $_->{title} = $borrowerData->{'title'};
177 $_->{surname} = $borrowerData->{'surname'};
178 $_->{firstname} = $borrowerData->{'firstname'};
179 $_->{userid} = $borrowerData->{'userid'};
180 $_->{datereviewed} = format_date($_->{datereviewed});
181 if($borrowerData->{'borrowernumber'} eq $borrowernumber){ $loggedincommenter = 1; }
185 if(C4::Context->preference("ISBD")) {
186 $template->param(ISBD => 1);
190 ITEM_RESULTS => \@items,
191 subscriptionsnumber => $subscriptionsnumber,
192 biblionumber => $biblionumber,
193 subscriptions => \@subs,
194 subscriptionsnumber => $subscriptionsnumber,
196 loggedincommenter => $loggedincommenter
200 my $xisbn=$dat->{'isbn'};
201 $xisbn =~ s/(p|-| |:)//g;
202 $template->param(amazonisbn => $xisbn);
203 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
207 XISBNS => get_xisbns($xisbn)
210 if ($@) { warn "XISBN Failed $@"; }
213 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
214 my $similar_products_exist;
215 my $amazon_details = &get_amazon_details( $xisbn );
216 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
217 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
218 for my $one_review (@$customer_reviews) {
219 $one_review->{Date} = format_date($one_review->{Date});
221 my @similar_products;
222 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
223 # do we have any of these isbns in our collection?
224 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
225 # verify that there is at least one similar item
226 $similar_products_exist++ if ${@$similar_biblionumbers}[0];
227 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
229 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
230 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
231 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
232 $template->param( amazon_average_rating => $average_rating * 20);
233 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
234 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
235 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
237 # Shelf Browser Stuff
238 if (C4::Context->preference("OPACShelfBrowser")) {
239 # pick the first itemnumber unless one was selected by the user
240 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
241 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
242 # find the right cn_sort value for this item
243 my ($starting_cn_sort, $starting_homebranch, $starting_location);
244 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
245 $sth_get_cn_sort->execute($starting_itemnumber);
246 my $branches = GetBranches();
247 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
248 $starting_cn_sort = $result->{'cn_sort'};
249 $starting_homebranch->{code} = $result->{'homebranch'};
250 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
251 $starting_location->{code} = $result->{'location'};
252 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
256 ## List of Previous Items
257 # order by cn_sort, which should include everything we need for ordering purposes (though not
258 # for limits, those need to be handled separately
259 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");
260 $sth_shelfbrowse_previous->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
262 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
263 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=?");
264 $sth_get_biblio->execute($this_item->{biblionumber});
265 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
266 $this_item->{'title'} = $this_biblio->{'title'};
267 $this_item->{'isbn'} = $this_biblio->{'isbn'};
269 unshift @previous_items, $this_item;
271 my $throwaway = pop @previous_items;
272 ## List of Next Items
273 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");
274 $sth_shelfbrowse_next->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
276 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
277 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=?");
278 $sth_get_biblio->execute($this_item->{biblionumber});
279 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
280 $this_item->{'title'} = $this_biblio->{'title'};
281 $this_item->{'isbn'} = $this_biblio->{'isbn'};
283 push @next_items, $this_item;
286 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
287 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
288 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
291 starting_homebranch => $starting_homebranch->{description},
292 starting_location => $starting_location->{description},
293 shelfbrowser_prev_itemnumber => $previous_items[0]->{itemnumber},
294 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
295 shelfbrowser_prev_biblionumber => $previous_items[0]->{biblionumber},
296 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
297 PREVIOUS_SHELF_BROWSE => \@previous_items,
298 NEXT_SHELF_BROWSE => \@next_items,
302 output_html_with_http_headers $query, $cookie, $template->output;