From 082aa35b122b5e682c46abb15fe0b8793f90aa62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick?= Date: Mon, 9 Dec 2013 17:19:22 -0500 Subject: [PATCH] Add a Z39.50 search page to the OPAC to let users search for records on a remote Koha instance. --- C4/Auth.pm | 1 + admin/z3950servers.pl | 22 +- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 + .../prog/en/modules/admin/preferences/opac.pref | 6 + .../prog/en/modules/admin/z3950servers.tt | 12 +- koha-tmpl/opac-tmpl/ccsr/en/css/datatables.css | 10 +- koha-tmpl/opac-tmpl/ccsr/en/includes/masthead.inc | 1 + koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc | 1 + .../opac-tmpl/prog/en/modules/opac-z3950-search.tt | 253 +++++++++++++++ opac/opac-z3950-search.pl | 323 ++++++++++++++++++++ 11 files changed, 622 insertions(+), 16 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/prog/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 00eeeef..c4d5b5b 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -412,6 +412,7 @@ sub get_template_and_user { OPACMobileUserCSS => "". C4::Context->preference("OPACMobileUserCSS"), OPACViewOthersSuggestions => "" . C4::Context->preference("OPACViewOthersSuggestions"), OpacAuthorities => C4::Context->preference("OpacAuthorities"), + OpacZ3950 => C4::Context->preference("OpacZ3950"), OPACBaseURL => ($in->{'query'}->https() ? "https://" : "http://") . $ENV{'SERVER_NAME'} . ($ENV{'SERVER_PORT'} eq ($in->{'query'}->https() ? "443" : "80") ? '' : ":$ENV{'SERVER_PORT'}"), opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'}, diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index 1dbd118..ad23d43 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -40,7 +40,7 @@ sub StringSearch { $searchstring = ''; } - my $query = "SELECT host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype"; + my $query = "SELECT host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype,opac"; $query .= " FROM z3950servers"; if ( $searchstring ne '' ) { $query .= " WHERE (name like ?)" } $query .= " ORDER BY rank,name"; @@ -93,14 +93,14 @@ if ( $op eq 'add_form' ) { if ($searchfield) { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( -"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype from z3950servers where (name = ?) order by rank,name" +"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype,opac from z3950servers where (name = ?) order by rank,name" ); $sth->execute($searchfield); $data = $sth->fetchrow_hashref; $sth->finish; } $template->param( $_ => $data->{$_} ) - for (qw( host port db userid password checked rank timeout encoding )); + for (qw( host port db userid password checked rank timeout encoding opac )); $template->param( $_ . $data->{$_} => 1 ) for (qw( syntax recordtype )); # END $OP eq ADD_FORM @@ -113,7 +113,7 @@ if ( $op eq 'add_form' ) { my $checked = $input->param('checked') ? 1 : 0; if ($sth->rows) { $template->param(confirm_update => 1); - $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=?,timeout=?,recordtype=? where name=?"); + $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=?,timeout=?,recordtype=?,opac=? where name=?"); $sth->execute($input->param('host'), $input->param('port'), $input->param('db'), @@ -126,6 +126,7 @@ if ( $op eq 'add_form' ) { $input->param('encoding'), $input->param('timeout'), $input->param('recordtype'), + ($input->param('opac') || 0), $input->param('searchfield'), ); } @@ -133,15 +134,16 @@ if ( $op eq 'add_form' ) { $template->param(confirm_add => 1); $sth=$dbh->prepare( "INSERT INTO z3950servers " . - "(host,port,db,userid,password,name,checked,rank,syntax,encoding,timeout,recordtype) " . - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); + "(host,port,db,userid,password,name,checked,rank,syntax,encoding,timeout,recordtype,opac) " . + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); $sth->execute( $input->param('host'), $input->param('port'), $input->param('db'), $input->param('userid'), $input->param('password'), $input->param('searchfield'), $checked, $input->param('rank'), $input->param('syntax'), $input->param('encoding'), - $input->param('timeout'), $input->param('recordtype') + $input->param('timeout'), $input->param('recordtype'), + ($input->param('opac') || 0), ); } $sth->finish; @@ -154,7 +156,7 @@ if ( $op eq 'add_form' ) { my $dbh = C4::Context->dbh; my $sth2 = $dbh->prepare( -"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype from z3950servers where (name = ?) order by rank,name" +"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype,opac from z3950servers where (name = ?) order by rank,name" ); $sth2->execute($searchfield); my $data = $sth2->fetchrow_hashref; @@ -171,6 +173,7 @@ if ( $op eq 'add_form' ) { syntax => $data->{'syntax'}, timeout => $data->{'timeout'}, recordtype => $data->{'recordtype'}, + opac => $data->{'opac'}, encoding => $data->{'encoding'} ); @@ -203,7 +206,8 @@ if ( $op eq 'add_form' ) { rank => $results->[$i]{'rank'}, syntax => $results->[$i]{'syntax'}, encoding => $results->[$i]{'encoding'}, - timeout => $results->[$i]{'timeout'}, + timeout => $results->[$i]{'timeout'}, + opac => $results->[$i]{'opac'}, recordtype => $results->[$i]{'recordtype'}); push @loop, \%row; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 6438483..1711cfc 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -424,4 +424,5 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('yuipath','local','local|http://yui.yahooapis.com/2.5.1/build','Insert the path to YUI libraries, choose local if you use koha offline','Choice'), ('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') +('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 19893b4..d3e07c3 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7824,6 +7824,14 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$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); +} + =head1 FUNCTIONS 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 a75c7ef..b9358e3 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 @@ -338,6 +338,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 915e531..2149f56 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt @@ -137,6 +137,13 @@ [% END %] +
  • + [% IF ( opac ) %] + + [% ELSE %] + + [% END %] +
  • @@ -289,6 +296,7 @@
  • Encoding: [% encoding %]
  • Timeout: [% timeout %]
  • Record type: [% recordtype %]
  • +
  • OPAC: [% opac %]
  • @@ -314,7 +322,7 @@ You searched for [% searchfield %] [% END %] - + [% FOREACH loo IN loop %] [% UNLESS ( loop.odd ) %] @@ -324,7 +332,7 @@ [% END %] - + [% END %]
    TargetHostname/PortDatabaseUseridPasswordCheckedRankSyntaxEncodingTimeoutRecord type  
    TargetHostname/PortDatabaseUseridPasswordCheckedRankSyntaxEncodingTimeoutRecord typeOPAC  
    [% loo.name %][% loo.host %]:[% loo.port %][% loo.db %][% loo.userid %][% loo.password %][% IF ( loo.checked ) %]Yes[% ELSE %]No[% END %][% loo.rank %][% loo.syntax %][% loo.encoding %][% loo.timeout %][% loo.recordtype %]EditDelete
    [% loo.syntax %][% loo.encoding %][% loo.timeout %][% loo.recordtype %][% loo.opac %]EditDelete
    diff --git a/koha-tmpl/opac-tmpl/ccsr/en/css/datatables.css b/koha-tmpl/opac-tmpl/ccsr/en/css/datatables.css index e7b11bd..cd34861 100644 --- a/koha-tmpl/opac-tmpl/ccsr/en/css/datatables.css +++ b/koha-tmpl/opac-tmpl/ccsr/en/css/datatables.css @@ -3,23 +3,23 @@ input.search_init { } .sorting_asc { padding-right: 19px; - background: url("../../img/asc.gif") no-repeat scroll right center #EEEEEE; + background: url("../../images/asc.gif") no-repeat scroll right center #EEEEEE; } .sorting_desc { padding-right: 19px; - background: url("../../img/desc.gif") no-repeat scroll right center #EEEEEE; + background: url("../../images/desc.gif") no-repeat scroll right center #EEEEEE; } .sorting { padding-right: 19px; - background: url("../../img/ascdesc.gif") no-repeat scroll right center #EEEEEE; + background: url("../../images/ascdesc.gif") no-repeat scroll right center #EEEEEE; } .sorting_asc_disabled { padding-right: 19px; - background: url("../../img/datatables/sort_asc_disabled.png") no-repeat scroll right center #EEEEEE; + background: url("../../images/datatables/sort_asc_disabled.png") no-repeat scroll right center #EEEEEE; } .sorting_desc_disabled { padding-right: 19px; - background: url("../../img/datatables/sort_desc_disabled.png") no-repeat scroll right center #EEEEEE; + background: url("../../images/datatables/sort_desc_disabled.png") no-repeat scroll right center #EEEEEE; } .sorting_disabled { padding-right: 19px; diff --git a/koha-tmpl/opac-tmpl/ccsr/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/ccsr/en/includes/masthead.inc index eba9b78..d792f1c 100644 --- a/koha-tmpl/opac-tmpl/ccsr/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/ccsr/en/includes/masthead.inc @@ -195,6 +195,7 @@ [% IF Koha.Preference( 'UseCourseReserves' ) == 1 %] | Course reserves[% END %] [% IF ( OpacBrowser ) %] | Browse by hierarchy[% END %] [% IF ( OpacAuthorities ) %] | Authority search[% END %] +[% IF ( OpacZ3950 ) %] | Z39.50 Search[% END %] [% IF ( opacuserlogin && ( Koha.Preference( 'reviewson' ) == 1 ) && ( Koha.Preference( 'OpacShowRecentComments' ) == 1 ) ) %] | Recent comments[% END %] [% IF ( TagsEnabled ) %] | Tag cloud[% END %] [% IF ( OpacCloud ) %] | Subject cloud[% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc index 79eb1a1..8910eaa 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc @@ -134,6 +134,7 @@ [% IF Koha.Preference( 'UseCourseReserves' ) == 1 %] | Course reserves[% END %] [% IF ( OpacBrowser ) %] | Browse by hierarchy[% END %] [% IF ( OpacAuthorities ) %] | Authority search[% END %] +[% IF ( OpacZ3950 ) %] | Z39.50 Search[% END %] [% IF ( opacuserlogin && ( Koha.Preference( 'reviewson' ) == 1 ) && ( Koha.Preference( 'OpacShowRecentComments' ) == 1 ) ) %] | Recent comments[% END %] [% IF ( TagsEnabled ) %] | Tag cloud[% END %] [% IF ( OpacCloud ) %] | Subject cloud[% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-z3950-search.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-z3950-search.tt new file mode 100644 index 0000000..693e6b5 --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-z3950-search.tt @@ -0,0 +1,253 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Z39.50 Search Results + + + + + + + + + +[% INCLUDE 'doc-head-close.inc' %] + + + + + + + + + [% IF ( opsearch ) %] + + + + +
    +[% ELSE %] + + +
    +[% END %] +
    + [% IF ( opsearch ) %] +

    Z39.50 Search Points

    +
    + +
    +
    +
    +
    1. +
    2. +
    3. +
    4. +
    +
    +
    +
    +
    1. +
    2. +
    3. +
    +
    +
    +
    +
    +

    Search targets Select allClear all

    + + [% FOREACH serverloo IN serverloop %] +

    + [% IF ( serverloo.checked ) %] + + [% ELSE %] + + [% END %] + + +

    + [% END %] +
    +
    Cancel
    +
    + + +[% ELSE %] +

    Results

    + [% IF ( breeding_loop ) %] + + + + + + + + + + + + + + [% FOREACH breeding_loo IN breeding_loop %] + [% IF ( breeding_loo.biblionumber ) %] + + + + + + + + + + + + + + [% END %] + [% END %] +
    ServerTitleAuthorDateEditionISBNLCCNMARCCard 
    [% breeding_loo.server %] [% breeding_loo.title |html %][% breeding_loo.author %][% breeding_loo.date %][% breeding_loo.edition %][% breeding_loo.isbn %][% breeding_loo.lccn %]MARCCardShow
    + +
    + + + + + + + + + + + + + [% FOREACH server IN servers %] + + [% END %] + + [% IF ( show_prevbutton ) %] + + [% END %] + Page [% current_page %] / [% total_pages %] + [% IF ( show_nextbutton ) %] + + [% END %] +
    Go to page : +
    + + [% ELSE %] + [% IF ( emptyserverlist ) %] + You didn't select any Z39.50 target. + [% ELSE %] + [% FOREACH errcon IN errconn %] + Connection failed to [% errcon.server %] + [% END %] + [% END %] +

    Nothing found.

    +

    + [% END %] +[% END %] + +
    +
    +[% IF ( numberpending ) %]

    Still [% numberpending %] servers to search

    [% END %] + + + + diff --git a/opac/opac-z3950-search.pl b/opac/opac-z3950-search.pl new file mode 100755 index 0000000..a7316ca --- /dev/null +++ b/opac/opac-z3950-search.pl @@ -0,0 +1,323 @@ +#!/usr/bin/perl + +# This is a completely new Z3950 clients search using async ZOOM -TG 02/11/06 +# Copyright 2000-2002 Katipo Communications +# +# 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 2 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 strict; +use warnings; +use CGI; + +use C4::Auth; +use C4::Output; +use C4::Biblio; +use C4::Context; +use C4::Koha; +use C4::Charset; +use ZOOM; + +my $input = new CGI; +my $dbh = C4::Context->dbh; +my $error = $input->param('error'); +my $title = $input->param('title'); +my $author = $input->param('author'); +my $isbn = $input->param('isbn'); +my $issn = $input->param('issn'); +my $lccn = $input->param('lccn'); +my $lccall = $input->param('lccall'); +my $subject = $input->param('subject'); +my $dewey = $input->param('dewey'); +my $controlnumber = $input->param('controlnumber'); +my $stdid = $input->param('stdid'); +my $srchany = $input->param('srchany'); +my $random = $input->param('random') || rand(1000000000); # this var is not useful anymore just kept for rel2_2 compatibility +my $op = $input->param('op'); + +my $page = $input->param('current_page') || 1; +$page = $input->param('goto_page') if $input->param('changepage_goto'); +my $show_next = 0; +my $total_pages = 0; + +my $numberpending; +my $attr = ''; +my $term; +my $host; +my $server; +my $database; +my $port; +my $marcdata; +my @encoding; +my @results; +my $count; +my $record; +my $oldbiblio; +my $errmsg; +my @serverloop = (); +my @serverhost; +my @servername; +my @breeding_loop = (); + +my $DEBUG = 0; # if set to 1, many debug message are send on syslog. + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ + template_name => "opac-z3950-search.tt", + query => $input, + type => "opac", + authnotrequired => 1, + debug => 1, +}); + +$template->param( + isbn => $isbn, + issn => $issn, + lccn => $lccn, + lccall => $lccall, + title => $title, + author => $author, + controlnumber=> $controlnumber, + stdid => $stdid, + srchany => $srchany, + dewey => $dewey, + subject => $subject, +); + +if ( $op ne "do_search" ) { + my $sth = $dbh->prepare("select id,host,name,checked from z3950servers where opac=1 order by host;"); + $sth->execute(); + my $serverloop = $sth->fetchall_arrayref( {} ); + $template->param( + serverloop => $serverloop, + opsearch => "search", + ); + output_html_with_http_headers $input, $cookie, $template->output; +} +else { + my @id = $input->param('id'); + + if ( not defined @id ) { + # empty server list -> report and exit + $template->param( emptyserverlist => 1 ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; + } + + my @oConnection; + my @oResult; + my @errconn; + my $s = 0; + my $query; + my $nterms; + if ($isbn || $issn) { + $term=$isbn if ($isbn); + $term=$issn if ($issn); + $term =~ s/"/\\"/; + $query .= " \@or \@attr 1=8 \"$term\" \@attr 1=7 \"$term\" "; + $nterms++; + } + if ($title) { + utf8::decode($title); + $title =~ s/"/\\"/; + $query .= " \@attr 1=4 \"$title\" "; + $nterms++; + } + if ($author) { + utf8::decode($author); + $author =~ s/"/\\"/; + $query .= " \@attr 1=1003 \"$author\" "; + $nterms++; + } + if ($dewey) { + $dewey =~ s/"/\\"/; + $query .= " \@attr 1=16 \"$dewey\" "; + $nterms++; + } + if ($subject) { + utf8::decode($subject); + $subject =~ s/"/\\"/; + $query .= " \@attr 1=21 \"$subject\" "; + $nterms++; + } + if ($lccn) { + $lccn =~ s/"/\\"/; + $query .= " \@attr 1=9 \"$lccn\" "; + $nterms++; + } + if ($lccall) { + $lccall =~ s/"/\\"/; + $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" "; + $nterms++; + } + if ($controlnumber) { + $controlnumber =~ s/"/\\"/; + $query .= " \@attr 1=12 \"$controlnumber\" "; + $nterms++; + } + if ($stdid) { + $stdid =~ s/"/\\"/; + $query .= " \@attr 1=1007 \"$stdid\" "; + $nterms++; + } + if ($srchany) { + $srchany =~ s/"/\\"/; + $query .= " \@attr 1=1016 \"$srchany\" "; + $nterms++; + } +for my $i (1..$nterms-1) { + $query = "\@and " . $query; +} +warn "query ".$query if $DEBUG; + + foreach my $servid (@id) { + my $sth = $dbh->prepare("select * from z3950servers where id=?"); + $sth->execute($servid); + while ( $server = $sth->fetchrow_hashref ) { + warn "serverinfo ".join(':',%$server) if $DEBUG; + my $option1 = new ZOOM::Options(); + $option1->option('async' => 1); + $option1->option('elementSetName', 'F'); + $option1->option('databaseName', $server->{db}); + $option1->option('user', $server->{userid} ) if $server->{userid}; + $option1->option('password', $server->{password}) if $server->{password}; + $option1->option('preferredRecordSyntax', $server->{syntax}); + $oConnection[$s] = create ZOOM::Connection($option1) + || $DEBUG + && warn( "" . $oConnection[$s]->errmsg() ); + warn( "server data", $server->{name}, $server->{port} ) if $DEBUG; + $oConnection[$s]->connect( $server->{host}, $server->{port} ) + || $DEBUG + && warn( "" . $oConnection[$s]->errmsg() ); + $serverhost[$s] = $server->{host}; + $servername[$s] = $server->{name}; + $encoding[$s] = ($server->{encoding}?$server->{encoding}:"iso-5426"); + $s++; + } ## while fetch + } # foreach + my $nremaining = $s; + my $firstresult = 1; + + for ( my $z = 0 ; $z < $s ; $z++ ) { + warn "doing the search" if $DEBUG; + $oResult[$z] = $oConnection[$z]->search_pqf($query) + || $DEBUG + && warn( "somthing went wrong: " . $oConnection[$s]->errmsg() ); + + # $oResult[$z] = $oConnection[$z]->search_pqf($query); + } + + AGAIN: + my $k; + my $event; + while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) { + $event = $oConnection[ $k - 1 ]->last_event(); + warn( "connection ", $k - 1, ": event $event (", + ZOOM::event_str($event), ")\n" ) + if $DEBUG; + last if $event == ZOOM::Event::ZEND; + } + + if ( $k != 0 ) { + $k--; + warn $serverhost[$k] if $DEBUG; + my ( $error, $errmsg, $addinfo, $diagset ) = + $oConnection[$k]->error_x(); + if ($error) { + if ($error =~ m/^(10000|10007)$/ ) { + push(@errconn, {'server' => $serverhost[$k]}); + } + $DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n"; + } + else { + my $numresults = $oResult[$k]->size(); + my $i; + my $result = ''; + if ( $numresults > 0 and $numresults >= (($page-1)*20)) { + $show_next = 1 if $numresults >= ($page*20); + $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20); + for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) { + my $rec = $oResult[$k]->record($i); + if ($rec) { + my $marcrecord; + $marcdata = $rec->raw(); + + my ($charset_result, $charset_errors); + ($marcrecord, $charset_result, $charset_errors) = + MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]); +####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc +## In HEAD i change everything to UTF-8 +# In rel2_2 i am not sure what encoding is so no character conversion is done here +##Add necessary encoding changes to here -TG + + SetUTF8Flag($marcrecord); + + my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" ); + $oldbiblio->{isbn} =~ s/ |-|\.//g if $oldbiblio->{isbn}; + # pad | and ( with spaces to allow line breaks in the html + $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn}; + $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn}; + + $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn}; + # pad | and ( with spaces to allow line breaks in the html + $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn}; + $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn}; + my %row_data; + $row_data{server} = $servername[$k]; + $row_data{host} = $serverhost[$k]; + $row_data{isbn} = $oldbiblio->{isbn}; + $row_data{lccn} = $oldbiblio->{lccn}; + $row_data{title} = $oldbiblio->{title}; + $row_data{author} = $oldbiblio->{author}; + $row_data{date} = $oldbiblio->{copyrightdate}; + $row_data{edition} = $oldbiblio->{editionstatement}; + $row_data{biblionumber} = $oldbiblio->{biblionumber}; + push( @breeding_loop, \%row_data ); + + } else { + push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'biblionumber'=>-1}); + } # $rec + } + } #$numresults + } + } # if $k !=0 + $numberpending = $nremaining - 1; + + my @servers = (); + foreach my $id (@id) { + push(@servers,{id => $id}); + } + + $template->param( + breeding_loop => \@breeding_loop, + server => $servername[$k], + numberpending => $numberpending, + errconn => \@errconn, + current_page => $page, + servers => \@servers, + total_pages => $total_pages, + ); + $template->param(show_nextbutton=>1) if $show_next; + $template->param(show_prevbutton=>1) if $page != 1; + + output_html_with_http_headers $input, $cookie, $template->output if $numberpending == 0; + + # print $template->output if $firstresult !=1; + $firstresult++; + + MAYBE_AGAIN: + if ( --$nremaining > 0 ) { + goto AGAIN; + } +} ## if op=search -- 1.7.2.5