Bug 13200 - Followup of Bug 12246 - noisy C4/Auth.pm
[koha.git] / cataloguing / value_builder / unimarc_field_010.pl
blob1675e53b89a687ff44d118147e986e75c59a156b
1 #!/usr/bin/perl
4 # Copyright 2008 Biblibre SARL
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 use warnings;
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
28 =head1 FUNCTIONS
30 =head2 plugin_parameters
32 other parameters added when the plugin is called by the dopop function
34 =cut
36 sub plugin_parameters {
37 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
38 return "";
41 sub plugin_javascript {
42 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
43 my $res="
44 <script type='text/javascript'>
45 function Focus$field_number() {
46 return 1;
49 function Blur$field_number() {
50 var isbn = document.getElementById('$field_number');
51 var url = '../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_010.pl&isbn=' + isbn.value;
52 var req = \$.get(url);
53 req.done(function(resp){
54 var elems = document.getElementsByTagName('input');
55 for( i = 0 ; elems[i] ; i++ )
57 if(elems[i].id.match(/^tag_210_subfield_c/)) {
58 elems[i].value = resp;
59 return 1;
62 });
63 return 1;
66 function Clic$field_number() {
67 return 1;
69 </script>
72 return ($field_number,$res);
75 sub plugin {
76 my ($input) = @_;
77 my $isbn = $input->param('isbn');
79 my ($template, $loggedinuser, $cookie)
80 = get_template_and_user({template_name => "cataloguing/value_builder/ajax.tt",
81 query => $input,
82 type => "intranet",
83 authnotrequired => 0,
84 flagsrequired => {editcatalogue => '*'},
85 debug => 1,
86 });
89 my $dbh = C4::Context->dbh;
90 my $len = 0;
91 my $sth = $dbh->prepare('SELECT publishercode FROM biblioitems WHERE REPLACE(isbn, "-", "") LIKE ? OR isbn LIKE ? LIMIT 1');
93 $isbn =~ s/-//g;
94 if (length ($isbn) == 13){
95 $isbn = substr($isbn, 3, length($isbn)-3);
98 if(length($isbn) <= 10){
100 $len = 5;
101 if ( substr( $isbn, 0, 1 ) <= 7 ){
102 $len = 1;
103 }elsif ( substr( $isbn, 0, 2 ) <= 94 ){
104 $len = 2;
105 }elsif ( substr( $isbn, 0, 3 ) <= 995 ){
106 $len = 3;
107 }elsif ( substr( $isbn, 0, 4 ) <= 9989 ){
108 $len = 4 ;
111 my $x = substr( $isbn, $len );
112 my $seg2 = "";
114 if ( substr( $x, 0, 2 ) <= 19 ) {
115 $seg2 = substr( $x, 0, 2 );
117 elsif ( substr( $x, 0, 3 ) <= 699 ) {
118 $seg2 = substr( $x, 0, 3 );
120 elsif ( substr( $x, 0, 4 ) <= 8399 ) {
121 $seg2 = substr( $x, 0, 4 );
123 elsif ( substr( $x, 0, 5 ) <= 89999 ) {
124 $seg2 = substr( $x, 0, 5 );
126 elsif ( substr( $x, 0, 6 ) <= 9499999 ) {
127 $seg2 = substr( $x, 0, 6 );
129 else {
130 $seg2 = substr( $x, 0, 7 );
133 while($len--){
134 $seg2 = "_".$seg2;
137 $len = 10 -length($seg2);
139 while($len--){
140 $seg2 .= "_";
143 $sth->execute($seg2, "978$seg2");
146 if( (my $publishercode) = $sth->fetchrow )
148 $template->param(return => $publishercode);
150 output_html_with_http_headers $input, $cookie, $template->output;