Bugfixing interface issues. Also enabling contextual menu highlighting for catalogue...
[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::Branch;     # GetBranchDetail
46 use C4::Serials;    # CountSubscriptionFromBiblionumber
47
48
49 #---- Internal function
50
51
52 my $query = new CGI;
53 my $dbh = C4::Context->dbh;
54
55 my $biblionumber = $query->param('biblionumber');
56 my $itemtype     = &GetFrameworkCode($biblionumber);
57 my $tagslib      = &GetMarcStructure( 1, $itemtype );
58
59 my $record = GetMarcBiblio($biblionumber);
60
61 # open template
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63     {
64         template_name => "catalogue/ISBDdetail.tmpl",
65         query         => $query,
66         type          => "intranet",
67         authnotrequired => 0,
68         flagsrequired   => { catalogue => 1 },
69     }
70 );
71
72 my $ISBD = C4::Context->preference('ISBD');
73
74 # my @blocs = split /\@/,$ISBD;
75 # my @fields = $record->fields();
76 my $res;
77
78 # foreach my $bloc (@blocs) {
79 #     $bloc =~ s/\n//g;
80 my $bloc = $ISBD;
81 my $blocres;
82
83 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
84 # @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
85
86 foreach my $isbdfield ( split /#/, $bloc ) {
87
88     #         $isbdfield= /(.?.?.?)/;
89     $isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
90     my $fieldvalue    = $1;
91     my $textbefore    = $2;
92     my $analysestring = $3;
93     my $textafter     = $4;
94
95     #         warn "==> $1 / $2 / $3 / $4";
96     #         my $fieldvalue=substr($isbdfield,0,3);
97     if ( $fieldvalue > 0 ) {
98
99    #         warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
100    #             warn "FV : $fieldvalue";
101         my $hasputtextbefore = 0;
102         my @fieldslist = $record->field($fieldvalue);
103         @fieldslist= sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
104         foreach my $field ( @fieldslist ) {
105             my $calculated = $analysestring;
106             my $tag        = $field->tag();
107             if ( $tag < 10 ) {
108             }
109             else {
110                 my @subf = $field->subfields;
111                 for my $i ( 0 .. $#subf ) {
112                     my $subfieldcode  = $subf[$i][0];
113                     my $subfieldvalue =
114                       GetAuthorisedValueDesc( $tag, $subf[$i][0],
115                         $subf[$i][1], $itemtype,$tagslib);
116                     my $tagsubf = $tag . $subfieldcode;
117                     $calculated =~s/\{(.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
118                 }
119                 # field builded, store the result
120                 if ( $calculated && !$hasputtextbefore )
121                 {    # put textbefore if not done
122                     $blocres .= $textbefore;
123                     $hasputtextbefore = 1;
124                 }
125
126                 # remove punctuation at start
127                 $calculated =~ s/^( |;|:|\.|-)*//g;
128                 $blocres .= $calculated;
129             }
130         }
131         $blocres .= $textafter if $hasputtextbefore;
132     }
133     else {
134         $blocres .= $isbdfield;
135     }
136 }
137 $res .= $blocres;
138
139 # }
140 $res =~ s/\{(.*?)\}//g;
141 $res =~ s/\\n/\n/g;
142 $res =~ s/\n/<br\/>/g;
143
144 # remove empty ()
145 $res =~ s/\(\)//g;
146 # count of item linked with biblio
147 my $itemcount = GetItemsCount($biblionumber);
148 $template->param( count => $itemcount);
149 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
150  
151 if ($subscriptionsnumber) {
152     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
153     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
154     $template->param(
155         subscriptionsnumber => $subscriptionsnumber,
156         subscriptiontitle   => $subscriptiontitle,
157     );
158 }
159
160 $template->param (
161     ISBD                => $res,
162     biblionumber        => $biblionumber,
163         isbdview => 1,
164 );
165
166 output_html_with_http_headers $query, $cookie, $template->output;
167