From 08beddab7909fd381556bd000ea5ec3ad190f97a Mon Sep 17 00:00:00 2001 From: Blou Date: Wed, 10 Feb 2016 16:01:11 -0500 Subject: [PATCH] Bug 11361 - Add a Z39.50 search page in the OPAC to let members search for records on remote Koha instances This patch adds the OPACZ3950 preference which activates a "Z39.50 Search" page in the OPAC. This page can be used to let members search for biblio records on remote Koha instances. If the "Show" link is clicked in the results page, the user is then redirected to the remote Koha's OPAC to see the record's details. This feature can be useful if you have multiple libraries with their own Koha instance and you want your users to be able to search for books in your other libraries. Please note that this will only work with Koha instances. The links in the results page won't work with other normal Z39.50 servers. Sponsored-by: CCSR ( http://www.ccsr.qc.ca ) --- C4/Auth.pm | 1 + C4/Breeding.pm | 11 +- Koha/Schema/Result/Z3950server.pm | 16 ++ admin/z3950servers.pl | 2 +- installer/data/mysql/sysprefs.sql | 3 +- installer/data/mysql/updatedatabase.pl | 10 + .../prog/en/modules/admin/preferences/opac.pref | 6 + .../prog/en/modules/admin/z3950servers.tt | 11 +- .../opac-tmpl/bootstrap/en/includes/masthead.inc | 1 + .../bootstrap/en/includes/opac-bottom.inc | 12 + .../bootstrap/en/modules/opac-z3950-search.tt | 298 +++++++++++++++++++++ opac/opac-z3950-search.pl | 117 ++++++++ 12 files changed, 480 insertions(+), 8 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-z3950-search.tt create mode 100755 opac/opac-z3950-search.pl diff --git a/C4/Auth.pm b/C4/Auth.pm index c3ad351..cddeb55 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -529,6 +529,7 @@ sub get_template_and_user { OPACURLOpenInNewWindow => "" . C4::Context->preference("OPACURLOpenInNewWindow"), OPACUserCSS => "" . C4::Context->preference("OPACUserCSS"), OpacAuthorities => C4::Context->preference("OpacAuthorities"), + OpacZ3950 => C4::Context->preference("OpacZ3950"), opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'}, opac_search_limit => $opac_search_limit, opac_limit_override => $opac_limit_override, diff --git a/C4/Breeding.pm b/C4/Breeding.pm index a17406b..5a71845 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -131,12 +131,11 @@ The second parameter $template is a Template object. The routine uses this param =cut sub Z3950Search { - my ($pars, $template)= @_; + my ($pars, $template, $fromopac)= @_; my @id= @{$pars->{id}}; my $page= $pars->{page}; my $biblionumber= $pars->{biblionumber}; - my $show_next = 0; my $total_pages = 0; my @results; @@ -193,7 +192,7 @@ sub Z3950Search { for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) { if ( $oResult[$k]->record($i) ) { undef $error; - ( $res, $error ) = _handle_one_result( $oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber, $xslh ); #ignores error in sequence numbering + ( $res, $error ) = _handle_one_result( $oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber, $xslh, $fromopac ); #ignores error in sequence numbering push @breeding_loop, $res if $res; push @errconn, { server => $servers[$k]->{servername}, error => $error, seq => $i+1 } if $error; } @@ -263,7 +262,7 @@ sub _build_query { } sub _handle_one_result { - my ( $zoomrec, $servhref, $seq, $bib, $xslh )= @_; + my ( $zoomrec, $servhref, $seq, $bib, $xslh, $fromopac )= @_; my $raw= $zoomrec->raw(); my $marcrecord; @@ -275,7 +274,7 @@ sub _handle_one_result { } SetUTF8Flag($marcrecord); my $error; - ( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh); + ( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh) unless $fromopac; my $batch_id = GetZ3950BatchId($servhref->{servername}); my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0); @@ -291,6 +290,7 @@ sub _handle_one_result { { biblionumber => $bib, server => $servhref->{servername}, + host => $servhref->{host}, breedingid => $breedingid, }, $marcrecord) if $breedingid; return ( $row, $error ); @@ -323,6 +323,7 @@ sub _do_xslt_proc { sub _add_rowdata { my ($row, $record)=@_; my %fetch= ( + biblionumber => 'biblio.biblionumber', title => 'biblio.title', author => 'biblio.author', isbn =>'biblioitems.isbn', diff --git a/Koha/Schema/Result/Z3950server.pm b/Koha/Schema/Result/Z3950server.pm index f2a5de2..0735bf1 100644 --- a/Koha/Schema/Result/Z3950server.pm +++ b/Koha/Schema/Result/Z3950server.pm @@ -120,6 +120,18 @@ __PACKAGE__->table("z3950servers"); data_type: 'longtext' is_nullable: 1 +=head2 attributes + + data_type: 'varchar' + is_nullable: 1 + size: 255 + +=head2 opac + + data_type: 'tinyint' + is_nullable: 1 + size: 1 + =cut __PACKAGE__->add_columns( @@ -167,6 +179,10 @@ __PACKAGE__->add_columns( { data_type => "longtext", is_nullable => 1 }, "add_xslt", { data_type => "longtext", is_nullable => 1 }, + "attributes", + { data_type => "varchar", is_nullable => 1, size => 255 }, + "opac", + { data_type => "tinyint", is_nullable => 1, size => 1 }, ); =head1 PRIMARY KEY diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index d1fe85b..cfe4c74 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -66,7 +66,7 @@ if( $op eq 'delete_confirmed' && $id ) { $id = 0; } elsif ( $op eq 'add_validated' ) { my @fields=qw/host port db userid password rank syntax encoding timeout - recordtype checked servername servertype sru_options sru_fields + recordtype checked servername servertype sru_options sru_fields attributes opac add_xslt/; my $formdata = _form_data_hashref( $input, \@fields ); if( $id ) { diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 76bb2cc..e4c69d9 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -603,5 +603,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'), ('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'), ('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'), -('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo') +('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'), +('OPACZ3950','0','','Allow patrons to search for bibliographic records in other libraries via Z39.50.','YesNo') ; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e8121d0..86ff057 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -15613,6 +15613,16 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 13287 - Add system preference PurgeSuggestionsOlderThan)\n"; } +$DBversion = "XXX"; +if( CheckVersion( $DBversion ) ) { + $dbh->do("ALTER TABLE z3950servers ADD COLUMN opac TINYINT(1);"); + $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('OPACZ3950','0','','Allow patrons to search for bibliographic records in other libraries via Z39.50.','YesNo')"); + print "Add opac column to z3950servers table.\nAdd OPACZ3950 preference.\n"; + SetVersion($DBversion); +} + + +# DEVELOPER PROCESS, search for anything to execute in the db_update directory # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index c44b109..930c25c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -410,6 +410,12 @@ OPAC: no: "Don't allow" - patrons to search your authority records. - + - pref: OpacZ3950 + choices: + yes: Allow + no: "Don't allow" + - patrons to search for bibliographic records in other libraries via Z39.50. + - - pref: opacbookbag choices: yes: Allow diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt index 8bf8483..8d2c1b2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt @@ -81,6 +81,13 @@ [% END %] +
  • + [% IF ( server.opac ) %] + + [% ELSE %] + + [% END %] +
  • @@ -159,7 +166,7 @@ You searched for [% searchfield |html %] [% END %] - + [% FOREACH loo IN loop %] @@ -172,6 +179,8 @@ Authority [% END %] + +
    TargetHostname/PortDatabaseUseridPasswordPreselectedRankSyntaxEncodingTimeoutRecord type
    TargetHostname/PortDatabaseUseridPasswordPreselectedRankSyntaxEncodingTimeoutRecord typeAttributesOPACOptions
    [% loo.attributes %][% IF loo.opac %]X[% END %]