3 # $Id: barcode.pl,v 1.1.2.2 2006/09/20 02:24:42 kados Exp $
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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #use warnings; FIXME - Bug 2505
30 plugin_parameters : other parameters added when the plugin is called by the dopop function
33 sub plugin_parameters
{
34 # my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
40 plugin_javascript : the javascript function called when the user enters the subfield.
41 contain 3 javascript functions :
42 * one called when the field is entered (OnFocus). Named FocusXXX
43 * one called when the field is leaved (onBlur). Named BlurXXX
44 * one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX
48 * a variable containing the 3 scripts.
49 the 3 scripts are inserted after the <input> in the html code
52 sub plugin_javascript
{
53 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
54 my $function_name= "barcode".(int(rand(100000))+1);
57 my ($year, $mon, $day) = split('-', C4
::Dates
->today('iso'));
58 my ($tag,$subfield) = GetMarcFromKohaField
("items.barcode", '');
59 my ($loctag,$locsubfield) = GetMarcFromKohaField
("items.homebranch", '');
64 my $autoBarcodeType = C4
::Context
->preference("autoBarcode");
65 warn "Barcode type = $autoBarcodeType" if $DEBUG;
66 if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
67 # don't return a value unless we have the appropriate syspref set
68 return ($function_name,
69 "<script type=\"text/javascript\">
70 // autoBarcodeType OFF (or not defined)
71 function Focus$function_name() { return 0;}
72 function Clic$function_name() { return 0;}
73 function Blur$function_name() { return 0;}
76 if ($autoBarcodeType eq 'annual') {
77 $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
78 my $sth=$dbh->prepare($query);
79 $sth->execute("$year%");
80 while (my ($count)= $sth->fetchrow_array) {
81 warn "Examining Record: $count" if $DEBUG;
82 $nextnum = $count if $count;
85 $nextnum = sprintf("%0*d", "4",$nextnum);
86 $nextnum = "$year-$nextnum";
88 elsif ($autoBarcodeType eq 'incremental') {
89 # not the best, two catalogers could add the same barcode easily this way :/
90 $query = "select max(abs(barcode)) from items";
91 my $sth = $dbh->prepare($query);
93 while (my ($count)= $sth->fetchrow_array) {
98 elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit
99 $year = substr($year, -2);
100 $query = "SELECT MAX(CAST(SUBSTRING(barcode,7,4) AS signed)) FROM items WHERE barcode REGEXP ?";
101 my $sth = $dbh->prepare($query);
102 $sth->execute("^[a-zA-Z]{1,}$year");
103 while (my ($count)= $sth->fetchrow_array) {
104 $nextnum = $count if $count;
105 warn "Existing incremental number = $nextnum" if $DEBUG;
108 $nextnum = sprintf("%0*d", "4",$nextnum);
109 $nextnum = $year . $mon . $nextnum;
110 warn "New hbyymmincr Barcode = $nextnum" if $DEBUG;
112 for (i=0 ; i<document.f.field_value.length ; i++) {
113 if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') {
117 if (\$('#' + id).val() == '' || force) {
118 \$('#' + id).val(document.f.field_value[fnum].value + '$nextnum');
123 # default js body (if not filled by hbyymmincr)
124 $scr or $scr = <<END_OF_JS;
125 if (\$('#' + id).val() == '' || force) {
126 \$('#' + id).val('$nextnum');
130 my $js = <<END_OF_JS
;
131 <script type
="text/javascript">
134 function Blur
$function_name(index) {
135 //barcode validation might go here
138 function Focus
$function_name(subfield_managed
, id
, force
) {
143 function Clic
$function_name(id
) {
144 return Focus
$function_name('not_relavent', id
, 1);
149 return ($function_name, $js);