updating install dependancies
[koha.git] / opac / opac-ISBDdetail.pl
blobc052d5a942f58079b45460c9ba69b4e4333197d8
1 #!/usr/bin/perl
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
10 # version.
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
21 =head1 NAME
23 opac-ISBDdetail.pl : script to show a biblio in ISBD format
26 =head1 DESCRIPTION
28 This script needs a biblionumber as parameter
30 It shows the biblio
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
38 =head1 FUNCTIONS
40 =over 2
42 =cut
44 use strict;
45 require Exporter;
46 use C4::Auth;
47 use C4::Context;
48 use C4::Output;
49 use CGI;
50 use MARC::Record;
51 use C4::Biblio;
52 use C4::Acquisition;
53 use C4::Review;
54 use C4::Serials; # uses getsubscriptionfrom biblionumber
55 use C4::Koha; # use getitemtypeinfo
56 use C4::Members; # GetMember
58 my $query = new CGI;
60 my $dbh = C4::Context->dbh;
62 my $biblionumber = $query->param('biblionumber');
63 my $itemtype = &GetFrameworkCode($biblionumber);
64 my $tagslib = &GetMarcStructure( 1, $itemtype );
66 my $record = GetMarcBiblio($biblionumber);
68 #coping with subscriptions
69 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
70 my $dat = TransformMarcToKoha( $dbh, $record );
71 my @subscriptions =
72 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
73 my @subs;
74 foreach my $subscription (@subscriptions) {
75 my %cell;
76 $cell{subscriptionid} = $subscription->{subscriptionid};
77 $cell{subscriptionnotes} = $subscription->{notes};
79 #get the three latest serials.
80 $cell{latestserials} =
81 GetLatestSerials( $subscription->{subscriptionid}, 3 );
82 push @subs, \%cell;
85 # open template
86 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
88 template_name => "opac-ISBDdetail.tmpl",
89 query => $query,
90 type => "opac",
91 authnotrequired => 1,
92 debug => 1,
95 $template->param(
96 subscriptions => \@subs,
97 subscriptionsnumber => $subscriptionsnumber,
100 my $ISBD = C4::Context->preference('ISBD');
102 # my @blocs = split /\@/,$ISBD;
103 # my @fields = $record->fields();
104 my $res;
106 # foreach my $bloc (@blocs) {
107 # $bloc =~ s/\n//g;
108 my $bloc = $ISBD;
109 my $blocres;
110 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
112 foreach my $isbdfield ( split /#/, $bloc ) {
114 # $isbdfield= /(.?.?.?)/;
115 $isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
116 my $fieldvalue = $1;
117 my $textbefore = $2;
118 my $analysestring = $3;
119 my $textafter = $4;
121 # warn "==> $1 / $2 / $3 / $4";
122 # my $fieldvalue=substr($isbdfield,0,3);
123 if ( $fieldvalue > 0 ) {
124 my $hasputtextbefore = 0;
125 my @fieldslist = $record->field($fieldvalue);
126 @fieldslist = sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
128 # warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
129 # warn "FV : $fieldvalue";
130 foreach my $field ( @fieldslist ) {
131 my $calculated = $analysestring;
132 my $tag = $field->tag();
133 if ( $tag < 10 ) {
135 else {
136 my @subf = $field->subfields;
137 for my $i ( 0 .. $#subf ) {
138 my $subfieldcode = $subf[$i][0];
139 my $subfieldvalue =
140 GetAuthorisedValueDesc( $tag, $subf[$i][0],
141 $subf[$i][1], '', $tagslib );
142 my $tagsubf = $tag . $subfieldcode;
143 $calculated =~
144 s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
147 # field builded, store the result
148 if ( $calculated && !$hasputtextbefore )
149 { # put textbefore if not done
150 $blocres .= $textbefore;
151 $hasputtextbefore = 1;
154 # remove punctuation at start
155 $calculated =~ s/^( |;|:|\.|-)*//g;
156 $blocres .= $calculated;
159 $blocres .= $textafter if $hasputtextbefore;
161 else {
162 $blocres .= $isbdfield;
165 $res .= $blocres;
168 $res =~ s/\{(.*?)\}//g;
169 $res =~ s/\\n/\n/g;
170 $res =~ s/\n/<br\/>/g;
172 # remove empty ()
173 $res =~ s/\(\)//g;
175 my $reviews = getreviews( $biblionumber, 1 );
176 foreach ( @$reviews ) {
177 my $borrower_number_review = $_->{borrowernumber};
178 my $borrowerData = GetMember($borrower_number_review,'borrowernumber');
179 # setting some borrower info into this hash
180 $_->{title} = $borrowerData->{'title'};
181 $_->{surname} = $borrowerData->{'surname'};
182 $_->{firstname} = $borrowerData->{'firstname'};
186 $template->param(
187 ISBD => $res,
188 biblionumber => $biblionumber,
189 reviews => $reviews,
192 ## Amazon.com stuff
193 #not used unless preference set
194 if ( C4::Context->preference("AmazonContent") == 1 ) {
195 use C4::Amazon;
196 $dat->{'amazonisbn'} = $dat->{'isbn'};
197 $dat->{'amazonisbn'} =~ s|-||g;
199 $template->param( amazonisbn => $dat->{amazonisbn} );
201 my $amazon_details = &get_amazon_details( $dat->{amazonisbn} );
203 foreach my $result ( @{ $amazon_details->{Details} } ) {
204 $template->param( item_description => $result->{ProductDescription} );
205 $template->param( image => $result->{ImageUrlMedium} );
206 $template->param( list_price => $result->{ListPrice} );
207 $template->param( amazon_url => $result->{url} );
210 my @products;
211 my @reviews;
212 for my $details ( @{ $amazon_details->{Details} } ) {
213 next unless $details->{SimilarProducts};
214 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
215 push @products, +{ Product => $product };
217 next unless $details->{Reviews};
218 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
219 $template->param( rating => $product * 20 );
221 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
222 push @reviews,
224 Summary => $reviews->{Summary},
225 Comment => $reviews->{Comment},
229 $template->param( SIMILAR_PRODUCTS => \@products );
230 $template->param( AMAZONREVIEWS => \@reviews );
233 output_html_with_http_headers $query, $cookie, $template->output;