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
23 opac-ISBDdetail.pl : script to show a biblio in ISBD format
28 This script needs a biblionumber as parameter
32 The template is in <templates_dir>/catalogue/ISBDdetail.tmpl.
33 this template must be divided into 11 "tabs".
35 The first 10 tabs present the biblio, the 11th one presents
36 the items attached to the biblio
53 use C4::Serials; # uses getsubscriptionfrom biblionumber
55 use C4::Members; # GetMember
56 use C4::External::Amazon;
58 my $query = CGI->new();
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 template_name => "opac-ISBDdetail.tmpl",
69 my $biblionumber = $query->param('biblionumber');
70 my $itemtype = &GetFrameworkCode($biblionumber);
71 my $tagslib = &GetMarcStructure( 1, $itemtype );
73 my $marcflavour = C4::Context->preference("marcflavour");
74 my $record = GetMarcBiblio($biblionumber);
76 # some useful variables for enhanced content;
77 # in each case, we're grabbing the first value we find in
78 # the record and normalizing it
79 my $upc = GetNormalizedUPC($record,$marcflavour);
80 my $ean = GetNormalizedEAN($record,$marcflavour);
81 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
82 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
83 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
85 normalized_upc => $upc,
86 normalized_ean => $ean,
87 normalized_oclc => $oclc,
88 normalized_isbn => $isbn,
89 content_identifier_exists => $content_identifier_exists,
92 #coping with subscriptions
93 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
94 my $dbh = C4::Context->dbh;
95 my $dat = TransformMarcToKoha( $dbh, $record );
97 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
99 foreach my $subscription (@subscriptions) {
101 my $serials_to_display;
102 $cell{subscriptionid} = $subscription->{subscriptionid};
103 $cell{subscriptionnotes} = $subscription->{notes};
104 $cell{branchcode} = $subscription->{branchcode};
106 #get the three latest serials.
107 $serials_to_display = $subscription->{opacdisplaycount};
108 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
109 $cell{opacdisplaycount} = $serials_to_display;
110 $cell{latestserials} =
111 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
116 subscriptions => \@subs,
117 subscriptionsnumber => $subscriptionsnumber,
120 my $ISBD = C4::Context->preference('ISBD');
122 # my @blocs = split /\@/,$ISBD;
123 # my @fields = $record->fields();
126 # foreach my $bloc (@blocs) {
130 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
132 foreach my $isbdfield ( split /#/, $bloc ) {
134 # $isbdfield= /(.?.?.?)/;
135 $isbdfield =~ /(\d\d\d)([^\|])?\|(.*)\|(.*)\|(.*)/;
139 my $analysestring = $4;
142 # warn "==> $1 / $2 / $3 / $4";
143 # my $fieldvalue=substr($isbdfield,0,3);
144 if ( $fieldvalue > 0 ) {
145 my $hasputtextbefore = 0;
146 my @fieldslist = $record->field($fieldvalue);
147 @fieldslist = sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
149 # warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
150 # warn "FV : $fieldvalue";
151 if ($subfvalue ne ""){
152 foreach my $field ( @fieldslist ) {
153 foreach my $subfield ($field->subfield($subfvalue)){
154 warn $fieldvalue."$subfvalue";
155 my $calculated = $analysestring;
156 my $tag = $field->tag();
161 GetAuthorisedValueDesc( $tag, $subfvalue,
162 $subfield, '', $tagslib );
163 my $tagsubf = $tag . $subfvalue;
165 s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
166 $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
168 # field builded, store the result
169 if ( $calculated && !$hasputtextbefore )
170 { # put textbefore if not done
171 $blocres .= $textbefore;
172 $hasputtextbefore = 1;
175 # remove punctuation at start
176 $calculated =~ s/^( |;|:|\.|-)*//g;
177 $blocres .= $calculated;
182 $blocres .= $textafter if $hasputtextbefore;
184 foreach my $field ( @fieldslist ) {
185 my $calculated = $analysestring;
186 my $tag = $field->tag();
190 my @subf = $field->subfields;
191 for my $i ( 0 .. $#subf ) {
192 my $valuecode = $subf[$i][1];
193 my $subfieldcode = $subf[$i][0];
195 GetAuthorisedValueDesc( $tag, $subf[$i][0],
196 $subf[$i][1], '', $tagslib );
197 my $tagsubf = $tag . $subfieldcode;
199 $calculated =~ s/ # replace all {{}} codes by the value code.
200 \{\{$tagsubf\}\} # catch the {{actualcode}}
202 $valuecode # replace by the value code
206 s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
207 $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
210 # field builded, store the result
211 if ( $calculated && !$hasputtextbefore )
212 { # put textbefore if not done
213 $blocres .= $textbefore;
214 $hasputtextbefore = 1;
217 # remove punctuation at start
218 $calculated =~ s/^( |;|:|\.|-)*//g;
219 $blocres .= $calculated;
222 $blocres .= $textafter if $hasputtextbefore;
226 $blocres .= $isbdfield;
232 $res =~ s/\{(.*?)\}//g;
234 $res =~ s/\n/<br\/>/g;
239 my $reviews = getreviews( $biblionumber, 1 );
240 foreach ( @$reviews ) {
241 my $borrower_number_review = $_->{borrowernumber};
242 my $borrowerData = GetMember($borrower_number_review,'borrowernumber');
243 # setting some borrower info into this hash
244 $_->{title} = $borrowerData->{'title'};
245 $_->{surname} = $borrowerData->{'surname'};
246 $_->{firstname} = $borrowerData->{'firstname'};
252 biblionumber => $biblionumber,
257 #not used unless preference set
258 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
260 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
262 foreach my $result ( @{ $amazon_details->{Details} } ) {
263 $template->param( item_description => $result->{ProductDescription} );
264 $template->param( image => $result->{ImageUrlMedium} );
265 $template->param( list_price => $result->{ListPrice} );
266 $template->param( amazon_url => $result->{url} );
271 for my $details ( @{ $amazon_details->{Details} } ) {
272 next unless $details->{SimilarProducts};
273 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
274 push @products, +{ Product => $product };
276 next unless $details->{Reviews};
277 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
278 $template->param( rating => $product * 20 );
280 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
283 Summary => $reviews->{Summary},
284 Comment => $reviews->{Comment},
288 $template->param( SIMILAR_PRODUCTS => \@products );
289 $template->param( AMAZONREVIEWS => \@reviews );
292 output_html_with_http_headers $query, $cookie, $template->output;