Bug 17117: Patron personal details not displayed unless branch update request is...
[koha.git] / cataloguing / value_builder / barcode_manual.pl
1 #!/usr/bin/perl
2 # Copyright 2000-2002 Katipo Communications
3 # Parts copyright 2008-2010 Foundations Bible College
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 strict;
21 use warnings;
22 no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings
23
24 use C4::Context;
25 require C4::Barcodes::ValueBuilder;
26 use Koha::DateUtils;
27
28 my $DEBUG = 0;
29
30 sub plugin_javascript {
31     my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
32     my $function_name= "barcode".(int(rand(100000))+1);
33     my %args;
34
35     $args{dbh} = $dbh;
36
37 # find today's date
38     ($args{year}, $args{mon}, $args{day}) = split('-', output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }));
39     ($args{tag},$args{subfield})       =  GetMarcFromKohaField("items.barcode", '');
40     ($args{loctag},$args{locsubfield}) =  GetMarcFromKohaField("items.homebranch", '');
41
42     my $nextnum;
43     my $scr;
44     my $autoBarcodeType = C4::Context->preference("autoBarcode");
45     warn "Barcode type = $autoBarcodeType" if $DEBUG;
46     if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
47 # don't return a value unless we have the appropriate syspref set
48         return ($function_name,
49                 "<script type=\"text/javascript\">
50                 // autoBarcodeType OFF (or not defined)
51                 function Focus$function_name() { return 0;}
52                 function  Clic$function_name() { return 0;}
53                 function  Blur$function_name() { return 0;}
54                 </script>");
55     }
56     if ($autoBarcodeType eq 'annual') {
57         ($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args);
58     }
59     elsif ($autoBarcodeType eq 'incremental') {
60         ($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args);
61     }
62     elsif ($autoBarcodeType eq 'hbyymmincr') {      # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit
63         ($nextnum, $scr) = C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode(\%args);
64     }
65
66 # default js body (if not filled by hbyymmincr)
67     $scr or $scr = <<END_OF_JS;
68     if (\$('#' + id).val() == '') {
69         \$('#' + id).val('$nextnum');
70     }
71 END_OF_JS
72
73         my $js  = <<END_OF_JS;
74     <script type="text/javascript">
75         //<![CDATA[
76
77     function Clic$function_name(id) {
78         $scr
79             return 0;
80     }
81     //]]>
82     </script>
83 END_OF_JS
84         return ($function_name, $js);
85 }