Bug 30941: (QA follow-up) Add exec flag to scripts
[srvgit] / cataloguing / value_builder / unimarc_field_146e.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Scalar::Util;
21
22 use C4::Auth qw( get_template_and_user );
23 use C4::Output qw( output_html_with_http_headers );
24
25 use Koha::I18N;
26 use Koha::CodeList::Unimarc::MediumOfPerformance;
27
28 my $builder = sub {
29     my $params = shift;
30     my $id = $params->{id};
31
32     return qq|
33 <script>
34 function Click$id (event) {
35     event.preventDefault();
36     const value = document.getElementById(event.data.id).value;
37     const url = new URL('/cgi-bin/koha/cataloguing/plugin_launcher.pl', location);
38     url.searchParams.set('plugin_name', 'unimarc_field_146e.pl');
39     url.searchParams.set('id', event.data.id);
40     url.searchParams.set('value', value);
41     window.open(url.toString(), 'tag_editor', 'width=700,height=700,toolbar=false,scrollbars=yes');
42 }
43 </script>|;
44 };
45
46 my $launcher = sub {
47     my $params = shift;
48     my $cgi = $params->{cgi};
49     my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
50         template_name => "cataloguing/value_builder/unimarc_field_146e.tt",
51         query => $cgi,
52         type => 'intranet',
53         flagsrequired => { editcatalogue => '*' },
54     });
55
56     my @category_optgroups = (
57         { label => __('Voices'), values => Koha::CodeList::Unimarc::MediumOfPerformance->voices() },
58         { label => __('Woodwinds'), values => Koha::CodeList::Unimarc::MediumOfPerformance->woodwinds() },
59         { label => __('Brass instruments'), values => Koha::CodeList::Unimarc::MediumOfPerformance->brass() },
60         { label => __('Strings, bowed'), values => Koha::CodeList::Unimarc::MediumOfPerformance->strings_bowed() },
61         { label => __('Strings, plucked'), values => Koha::CodeList::Unimarc::MediumOfPerformance->strings_plucked() },
62         { label => __('Keyboard'), values => Koha::CodeList::Unimarc::MediumOfPerformance->keyboard() },
63         { label => __('Percussion'), values => Koha::CodeList::Unimarc::MediumOfPerformance->percussion() },
64         { label => __('Electric / electronic instruments and devices'), values => Koha::CodeList::Unimarc::MediumOfPerformance->electronic() },
65         { label => __('Miscellaneous, other, unspecified instruments'), values => Koha::CodeList::Unimarc::MediumOfPerformance->misc() },
66         { label => __('Conductors'), values => Koha::CodeList::Unimarc::MediumOfPerformance->conductors() },
67         { label => __('Other performers'), values => Koha::CodeList::Unimarc::MediumOfPerformance->other_performers() },
68     );
69
70     foreach my $optgroup (@category_optgroups) {
71         my $values = delete $optgroup->{values};
72         $optgroup->{options} = [
73             map {
74                 { value => $_, label => __( $values->{$_} ) }
75             } sort keys %$values
76         ];
77     }
78
79     my $tessitura_hash = Koha::CodeList::Unimarc::MediumOfPerformance->tessitura();
80     my @tessitura_options = map {
81         { value => $_, label => __p('tessitura', $tessitura_hash->{$_}) }
82     } sort keys %$tessitura_hash;
83
84     my $number_of_hands_or_keys_hash = Koha::CodeList::Unimarc::MediumOfPerformance->number_of_hands_or_keys();
85     my @number_of_hands_or_keys_options = map {
86         { value => $_, label => __p('music', $number_of_hands_or_keys_hash->{$_}) }
87     } sort keys %$number_of_hands_or_keys_hash;
88
89     my $other_hash = Koha::CodeList::Unimarc::MediumOfPerformance->other();
90     my @other_options = map {
91         { value => $_, label => __($other_hash->{$_}) }
92     } sort keys %$other_hash;
93
94     my $other2_hash = Koha::CodeList::Unimarc::MediumOfPerformance->other2();
95     my @other2_options = map {
96         { value => $_, label => __($other2_hash->{$_}) }
97     } sort keys %$other2_hash;
98
99     my $value = $cgi->param('value');
100     my $number = substr($value, 0, 2);
101     unless (Scalar::Util::looks_like_number($number)) {
102         $number = '';
103     }
104     my $category = substr($value, 2, 3);
105     my $tessitura = substr($value, 5, 1);
106     my $number_of_hands_or_keys = substr($value, 6, 1);
107     my $other = substr($value, 7, 1);
108     my $other2 = substr($value, 8, 1);
109
110     $template->param(
111         id => scalar $cgi->param('id'),
112         number => $number,
113         category => $category,
114         tessitura => $tessitura,
115         number_of_hands_or_keys => $number_of_hands_or_keys,
116         other => $other,
117         other2 => $other2,
118         category_optgroups => \@category_optgroups,
119         tessitura_options => \@tessitura_options,
120         number_of_hands_or_keys_options => \@number_of_hands_or_keys_options,
121         other_options => \@other_options,
122         other2_options => \@other2_options,
123     );
124     output_html_with_http_headers $cgi, $cookie, $template->output;
125 };
126
127 return { builder => $builder, launcher => $launcher };