3 # Converted to new plugin style (Bug 13437)
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 use C4::Auth qw ( get_template_and_user );
27 use C4::Output qw ( output_html_with_http_headers );
34 jQuery(document).ready(function () {
35 const input = document.getElementById('$params->{id}');
36 const isbn_input = jQuery('input[id^="tag_010_subfield_a_"]');
37 const issn_input = jQuery('input[id^="tag_011_subfield_a_"]');
38 const ean_input = jQuery('input[id^="tag_073_subfield_a_"]');
40 isbn_input.on('change', function () {
41 update_ppn('isbn', this.value);
43 issn_input.on('change', function () {
44 update_ppn('issn', this.value);
46 ean_input.on('change', function () {
47 update_ppn('ean', this.value);
50 jQuery(input).on('focus', function () {
51 const isbn = isbn_input.val().trim();
52 const issn = issn_input.val().trim();
53 const ean = ean_input.val().trim();
55 update_ppn('isbn', isbn);
56 } else if (issn !== '') {
57 update_ppn('issn', issn);
58 } else if (ean !== '') {
59 update_ppn('ean', ean);
63 function update_ppn(search_type, search_text) {
64 if (input.value.trim() === '') {
65 get_ppn(search_type, search_text).then(function (ppn) {
71 function get_ppn(search_type, search_text) {
72 const url = '/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_009_ppn.pl&' + search_type + '=' + encodeURIComponent(search_text);
74 return jQuery.get(url);
84 my $input = $params->{cgi};
85 my $isbn = $input->param('isbn');
86 my $issn = $input->param('issn');
87 my $ean = $input->param('ean');
89 my ($template, $loggedinuser, $cookie) = get_template_and_user({
90 template_name => "cataloguing/value_builder/ajax.tt",
93 flagsrequired => {editcatalogue => '*'},
98 $url = "https://www.sudoc.fr/services/isbn2ppn/$isbn&format=text/json";
100 $url = "https://www.sudoc.fr/services/issn2ppn/$issn&format=text/json";
102 $url = "https://www.sudoc.fr/services/ean2ppn/$ean&format=text/json";
106 my $json = LWP::Simple::get($url);
108 my $response = JSON->new->utf8->decode($json);
109 my $result = $response->{sudoc}->{query}->{result};
110 my $ppn = ref $result eq 'ARRAY' ? $result->[0]->{ppn} : $result->{ppn};
111 $template->param( return => $ppn );
115 output_html_with_http_headers $input, $cookie, $template->output;
118 return { builder => $builder, launcher => $launcher };