Add a new Debian package and GoogleJacket on OPAC detail page
[koha.git] / catalogue / ISBDdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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
19
20 =head1 NAME
21
22 ISBDdetail.pl : script to show a biblio in ISBD format
23
24 =head1 SYNOPSIS
25
26
27 =head1 DESCRIPTION
28
29 This script needs a biblionumber as parameter 
30
31 =head1 FUNCTIONS
32
33 =over 2
34
35 =cut
36
37 use strict;
38 require Exporter;
39 use C4::Auth;
40 use C4::Context;
41 use C4::Output;
42 use CGI;
43 use C4::Koha;
44 use C4::Biblio;
45 use C4::Items;
46 use C4::Branch;     # GetBranchDetail
47 use C4::Serials;    # CountSubscriptionFromBiblionumber
48
49
50 #---- Internal function
51
52
53 my $query = new CGI;
54 my $dbh = C4::Context->dbh;
55
56 my $biblionumber = $query->param('biblionumber');
57 my $itemtype     = &GetFrameworkCode($biblionumber);
58 my $tagslib      = &GetMarcStructure( 1, $itemtype );
59
60 my $record = GetMarcBiblio($biblionumber);
61
62 # open template
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64     {
65         template_name => "catalogue/ISBDdetail.tmpl",
66         query         => $query,
67         type          => "intranet",
68         authnotrequired => 0,
69         flagsrequired   => { catalogue => 1 },
70     }
71 );
72
73 my $ISBD = C4::Context->preference('ISBD');
74
75 # my @blocs = split /\@/,$ISBD;
76 # my @fields = $record->fields();
77 my $res;
78
79 # foreach my $bloc (@blocs) {
80 #     $bloc =~ s/\n//g;
81 my $bloc = $ISBD;
82 my $blocres;
83
84 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
85 # @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
86
87 foreach my $isbdfield ( split /#/, $bloc ) {
88
89     #         $isbdfield= /(.?.?.?)/;
90     $isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
91     my $fieldvalue    = $1;
92     my $textbefore    = $2;
93     my $analysestring = $3;
94     my $textafter     = $4;
95
96     #         warn "==> $1 / $2 / $3 / $4";
97     #         my $fieldvalue=substr($isbdfield,0,3);
98     if ( $fieldvalue > 0 ) {
99
100    #         warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
101    #             warn "FV : $fieldvalue";
102         my $hasputtextbefore = 0;
103         my @fieldslist = $record->field($fieldvalue);
104         @fieldslist= sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
105         foreach my $field ( @fieldslist ) {
106             my $calculated = $analysestring;
107             my $tag        = $field->tag();
108             if ( $tag < 10 ) {
109             }
110             else {
111                 my @subf = $field->subfields;
112                 for my $i ( 0 .. $#subf ) {
113                     my $subfieldcode  = $subf[$i][0];
114                     my $subfieldvalue =
115                       GetAuthorisedValueDesc( $tag, $subf[$i][0],
116                         $subf[$i][1], $itemtype,$tagslib);
117                     my $tagsubf = $tag . $subfieldcode;
118                     $calculated =~s/\{(.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
119                 }
120                 # field builded, store the result
121                 if ( $calculated && !$hasputtextbefore )
122                 {    # put textbefore if not done
123                     $blocres .= $textbefore;
124                     $hasputtextbefore = 1;
125                 }
126
127                 # remove punctuation at start
128                 $calculated =~ s/^( |;|:|\.|-)*//g;
129                 $blocres .= $calculated;
130             }
131         }
132         $blocres .= $textafter if $hasputtextbefore;
133     }
134     else {
135         $blocres .= $isbdfield;
136     }
137 }
138 $res .= $blocres;
139
140 # }
141 $res =~ s/\{(.*?)\}//g;
142 $res =~ s/\\n/\n/g;
143 $res =~ s/\n/<br\/>/g;
144
145 # remove empty ()
146 $res =~ s/\(\)//g;
147 # count of item linked with biblio
148 my $itemcount = GetItemsCount($biblionumber);
149 $template->param( count => $itemcount);
150 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
151  
152 if ($subscriptionsnumber) {
153     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
154     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
155     $template->param(
156         subscriptionsnumber => $subscriptionsnumber,
157         subscriptiontitle   => $subscriptiontitle,
158     );
159 }
160
161 $template->param (
162     ISBD                => $res,
163     biblionumber        => $biblionumber,
164         isbdview => 1,
165 );
166
167 output_html_with_http_headers $query, $cookie, $template->output;
168