Added combined, line-wise smart-rules script for defining issuingrules.
[koha.git] / opac / opac-ISBDdetail.pl
blobdb2560345c0199ca66ee4d7f0213bef09a4ddde1
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};
78 $cell{branchcode} = $subscription->{branchcode};
80 #get the three latest serials.
81 $cell{latestserials} =
82 GetLatestSerials( $subscription->{subscriptionid}, 3 );
83 push @subs, \%cell;
86 # open template
87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
89 template_name => "opac-ISBDdetail.tmpl",
90 query => $query,
91 type => "opac",
92 authnotrequired => 1,
93 debug => 1,
96 $template->param(
97 subscriptions => \@subs,
98 subscriptionsnumber => $subscriptionsnumber,
101 my $ISBD = C4::Context->preference('ISBD');
103 # my @blocs = split /\@/,$ISBD;
104 # my @fields = $record->fields();
105 my $res;
107 # foreach my $bloc (@blocs) {
108 # $bloc =~ s/\n//g;
109 my $bloc = $ISBD;
110 my $blocres;
111 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
113 foreach my $isbdfield ( split /#/, $bloc ) {
115 # $isbdfield= /(.?.?.?)/;
116 $isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
117 my $fieldvalue = $1;
118 my $textbefore = $2;
119 my $analysestring = $3;
120 my $textafter = $4;
122 # warn "==> $1 / $2 / $3 / $4";
123 # my $fieldvalue=substr($isbdfield,0,3);
124 if ( $fieldvalue > 0 ) {
125 my $hasputtextbefore = 0;
126 my @fieldslist = $record->field($fieldvalue);
127 @fieldslist = sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
129 # warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
130 # warn "FV : $fieldvalue";
131 foreach my $field ( @fieldslist ) {
132 my $calculated = $analysestring;
133 my $tag = $field->tag();
134 if ( $tag < 10 ) {
136 else {
137 my @subf = $field->subfields;
138 for my $i ( 0 .. $#subf ) {
139 my $subfieldcode = $subf[$i][0];
140 my $subfieldvalue =
141 GetAuthorisedValueDesc( $tag, $subf[$i][0],
142 $subf[$i][1], '', $tagslib );
143 my $tagsubf = $tag . $subfieldcode;
144 $calculated =~
145 s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
146 $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
149 # field builded, store the result
150 if ( $calculated && !$hasputtextbefore )
151 { # put textbefore if not done
152 $blocres .= $textbefore;
153 $hasputtextbefore = 1;
156 # remove punctuation at start
157 $calculated =~ s/^( |;|:|\.|-)*//g;
158 $blocres .= $calculated;
161 $blocres .= $textafter if $hasputtextbefore;
163 else {
164 $blocres .= $isbdfield;
167 $res .= $blocres;
170 $res =~ s/\{(.*?)\}//g;
171 $res =~ s/\\n/\n/g;
172 $res =~ s/\n/<br\/>/g;
174 # remove empty ()
175 $res =~ s/\(\)//g;
177 my $reviews = getreviews( $biblionumber, 1 );
178 foreach ( @$reviews ) {
179 my $borrower_number_review = $_->{borrowernumber};
180 my $borrowerData = GetMember($borrower_number_review,'borrowernumber');
181 # setting some borrower info into this hash
182 $_->{title} = $borrowerData->{'title'};
183 $_->{surname} = $borrowerData->{'surname'};
184 $_->{firstname} = $borrowerData->{'firstname'};
188 $template->param(
189 ISBD => $res,
190 biblionumber => $biblionumber,
191 reviews => $reviews,
194 ## Amazon.com stuff
195 #not used unless preference set
196 if ( C4::Context->preference("AmazonContent") == 1 ) {
197 use C4::Amazon;
198 $dat->{'amazonisbn'} = $dat->{'isbn'};
199 $dat->{'amazonisbn'} =~ s|-||g;
201 $template->param( amazonisbn => $dat->{amazonisbn} );
203 my $amazon_details = &get_amazon_details( $dat->{amazonisbn} );
205 foreach my $result ( @{ $amazon_details->{Details} } ) {
206 $template->param( item_description => $result->{ProductDescription} );
207 $template->param( image => $result->{ImageUrlMedium} );
208 $template->param( list_price => $result->{ListPrice} );
209 $template->param( amazon_url => $result->{url} );
212 my @products;
213 my @reviews;
214 for my $details ( @{ $amazon_details->{Details} } ) {
215 next unless $details->{SimilarProducts};
216 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
217 push @products, +{ Product => $product };
219 next unless $details->{Reviews};
220 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
221 $template->param( rating => $product * 20 );
223 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
224 push @reviews,
226 Summary => $reviews->{Summary},
227 Comment => $reviews->{Comment},
231 $template->param( SIMILAR_PRODUCTS => \@products );
232 $template->param( AMAZONREVIEWS => \@reviews );
235 output_html_with_http_headers $query, $cookie, $template->output;