3 # This is a completely new Z3950 clients search using async ZOOM -TG 02/11/06
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
34 my $dbh = C4
::Context
->dbh;
35 my $error = $input->param('error');
36 my $biblionumber = $input->param('biblionumber');
37 $biblionumber = 0 unless $biblionumber;
38 my $frameworkcode = $input->param('frameworkcode');
39 my $title = $input->param('title');
40 my $author = $input->param('author');
41 my $isbn = $input->param('isbn');
42 my $issn = $input->param('issn');
43 my $lccn = $input->param('lccn');
44 my $random = $input->param('random');
45 my $op = $input->param('op');
64 my @breeding_loop = ();
66 my $DEBUG = 0; # if set to 1, many debug message are send on syslog.
69 { # this var is not useful anymore just kept to keep rel2_2 compatibility
70 $random = rand(1000000000);
73 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
75 template_name
=> "cataloguing/z3950_search.tmpl",
79 flagsrequired
=> { catalogue
=> 1 },
84 $template->param( frameworkcode
=> $frameworkcode, );
86 if ( $op ne "do_search" ) {
87 my $sth = $dbh->prepare("select id,host,name,checked from z3950servers order by host");
89 my $serverloop = $sth->fetchall_arrayref( {} );
96 serverloop
=> $serverloop,
98 biblionumber
=> $biblionumber,
100 output_html_with_http_headers
$input, $cookie, $template->output;
103 my @id = $input->param('id');
108 if ( $isbn || $issn ) {
110 $term = $isbn if ($isbn);
111 $term = $issn if ($issn);
119 utf8
::decode
($title);
124 utf8
::decode
($author);
128 my $query = "\@attr $attr \"$term\"";
129 warn "query " . $query if $DEBUG;
130 foreach my $servid (@id) {
131 my $sth = $dbh->prepare("select * from z3950servers where id=?");
132 $sth->execute($servid);
133 while ( $server = $sth->fetchrow_hashref ) {
134 my $noconnection = 0;
135 my $option1 = new ZOOM
::Options
();
136 $option1->option( 'async' => 1 );
137 $option1->option( 'elementSetName', 'F' );
138 $option1->option( 'databaseName', $server->{db
} );
139 $option1->option( 'user', $server->{userid
} ) if $server->{userid
};
140 $option1->option( 'password', $server->{password
} )
141 if $server->{password
};
142 $option1->option( 'preferredRecordSyntax', $server->{syntax
} );
143 $oConnection[$s] = create ZOOM
::Connection
($option1)
145 && warn( "" . $oConnection[$s]->errmsg() );
146 warn( "server data", $server->{name
}, $server->{port
} ) if $DEBUG;
147 $oConnection[$s]->connect( $server->{host
}, $server->{port
} )
149 && warn( "" . $oConnection[$s]->errmsg() );
150 $serverhost[$s] = $server->{host
};
151 $encoding[$s] = ($server->{encoding
}?
$server->{encoding
}:"iso-5426");
158 for ( my $z = 0 ; $z < $s ; $z++ ) {
159 warn "doing the search" if $DEBUG;
160 $oResult[$z] = $oConnection[$z]->search_pqf($query)
162 && warn( "somthing went wrong: " . $oConnection[$s]->errmsg() );
164 # $oResult[$z] = $oConnection[$z]->search_pqf($query);
170 while ( ( $k = ZOOM
::event
( \
@oConnection ) ) != 0 ) {
171 $event = $oConnection[ $k - 1 ]->last_event();
172 warn( "connection ", $k - 1, ": event $event (",
173 ZOOM
::event_str
($event), ")\n" )
175 last if $event == ZOOM
::Event
::ZEND
;
180 warn $serverhost[$k] if $DEBUG;
181 my ( $error, $errmsg, $addinfo, $diagset ) =
182 $oConnection[$k]->error_x();
184 warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n"
189 my $numresults = $oResult[$k]->size();
192 if ( $numresults > 0 ) {
195 $i < ( ( $numresults < 20 ) ?
($numresults) : (20) ) ;
199 my $rec = $oResult[$k]->record($i);
201 $marcdata = $rec->raw();
203 my ($charset_result, $charset_errors);
204 ($marcrecord, $charset_result, $charset_errors) =
205 MarcToUTF8Record
($marcdata, C4
::Context
->preference('marcflavour'), $encoding[$k]);
206 ####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
207 ## In HEAD i change everything to UTF-8
208 # In rel2_2 i am not sure what encoding is so no character conversion is done here
209 ##Add necessary encoding changes to here -TG
210 my $oldbiblio = TransformMarcToKoha
( $dbh, $marcrecord, "" );
211 $oldbiblio->{isbn
} =~ s/ |-|\.//g,
212 $oldbiblio->{issn
} =~ s/ |-|\.//g,
214 $notmarcrecord, $alreadyindb, $alreadyinfarm,
215 $imported, $breedingid
217 = ImportBreeding
( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
225 $row_data{toggle
} = $toggle;
226 $row_data{server
} = $serverhost[$k];
227 $row_data{isbn
} = $oldbiblio->{isbn
};
228 $row_data{lccn
} = $oldbiblio->{lccn
};
229 $row_data{title
} = $oldbiblio->{title
};
230 $row_data{author
} = $oldbiblio->{author
};
231 $row_data{breedingid
} = $breedingid;
232 $row_data{biblionumber
} = $biblionumber;
233 push( @breeding_loop, \
%row_data );
238 $numberpending = $nremaining - 1;
240 breeding_loop
=> \
@breeding_loop,
241 server
=> $serverhost[$k],
242 numberpending
=> $numberpending,
245 output_html_with_http_headers
$input, $cookie, $template->output if $numberpending == 0;
247 # print $template->output if $firstresult !=1;
251 if ( --$nremaining > 0 ) {