Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2019 KohaSuomi oy |
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 |
|
22 |
use C4::Context; |
23 |
use C4::Languages; |
24 |
|
25 |
my $builder = sub { |
26 |
my ( $params ) = @_; |
27 |
my $function_name = $params->{id}; |
28 |
|
29 |
my $js = <<END_OF_JS; |
30 |
<script type="text/javascript"> |
31 |
//<![CDATA[ |
32 |
|
33 |
function CheckISBN$function_name(str) { |
34 |
var sum, |
35 |
weight, |
36 |
digit, |
37 |
check, |
38 |
i; |
39 |
str = str.replace(/[^0-9X]/gi, ''); |
40 |
if (str.length != 10 && str.length != 13) { |
41 |
return false; |
42 |
} |
43 |
|
44 |
if (str.length == 13) { |
45 |
sum = 0; |
46 |
for (i = 0; i < 12; i++) { |
47 |
digit = parseInt(str[i]); |
48 |
if (i % 2 == 1) { |
49 |
sum += 3*digit; |
50 |
} else { |
51 |
sum += digit; |
52 |
} |
53 |
} |
54 |
check = (10 - (sum % 10)) % 10; |
55 |
return (check == str[str.length-1]); |
56 |
} |
57 |
|
58 |
if (str.length == 10) { |
59 |
weight = 10; |
60 |
sum = 0; |
61 |
for (i = 0; i < 9; i++) { |
62 |
digit = parseInt(str[i]); |
63 |
sum += weight*digit; |
64 |
weight--; |
65 |
} |
66 |
check = 11 - (sum % 11); |
67 |
if (check == 10) { |
68 |
check = 'X'; |
69 |
} |
70 |
return (check == str[str.length-1].toUpperCase()); |
71 |
} |
72 |
} |
73 |
|
74 |
function Blur$function_name(id) { |
75 |
var v = \$('#' + id).val(); |
76 |
\$('#' + id).val(v.trim()); |
77 |
return false; |
78 |
} |
79 |
|
80 |
function SaveCheck$function_name(id) { |
81 |
var v = \$('#' + id).val(); |
82 |
if (v && v != '') { |
83 |
if (!CheckISBN$function_name(v)) { |
84 |
return { funcname: id, msg: _("Illegal ISBN") }; |
85 |
} |
86 |
} |
87 |
return undefined; |
88 |
} |
89 |
|
90 |
//]]> |
91 |
</script> |
92 |
END_OF_JS |
93 |
return $js; |
94 |
}; |
95 |
|
96 |
return { builder => $builder }; |