From 59bf629f5c966bcf68f5b066ce6f4bfe696606ed 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 | 9 + .../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, 479 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 20d64a5..b8a1cfe 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -523,6 +523,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 ee14c81..9d77142 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 d3f3f50..df13cf4 100644 --- a/Koha/Schema/Result/Z3950server.pm +++ b/Koha/Schema/Result/Z3950server.pm @@ -120,6 +120,18 @@ __PACKAGE__->table("z3950servers"); data_type: 'mediumtext' 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 => "mediumtext", is_nullable => 1 }, "add_xslt", { data_type => "mediumtext", 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 1aa3f8d..a6d1cd8 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -569,5 +569,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 7a80e41..508d16a 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -13959,6 +13959,15 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 16530 - Add a circ sidebar navigation menu)\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 b6954ef..2c5c49a 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 @@ -409,6 +409,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 4a6a968..26823c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt @@ -150,6 +150,13 @@ [% END %] +
  • + [% IF ( server.opac ) %] + + [% ELSE %] + + [% END %] +
  • @@ -228,7 +235,7 @@ You searched for [% searchfield %] [% END %] - + [% FOREACH loo IN loop %] @@ -241,6 +248,8 @@ Authority [% END %] + +
    TargetHostname/PortDatabaseUseridPasswordPreselectedRankSyntaxEncodingTimeoutRecord type
    TargetHostname/PortDatabaseUseridPasswordPreselectedRankSyntaxEncodingTimeoutRecord typeAttributesOPACOptions
    [% loo.attributes %][% IF loo.opac %]X[% END %]