3 # This file is part of Koha.
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.
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.
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>.
22 use C4::Auth qw( get_template_and_user );
23 use C4::Output qw( output_html_with_http_headers );
26 use Koha::CodeList::Unimarc::MediumOfPerformance;
30 my $id = $params->{id};
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_146d.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');
48 my $cgi = $params->{cgi};
49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
50 template_name => "cataloguing/value_builder/unimarc_field_146d.tt",
53 flagsrequired => { editcatalogue => '*' },
56 my @category_optgroups = (
57 { label => __('Choruses'), values => Koha::CodeList::Unimarc::MediumOfPerformance->choruses() },
58 { label => __('Orchestras, ensembles'), values => Koha::CodeList::Unimarc::MediumOfPerformance->orchestras() },
61 foreach my $optgroup (@category_optgroups) {
62 my $values = delete $optgroup->{values};
63 $optgroup->{options} = [
65 { value => $_, label => __( $values->{$_} ) }
70 my $other_hash = Koha::CodeList::Unimarc::MediumOfPerformance->other();
71 my @other_options = map {
72 { value => $_, label => __($other_hash->{$_}) }
73 } sort keys %$other_hash;
75 my $other2_hash = Koha::CodeList::Unimarc::MediumOfPerformance->other2();
76 my @other2_options = map {
77 { value => $_, label => __($other2_hash->{$_}) }
78 } sort keys %$other2_hash;
80 my $value = $cgi->param('value');
81 my $number = substr($value, 0, 2);
82 unless (Scalar::Util::looks_like_number($number)) {
85 my $category = substr($value, 2, 3);
86 my $number_of_real_parts = substr($value, 5, 2);
87 unless (Scalar::Util::looks_like_number($number_of_real_parts)) {
88 $number_of_real_parts = '';
90 my $other = substr($value, 7, 1);
91 my $other2 = substr($value, 8, 1);
94 id => scalar $cgi->param('id'),
96 category => $category,
97 number_of_real_parts => $number_of_real_parts,
100 category_optgroups => \@category_optgroups,
101 other_options => \@other_options,
102 other2_options => \@other2_options,
104 output_html_with_http_headers $cgi, $cookie, $template->output;
107 return { builder => $builder, launcher => $launcher };