Bug 29788: Fix batch delete item
[koha.git] / authorities / blinddetail-biblio-search.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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 =head1 NAME
21
22 blinddetail-biblio-search.pl : script to show an authority in MARC format
23
24 =head1 SYNOPSIS
25
26 =cut
27
28 =head1 DESCRIPTION
29
30 This script needs an authid
31
32 It shows the authority in a (nice) MARC format depending on authority MARC
33 parameters tables.
34
35 =head1 FUNCTIONS
36
37 =cut
38
39 use Modern::Perl;
40
41 use C4::Auth qw( get_template_and_user );
42 use C4::AuthoritiesMarc qw( GetAuthority );
43 use C4::Context;
44 use C4::Output qw( output_html_with_http_headers );
45 use CGI qw ( -utf8 );
46
47 use Koha::Authorities;
48 use Koha::Authority::Types;
49
50 my $query = CGI->new;
51
52 my $dbh = C4::Context->dbh;
53
54 my $authid       = $query->param('authid');
55 my $index        = $query->param('index');
56 my $tagid        = $query->param('tagid');
57 my $relationship = $query->param('relationship');
58
59 # open template
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61     {
62         template_name   => "authorities/blinddetail-biblio-search.tt",
63         query           => $query,
64         type            => "intranet",
65         flagsrequired   => { editcatalogue => 'edit_catalogue' },
66     }
67 );
68
69 # Extract the tag number from the index
70 my $tag_number = $index;
71 $tag_number =~ s/^tag_(\d*)_.*$/$1/;
72
73 # fill arrays
74 my @subfield_loop;
75 my ($indicator1, $indicator2);
76 if ($authid) {
77     my $auth = Koha::Authorities->find( $authid );
78     my $authtypecode = $auth ? $auth->authtypecode : q{};
79     my $auth_type = Koha::Authority::Types->find($authtypecode);
80     my $record = GetAuthority($authid);
81     my @fields = $record->field( $auth_type->auth_tag_to_report );
82     my $repet = ($query->param('repet') || 1) - 1;
83     my $field = $fields[$repet];
84
85     # Get all values for each distinct subfield and add to subfield loop
86     my %done_subfields;
87     for ( $field->subfields ) {
88         next if $_->[0] eq '9'; # $9 will be set with authid value
89         my $letter = $_->[0];
90         $letter ||= '@';
91         next if defined $done_subfields{$letter};
92         my @values = $field->subfield($letter);
93         push @subfield_loop, {marc_subfield => $letter, marc_values => \@values };
94         $done_subfields{$letter} = 1;
95     }
96
97     push( @subfield_loop, { marc_subfield => 'w', marc_values => $relationship } ) if ( $relationship );
98
99     my $controlled_ind = $auth->controlled_indicators({ record => $record, biblio_tag => $tag_number });
100     $indicator1 = $controlled_ind->{ind1};
101     $indicator2 = $controlled_ind->{ind2};
102     if( defined $controlled_ind->{sub2} ) {
103         my $v = $controlled_ind->{sub2};
104         push @subfield_loop, { marc_subfield => '2', marc_values => [ $v ] };
105     }
106 } else {
107     # authid is empty => the user want to empty the entry.
108     $template->param( "clear" => 1 );
109 }
110
111
112
113 $template->param(
114     authid          => $authid ? $authid : "",
115     index           => $index,
116     tagid           => $tagid,
117     update_ind1     => defined($indicator1),
118     indicator1      => $indicator1,
119     update_ind2     => defined($indicator2),
120     indicator2      => $indicator2,
121     SUBFIELD_LOOP   => \@subfield_loop,
122     tag_number      => $tag_number,
123     rancor          => $index =~ /rancor$/,
124 );
125
126
127 output_html_with_http_headers $query, $cookie, $template->output;