@@ -, +, @@
---
cataloguing/addbiblio.pl | 36 ++++++-
cataloguing/value_builder/marc21_leader.pl | 117 ++++++++++++-----------
cataloguing/value_builder/new_example_plugin.pl | 71 ++++++++++++++
3 files changed, 163 insertions(+), 61 deletions(-)
create mode 100755 cataloguing/value_builder/new_example_plugin.pl
--- a/cataloguing/addbiblio.pl
+++ a/cataloguing/addbiblio.pl
@@ -46,6 +46,10 @@ if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
}
our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
+our $building_plugin={};
+ #hashref { record => .., subfieldid => .., tabno => .., }
+ #used in building the new cataloging plugins (without redefinitions)
+ #plugin script should add function and javascript to hash
=head1 FUNCTIONS
@@ -406,10 +410,8 @@ sub create_input {
closedir( DIR );
}
my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
- if (do $plugin) {
- my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
- my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
-
+ my ( $function_name, $javascript ) = _new_plugin_builder( $plugin, $rec, $subfield_data{id}, $tabloop );
+ if ($function_name) {
$subfield_data{marc_value} =
" $record,
+ subfieldid => $subfieldid,
+ tabno => $tabno,
+ };
+ do $plugin || return;
+
+ #first, try the new way without redefines using building_plugin hash
+ if( defined $building_plugin->{function} &&
+ defined $building_plugin->{javascript} ) {
+ return ($building_plugin->{function},
+ $building_plugin->{javascript} );
+ }
+
+ #arriving here, we try the old way with redefines: we are PHASING this OUT
+ #next call is of no use, commented
+ #my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
+ my ( $function_name, $javascript ) = plugin_javascript( undef, $record, $tagslib, $subfieldid, $tabno );
+ #first param was dbh, not needed: use C4::Context->dbh in plugin
+ #note also that tagslib is global (so actually superfluous)
+ return ( $function_name, $javascript );
+ #caller tests if function_name is defined
+}
=head2 format_indicator
--- a/cataloguing/value_builder/marc21_leader.pl
+++ a/cataloguing/value_builder/marc21_leader.pl
@@ -1,6 +1,5 @@
#!/usr/bin/perl
-
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
@@ -19,29 +18,32 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
-#use warnings; FIXME - Bug 2505
-use C4::Auth;
+use warnings;
+
use CGI;
-use C4::Context;
+use C4::Auth;
+use C4::Context;
use C4::Search;
use C4::Output;
-=head1
+# This plugin has been moved to the new style using $building_plugin
-plugin_parameters : other parameters added when the plugin is called by the dopop function
+our $building_plugin;
+if(defined $building_plugin) {
+ pass_script_for_marc21_leader();
+}
+else {
+ run_marc21_leader_plugin();
+}
-=cut
+#-------------------------------------------------------------------------------
-sub plugin_parameters {
-my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
-return "";
-}
+sub pass_script_for_marc21_leader {
+ my $field_number= $building_plugin->{subfieldid};
-sub plugin_javascript {
-my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
-my $function_name= $field_number;
-my $res="
+ my $function_name= $field_number;
+ my $res="
";
-
-return ($function_name,$res);
+ $building_plugin->{function}= $function_name;
+ $building_plugin->{javascript}= $res;
}
-sub plugin {
-my ($input) = @_;
- my $index= $input->param('index');
- my $result= $input->param('result');
-
-
- my $dbh = C4::Context->dbh;
-
-my ($template, $loggedinuser, $cookie)
- = get_template_and_user({template_name => "cataloguing/value_builder/marc21_leader.tmpl",
- query => $input,
- type => "intranet",
- authnotrequired => 0,
- flagsrequired => {editcatalogue => '*'},
- debug => 1,
- });
- $result = " nam a22 7a 4500" unless $result;
- my $f5 = substr($result,5,1);
- my $f6 = substr($result,6,1);
- my $f7 = substr($result,7,1);
- my $f8 = substr($result,8,1);
- my $f17 = substr($result,17,1);
- my $f18 = substr($result,18,1);
- my $f19 = substr($result,19,1);
- my $f2023 = substr($result,20,4);
- $template->param(index => $index,
- "f5$f5" => 1,
- "f6$f6" => 1,
- "f7$f7" => 1,
- "f8$f8" => 1,
- "f17$f17" => 1,
- "f18$f18" => 1,
- "f19$f19" => 1,
- "f2023" => $f2023,
- );
- output_html_with_http_headers $input, $cookie, $template->output;
+
+sub run_marc21_leader_plugin {
+ my $input = new CGI;
+ my $index= $input->param('index');
+ my $result= $input->param('result');
+
+ my $dbh = C4::Context->dbh;
+
+ my ($template, $loggedinuser, $cookie) = get_template_and_user(
+ {
+ template_name => "cataloguing/value_builder/marc21_leader.tmpl",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => {editcatalogue => '*'},
+ debug => 1,
+ });
+ $result = " nam a22 7a 4500" unless $result;
+ my $f5 = substr($result,5,1);
+ my $f6 = substr($result,6,1);
+ my $f7 = substr($result,7,1);
+ my $f8 = substr($result,8,1);
+ my $f17 = substr($result,17,1);
+ my $f18 = substr($result,18,1);
+ my $f19 = substr($result,19,1);
+ my $f2023 = substr($result,20,4);
+ $template->param(
+ index => $index,
+ "f5$f5" => 1,
+ "f6$f6" => 1,
+ "f7$f7" => 1,
+ "f8$f8" => 1,
+ "f17$f17" => 1,
+ "f18$f18" => 1,
+ "f19$f19" => 1,
+ "f2023" => $f2023,
+ );
+ output_html_with_http_headers $input, $cookie, $template->output;
}
1;
--- a/cataloguing/value_builder/new_example_plugin.pl
+++ a/cataloguing/value_builder/new_example_plugin.pl
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use CGI;
+
+#-------------------------------------------------------------------------------
+
+# example of new cataloging plugin style without redefines
+# if addbiblio calls this script, the global $building_plugin exists
+# when copying this example, pick two new names to prevent redefining
+
+our $building_plugin;
+if(defined $building_plugin) {
+ pass_script_for_myexample_plugin(); #TODO: pick a new name !
+}
+else {
+ run_myexample_plugin(); #TODO: pick a new name !
+}
+
+#-------------------------------------------------------------------------------
+
+sub pass_script_for_myexample_plugin { #TODO: pick a new name
+
+ #via global $building_plugin, you receive three parameters:
+ my $subfieldid = $building_plugin->{subfieldid};
+ #uncomment following lines, if you need them
+ #my $tabno = $building_plugin->{tabno};
+ #my $oldrecord = $building_plugin->{record};
+
+ #now return function name and javascript via global $building_plugin
+ #your javascript normally contains a Blur, Clic and Focus function
+ #call your plugin NO LONGER via plugin_launcher but directly
+ #see also marc21_leader.pl
+ my $function_name= $subfieldid; #valid choice, but may be different
+ my $javascript=qq|
+
+|;
+#as you may be aware, this example just puts 12345 in your field and does not
+#call a popup
+
+ #FUNDAMENTAL: pass back via global hashref
+ $building_plugin->{function}= $function_name;
+ $building_plugin->{javascript}= $javascript;
+}
+
+
+#-------------------------------------------------------------------------------
+
+sub run_myexample_plugin { #TODO: pick a new name !
+ my $query=new CGI;
+
+ #does nothing now
+ #rest of your plugin script comes here
+}
+
+1;
--