View | Details | Raw Unified | Return to bug 9105
Collapse All | Expand All

(-)a/C4/Breeding.pm (-1 / +260 lines)
Lines 33-39 BEGIN { Link Here
33
    $VERSION = 3.07.00.049;
33
    $VERSION = 3.07.00.049;
34
	require Exporter;
34
	require Exporter;
35
	@ISA = qw(Exporter);
35
	@ISA = qw(Exporter);
36
	@EXPORT = qw(&ImportBreeding &BreedingSearch);
36
    @EXPORT = qw(&ImportBreeding &BreedingSearch &Z3950Search);
37
}
37
}
38
38
39
=head1 NAME
39
=head1 NAME
Lines 213-218 sub BreedingSearch { Link Here
213
    return($count, @results);
213
    return($count, @results);
214
} # sub breedingsearch
214
} # sub breedingsearch
215
215
216
217
=head2 Z3950Search
218
219
Z3950Search($pars, $template);
220
221
Parameters for Z3950 search are all passed via the $pars hash. It may contain isbn, title, author, dewey, subject, lccall, controlnumber, stdid, srchany.
222
Also it should contain an arrayref id that points to a list of id's of the z3950 targets to be queried (see z3950servers table).
223
This code is used in acqui/z3950_search and cataloging/z3950_search.
224
The second parameter $template is a Template object. The routine uses this parameter to store the found values into the template.
225
226
=cut
227
228
sub Z3950Search {
229
    my ($pars, $template)= @_;
230
231
    my $dbh   = C4::Context->dbh;
232
    my @id= @{$pars->{id}};
233
    my $random= $pars->{random};
234
    my $page= $pars->{page};
235
    my $biblionumber= $pars->{biblionumber};
236
237
    my $isbn= $pars->{isbn};
238
    my $issn= $pars->{issn};
239
    my $title= $pars->{title};
240
    my $author= $pars->{author};
241
    my $dewey= $pars->{dewey};
242
    my $subject= $pars->{subject};
243
    my $lccn= $pars->{lccn};
244
    my $lccall= $pars->{lccall};
245
    my $controlnumber= $pars->{controlnumber};
246
247
248
my $show_next       = 0;
249
my $total_pages     = 0;
250
251
my $noconnection;
252
my $attr = '';
253
my $term;
254
my $host;
255
my $server;
256
my $database;
257
my $port;
258
my $marcdata;
259
my @encoding;
260
my @results;
261
my $count;
262
my $toggle;
263
my $record;
264
my $oldbiblio;
265
my $errmsg;
266
my @serverhost;
267
my @servername;
268
my @breeding_loop = ();
269
270
271
    my @oConnection;
272
    my @oResult;
273
    my @errconn;
274
    my $s = 0;
275
    my $query;
276
    my $nterms=0;
277
    if ($isbn) {
278
        $term=$isbn;
279
        $query .= " \@attr 1=7 \@attr 5=1 \"$term\" ";
280
        $nterms++;
281
    }
282
    if ($issn) {
283
        $term=$issn;
284
        $query .= " \@attr 1=8 \@attr 5=1 \"$term\" ";
285
        $nterms++;
286
    }
287
    if ($title) {
288
        utf8::decode($title);
289
        $query .= " \@attr 1=4 \"$title\" ";
290
        $nterms++;
291
    }
292
    if ($author) {
293
        utf8::decode($author);
294
        $query .= " \@attr 1=1003 \"$author\" ";
295
        $nterms++;
296
    }
297
    if ($dewey) {
298
        $query .= " \@attr 1=16 \"$dewey\" ";
299
        $nterms++;
300
    }
301
    if ($subject) {
302
        utf8::decode($subject);
303
        $query .= " \@attr 1=21 \"$subject\" ";
304
        $nterms++;
305
    }
306
    if ($lccn) {
307
        $query .= " \@attr 1=9 $lccn ";
308
        $nterms++;
309
    }
310
    if ($lccall) {
311
        $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" ";
312
        $nterms++;
313
    }
314
    if ($controlnumber) {
315
        $query .= " \@attr 1=12 \"$controlnumber\" ";
316
        $nterms++;
317
    }
318
for my $i (1..$nterms-1) {
319
    $query = "\@and " . $query;
320
}
321
warn "query ".$query  if $DEBUG;
322
323
    foreach my $servid (@id) {
324
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
325
        $sth->execute($servid);
326
        while ( $server = $sth->fetchrow_hashref ) {
327
            warn "serverinfo ".join(':',%$server) if $DEBUG;
328
            my $option1      = new ZOOM::Options();
329
            $option1->option( 'async' => 1 );
330
            $option1->option( 'elementSetName', 'F' );
331
            $option1->option( 'databaseName',   $server->{db} );
332
            $option1->option( 'user', $server->{userid} ) if $server->{userid};
333
            $option1->option( 'password', $server->{password} )
334
              if $server->{password};
335
            $option1->option( 'preferredRecordSyntax', $server->{syntax} );
336
            $oConnection[$s] = create ZOOM::Connection($option1)
337
              || $DEBUG
338
              && warn( "" . $oConnection[$s]->errmsg() );
339
            warn( "server data", $server->{name}, $server->{port} ) if $DEBUG;
340
            $oConnection[$s]->connect( $server->{host}, $server->{port} )
341
              || $DEBUG
342
              && warn( "" . $oConnection[$s]->errmsg() );
343
            $serverhost[$s] = $server->{host};
344
            $servername[$s] = $server->{name};
345
            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
346
            $s++;
347
        }    ## while fetch
348
    }    # foreach
349
    my $nremaining  = $s;
350
    my $firstresult = 1;
351
352
    for ( my $z = 0 ; $z < $s ; $z++ ) {
353
        warn "doing the search" if $DEBUG;
354
        $oResult[$z] = $oConnection[$z]->search_pqf($query)
355
          || $DEBUG
356
          && warn( "somthing went wrong: " . $oConnection[$s]->errmsg() );
357
358
        # $oResult[$z] = $oConnection[$z]->search_pqf($query);
359
    }
360
361
  warn "# nremaining = $nremaining\n" if $DEBUG;
362
363
  while ( $nremaining-- ) {
364
365
    my $k;
366
    my $event;
367
    while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
368
        $event = $oConnection[ $k - 1 ]->last_event();
369
        warn( "connection ", $k - 1, ": event $event (",
370
            ZOOM::event_str($event), ")\n" )
371
          if $DEBUG;
372
        last if $event == ZOOM::Event::ZEND;
373
    }
374
375
    if ( $k != 0 ) {
376
        $k--;
377
        warn "event from $k server = ",$serverhost[$k] if $DEBUG;
378
        my ( $error, $errmsg, $addinfo, $diagset ) =
379
          $oConnection[$k]->error_x();
380
        if ($error) {
381
            if ($error =~ m/^(10000|10007)$/ ) {
382
                push(@errconn, {'server' => $serverhost[$k]});
383
            }
384
            $DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n";
385
        }
386
        else {
387
            my $numresults = $oResult[$k]->size();
388
            warn "numresults = $numresults" if $DEBUG;
389
            my $i;
390
            my $result = '';
391
            if ( $numresults > 0  and $numresults >= (($page-1)*20)) {
392
                $show_next = 1 if $numresults >= ($page*20);
393
                $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
394
                for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
395
                    my $rec = $oResult[$k]->record($i);
396
                    if ($rec) {
397
                        my $marcrecord;
398
                        $marcdata   = $rec->raw();
399
400
                        my ($charset_result, $charset_errors);
401
                        ($marcrecord, $charset_result, $charset_errors) =
402
                          MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]);
403
####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
404
## In HEAD i change everything to UTF-8
405
# In rel2_2 i am not sure what encoding is so no character conversion is done here
406
##Add necessary encoding changes to here -TG
407
408
                        # Normalize the record so it doesn't have separated diacritics
409
                        SetUTF8Flag($marcrecord);
410
411
                        my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" );
412
                        $oldbiblio->{isbn}   =~ s/ |-|\.//g if $oldbiblio->{isbn};
413
                        # pad | and ( with spaces to allow line breaks in the HTML
414
                        $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn};
415
                        $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn};
416
417
                        $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn};
418
                        # pad | and ( with spaces to allow line breaks in the HTML
419
                        $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn};
420
                        $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn};
421
                          my (
422
                            $notmarcrecord, $alreadyindb, $alreadyinfarm,
423
                            $imported,      $breedingid
424
                          )
425
                          = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
426
                        my %row_data;
427
                        $row_data{server}       = $servername[$k];
428
                        $row_data{isbn}         = $oldbiblio->{isbn};
429
                        $row_data{lccn}         = $oldbiblio->{lccn};
430
                        $row_data{title}        = $oldbiblio->{title};
431
                        $row_data{author}       = $oldbiblio->{author};
432
                        $row_data{breedingid}   = $breedingid;
433
                        $row_data{biblionumber} = $biblionumber;
434
                        push( @breeding_loop, \%row_data );
435
436
                    } else {
437
                        push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1});
438
                    } # $rec
439
                }    # upto 5 results
440
            }    #$numresults
441
        }
442
    }    # if $k !=0
443
    my $numberpending = $nremaining - 1;
444
445
    my @servers = ();
446
    foreach my $id (@id) {
447
        push(@servers,{id => $id});
448
    }
449
450
    $template->param(
451
        breeding_loop => \@breeding_loop,
452
        server        => $servername[$k],
453
        numberpending => $numberpending,
454
        current_page => $page,
455
        servers => \@servers,
456
        total_pages => $total_pages,
457
    );
458
    $template->param(show_nextbutton=>1) if $show_next;
459
    $template->param(show_prevbutton=>1) if $page != 1;
460
461
    #  print  $template->output  if $firstresult !=1;
462
    $firstresult++;
463
464
  } # while nremaining
465
466
    $template->param(
467
        breeding_loop => \@breeding_loop,
468
        #server        => $servername[$k],
469
        numberpending => $nremaining > 0 ? $nremaining : 0,
470
        errconn       => \@errconn
471
    );
472
473
}
474
216
1;
475
1;
217
__END__
476
__END__
218
477
(-)a/acqui/z3950_search.pl (-259 / +38 lines)
Lines 25-37 use CGI; Link Here
25
25
26
use C4::Auth;
26
use C4::Auth;
27
use C4::Output;
27
use C4::Output;
28
use C4::Biblio;
28
#use C4::Biblio;
29
use C4::Context;
29
use C4::Context;
30
use C4::Breeding;
30
use C4::Breeding;
31
use C4::Koha;
31
use C4::Koha;
32
use C4::Charset;
32
#use C4::Charset;
33
use C4::Bookseller qw/ GetBookSellerFromId /;
33
use C4::Bookseller qw/ GetBookSellerFromId /;
34
use ZOOM;
34
#use ZOOM;
35
35
36
my $input        = new CGI;
36
my $input        = new CGI;
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 47-56 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
47
47
48
48
49
my $dbh             = C4::Context->dbh;
49
my $dbh             = C4::Context->dbh;
50
my $error           = $input->param('error');
50
my $biblionumber    = $input->param('biblionumber')||0;
51
my $biblionumber    = $input->param('biblionumber');
51
my $frameworkcode   = $input->param('frameworkcode')||'';
52
$biblionumber       = 0 unless $biblionumber;
53
my $frameworkcode   = $input->param('frameworkcode');
54
my $title           = $input->param('title');
52
my $title           = $input->param('title');
55
my $author          = $input->param('author');
53
my $author          = $input->param('author');
56
my $isbn            = $input->param('isbn');
54
my $isbn            = $input->param('isbn');
Lines 60-99 my $lccall = $input->param('lccall'); Link Here
60
my $subject         = $input->param('subject');
58
my $subject         = $input->param('subject');
61
my $dewey           = $input->param('dewey');
59
my $dewey           = $input->param('dewey');
62
my $controlnumber   = $input->param('controlnumber');
60
my $controlnumber   = $input->param('controlnumber');
63
my $op              = $input->param('op');
61
my $op              = $input->param('op')||'';
64
my $booksellerid    = $input->param('booksellerid');
62
my $booksellerid    = $input->param('booksellerid');
65
my $basketno        = $input->param('basketno');
63
my $basketno        = $input->param('basketno');
66
64
67
my $page            = $input->param('current_page') || 1;
65
my $page            = $input->param('current_page') || 1;
68
$page               = $input->param('goto_page') if $input->param('changepage_goto');
66
$page               = $input->param('goto_page') if $input->param('changepage_goto');
69
my $show_next       = 0;
70
my $total_pages     = 0;
71
72
my $noconnection;
73
my $attr = '';
74
my $term;
75
my $host;
76
my $server;
77
my $database;
78
my $port;
79
my $marcdata;
80
my @encoding;
81
my @results;
82
my $count;
83
my $toggle;
84
my $record;
85
my $oldbiblio;
86
my $errmsg;
87
my @serverhost;
88
my @servername;
89
my @breeding_loop = ();
90
my $random        = $input->param('random');
91
unless ($random)
92
{    # this var is not useful anymore just kept to keep rel2_2 compatibility
93
    $random = rand(1000000000);
94
}
95
96
my $DEBUG = $ENV{DEBUG} || 0;    # if set to 1, many debug message are send on syslog.
97
67
98
# get framework list
68
# get framework list
99
my $frameworks = getframeworks;
69
my $frameworks = getframeworks;
Lines 114-136 $template->param( frameworkcode => $frameworkcode, Link Here
114
                                    frameworkcodeloop => \@frameworkcodeloop,
84
                                    frameworkcodeloop => \@frameworkcodeloop,
115
                                    booksellerid => $booksellerid,
85
                                    booksellerid => $booksellerid,
116
                                    basketno => $basketno,
86
                                    basketno => $basketno,
117
                                    name => $vendor->{'name'}
87
                                    name => $vendor->{'name'},
88
        isbn         => $isbn,
89
        issn         => $issn,
90
        lccn         => $lccn,
91
        lccall       => $lccall,
92
        title        => $title,
93
        author       => $author,
94
        controlnumber=> $controlnumber,
95
        biblionumber => $biblionumber,
96
        dewey        => $dewey,
97
        subject      => $subject,
118
                                    );
98
                                    );
119
                                    
99
                                    
120
121
$template->param(
122
    isbn         => $isbn,
123
    issn         => $issn,
124
    lccn         => $lccn,
125
    lccall       => $lccall,
126
    title        => $title,
127
    author       => $author,
128
    controlnumber=> $controlnumber,
129
    biblionumber => $biblionumber,
130
    dewey        => $dewey,
131
    subject      => $subject,
132
);
133
134
if ( $op ne "do_search" ) {
100
if ( $op ne "do_search" ) {
135
    my $sth = $dbh->prepare("select id,host,name,checked from z3950servers  order by host");
101
    my $sth = $dbh->prepare("select id,host,name,checked from z3950servers  order by host");
136
    $sth->execute();
102
    $sth->execute();
Lines 143-356 if ( $op ne "do_search" ) { Link Here
143
    exit;
109
    exit;
144
}
110
}
145
111
146
    my @id = $input->param('id');
112
my @id = $input->param('id');
147
113
if (@id==0) {
148
    if ( not @id ) {
114
    $template->param( emptyserverlist => 1 );
149
        # empty server list -> report and exit
115
    output_html_with_http_headers $input, $cookie, $template->output;
150
        $template->param( emptyserverlist => 1 );
116
    exit;
151
        output_html_with_http_headers $input, $cookie, $template->output;
152
        exit;
153
    }
154
155
    my @oConnection;
156
    my @oResult;
157
    my @errconn;
158
    my $s = 0;
159
    my $query;
160
    my $nterms;
161
    if ($isbn) {
162
        $term=$isbn;
163
        $query .= " \@attr 1=7 \@attr 5=1 \"$term\" ";
164
        $nterms++;
165
    }
166
    if ($issn) {
167
        $term=$issn;
168
        $query .= " \@attr 1=8 \@attr 5=1 \"$term\" ";
169
        $nterms++;
170
    }
171
    if ($title) {
172
        utf8::decode($title);
173
        $query .= " \@attr 1=4 \"$title\" ";
174
        $nterms++;
175
    }
176
    if ($author) {
177
        utf8::decode($author);
178
        $query .= " \@attr 1=1003 \"$author\" ";
179
        $nterms++;
180
    }
181
    if ($dewey) {
182
        $query .= " \@attr 1=16 \"$dewey\" ";
183
        $nterms++;
184
    }
185
    if ($subject) {
186
        utf8::decode($subject);
187
        $query .= " \@attr 1=21 \"$subject\" ";
188
        $nterms++;
189
    }
190
    if ($lccn) {
191
        $query .= " \@attr 1=9 $lccn ";
192
        $nterms++;
193
    }
194
    if ($lccall) {
195
        $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" ";
196
        $nterms++;
197
    }
198
    if ($controlnumber) {
199
        $query .= " \@attr 1=12 \"$controlnumber\" ";
200
        $nterms++;
201
    }
202
for my $i (1..$nterms-1) {
203
    $query = "\@and " . $query;
204
}
117
}
205
warn "query ".$query  if $DEBUG;
206
207
    foreach my $servid (@id) {
208
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
209
        $sth->execute($servid);
210
        while ( $server = $sth->fetchrow_hashref ) {
211
            warn "serverinfo ".join(':',%$server) if $DEBUG;
212
            my $option1      = new ZOOM::Options();
213
            $option1->option( 'async' => 1 );
214
            $option1->option( 'elementSetName', 'F' );
215
            $option1->option( 'databaseName',   $server->{db} );
216
            $option1->option( 'user', $server->{userid} ) if $server->{userid};
217
            $option1->option( 'password', $server->{password} )
218
              if $server->{password};
219
            $option1->option( 'preferredRecordSyntax', $server->{syntax} );
220
            $oConnection[$s] = create ZOOM::Connection($option1)
221
              || $DEBUG
222
              && warn( "" . $oConnection[$s]->errmsg() );
223
            warn( "server data", $server->{name}, $server->{port} ) if $DEBUG;
224
            $oConnection[$s]->connect( $server->{host}, $server->{port} )
225
              || $DEBUG
226
              && warn( "" . $oConnection[$s]->errmsg() );
227
            $serverhost[$s] = $server->{host};
228
            $servername[$s] = $server->{name};
229
            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
230
            $s++;
231
        }    ## while fetch
232
    }    # foreach
233
    my $nremaining  = $s;
234
    my $firstresult = 1;
235
118
236
    for ( my $z = 0 ; $z < $s ; $z++ ) {
119
my $pars= {
237
        warn "doing the search" if $DEBUG;
120
        random => $input->param('random') || rand(1000000000),
238
        $oResult[$z] = $oConnection[$z]->search_pqf($query)
121
        biblionumber => $biblionumber,
239
          || $DEBUG
122
        page => $page,
240
          && warn( "somthing went wrong: " . $oConnection[$s]->errmsg() );
123
        id => \@id,
241
124
        isbn => $isbn,
242
        # $oResult[$z] = $oConnection[$z]->search_pqf($query);
125
        title => $title,
243
    }
126
        author => $author,
244
127
        dewey => $dewey,
245
  warn "# nremaining = $nremaining\n" if $DEBUG;
128
        subject => $subject,
246
129
        lccall => $lccall,
247
  while ( $nremaining-- ) {
130
        controlnumber => $controlnumber,
248
131
        stdid => 0,
249
    my $k;
132
        srchany => 0,
250
    my $event;
133
};
251
    while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
134
Z3950Search($pars, $template);
252
        $event = $oConnection[ $k - 1 ]->last_event();
253
        warn( "connection ", $k - 1, ": event $event (",
254
            ZOOM::event_str($event), ")\n" )
255
          if $DEBUG;
256
        last if $event == ZOOM::Event::ZEND;
257
    }
258
259
    if ( $k != 0 ) {
260
        $k--;
261
        warn "event from $k server = ",$serverhost[$k] if $DEBUG;
262
        my ( $error, $errmsg, $addinfo, $diagset ) =
263
          $oConnection[$k]->error_x();
264
        if ($error) {
265
            if ($error =~ m/^(10000|10007)$/ ) {
266
                push(@errconn, {'server' => $serverhost[$k]});
267
            }
268
            $DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n";
269
        }
270
        else {
271
            my $numresults = $oResult[$k]->size();
272
            warn "numresults = $numresults" if $DEBUG;
273
            my $i;
274
            my $result = '';
275
            if ( $numresults > 0  and $numresults >= (($page-1)*20)) {
276
                $show_next = 1 if $numresults >= ($page*20);
277
                $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
278
                for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
279
                    my $rec = $oResult[$k]->record($i);
280
                    if ($rec) {
281
                        my $marcrecord;
282
                        $marcdata   = $rec->raw();
283
284
                        my ($charset_result, $charset_errors);
285
                        ($marcrecord, $charset_result, $charset_errors) = 
286
                          MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]);
287
####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
288
## In HEAD i change everything to UTF-8
289
# In rel2_2 i am not sure what encoding is so no character conversion is done here
290
##Add necessary encoding changes to here -TG
291
292
                        # Normalize the record so it doesn't have separated diacritics
293
                        SetUTF8Flag($marcrecord);
294
295
                        my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" );
296
                        $oldbiblio->{isbn}   =~ s/ |-|\.//g if $oldbiblio->{isbn};
297
                        # pad | and ( with spaces to allow line breaks in the HTML
298
                        $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn};
299
                        $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn};
300
301
                        $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn};
302
                        # pad | and ( with spaces to allow line breaks in the HTML
303
                        $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn};
304
                        $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn};
305
                          my (
306
                            $notmarcrecord, $alreadyindb, $alreadyinfarm,
307
                            $imported,      $breedingid
308
                          )
309
                          = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
310
                        my %row_data;
311
                        $row_data{server}       = $servername[$k];
312
                        $row_data{isbn}         = $oldbiblio->{isbn};
313
                        $row_data{lccn}         = $oldbiblio->{lccn};
314
                        $row_data{title}        = $oldbiblio->{title};
315
                        $row_data{author}       = $oldbiblio->{author};
316
                        $row_data{breedingid}   = $breedingid;
317
                        $row_data{biblionumber} = $biblionumber;
318
                        push( @breeding_loop, \%row_data );
319
320
                    } else {
321
                        push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1});
322
                    } # $rec
323
                }    # upto 5 results
324
            }    #$numresults
325
        }
326
    }    # if $k !=0
327
    my $numberpending = $nremaining - 1;
328
329
    my @servers = ();
330
    foreach my $id (@id) {
331
        push(@servers,{id => $id});
332
    }
333
334
    $template->param(
335
        breeding_loop => \@breeding_loop,
336
        server        => $servername[$k],
337
        numberpending => $numberpending,
338
        current_page => $page,
339
        servers => \@servers,
340
        total_pages => $total_pages,
341
    );
342
    $template->param(show_nextbutton=>1) if $show_next;
343
    $template->param(show_prevbutton=>1) if $page != 1;
344
345
    #  print  $template->output  if $firstresult !=1;
346
    $firstresult++;
347
348
  } # while nremaining
349
350
$template->param(
351
breeding_loop => \@breeding_loop,
352
#server        => $servername[$k],
353
numberpending => $nremaining > 0 ? $nremaining : 0,
354
errconn       => \@errconn
355
);
356
output_html_with_http_headers $input, $cookie, $template->output;
135
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/cataloguing/z3950_search.pl (-241 / +25 lines)
Lines 19-35 Link Here
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
20
21
use strict;
21
use strict;
22
#use warnings; FIXME - Bug 2505
22
use warnings;
23
use CGI;
23
use CGI;
24
24
25
use C4::Auth;
25
use C4::Auth;
26
use C4::Output;
26
use C4::Output;
27
use C4::Biblio;
27
#use C4::Biblio;
28
use C4::Context;
28
use C4::Context;
29
use C4::Breeding;
29
use C4::Breeding;
30
use C4::Koha;
30
use C4::Koha;
31
use C4::Charset;
31
#use C4::Charset;
32
use ZOOM;
32
#use ZOOM;
33
33
34
my $input        = new CGI;
34
my $input        = new CGI;
35
my $dbh          = C4::Context->dbh;
35
my $dbh          = C4::Context->dbh;
Lines 47-80 my $dewey = $input->param('dewey'); Link Here
47
my $controlnumber	= $input->param('controlnumber');
47
my $controlnumber	= $input->param('controlnumber');
48
my $stdid			= $input->param('stdid');
48
my $stdid			= $input->param('stdid');
49
my $srchany			= $input->param('srchany');
49
my $srchany			= $input->param('srchany');
50
my $random        = $input->param('random') || rand(1000000000); # this var is not useful anymore just kept for rel2_2 compatibility
50
my $op            = $input->param('op')||'';
51
my $op            = $input->param('op');
52
51
53
my $page            = $input->param('current_page') || 1;
52
my $page            = $input->param('current_page') || 1;
54
$page = $input->param('goto_page') if $input->param('changepage_goto');
53
$page = $input->param('goto_page') if $input->param('changepage_goto');
55
my $show_next = 0;
56
my $total_pages = 0;
57
58
my $numberpending;
59
my $attr = '';
60
my $term;
61
my $host;
62
my $server;
63
my $database;
64
my $port;
65
my $marcdata;
66
my @encoding;
67
my @results;
68
my $count;
69
my $record;
70
my $oldbiblio;
71
my $errmsg;
72
my @serverloop = ();
73
my @serverhost;
74
my @servername;
75
my @breeding_loop = ();
76
77
my $DEBUG = 0;    # if set to 1, many debug message are send on syslog.
78
54
79
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
55
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
80
        template_name   => "cataloguing/z3950_search.tmpl",
56
        template_name   => "cataloguing/z3950_search.tmpl",
Lines 110-331 if ( $op ne "do_search" ) { Link Here
110
        opsearch     => "search",
86
        opsearch     => "search",
111
    );
87
    );
112
    output_html_with_http_headers $input, $cookie, $template->output;
88
    output_html_with_http_headers $input, $cookie, $template->output;
89
    exit;
113
}
90
}
114
else {
115
    my @id = $input->param('id');
116
91
117
    if ( not defined @id ) {
92
my @id = $input->param('id');
93
if ( @id==0 ) {
118
        # empty server list -> report and exit
94
        # empty server list -> report and exit
119
        $template->param( emptyserverlist => 1 );
95
        $template->param( emptyserverlist => 1 );
120
        output_html_with_http_headers $input, $cookie, $template->output;
96
        output_html_with_http_headers $input, $cookie, $template->output;
121
        exit;
97
        exit;
122
    }
123
124
    my @oConnection;
125
    my @oResult;
126
    my @errconn;
127
    my $s = 0;
128
    my $query = '';
129
    my $nterms;
130
    if ($isbn) {
131
        $term=$isbn;
132
        $query .= " \@attr 1=7 \@attr 5=1 \"$term\" ";
133
        $nterms++;
134
    }
135
    if ($issn) {
136
        $term=$issn;
137
        $query .= " \@attr 1=8 \@attr 5=1 \"$term\" ";
138
        $nterms++;
139
    }
140
    if ($title) {
141
        utf8::decode($title);
142
        $query .= " \@attr 1=4 \"$title\" ";
143
        $nterms++;
144
    }
145
    if ($author) {
146
        utf8::decode($author);
147
        $query .= " \@attr 1=1003 \"$author\" ";
148
        $nterms++;
149
    }
150
    if ($dewey) {
151
        $query .= " \@attr 1=16 \"$dewey\" ";
152
        $nterms++;
153
    }
154
    if ($subject) {
155
        utf8::decode($subject);
156
        $query .= " \@attr 1=21 \"$subject\" ";
157
        $nterms++;
158
    }
159
	if ($lccn) {	
160
        $query .= " \@attr 1=9 $lccn ";
161
        $nterms++;
162
    }
163
    if ($lccall) {
164
        $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" ";
165
        $nterms++;
166
    }
167
    if ($controlnumber) {
168
        $query .= " \@attr 1=12 \"$controlnumber\" ";
169
        $nterms++;
170
    }
171
    if ($stdid) {
172
        $query .= " \@attr 1=1007 \"$stdid\" ";
173
        $nterms++;
174
    }
175
    if ($srchany) {
176
        $query .= " \@attr 1=1016 \"$srchany\" ";
177
        $nterms++;
178
    }
179
for my $i (1..$nterms-1) {
180
    $query = "\@and " . $query;
181
}
98
}
182
warn "query ".$query  if $DEBUG;
183
184
    foreach my $servid (@id) {
185
        my $sth = $dbh->prepare("SELECT * FROM z3950servers WHERE id=? ORDER BY rank, name");
186
        $sth->execute($servid);
187
        while ( $server = $sth->fetchrow_hashref ) {
188
            warn "serverinfo ".join(':',%$server) if $DEBUG;
189
            my $option1      = new ZOOM::Options();
190
            $option1->option('async' => 1);
191
            $option1->option('elementSetName', 'F');
192
            $option1->option('databaseName', $server->{db});
193
            $option1->option('user',         $server->{userid}  ) if $server->{userid};
194
            $option1->option('password',     $server->{password}) if $server->{password};
195
            $option1->option('preferredRecordSyntax', $server->{syntax});
196
            $option1->option( 'timeout', $server->{timeout} ) if ($server->{timeout});
197
            $oConnection[$s] = create ZOOM::Connection($option1)
198
              || $DEBUG
199
              && warn( "" . $oConnection[$s]->errmsg() );
200
            warn( "server data", $server->{name}, $server->{port} ) if $DEBUG;
201
            $oConnection[$s]->connect( $server->{host}, $server->{port} )
202
              || $DEBUG
203
              && warn( "" . $oConnection[$s]->errmsg() );
204
            $serverhost[$s] = $server->{host};
205
            $servername[$s] = $server->{name};
206
            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
207
            $s++;
208
        }    ## while fetch
209
    }    # foreach
210
    my $nremaining  = $s;
211
    my $firstresult = 1;
212
213
    for ( my $z = 0 ; $z < $s ; $z++ ) {
214
        warn "doing the search" if $DEBUG;
215
        $oResult[$z] = $oConnection[$z]->search_pqf($query)
216
          || $DEBUG
217
          && warn( "somthing went wrong: " . $oConnection[$s]->errmsg() );
218
219
        # $oResult[$z] = $oConnection[$z]->search_pqf($query);
220
    }
221
222
  AGAIN:
223
    my $k;
224
    my $event;
225
    while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
226
        $event = $oConnection[ $k - 1 ]->last_event();
227
        warn( "connection ", $k - 1, ": event $event (",
228
            ZOOM::event_str($event), ")\n" )
229
          if $DEBUG;
230
        last if $event == ZOOM::Event::ZEND;
231
    }
232
233
    if ( $k != 0 ) {
234
        $k--;
235
        warn $serverhost[$k] if $DEBUG;
236
        my ( $error, $errmsg, $addinfo, $diagset ) =
237
          $oConnection[$k]->error_x();
238
        if ($error) {
239
            if ($error =~ m/^(10000|10007)$/ ) {
240
                push(@errconn, {'server' => $serverhost[$k], 'error' => $error});
241
            }
242
            $DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n";
243
        }
244
        else {
245
            my $numresults = $oResult[$k]->size();
246
            my $i;
247
            my $result = '';
248
            if ( $numresults > 0  and $numresults >= (($page-1)*20)) {
249
                $show_next = 1 if $numresults >= ($page*20);
250
                $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
251
                for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
252
                    my $rec = $oResult[$k]->record($i);
253
                    if ($rec) {
254
                        my $marcrecord;
255
                        $marcdata   = $rec->raw();
256
257
                        my ($charset_result, $charset_errors);
258
                        ($marcrecord, $charset_result, $charset_errors) = 
259
                          MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]);
260
####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
261
## In HEAD i change everything to UTF-8
262
# In rel2_2 i am not sure what encoding is so no character conversion is done here
263
##Add necessary encoding changes to here -TG
264
265
                        # Normalize the record so it doesn't have separated diacritics
266
                        SetUTF8Flag($marcrecord);
267
268
                        my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" );
269
                        $oldbiblio->{isbn}   =~ s/ |-|\.//g if $oldbiblio->{isbn};
270
                        # pad | and ( with spaces to allow line breaks in the HTML
271
                        $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn};
272
                        $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn};
273
274
                        $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn};
275
                        # pad | and ( with spaces to allow line breaks in the HTML
276
                        $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn};
277
                        $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn};
278
                          my (
279
                            $notmarcrecord, $alreadyindb, $alreadyinfarm,
280
                            $imported,      $breedingid
281
                          )
282
                          = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
283
                        my %row_data;
284
                        $row_data{server}       = $servername[$k];
285
                        $row_data{isbn}         = $oldbiblio->{isbn};
286
                        $row_data{lccn}         = $oldbiblio->{lccn};
287
                        $row_data{title}        = $oldbiblio->{title};
288
                        $row_data{author}       = $oldbiblio->{author};
289
                        $row_data{date}         = $oldbiblio->{copyrightdate};
290
                        $row_data{edition}      = $oldbiblio->{editionstatement};
291
                        $row_data{breedingid}   = $breedingid;
292
                        $row_data{biblionumber} = $biblionumber;
293
                        push( @breeding_loop, \%row_data );
294
		            
295
                    } else {
296
                        push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1});
297
                    } # $rec
298
                }
299
            }    #$numresults
300
        }
301
    }    # if $k !=0
302
    $numberpending = $nremaining - 1;
303
304
    my @servers = ();
305
    foreach my $id (@id) {
306
        push(@servers,{id => $id});
307
    }
308
309
    $template->param(
310
        breeding_loop => \@breeding_loop,
311
        server        => $servername[$k],
312
        numberpending => $numberpending,
313
        biblionumber  => $biblionumber,
314
        errconn       => \@errconn,
315
        current_page => $page,
316
        servers => \@servers,
317
        total_pages => $total_pages,
318
    );
319
    $template->param(show_nextbutton=>1) if $show_next;
320
    $template->param(show_prevbutton=>1) if $page != 1;
321
    
322
    output_html_with_http_headers $input, $cookie, $template->output if $numberpending == 0;
323
324
    #  	print  $template->output  if $firstresult !=1;
325
    $firstresult++;
326
99
327
  MAYBE_AGAIN:
100
my $pars= {
328
    if ( --$nremaining > 0 ) {
101
        random => $input->param('random') || rand(1000000000),
329
        goto AGAIN;
102
        biblionumber => $biblionumber,
330
    }
103
        page => $page,
331
}    ## if op=search
104
        id => \@id,
105
        isbn => $isbn,
106
        title => $title,
107
        author => $author,
108
        dewey => $dewey,
109
        subject => $subject,
110
        lccall => $lccall,
111
        controlnumber => $controlnumber,
112
        stdid => 0,
113
        srchany => 0,
114
};
115
Z3950Search($pars, $template);
116
output_html_with_http_headers $input, $cookie, $template->output;
332
- 

Return to bug 9105