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);
39 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
41 template_name => "opac-detail.tmpl",
45 flagsrequired => { borrow => 1 },
49 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
50 $template->param( biblionumber => $biblionumber );
52 # change back when ive fixed request.pl
53 my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
55 @items = @all_items unless C4::Context->preference('hidelostitems');
57 if (C4::Context->preference('hidelostitems')) {
59 for my $itm (@all_items) {
60 push @items, $itm unless $itm->{itemlost};
63 my $dat = &GetBiblioData($biblionumber);
66 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
69 my $imgdir = getitemtypeimagesrc();
70 my $itemtypes = GetItemTypes();
72 my $itemtype = $dat->{'itemtype'};
74 $dat->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
75 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
78 #coping with subscriptions
79 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
81 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
83 $dat->{'serial'}=1 if $subscriptionsnumber;
84 foreach my $subscription (@subscriptions) {
86 $cell{subscriptionid} = $subscription->{subscriptionid};
87 $cell{subscriptionnotes} = $subscription->{notes};
88 $cell{branchcode} = $subscription->{branchcode};
89 $cell{hasalert} = $subscription->{hasalert};
90 #get the three latest serials.
91 $cell{latestserials} =
92 GetLatestSerials( $subscription->{subscriptionid}, 3 );
96 $dat->{'count'} = scalar(@items);
98 #adding RequestOnOpac filter to allow or not the display of plce reserve button
99 # FIXME - use me or delete me.
101 if (C4::Context->preference("RequestOnOpac")) {
106 foreach my $itm (@items) {
107 $norequests = 0 && $norequests
108 if ( (not $itm->{'wthdrawn'} )
109 || (not $itm->{'itemlost'} )
110 || (not $itm->{'itemnotforloan'} )
111 || ($itm->{'itemnumber'} ) );
112 $itm->{ $itm->{'publictype'} } = 1;
113 $itm->{datedue} = format_date($itm->{datedue});
114 $itm->{datelastseen} = format_date($itm->{datelastseen});
116 #get collection code description, too
117 $itm->{'ccode'} = GetAuthorisedValueDesc('','', $itm->{'ccode'} ,'','','CCODE');
118 $itm->{'location_description'} = GetAuthorisedValueDesc('','', $itm->{'location'} ,'','','LOC');
121 $template->param( norequests => $norequests, RequestOnOpac=>$RequestOnOpac );
123 ## get notes and subjects from MARC record
124 my $dbh = C4::Context->dbh;
125 my $marcflavour = C4::Context->preference("marcflavour");
126 my $record = GetMarcBiblio($biblionumber);
127 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
128 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
129 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
130 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
131 my $marcurlsarray = GetMarcUrls($record,$marcflavour);
134 MARCNOTES => $marcnotesarray,
135 MARCSUBJCTS => $marcsubjctsarray,
136 MARCAUTHORS => $marcauthorsarray,
137 MARCSERIES => $marcseriesarray,
138 MARCURLS => $marcurlsarray,
141 foreach ( keys %{$dat} ) {
142 $template->param( "$_" => $dat->{$_} . "" );
145 # COinS format FIXME: for books Only
147 my $fmt = substr $record->leader(), 6,2;
149 $fmts->{'am'} = 'book';
150 $coins_format = $fmts->{$fmt};
152 ocoins_format => $coins_format,
155 my $reviews = getreviews( $biblionumber, 1 );
156 foreach ( @$reviews ) {
157 my $borrower_number_review = $_->{borrowernumber};
158 my $borrowerData = GetMember($borrower_number_review,'borrowernumber');
159 # setting some borrower info into this hash
160 $_->{title} = $borrowerData->{'title'};
161 $_->{surname} = $borrowerData->{'surname'};
162 $_->{firstname} = $borrowerData->{'firstname'};
163 $_->{datereviewed} = format_date($_->{datereviewed});
167 if(C4::Context->preference("ISBD")) {
168 $template->param(ISBD => 1);
172 ITEM_RESULTS => \@items,
173 subscriptionsnumber => $subscriptionsnumber,
174 biblionumber => $biblionumber,
175 subscriptions => \@subs,
176 subscriptionsnumber => $subscriptionsnumber,
181 my $xisbn=$dat->{'isbn'};
182 $xisbn =~ s/(p|-| |:)//g;
183 $template->param(amazonisbn => $xisbn);
184 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
188 XISBNS => get_xisbns($xisbn)
191 if ($@) { warn "XISBN Failed $@"; }
194 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
195 my $similar_products_exist;
196 my $amazon_details = &get_amazon_details( $xisbn );
197 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
198 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
199 for my $one_review (@$customer_reviews) {
200 $one_review->{Date} = format_date($one_review->{Date});
202 my @similar_products;
203 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
204 # do we have any of these isbns in our collection?
205 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
206 # verify that there is at least one similar item
207 $similar_products_exist++ if ${@$similar_biblionumbers}[0];
208 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
210 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
211 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
212 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
213 $template->param( amazon_average_rating => $average_rating * 20);
214 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
215 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
216 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
218 # Shelf Browser Stuff
219 if (C4::Context->preference("OPACShelfBrowser")) {
220 # pick the first itemnumber unless one was selected by the user
221 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
222 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
223 # find the right cn_sort value for this item
224 my ($starting_cn_sort, $starting_homebranch, $starting_location);
225 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
226 $sth_get_cn_sort->execute($starting_itemnumber);
227 my $branches = GetBranches();
228 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
229 $starting_cn_sort = $result->{'cn_sort'};
230 $starting_homebranch->{code} = $result->{'homebranch'};
231 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
232 $starting_location->{code} = $result->{'location'};
233 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
237 ## List of Previous Items
238 # order by cn_sort, which should include everything we need for ordering purposes (though not
239 # for limits, those need to be handled separately
240 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");
241 $sth_shelfbrowse_previous->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
243 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
244 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=?");
245 $sth_get_biblio->execute($this_item->{biblionumber});
246 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
247 $this_item->{'title'} = $this_biblio->{'title'};
248 $this_item->{'isbn'} = $this_biblio->{'isbn'};
250 unshift @previous_items, $this_item;
252 my $throwaway = pop @previous_items;
253 ## List of Next Items
254 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");
255 $sth_shelfbrowse_next->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
257 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
258 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=?");
259 $sth_get_biblio->execute($this_item->{biblionumber});
260 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
261 $this_item->{'title'} = $this_biblio->{'title'};
262 $this_item->{'isbn'} = $this_biblio->{'isbn'};
264 push @next_items, $this_item;
267 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
268 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
269 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
272 starting_homebranch => $starting_homebranch->{description},
273 starting_location => $starting_location->{description},
274 shelfbrowser_prev_itemnumber => $previous_items[0]->{itemnumber},
275 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
276 shelfbrowser_prev_biblionumber => $previous_items[0]->{biblionumber},
277 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
278 PREVIOUS_SHELF_BROWSE => \@previous_items,
279 NEXT_SHELF_BROWSE => \@next_items,
283 output_html_with_http_headers $query, $cookie, $template->output;