Bug 16203: Convert item plugins to new style (see bug 10480)

Converts item plugins to new style (with builder and launcher).
See also bugs 10480 and 13437.

The following plugins have been adjusted:
barcode_manual.pl
barcode.pl
callnumber-KU.pl
callnumber.pl
cn_browser.pl (Added license statement too)
dateaccessioned.pl
macles.pl
stocknumberam123.pl
stocknumberAV.pl
stocknumber.pl

Test plan:
Connect the plugin to an item field.
Verify that the plugin still works.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested if all plugins compile okay.
Ran most of them thru FrameworkPlugin.t.
Tested them in the item editor.

Note: the form for macles.pl comes up, further hard to test.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Marcel de Rooy 2016-04-05 14:51:43 +02:00 committed by Kyle M Hall
parent d5a160ed95
commit b133b0e94d
10 changed files with 193 additions and 172 deletions

View File

@ -1,4 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2000-2002 Katipo Communications
# Parts copyright 2008-2010 Foundations Bible College
#
@ -17,21 +20,19 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings
use Modern::Perl;
use C4::Context;
require C4::Barcodes::ValueBuilder;
use C4::Barcodes::ValueBuilder;
use Koha::DateUtils;
use Algorithm::CheckDigits;
my $DEBUG = 0;
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $function_name= "barcode".(int(rand(100000))+1);
my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
my %args;
# find today's date
@ -45,13 +46,7 @@ sub plugin_javascript {
warn "Barcode type = $autoBarcodeType" if $DEBUG;
if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
# don't return a value unless we have the appropriate syspref set
return ($function_name,
"<script type=\"text/javascript\">
// autoBarcodeType OFF (or not defined)
function Focus$function_name() { return 0;}
function Clic$function_name() { return 0;}
function Blur$function_name() { return 0;}
</script>");
return q|<script type=\"text/javascript\"></script>|;
}
if ($autoBarcodeType eq 'annual') {
($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args);
@ -65,6 +60,7 @@ sub plugin_javascript {
elsif ($autoBarcodeType eq 'EAN13') {
# not the best, two catalogers could add the same barcode easily this way :/
my $query = "select max(abs(barcode)) from items";
my $dbh = $params->{dbh};
my $sth = $dbh->prepare($query);
$sth->execute();
while (my ($last)= $sth->fetchrow_array) {
@ -88,23 +84,25 @@ sub plugin_javascript {
$scr or $scr = <<END_OF_JS;
if (\$('#' + id).val() == '' || force) {
\$('#' + id).val('$nextnum');
}
};
END_OF_JS
my $js = <<END_OF_JS;
<script type="text/javascript">
//<![CDATA[
function Focus$function_name(subfield_managed, id, force) {
function Focus$function_name(id, force) {
$scr
return 0;
}
function Clic$function_name(id) {
return Focus$function_name('not_relavent', id, 1);
function Click$function_name(id) {
Focus$function_name(id, 1);
return false;
}
//]]>
</script>
END_OF_JS
return ($function_name, $js);
}
return $js;
};
return { builder => $builder };

View File

@ -1,4 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2000-2002 Katipo Communications
# Parts copyright 2008-2010 Foundations Bible College
#
@ -17,21 +20,20 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings
use Modern::Perl;
use C4::Context;
require C4::Barcodes::ValueBuilder;
use C4::Barcodes::ValueBuilder;
use Koha::DateUtils;
my $DEBUG = 0;
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $function_name= "barcode".(int(rand(100000))+1);
my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
my %args;
my $dbh = $params->{dbh};
$args{dbh} = $dbh;
# find today's date
@ -45,13 +47,7 @@ sub plugin_javascript {
warn "Barcode type = $autoBarcodeType" if $DEBUG;
if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
# don't return a value unless we have the appropriate syspref set
return ($function_name,
"<script type=\"text/javascript\">
// autoBarcodeType OFF (or not defined)
function Focus$function_name() { return 0;}
function Clic$function_name() { return 0;}
function Blur$function_name() { return 0;}
</script>");
return q|<script type=\"text/javascript\"></script>|;
}
if ($autoBarcodeType eq 'annual') {
($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args);
@ -70,16 +66,18 @@ sub plugin_javascript {
}
END_OF_JS
my $js = <<END_OF_JS;
my $js = <<END_OF_JS;
<script type="text/javascript">
//<![CDATA[
function Clic$function_name(id) {
function Click$function_name(id) {
$scr
return 0;
return false;
}
//]]>
</script>
END_OF_JS
return ($function_name, $js);
}
return $js;
};
return { builder => $builder };

View File

@ -1,5 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2012 CatalystIT Ltd
#
# This file is part of Koha.
@ -17,10 +19,10 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use C4::Auth;
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Context;
use C4::Output;
@ -40,12 +42,12 @@ CCC QW - returns first unused number CCC QWxx starting with CCC QW01
=cut
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $builder = sub {
my ( $params ) = @_;
my $res="
<script type='text/javascript'>
function Clic$field_number() {
var code = document.getElementById('$field_number');
function Click$params->{id}() {
var code = document.getElementById('$params->{id}');
var url = '../cataloguing/plugin_launcher.pl?plugin_name=callnumber-KU.pl&code=' + code.value;
var req = \$.get(url);
req.done(function(resp){
@ -56,13 +58,12 @@ sub plugin_javascript {
}
</script>
";
return $res;
};
return ($field_number,$res);
}
my $BASE_CALLNUMBER_RE = qr/^(\w+) (\w+)$/;
sub plugin {
my ($input) = @_;
my $launcher = sub {
my ( $params ) = @_;
my $input = $params->{cgi};
my $code = $input->param('code');
my ($template, $loggedinuser, $cookie) = get_template_and_user({
@ -74,6 +75,7 @@ sub plugin {
debug => 1,
});
my $BASE_CALLNUMBER_RE = qr/^(\w+) (\w+)$/;
my $ret;
my ($alpha, $num) = ($code =~ $BASE_CALLNUMBER_RE);
if (defined $num) { # otherwise no point
@ -117,4 +119,6 @@ sub plugin {
return => $ret || $code
);
output_html_with_http_headers $input, $cookie, $template->output;
}
};
return { builder => $builder, launcher => $launcher };

View File

@ -1,5 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2010 BibLibre SARL
#
# This file is part of Koha.
@ -17,10 +19,10 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use C4::Auth;
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Context;
use C4::Output;
@ -37,12 +39,12 @@ In this case, a callnumber has this form : "PREFIX 0009678570".
=cut
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $builder = sub {
my ( $params ) = @_;
my $res="
<script type='text/javascript'>
function Blur$field_number() {
var code = document.getElementById('$field_number');
function Blur$params->{id}() {
var code = document.getElementById('$params->{id}');
var url = '../cataloguing/plugin_launcher.pl?plugin_name=callnumber.pl&code=' + code.value;
var req = \$.get(url);
req.done(function(resp){
@ -54,12 +56,12 @@ sub plugin_javascript {
</script>
";
return $res;
};
return ($field_number,$res);
}
sub plugin {
my ($input) = @_;
my $launcher = sub {
my ( $params ) = @_;
my $input = $params->{cgi};
my $code = $input->param('code');
my ($template, $loggedinuser, $cookie) = get_template_and_user({
@ -82,7 +84,7 @@ sub plugin {
return => $max+1,
);
}
# If a prefix is submited, we look for the highest itemcallnumber with this prefix, and return it incremented
# If a prefix is submitted, we look for the highest itemcallnumber with this prefix, and return it incremented
} elsif ( $code =~ m/^[A-Z.\-']+$/ ) {
my $sth = $dbh->prepare("SELECT MAX(CAST(SUBSTRING_INDEX(itemcallnumber,' ',-1) AS SIGNED)) FROM items WHERE itemcallnumber LIKE ?");
$sth->execute($code.' %');
@ -104,4 +106,6 @@ sub plugin {
);
}
output_html_with_http_headers $input, $cookie, $template->output;
}
};
return { builder => $builder, launcher => $launcher };

View File

@ -1,34 +1,52 @@
use Modern::Perl;
no warnings 'redefine';
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2015 Koha Development Team
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use CGI;
use C4::Auth;
use C4::ClassSource;
use C4::Output;
sub plugin_javascript {
my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
my $function_name = "328" . ( int( rand(100000) ) + 1 );
my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
my $res = "
<script type=\"text/javascript\">
//<![CDATA[
function Clic$function_name(i) {
q = document.getElementById('$field_number');
function Click$function_name(i) {
q = document.getElementById('$params->{id}');
window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=cn_browser.pl&popup&q=\"+q.value,\"cnbrowser\",\"width=500,height=400,toolbar=false,scrollbars=yes\");
}
//]]>
</script>
";
return $res;
};
return ( $function_name, $res );
}
sub plugin {
my ($input) = @_;
my $cgi = new CGI;
my $params = $cgi->Vars;
my $launcher = sub {
my ( $params ) = @_;
my $cgi = $params->{cgi};
my $results_per_page = 30;
my $current_page = $cgi->param('page') || 1;
@ -143,6 +161,6 @@ sub plugin {
$template->param( 'popup' => defined( $cgi->param('popup') ) );
output_html_with_http_headers $cgi, $cookie, $template->output;
}
};
1;
return { builder => $builder, launcher => $launcher };

View File

@ -1,5 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
@ -18,12 +20,12 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use C4::Biblio qw/GetMarcFromKohaField/;
use Koha::DateUtils;
no warnings 'redefine';
sub plugin_javascript {
# my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $function_name = "dateaccessioned".(int(rand(100000))+1);
my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
@ -35,29 +37,25 @@ sub plugin_javascript {
//
// from: cataloguing/value_builder/dateaccessioned.pl
function Focus$function_name(subfield_managed, id, force) {
//var summary = "";
//for (i=0 ; i<document.f.field_value.length ; i++) {
// summary += i + ": " + document.f.tag[i].value + " " + document.f.subfield[i].value + ": " + document.f.field_value[i].value + "\\n";
//}
//alert("Got focus, subfieldmanaged: " + subfield_managed + "\\n" + summary);
set_to_today(id);
return 0;
function Focus$function_name(event) {
set_to_today(event.data.id);
}
function Clic$function_name(id) {
set_to_today(id, 1);
return 0;
function Click$function_name(event) {
set_to_today(event.data.id);
return false; // prevent page scroll
}
function set_to_today(id, force) {
function set_to_today( id ) {
if (! id) { alert(_("Bad id ") + id + _(" sent to set_to_today()")); return 0; }
if (\$("#" + id).val() == '' || \$("#" + id).val() == '0000-00-00' || force) {
if (\$("#" + id).val() == '' || \$("#" + id).val() == '0000-00-00' ) {
\$("#" + id).val("$date");
}
}
//]]>
</script>
END_OF_JS
return ($function_name, $res);
}
return $res;
};
return { builder => $builder };

View File

@ -1,5 +1,6 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2000-2002 Katipo Communications
#
@ -18,44 +19,33 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
#use warnings; FIXME - Bug 2505
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Context;
use C4::Output;
use C4::Auth;
# use Data::Dumper;
use vars qw( $tagslib);
use vars qw( $authorised_values_sth);
use vars qw( $is_a_modif );
use utf8;
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $function_name= "macles".(int(rand(100000))+1);
my $res="
my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
my $res="
<script type=\"text/javascript\">
//<![CDATA[
function Clic$function_name(i) {
newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
function Click$function_name(i) {
newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
}
//]]>
</script>
";
return $res;
};
return ($function_name,$res);
}
sub plugin {
my ($input) = @_;
# my $input = new CGI;
my $launcher = sub {
my ( $params ) = @_;
my $input = $params->{cgi};
my $index= $input->param('index');
my $dbh = C4::Context->dbh;
my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
#tabs
@ -90,7 +80,6 @@ my ($input) = @_;
} else {
unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
}
# use Data::Dumper;warn "BIGLOOP IN".Dumper(@BIGLOOP);
}
foreach my $num ( sort keys %numbers ) {
my @tmpcolhdr;
@ -168,7 +157,7 @@ my ($input) = @_;
$BIGLOOPcell{'number'} = $num;
push @BIGLOOP, \%BIGLOOPcell;
}
# warn "BIGLOOP OUT".Dumper(@BIGLOOP);
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "cataloguing/value_builder/macles.tt",
query => $input,
@ -180,4 +169,6 @@ my ($input) = @_;
$template->param(BIGLOOP=>\@BIGLOOP);
$template->param("index"=>$index);
output_html_with_http_headers $input, $cookie, $template->output;
}
};
return { builder => $builder, launcher => $launcher };

View File

@ -1,5 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
@ -17,13 +19,13 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use Modern::Perl;
use C4::Context;
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $function_name= "inventory".(int(rand(100000))+1);
my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
my $dbh = $params->{dbh};
my $branchcode = C4::Context->userenv->{'branch'};
@ -34,26 +36,24 @@ sub plugin_javascript {
my ($nextnum) = $sth->fetchrow;
$nextnum = $branchcode.'_'.$nextnum;
my $scr = <<END_OF_JS;
if (\$('#' + id).val() == '' || force) {
\$('#' + id).val('$nextnum');
}
END_OF_JS
my $js = <<END_OF_JS;
<script type="text/javascript">
//<![CDATA[
function Focus$function_name(subfield_managed, id, force) {
$scr
return 0;
function Focus$function_name(id, force) {
if (\$('#' + id).val() == '' || force) {
\$('#' + id).val('$nextnum');
}
}
function Clic$function_name(id) {
return Focus$function_name('not_relavent', id, 1);
function Click$function_name(event) {
Focus$function_name(event.data.id, 1);
return false;
}
//]]>
</script>
END_OF_JS
return ($function_name, $js);
}
return $js;
};
return { builder => $builder };

View File

@ -1,5 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2012 BibLibre SARL
#
# This file is part of Koha.
@ -18,8 +20,9 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use C4::Auth;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Context;
use C4::Output;
@ -37,12 +40,12 @@ In this case, a stocknumber has this form : "PREFIX 0009678570".
=cut
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $builder = sub {
my ( $params ) = @_;
my $res = qq{
<script type='text/javascript'>
function Clic$field_number() {
var code = document.getElementById('$field_number');
function Click$params->{id}() {
var code = document.getElementById('$params->{id}');
\$.ajax({
url: '/cgi-bin/koha/cataloguing/plugin_launcher.pl',
type: 'POST',
@ -51,7 +54,7 @@ sub plugin_javascript {
'code' : code.value,
},
success: function(data){
var field = document.getElementById('$field_number');
var field = document.getElementById('$params->{id}');
field.value = data;
return 1;
}
@ -60,11 +63,12 @@ sub plugin_javascript {
</script>
};
return ($field_number,$res);
}
return $res;
};
sub plugin {
my ($input) = @_;
my $launcher = sub {
my ( $params ) = @_;
my $input = $params->{cgi};
my $code = $input->param('code');
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@ -98,4 +102,6 @@ sub plugin {
}
output_html_with_http_headers $input, $cookie, $template->output;
}
};
return { builder => $builder, launcher => $launcher };

View File

@ -1,5 +1,7 @@
#!/usr/bin/perl
# Converted to new plugin style (Bug 13437)
# Copyright 2010 BibLibre SARL
#
# This file is part of Koha.
@ -17,10 +19,10 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use C4::Auth;
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Context;
use C4::Output;
@ -38,12 +40,12 @@ In this case, a stocknumber has this form : "PREFIX 0009678570".
=cut
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $builder = sub {
my ( $params ) = @_;
my $res="
<script type='text/javascript'>
function Blur$field_number() {
var code = document.getElementById('$field_number');
function Blur$params->{id}() {
var code = document.getElementById('$params->{id}');
var url = '../cataloguing/plugin_launcher.pl?plugin_name=stocknumberam123.pl&code=' + code.value;
var req = \$.get(url);
req.done(function(resp){
@ -52,15 +54,15 @@ sub plugin_javascript {
});
return 1;
}
</script>
";
return ($field_number,$res);
}
return $res;
};
sub plugin {
my ($input) = @_;
my $launcher = sub {
my ( $params ) = @_;
my $input = $params->{cgi};
my $code = $input->param('code');
my ($template, $loggedinuser, $cookie) = get_template_and_user({
@ -100,4 +102,6 @@ sub plugin {
);
}
output_html_with_http_headers $input, $cookie, $template->output;
}
};
return { builder => $builder, launcher => $launcher };