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 with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
29 plugin_parameters : other parameters added when the plugin is called by the dopop function
32 sub plugin_parameters {
33 # my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
39 plugin_javascript : the javascript function called when the user enters the subfield.
40 contain 3 javascript functions :
41 * one called when the field is entered (OnFocus). Named FocusXXX
42 * one called when the field is leaved (onBlur). Named BlurXXX
43 * one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX
47 * a variable containing the 3 scripts.
48 the 3 scripts are inserted after the <input> in the html code
51 sub plugin_javascript {
52 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
53 my $function_name= "barcode".(int(rand(100000))+1);
56 my ($year, $mon, $day) = split('-', C4::Dates->today('iso'));
57 my ($tag,$subfield) = GetMarcFromKohaField("items.barcode", '');
58 my ($loctag,$locsubfield) = GetMarcFromKohaField("items.homebranch", '');
63 my $autoBarcodeType = C4::Context->preference("autoBarcode");
64 warn "Barcode type = $autoBarcodeType" if $DEBUG;
65 if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
66 # don't return a value unless we have the appropriate syspref set
67 return ($function_name,
68 "<script type=\"text/javascript\">
69 // autoBarcodeType OFF (or not defined)
70 function Focus$function_name() { return 0;}
71 function Clic$function_name() { return 0;}
72 function Blur$function_name() { return 0;}
75 if ($autoBarcodeType eq 'annual') {
76 $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
77 my $sth=$dbh->prepare($query);
78 $sth->execute("$year%");
79 while (my ($count)= $sth->fetchrow_array) {
80 warn "Examining Record: $count" if $DEBUG;
81 $nextnum = $count if $count;
84 $nextnum = sprintf("%0*d", "4",$nextnum);
85 $nextnum = "$year-$nextnum";
87 elsif ($autoBarcodeType eq 'incremental') {
88 # not the best, two catalogers could add the same barcode easily this way :/
89 $query = "select max(abs(barcode)) from items";
90 my $sth = $dbh->prepare($query);
92 while (my ($count)= $sth->fetchrow_array) {
97 elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit
98 $year = substr($year, -2);
99 $query = "SELECT MAX(CAST(SUBSTRING(barcode,7,4) AS signed)) FROM items WHERE barcode REGEXP ?";
100 my $sth = $dbh->prepare($query);
101 $sth->execute("^[a-zA-Z]{1,}$year");
102 while (my ($count)= $sth->fetchrow_array) {
103 $nextnum = $count if $count;
104 warn "Existing incremental number = $nextnum" if $DEBUG;
107 $nextnum = sprintf("%0*d", "4",$nextnum);
108 $nextnum = $year . $mon . $nextnum;
109 warn "New hbyymmincr Barcode = $nextnum" if $DEBUG;
111 for (i=0 ; i<document.f.field_value.length ; i++) {
112 if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') {
116 if (\$('#' + id).val() == '' || force) {
117 \$('#' + id).val(document.f.field_value[fnum].value + '$nextnum');
122 # default js body (if not filled by hbyymmincr)
123 $scr or $scr = <<END_OF_JS;
124 if (\$('#' + id).val() == '' || force) {
125 \$('#' + id).val('$nextnum');
129 my $js = <<END_OF_JS;
130 <script type="text/javascript">
133 function Blur$function_name(index) {
134 //barcode validation might go here
137 function Focus$function_name(subfield_managed, id, force) {
142 function Clic$function_name(id) {
143 return Focus$function_name('not_relavent', id, 1);
148 return ($function_name, $js);