View | Details | Raw Unified | Return to bug 29980
Collapse All | Expand All

(-)a/cataloguing/value_builder/validate_isbn.pl (-1 / +69 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2025 BibLibre SARL
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
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
23
use C4::Auth       qw( get_template_and_user );
24
use C4::Output     qw( output_html_with_http_headers );
25
use Business::ISBN qw( valid_isbn_checksum );
26
27
my $builder = sub {
28
    my $params = shift;
29
    my $id     = $params->{id};
30
31
    return qq|
32
<script>
33
function Blur$id(event) {
34
    field = \$('#'+event.data.id);
35
    isbn = field.val();
36
    var url = '../cataloguing/plugin_launcher.pl?plugin_name=validate_isbn.pl&isbn=' + isbn;
37
    var req = \$.get(url);
38
    req.done(function(resp){
39
        if ( resp != 1 ) {
40
           field.addClass("subfield_not_filled");
41
           alert("Invalid ISBN : " + isbn);
42
           return;
43
        }
44
        field.removeClass("subfield_not_filled");
45
        alert("Valid ISBN : " + isbn);
46
    });
47
}
48
</script>|;
49
};
50
51
my $launcher = sub {
52
    my $params = shift;
53
    my $cgi    = $params->{cgi};
54
    my $isbn   = $cgi->param('isbn');
55
56
    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
57
        {
58
            template_name => "cataloguing/value_builder/ajax.tt",
59
            query         => $cgi,
60
            type          => "intranet",
61
            flagsrequired => { editcatalogue => '*' },
62
        }
63
    );
64
    my $is_valid = valid_isbn_checksum($isbn);
65
    $template->param( return => $is_valid );
66
    output_html_with_http_headers $cgi, $cookie, $template->output;
67
};
68
69
return { builder => $builder, launcher => $launcher };

Return to bug 29980