Major upgrade to the Z3950 client in Koha. It no longer requires the use of

the processqueue daemon, but relies on ZOOM Perl's asynch searching. Thanks
to Tumer Garip for commiting this to dev_week and to Chris for helping me
troubleshoot it.
This commit is contained in:
kados 2006-11-03 03:29:30 +00:00
parent 8ceffe1908
commit c37fa9c366
4 changed files with 232 additions and 105 deletions

View File

@ -70,6 +70,7 @@ where isbn=? and title=?");
my $alreadyindb = 0;
my $alreadyinfarm = 0;
my $notmarcrecord = 0;
my $breedingid;
for (my $i=0;$i<=$#marcarray;$i++) {
my $marcrecord = MARC::File::USMARC::decode($marcarray[$i]."\x1D");
my @warnings = $marcrecord->warnings();
@ -100,7 +101,7 @@ where isbn=? and title=?");
$alreadyindb++;
} else {
# search in breeding farm
my $breedingid;
if ($oldbiblio->{isbn}) {
$searchbreeding->execute($oldbiblio->{isbn},$oldbiblio->{title});
($breedingid) = $searchbreeding->fetchrow;
@ -117,13 +118,14 @@ where isbn=? and title=?");
$replacesql ->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded,$encoding,$z3950random,$breedingid);
} else {
$insertsql ->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded,$encoding,$z3950random);
$breedingid=$dbh->{'mysql_insertid'};
}
$imported++;
}
}
}
}
return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported);
return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid);
}

View File

@ -293,7 +293,7 @@ function PopupZ3950() {
}
}
if(error < 4){
newin=window.open("../z3950/search.pl?bibid=<!-- TMPL_VAR NAME="bibid" -->"+strQuery,"z3950search",'width=640,height=400,location=yes,toolbar=no,scrollbars=yes');
newin=window.open("../z3950/search.pl?oldbiblionumber=<!-- TMPL_VAR NAME="bibid" -->"+strQuery,"z3950search",'width=640,height=400,location=yes,toolbar=no,scrollbars=yes');
} else {
alert("To perform a z39.50 search, you must enter at least one of the following: \n\n ISBN\n ISSN\n Title\n Author\n");
}

View File

@ -3,11 +3,8 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Z39.50 Search Results</title>
<!-- TMPL_IF NAME="refresh" -->
<meta http-equiv="refresh" content="2; url=<!-- TMPL_VAR NAME="refresh" -->" />
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="TemplateEncoding" --><meta http-equiv="Content-Type" content="text/html; charset=<!-- TMPL_VAR NAME="TemplateEncoding" -->"><!-- TMPL_ELSE --><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><!-- /TMPL_IF -->
<link rel="shortcut icon" href="<!-- TMPL_VAR NAME='themelang' -->/includes/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/intranet-tmpl/npl/en/includes/favicon.ico" type="image/x-icon" />
<style type="text/css">
<!-- TMPL_IF NAME="intranetstylesheet" -->@import url(<!-- TMPL_VAR NAME='themelang' -->/includes/<!-- TMPL_VAR NAME="intranetstylesheet" -->);<!-- TMPL_ELSE -->@import url(<!-- TMPL_VAR NAME='themelang' -->/includes/intranet.css);<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="intranetcolorstylesheet" -->@import url(<!-- TMPL_VAR NAME='themelang' -->/includes/<!-- TMPL_VAR NAME="intranetcolorstylesheet" -->);<!-- /TMPL_IF -->
@ -15,40 +12,70 @@
</head>
<body>
<div id="main-compact">
<h2>Z3950 Search Results</h2>
<!-- TMPL_IF NAME="numberpending" --><h3>Still <!-- TMPL_VAR NAME="numberpending" --> requests to go</h3><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="breeding_loop" -->
<table>
<tr>
<th>Title</th>
<th>Author</th>
<th>ISBN</th>
<th>coming from</th>
<th>&nbsp;</th>
</tr>
<!-- TMPL_LOOP NAME="breeding_loop" -->
<!-- TMPL_IF NAME="toggle" --><tr><!-- TMPL_ELSE --><tr class="highlight"><!-- /TMPL_IF -->
<td><!-- TMPL_VAR NAME="title" --></td>
<td><!-- TMPL_VAR NAME="author" --></td>
<td><!-- TMPL_VAR NAME="isbn" --></td>
<td><!-- TMPL_VAR NAME="file" --></td>
<td><a href="#" onclick="Import(<!-- TMPL_VAR NAME="id" -->); return false;">Import this biblio</a></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
<table>
<!-- TMPL_IF name="opsearch" -->
<h3>Select Search Libraries</h3>
<form method="post" action="search.pl" name="f">
<input type="hidden" name="op" id="op" value="do_search" />
<input type="hidden" name="title" value=<!-- TMPL_VAR NAME="title" --> />
<input type="hidden" name="author" value=<!-- TMPL_VAR NAME="author" --> />
<input type="hidden" name="isbn" value=<!-- TMPL_VAR NAME="isbn" --> />
<input type="hidden" name="issn" value=<!-- TMPL_VAR NAME="issn" --> />
<input type="hidden" name="oldbiblionumber" value="<!-- TMPL_VAR NAME="oldbiblionumber" -->" />
<tr>
<th>Library</th>
<th>Select</th>
</tr>
<!-- TMPL_LOOP name="serverloop" -->
<tr bgcolor="<!-- TMPL_VAR NAME="toggle" -->">
<td><!-- TMPL_VAR NAME="server" --></td>
<td> <input type="checkbox" name="id" value=<!-- TMPL_VAR NAME="id" --> <!-- TMPL_IF name="checked" -->checked="1"<!-- /TMPL_IF --> ></td>
</tr>
<!-- /TMPL_LOOP -->
<tr><td><input type="submit" class="submit" value="Search internet" onclick="cursor :'wait'";
/></td></tr></form>
<!-- TMPL_ELSE -->
<caption>Bibliographic Records Found in <!-- TMPL_VAR NAME="server" --></caption>
<tr>
<th>Title</th>
<th>Author</th>
<th>ISBN</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<!-- TMPL_IF name="breeding_loop" -->
<!-- TMPL_LOOP name="breeding_loop" -->
<tr bgcolor="<!-- TMPL_VAR NAME="toggle" -->">
<td><!-- TMPL_VAR NAME="title" --></a>
<td><!-- TMPL_VAR NAME="author" --></td>
<td><!-- TMPL_VAR NAME="isbn" --></td>
<td><a href="javascript:Import(<!-- TMPL_VAR NAME="id" -->,<!-- TMPL_VAR NAME="oldbiblionumber" -->)">Import</a></td>
</tr>
<!-- /TMPL_LOOP -->
<!-- TMPL_ELSE -->
<p>Nothing found</p>
<tr><td colspan="6">Nothing found</td></tr>
<!-- /TMPL_IF -->
<script language="javascript" type="text/javascript">
function Import(GetThisOne) {
opener.document.location= "../acqui.simple/addbiblio.pl?z3950=1&oldbiblionumber=<!-- TMPL_VAR NAME="oldbiblionumber" -->&breedingid="+GetThisOne;
self.close();
return false;
}
</script>
</table>
<!-- /TMPL_IF -->
</div>
<!-- TMPL_IF name="numberpending" --><h3 align="center">Still <!-- TMPL_VAR NAME="numberpending" --> servers to search</h3><!-- /TMPL_IF -->
<script language="JavaScript" type="text/javascript">
function Import(GetThisOne,biblionumber) {
opener.document.location= "../acqui.simple/addbiblio.pl?oldbiblionumber="+biblionumber+"&z3950=1&breedingid="+GetThisOne;
self.close();
return false;
}
</script>
</div>
</body>
</html>
</html>

View File

@ -1,5 +1,5 @@
#!/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.
@ -19,98 +19,196 @@
use strict;
use CGI;
use C4::Auth;
use C4::Output;
use C4::Interface::CGI::Output;
use C4::Biblio;
use C4::Context;
use C4::Koha; # XXX subfield_is_koha_internal_p
use C4::Z3950;
use C4::Search;
use C4::Breeding;
use HTML::Template;
use MARC::File::USMARC;
use vars qw( $tagslib );
use vars qw( $is_a_modif );
use ZOOM;
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $error = $input->param('error');
my $bibid=$input->param('bibid');
my $oldbiblionumber=$input->param('oldbiblionumber');
$oldbiblionumber=0 unless $oldbiblionumber;
my $title = $input->param('title');
my $author = $input->param('author');
my $isbn = $input->param('isbn');
my $issn = $input->param('issn');
my $random = $input->param('random');
my $op=$input->param('op');
my $noconnection;
my $numberpending;
my $attr='';
my $term;
my $host;
my $server;
my $database;
my $port;
my $marcdata;
my @encoding;
my @results;
my $count;
my $toggle;
my $record;
my $biblionumber;
if ($bibid > 0) {
$record = MARCgetbiblio($dbh,$bibid);
$biblionumber=MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
my $oldbiblio;
my $dbh = C4::Context->dbh;
my $errmsg;
my @serverloop=();
my @serverhost;
my @breeding_loop = ();
unless ($random) { # this var is not useful anymore just kept to keep rel2_2 compatibility
$random =rand(1000000000);
}
my $errmsg;
unless ($random) { # if random is a parameter => we're just waiting for the search to end, it's a refresh.
if ($isbn) {
$random =rand(1000000000);
$errmsg = addz3950queue($isbn, "isbn", $random, 'CHECKED');
} elsif ($author) {
$random =rand(1000000000);
$errmsg = addz3950queue($author, "author", $random, 'CHECKED');
} elsif ($title) {
$random =rand(1000000000);
$errmsg = addz3950queue($title, "title", $random, 'CHECKED');
}
}
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "z3950/searchresult.tmpl",
my ($template, $loggedinuser, $cookie)= get_template_and_user({
template_name => "z3950/searchresult.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
authnotrequired => 1,
flagsrequired => {catalogue => 1},
debug => 1,
});
#MJR: check for pending then search results, else servers with fast
# z3950 links may miss results if the search completes between them
my $numberpending= &checkz3950searchdone($random);
# fill with books in breeding farm
($count, @results) = BreedingSearch($title,$isbn,$random);
my @breeding_loop = ();
for (my $i=0; $i <= $#results; $i++) {
my %row_data;
if ($i % 2) {
$toggle=1;
} else {
$toggle=0;
}
$row_data{toggle} = $toggle;
$row_data{id} = $results[$i]->{'id'};
$row_data{isbn} = $results[$i]->{'isbn'};
$row_data{file} = $results[$i]->{'file'};
$row_data{title} = $results[$i]->{'title'};
$row_data{author} = $results[$i]->{'author'};
push (@breeding_loop, \%row_data);
}
$template->param(isbn => $isbn,
title => $title,
author => $author,
breeding_loop => \@breeding_loop,
refresh => ($numberpending eq 0 ? "" : "search.pl?bibid=$bibid&random=$random"),
numberpending => $numberpending,
oldbiblionumber => $biblionumber,
$template->param(
intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
IntranetNav => C4::Context->preference("IntranetNav"),
);
print $input->header(
-type => guesstype($template->output),
-cookie => $cookie
),$template->output;
IntranetNav => C4::Context->preference("IntranetNav"));
if ($op ne "do_search"){
my $sth=$dbh->prepare("select id,host,checked from z3950servers order by host");
$sth->execute();
while ($server=$sth->fetchrow_hashref) {
my %temploop;
$temploop{server}=$server->{host};
$temploop{id}=$server->{id};
$temploop{checked}=$server->{checked};
push (@serverloop, \%temploop);
}
$template->param(isbn=>$isbn, issn=>$issn,title=>$title,author=>$author,
serverloop => \@serverloop,
opsearch => "search",
oldbiblionumber => $oldbiblionumber,
);
output_html_with_http_headers $input, $cookie, $template->output;
}else{
my @id=$input->param('id');
my @oConnection;
my @oResult;
my $s=0;
if ($isbn ne "/" || $issn ne "/") {
$attr='1=7';
$term=$isbn if ($isbn ne"/");
$term=$issn if ($issn ne"/");
} elsif ($title ne"/") {
$attr='1=4 @attr 4=1 ';
$term=$title;
} elsif ($author ne "/") {
$attr='1=1003';
$term=$author;
}
my $query="\@attr $attr \"$term\"";
foreach my $servid (@id){
my $sth=$dbh->prepare("select * from z3950servers where id=?");
$sth->execute($servid);
while ($server=$sth->fetchrow_hashref) {
my $noconnection=0;
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) || warn ("something went wrong: ".$oConnection[$s]->errmsg());
warn ("server data",$server->{name}, $server->{port});
$oConnection[$s]->connect($server->{host}, $server->{port}) || warn ("something went wrong: ".$oConnection[$s]->errmsg());
$serverhost[$s]=$server->{host};
$encoding[$s]=$server->{syntax};
$s++;
}## while fetch
}# foreach
my $nremaining = $s;
my $firstresult=1;
for (my $z=0 ;$z<$s;$z++){
warn "doing the search";
$oResult[$z] = $oConnection[$z]->search_pqf($query) || 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");
last if $event == ZOOM::Event::ZEND;
}
if ($k != 0) {
$k--;
warn $serverhost[$k];
my($error, $errmsg, $addinfo, $diagset) = $oConnection[$k]->error_x();
if ($error) {
warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n";
goto MAYBE_AGAIN;
}
my $numresults=$oResult[$k]->size() ;
my $i;
my $result='';
@breeding_loop = ();
if ($numresults>0){
for ($i=0; $i<(($numresults<5) ? ($numresults) : (5)) ; $i++) {
my $rec=$oResult[$k]->record($i);
my $marcrecord;
$marcdata = $rec->raw();
$marcrecord = MARC::File::USMARC::decode($marcdata);
####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
my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,"");
$oldbiblio->{isbn} =~ s/ |-|\.//g,
$oldbiblio->{issn} =~ s/ |-|\.//g,
my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$bid)=ImportBreeding($marcdata,1,$serverhost[$k],$encoding[$k],$random);
my %row_data;
if ($i % 2) {
$toggle="#ffffcc";
} else {
$toggle="white";
}
$row_data{toggle} = $toggle;
$row_data{server} = $serverhost[$k];
$row_data{isbn} = $oldbiblio->{isbn};
$row_data{title} =$oldbiblio->{title};
$row_data{author} = $oldbiblio->{author};
$row_data{id} = $bid;
$row_data{oldbiblionumber}=$oldbiblionumber;
push (@breeding_loop, \%row_data);
}# upto 5 results
}#$numresults
}# if $k !=0
$numberpending=$nremaining-1;
$template->param(breeding_loop => \@breeding_loop,server=>$serverhost[$k],
numberpending => $numberpending,
);
output_html_with_http_headers $input, "", $template->output if $firstresult==1;
print $template->output if $firstresult !=1;
$firstresult++;
MAYBE_AGAIN:
if (--$nremaining > 0) {
goto AGAIN;
}
} ## if op=search