Bug 2818 - Allow patron editing to coexist with minPasswordLength and '****'.
[koha.git] / opac / opac-MARCdetail.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 MARCdetail.pl : script to show a biblio in MARC format
23
24 =head1 SYNOPSIS
25
26
27 =head1 DESCRIPTION
28
29 This script needs a biblionumber as  parameter
30
31 It shows the biblio in a (nice) MARC format depending on MARC
32 parameters tables.
33
34 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
35 this template must be divided into 11 "tabs".
36
37 The first 10 tabs present the biblio, the 11th one presents
38 the items attached to the biblio
39
40 =cut
41
42 use strict;
43 use C4::Auth;
44 use C4::Context;
45 use C4::Output;
46 use CGI;
47 use MARC::Record;
48 use C4::Biblio;
49 use C4::Acquisition;
50 use C4::Koha;
51
52 my $query = new CGI;
53
54 my $dbh = C4::Context->dbh;
55
56 my $biblionumber = $query->param('biblionumber');
57 my $itemtype     = &GetFrameworkCode($biblionumber);
58 my $tagslib      = &GetMarcStructure( 0, $itemtype );
59 my $biblio = GetBiblioData($biblionumber);
60 my $record = GetMarcBiblio($biblionumber);
61
62 # open template
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64     {
65         template_name   => "opac-MARCdetail.tmpl",
66         query           => $query,
67         type            => "opac",
68         authnotrequired => 1,
69         debug           => 1,
70     }
71 );
72
73 $template->param(
74     bibliotitle => $biblio->{title},
75 );
76
77 # adding the $RequestOnOpac param
78 my $RequestOnOpac;
79 if (C4::Context->preference("RequestOnOpac")) {
80         $RequestOnOpac = 1;
81 }
82
83 # fill arrays
84 my @loop_data = ();
85 my $tag;
86
87 # loop through each tab 0 through 9
88 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
89
90     # loop through each tag
91     my @loop_data = ();
92     my @subfields_data;
93
94     # deal with leader
95     unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
96         or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
97     {
98         my %subfield_data;
99         $subfield_data{marc_lib}      = $tagslib->{'000'}->{'@'}->{lib};
100         $subfield_data{marc_value}    = $record->leader();
101         $subfield_data{marc_subfield} = '@';
102         $subfield_data{marc_tag}      = '000';
103         push( @subfields_data, \%subfield_data );
104         my %tag_data;
105         $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
106         my @tmp = @subfields_data;
107         $tag_data{subfield} = \@tmp;
108         push( @loop_data, \%tag_data );
109         undef @subfields_data;
110     }
111     my @fields = $record->fields();
112     for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
113
114         # if tag <10, there's no subfield, use the "@" trick
115         if ( $fields[$x_i]->tag() < 10 ) {
116             next
117               if (
118                 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
119             next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
120             my %subfield_data;
121             $subfield_data{marc_lib} =
122               $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
123             $subfield_data{marc_value}    = $fields[$x_i]->data();
124             $subfield_data{marc_subfield} = '@';
125             $subfield_data{marc_tag}      = $fields[$x_i]->tag();
126             push( @subfields_data, \%subfield_data );
127         }
128         else {
129             my @subf = $fields[$x_i]->subfields;
130
131             # loop through each subfield
132             for my $i ( 0 .. $#subf ) {
133                 $subf[$i][0] = "@" unless $subf[$i][0];
134                 next
135                   if (
136                     $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
137                     ne $tabloop );
138                 next
139                   if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{hidden} > 0 ); 
140                 my %subfield_data;
141                 $subfield_data{marc_lib} =
142                   $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
143                 $subfield_data{link} =
144                   $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
145                 $subf[$i][1] =~ s/\n/<br\/>/g;
146                 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
147                     ->{isurl} )
148                 {
149                     $subfield_data{marc_value} =
150                       "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
151                 }
152                 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
153                     ->{kohafield} eq "biblioitems.isbn" )
154                 {
155
156 #                    warn " tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}. "ISBN : ".$subf[$i][1]."PosttraitementISBN :".DisplayISBN($subf[$i][1]);
157                     $subfield_data{marc_value} = $subf[$i][1];
158                 }
159                 else {
160                     if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
161                         ->{authtypecode} )
162                     {
163                         $subfield_data{authority} = $fields[$x_i]->subfield(9);
164                     }
165                     $subfield_data{marc_value} =
166                       GetAuthorisedValueDesc( $fields[$x_i]->tag(),
167                         $subf[$i][0], $subf[$i][1], '', $tagslib );
168                 }
169                 $subfield_data{marc_subfield} = $subf[$i][0];
170                 $subfield_data{marc_tag}      = $fields[$x_i]->tag();
171                 push( @subfields_data, \%subfield_data );
172             }
173         }
174         if ( $#subfields_data >= 0 ) {
175             my %tag_data;
176             if (   ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
177                 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
178               )
179             {
180                 $tag_data{tag} = "";
181             }
182             else {
183                 if ( C4::Context->preference('hide_marc') ) {
184                     $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
185                 }
186                 else {
187                     $tag_data{tag} =
188                         $fields[$x_i]->tag() 
189                       . ' '
190                       . C4::Koha::display_marc_indicators($fields[$x_i])
191                       . ' - '
192                       . $tagslib->{ $fields[$x_i]->tag() }->{lib};
193                 }
194             }
195             my @tmp = @subfields_data;
196             $tag_data{subfield} = \@tmp;
197             push( @loop_data, \%tag_data );
198             undef @subfields_data;
199         }
200     }
201     $template->param( $tabloop . "XX" => \@loop_data );
202 }
203
204
205 # now, build item tab !
206 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
207 # loop through each tag
208 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
209 # then construct template.
210 my @fields = $record->fields();
211 my %witness
212   ; #---- stores the list of subfields used at least once, with the "meaning" of the code
213 my @big_array;
214 foreach my $field (@fields) {
215     next if ( $field->tag() < 10 );
216     my @subf = $field->subfields;
217     my %this_row;
218
219     # loop through each subfield
220     for my $i ( 0 .. $#subf ) {
221         next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
222                 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} > 0 );
223         $witness{ $subf[$i][0] } =
224           $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
225
226         if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) {
227             $this_row{ $subf[$i][0] } =
228               "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
229         }
230         elsif ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq
231             "biblioitems.isbn" )
232         {
233             $this_row{ $subf[$i][0] } = $subf[$i][1];
234         }
235         else {
236             $this_row{ $subf[$i][0] } =
237               GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
238                 $subf[$i][1], '', $tagslib );
239         }
240     }
241     if (%this_row) {
242         push( @big_array, \%this_row );
243     }
244 }
245 my ( $holdingbrtagf, $holdingbrtagsubf ) =
246   &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
247 @big_array =
248   sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
249
250 #fill big_row with missing datas
251 foreach my $subfield_code ( keys(%witness) ) {
252     for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
253         $big_array[$i]{$subfield_code} = "&nbsp;"
254           unless ( $big_array[$i]{$subfield_code} );
255     }
256 }
257
258 # now, construct template !
259 my @item_value_loop;
260 my @header_value_loop;
261 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
262     my $items_data;
263     foreach my $subfield_code ( keys(%witness) ) {
264         $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
265     }
266     my %row_data;
267     $row_data{item_value} = $items_data;
268     push( @item_value_loop, \%row_data );
269 }
270
271 foreach my $subfield_code ( keys(%witness) ) {
272     my %header_value;
273     $header_value{header_value} = $witness{$subfield_code};
274     push( @header_value_loop, \%header_value );
275 }
276
277 if(C4::Context->preference("ISBD")) {
278         $template->param(ISBD => 1);
279 }
280
281 $template->param(
282     item_loop        => \@item_value_loop,
283     item_header_loop => \@header_value_loop,
284     biblionumber     => $biblionumber,
285 );
286
287 output_html_with_http_headers $query, $cookie, $template->output;