Bug 12561: Add warning on about page
[koha.git] / C4 / Breeding.pm
1 package C4::Breeding;
2
3 # Copyright 2000-2002 Katipo Communications
4 # Parts Copyright 2013 Prosentient Systems
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use strict;
22 use warnings;
23
24 use C4::Biblio;
25 use C4::Koha qw( GetNormalizedISBN );
26 use C4::Charset qw( MarcToUTF8Record SetUTF8Flag );
27 use MARC::File::USMARC;
28 use MARC::Field;
29 use C4::ImportBatch qw( GetZ3950BatchId AddBiblioToBatch AddAuthToBatch );
30 use C4::AuthoritiesMarc qw( GuessAuthTypeCode );
31 use C4::Languages;
32 use Koha::Database;
33 use Koha::XSLT::Base;
34
35 our (@ISA, @EXPORT_OK);
36 BEGIN {
37     require Exporter;
38     @ISA       = qw(Exporter);
39     @EXPORT_OK = qw(BreedingSearch Z3950Search Z3950SearchAuth);
40 }
41
42 =head1 NAME
43
44 C4::Breeding : module to add biblios to import_records via
45                the breeding/reservoir API.
46
47 =head1 SYNOPSIS
48
49     Z3950Search($pars, $template);
50     ($count, @results) = &BreedingSearch($title,$isbn);
51
52 =head1 DESCRIPTION
53
54 This module contains routines related to Koha's Z39.50 search into
55 cataloguing reservoir features.
56
57 =head2 BreedingSearch
58
59 ($count, @results) = &BreedingSearch($title,$isbn);
60 C<$title> contains the title,
61 C<$isbn> contains isbn or issn,
62
63 C<$count> is the number of items in C<@results>. C<@results> is an
64 array of references-to-hash; the keys are the items from the C<import_records> and
65 C<import_biblios> tables of the Koha database.
66
67 =cut
68
69 sub BreedingSearch {
70     my ($search,$isbn) = @_;
71     my $dbh   = C4::Context->dbh;
72     my $count = 0;
73     my ($query,@bind);
74     my $sth;
75     my @results;
76
77     # normalise ISBN like at import
78     $isbn = C4::Koha::GetNormalizedISBN($isbn);
79
80     $query = "SELECT import_record_id, file_name, isbn, title, author
81               FROM  import_biblios 
82               JOIN import_records USING (import_record_id)
83               JOIN import_batches USING (import_batch_id)
84               WHERE ";
85     @bind=();
86     if (defined($search) && length($search)>0) {
87         $search =~ s/(\s+)/\%/g;
88         $query .= "title like ? OR author like ?";
89         push(@bind,"%$search%", "%$search%");
90     }
91     if ($#bind!=-1 && defined($isbn) && length($isbn)>0) {
92         $query .= " and ";
93     }
94     if (defined($isbn) && length($isbn)>0) {
95         $query .= "isbn like ?";
96         push(@bind,"$isbn%");
97     }
98     $sth = $dbh->prepare($query);
99     $sth->execute(@bind);
100     while (my $data = $sth->fetchrow_hashref) {
101             $results[$count] = $data;
102             # FIXME - hack to reflect difference in name 
103             # of columns in old marc_breeding and import_records
104             # There needs to be more separation between column names and 
105             # field names used in the templates </soapbox>
106             $data->{'file'} = $data->{'file_name'};
107             $data->{'id'} = $data->{'import_record_id'};
108             $count++;
109     } # while
110
111     $sth->finish;
112     return($count, @results);
113 } # sub breedingsearch
114
115
116 =head2 Z3950Search
117
118 Z3950Search($pars, $template);
119
120 Parameters for Z3950 search are all passed via the $pars hash. It may contain isbn, title, author, dewey, subject, lccall, controlnumber, stdid, srchany.
121 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).
122 This code is used in acqui/z3950_search and cataloging/z3950_search.
123 The second parameter $template is a Template object. The routine uses this parameter to store the found values into the template.
124
125 =cut
126
127 sub Z3950Search {
128     my ($pars, $template)= @_;
129
130     my @id= @{$pars->{id}};
131     my $page= $pars->{page};
132     my $biblionumber= $pars->{biblionumber};
133
134     my $show_next       = 0;
135     my $total_pages     = 0;
136     my @results;
137     my @breeding_loop = ();
138     my @oConnection;
139     my @oResult;
140     my @errconn;
141     my $s = 0;
142     my $imported=0;
143
144     my ( $zquery, $squery ) = _bib_build_query( $pars );
145
146     my $schema = Koha::Database->new()->schema();
147     my $rs = $schema->resultset('Z3950server')->search(
148         { id => [ @id ] },
149         { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
150     );
151     my @servers = $rs->all;
152     foreach my $server ( @servers ) {
153         my $server_zquery = $zquery;
154         if(my $attributes = $server->{attributes}){
155             $server_zquery = "$attributes $zquery";
156         }
157         $oConnection[$s] = _create_connection( $server );
158         $oResult[$s] =
159             $server->{servertype} eq 'zed'?
160                 $oConnection[$s]->search_pqf( $server_zquery ):
161                 $oConnection[$s]->search(ZOOM::Query::CQL->new(
162                     _translate_query( $server, $squery )));
163         $s++;
164     }
165     my $xslh = Koha::XSLT::Base->new;
166
167     my $nremaining = $s;
168     while ( $nremaining-- ) {
169         my $k;
170         my $event;
171         while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
172             $event = $oConnection[ $k - 1 ]->last_event();
173             last if $event == ZOOM::Event::ZEND;
174         }
175
176         if ( $k != 0 ) {
177             $k--;
178             my ($error)= $oConnection[$k]->error_x(); #ignores errmsg, addinfo, diagset
179             if ($error) {
180                 if ($error =~ m/^(10000|10007)$/ ) {
181                     push(@errconn, { server => $servers[$k]->{host}, error => $error } );
182                 }
183             }
184             else {
185                 my $numresults = $oResult[$k]->size();
186                 my $i;
187                 my $res;
188                 if ( $numresults > 0  and $numresults >= (($page-1)*20)) {
189                     $show_next = 1 if $numresults >= ($page*20);
190                     $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
191                     for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
192                         if ( $oResult[$k]->record($i) ) {
193                             undef $error;
194                             ( $res, $error ) = _handle_one_result( $oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber, $xslh ); #ignores error in sequence numbering
195                             push @breeding_loop, $res if $res;
196                             push @errconn, { server => $servers[$k]->{servername}, error => $error, seq => $i+1 } if $error;
197                         }
198                         else {
199                             push @errconn, { 'server' => $servers[$k]->{servername}, error => ( ( $oConnection[$k]->error_x() )[0] ), seq => $i+1 };
200                         }
201                     }
202                 }    #if $numresults
203             }
204         }    # if $k !=0
205
206         $template->param(
207             numberpending => $nremaining,
208             current_page => $page,
209             total_pages => $total_pages,
210             show_nextbutton => $show_next?1:0,
211             show_prevbutton => $page!=1,
212         );
213     } # while nremaining
214
215     #close result sets and connections
216     foreach(0..$s-1) {
217         $oResult[$_]->destroy();
218         $oConnection[$_]->destroy();
219     }
220
221     $template->param(
222         breeding_loop => \@breeding_loop,
223         servers => \@servers,
224         errconn       => \@errconn
225     );
226 }
227
228 sub _auth_build_query {
229     my ( $pars ) = @_;
230
231     my $qry_build = {
232         nameany           => '@attr 1=1002 "#term" ',
233         authorany         => '@attr 1=1003 "#term" ',
234         authorcorp        => '@attr 1=2 "#term" ',
235         authorpersonal    => '@attr 1=1 "#term" ',
236         authormeetingcon  => '@attr 1=3 "#term" ',
237         subject           => '@attr 1=21 "#term" ',
238         subjectsubdiv     => '@attr 1=47 "#term" ',
239         title             => '@attr 1=4 "#term" ',
240         uniformtitle      => '@attr 1=6 "#term" ',
241         srchany           => '@attr 1=1016 "#term" ',
242         controlnumber     => '@attr 1=12 "#term" ',
243     };
244
245     return _build_query( $pars, $qry_build );
246 }
247
248 sub _bib_build_query {
249
250     my ( $pars ) = @_;
251
252     my $qry_build = {
253         isbn    => '@attr 1=7 @attr 5=1 "#term" ',
254         issn    => '@attr 1=8 @attr 5=1 "#term" ',
255         title   => '@attr 1=4 "#term" ',
256         author  => '@attr 1=1003 "#term" ',
257         dewey   => '@attr 1=16 "#term" ',
258         subject => '@attr 1=21 "#term" ',
259         lccall  => '@attr 1=16 @attr 2=3 @attr 3=1 @attr 4=1 @attr 5=1 '.
260                    '@attr 6=1 "#term" ',
261         controlnumber => '@attr 1=12 "#term" ',
262         srchany => '@attr 1=1016 "#term" ',
263         stdid   => '@attr 1=1007 "#term" ',
264         publicationyear => '@attr 1=31 "#term" '
265     };
266
267     return _build_query( $pars, $qry_build );
268 }
269
270 sub _build_query {
271
272     my ( $pars, $qry_build ) = @_;
273
274     my $zquery='';
275     my $squery='';
276     my $nterms=0;
277     foreach my $k ( sort keys %$pars ) {
278     #note that the sort keys forces an identical result under Perl 5.18
279     #one of the unit tests is based on that assumption
280         if( ( my $val=$pars->{$k} ) && $qry_build->{$k} ) {
281             $qry_build->{$k} =~ s/#term/$val/g;
282             $zquery .= $qry_build->{$k};
283             $squery .= "[$k]=\"$val\" and ";
284             $nterms++;
285         }
286     }
287     $zquery = "\@and " . $zquery for 2..$nterms;
288     $squery =~ s/ and $//;
289     return ( $zquery, $squery );
290 }
291
292 sub _handle_one_result {
293     my ( $zoomrec, $servhref, $seq, $bib, $xslh )= @_;
294
295     my $raw= $zoomrec->raw();
296     my $marcrecord;
297     if( $servhref->{servertype} eq 'sru' ) {
298         $marcrecord= MARC::Record->new_from_xml( $raw, 'UTF-8',
299             $servhref->{syntax} );
300         $marcrecord->encoding('UTF-8');
301     } else {
302         ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encoding} // "iso-5426" ); #ignores charset return values
303     }
304     SetUTF8Flag($marcrecord);
305     my $error;
306     ( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh);
307
308     my $batch_id = GetZ3950BatchId($servhref->{servername});
309     my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0);
310         #Last zero indicates: no update for batch record counts
311
312
313     #call to TransformMarcToKoha replaced by next call
314     #we only need six fields from the marc record
315     my $row;
316     $row = _add_rowdata(
317         {
318             biblionumber => $bib,
319             server       => $servhref->{servername},
320             breedingid   => $breedingid,
321         }, $marcrecord) if $breedingid;
322     return ( $row, $error );
323 }
324
325 sub _do_xslt_proc {
326     my ( $marc, $server, $xslh ) = @_;
327     return $marc if !$server->{add_xslt};
328
329     my $htdocs = C4::Context->config('intrahtdocs');
330     my $theme = C4::Context->preference("template"); #staff
331     my $lang = C4::Languages::getlanguage() || 'en';
332
333     my @files= split ',', $server->{add_xslt};
334     my $xml = $marc->as_xml;
335     foreach my $f ( @files ) {
336         $f =~ s/^\s+//; $f =~ s/\s+$//; next if !$f;
337         $f = C4::XSLT::_get_best_default_xslt_filename(
338             $htdocs, $theme, $lang, $f ) unless $f =~ /^\//;
339         $xml = $xslh->transform( $xml, $f );
340         last if $xslh->err; #skip other files
341     }
342     if( !$xslh->err ) {
343         return MARC::Record->new_from_xml($xml, 'UTF-8');
344     } else {
345         return ( $marc, $xslh->err ); #original record in case of errors
346     }
347 }
348
349 sub _add_rowdata {
350     my ($row, $record)=@_;
351     my %fetch= (
352         title => 'biblio.title',
353         author => 'biblio.author',
354         isbn =>'biblioitems.isbn',
355         lccn =>'biblioitems.lccn', #LC control number (not call number)
356         edition =>'biblioitems.editionstatement'
357     );
358     $fetch{date} = C4::Context->preference('marcflavour') eq "MARC21" ? 'biblio.copyrightdate' : 'biblioitems.publicationyear';
359
360     foreach my $k (keys %fetch) {
361         $row->{$k} = C4::Biblio::TransformMarcToKohaOneField( $fetch{$k}, $record );
362     }
363     $row->{date}//= $row->{date2};
364     $row->{isbn}=_isbn_replace($row->{isbn});
365
366     $row = _add_custom_field_rowdata($row, $record);
367
368     return $row;
369 }
370
371 sub _add_custom_field_rowdata
372 {
373     my ( $row, $record ) = @_;
374     my $pref_newtags = C4::Context->preference('AdditionalFieldsInZ3950ResultSearch');
375     my $pref_flavour = C4::Context->preference('MarcFlavour');
376
377     $pref_newtags =~ s/^\s+|\s+$//g;
378     $pref_newtags =~ s/\h+/ /g;
379
380     my @addnumberfields;
381
382     foreach my $field (split /\,/, $pref_newtags) {
383         $field =~ s/^\s+|\s+$//g ;  # trim whitespace
384         my ($tag, $subtags) = split(/\$/, $field);
385
386         if ( $record->field($tag) ) {
387             my @content = ();
388
389             for my $marcfield ($record->field($tag)) {
390                 if ( $subtags ) {
391                     my $str = '';
392                     for my $code (split //, $subtags) {
393                         if ( $marcfield->subfield($code) ) {
394                             $str .= $marcfield->subfield($code) . ' ';
395                         }
396                     }
397                     if ( not $str eq '') {
398                         push @content, $str;
399                     }
400                 } elsif ( $tag == 10 ) {
401                     push @content, ( $pref_flavour eq "MARC21" ? $marcfield->data : $marcfield->as_string );
402                 } elsif ( $tag < 10 ) {
403                     push @content, $marcfield->data();
404                 } else {
405                     push @content, $marcfield->as_string();
406                 }
407             }
408
409             if ( @content ) {
410                 $row->{$field} = \@content;
411                 push( @addnumberfields, $field );
412             }
413         }
414     }
415
416     $row->{'addnumberfields'} = \@addnumberfields;
417
418     return $row;
419 }
420
421 sub _isbn_replace {
422     my ($isbn) = @_;
423     return unless defined $isbn;
424     $isbn =~ s/ |-|\.//g;
425     $isbn =~ s/\|/ \| /g;
426     $isbn =~ s/\(/ \(/g;
427     return $isbn;
428 }
429
430 sub _create_connection {
431     my ( $server ) = @_;
432     my $option1= ZOOM::Options->new();
433     $option1->option( 'async' => 1 );
434     $option1->option( 'elementSetName', 'F' );
435     $option1->option( 'preferredRecordSyntax', $server->{syntax} );
436     $option1->option( 'timeout', $server->{timeout} ) if $server->{timeout};
437
438     if( $server->{servertype} eq 'sru' ) {
439         foreach( split ',', $server->{sru_options}//'' ) {
440             #first remove surrounding spaces at comma and equals-sign
441             s/^\s+|\s+$//g;
442             my @temp= split '=', $_, 2;
443             @temp= map { my $c=$_; $c=~s/^\s+|\s+$//g; $c; } @temp;
444             $option1->option( $temp[0] => $temp[1] ) if @temp;
445         }
446     } elsif( $server->{servertype} eq 'zed' ) {
447         $option1->option( 'databaseName',   $server->{db} );
448         $option1->option( 'user', $server->{userid} ) if $server->{userid};
449         $option1->option( 'password', $server->{password} ) if $server->{password};
450     }
451     my $obj= ZOOM::Connection->create($option1);
452     if( $server->{servertype} eq 'sru' ) {
453         my $host= $server->{host};
454         if( $host !~ /^https?:\/\// ) {
455             #Normally, host will not be prefixed by protocol.
456             #In that case we can (safely) assume http.
457             #In case someone prefixed with https, give it a try..
458             $host = 'http://' . $host;
459         }
460         $obj->connect( $host.':'.$server->{port}.'/'.$server->{db} );
461     } else {
462         $obj->connect( $server->{host}, $server->{port} );
463     }
464     return $obj;
465 }
466
467 sub _translate_query { #SRU query adjusted per server cf. srufields column
468     my ($server, $query) = @_;
469
470     #sru_fields is in format title=field,isbn=field,...
471     #if a field doesn't exist, try anywhere or remove [field]=
472     my @parts= split(',', $server->{sru_fields} );
473     my %trans= map { if( /=/ ) { ( $`,$' ) } else { () } } @parts;
474     my $any= $trans{srchany}?$trans{srchany}.'=':'';
475
476     my $q=$query;
477     foreach my $key (keys %trans) {
478         my $f=$trans{$key};
479         if( $f ) {
480             $q=~s/\[$key\]/$f/g;
481         } else {
482             $q=~s/\[$key\]=/$any/g;
483         }
484     }
485     $q=~s/\[\w+\]=/$any/g; # remove remaining fields (not found in field list)
486     return $q;
487 }
488
489 =head2 ImportBreedingAuth
490
491 ImportBreedingAuth( $marcrecord, $filename, $encoding, $heading );
492
493     ImportBreedingAuth imports MARC records in the reservoir (import_records table) or returns their id if they already exist.
494
495 =cut
496
497 sub ImportBreedingAuth {
498     my ( $marcrecord, $filename, $encoding, $heading ) = @_;
499     my $dbh = C4::Context->dbh;
500
501     my $batch_id = GetZ3950BatchId($filename);
502     my $searchbreeding = $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?");
503
504     my $controlnumber = $marcrecord->field('001')->data;
505
506     # Normalize the record so it doesn't have separated diacritics
507     SetUTF8Flag($marcrecord);
508
509     $searchbreeding->execute($controlnumber,$heading);
510     my ($breedingid) = $searchbreeding->fetchrow;
511
512     return $breedingid if $breedingid;
513     $breedingid = AddAuthToBatch($batch_id, 0, $marcrecord, $encoding);
514     return $breedingid;
515 }
516
517 =head2 Z3950SearchAuth
518
519 Z3950SearchAuth($pars, $template);
520
521 Parameters for Z3950 search are all passed via the $pars hash. It may contain nameany, namepersonal, namecorp, namemeetingcon,
522 title, uniform title, subject, subjectsubdiv, srchany.
523 Also it should contain an arrayref id that points to a list of IDs of the z3950 targets to be queried (see z3950servers table).
524 This code is used in cataloging/z3950_auth_search.
525 The second parameter $template is a Template object. The routine uses this parameter to store the found values into the template.
526
527 =cut
528
529 sub Z3950SearchAuth {
530     my ($pars, $template)= @_;
531
532     my $dbh   = C4::Context->dbh;
533     my @id= @{$pars->{id}};
534     my $page= $pars->{page};
535
536
537     my $show_next       = 0;
538     my $total_pages     = 0;
539     my @encoding;
540     my @results;
541     my @serverhost;
542     my @breeding_loop = ();
543     my @oConnection;
544     my @oResult;
545     my @errconn;
546     my @servers;
547     my $s = 0;
548     my $query;
549     my $nterms=0;
550
551     my $marcflavour = C4::Context->preference('marcflavour');
552     my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
553     my $authid= $pars->{authid};
554     my ( $zquery, $squery ) = _auth_build_query( $pars );
555     foreach my $servid (@id) {
556         my $sth = $dbh->prepare("select * from z3950servers where id=?");
557         $sth->execute($servid);
558         while ( my $server = $sth->fetchrow_hashref ) {
559             $oConnection[$s] = _create_connection( $server );
560
561             if ( $server->{servertype} eq 'zed' ) {
562                 my $server_zquery = $zquery;
563                 if ( my $attributes = $server->{attributes} ) {
564                     $server_zquery = "$attributes $zquery";
565                 }
566                 $oResult[$s] = $oConnection[$s]->search_pqf( $server_zquery );
567             }
568             else {
569                 $oResult[$s] = $oConnection[$s]->search(
570                     ZOOM::Query::CQL->new(_translate_query( $server, $squery ))
571                 );
572             }
573             $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
574             $servers[$s] = $server;
575             $s++;
576         }   ## while fetch
577     }    # foreach
578     my $nremaining  = $s;
579
580     while ( $nremaining-- ) {
581         my $k;
582         my $event;
583         while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
584             $event = $oConnection[ $k - 1 ]->last_event();
585             last if $event == ZOOM::Event::ZEND;
586         }
587
588         if ( $k != 0 ) {
589             $k--;
590             my ($error )= $oConnection[$k]->error_x(); #ignores errmsg, addinfo, diagset
591             if ($error) {
592                 if ($error =~ m/^(10000|10007)$/ ) {
593                     push(@errconn, {'server' => $serverhost[$k]});
594                 }
595             }
596             else {
597                 my $numresults = $oResult[$k]->size();
598                 my $i;
599                 my $result = '';
600                 if ( $numresults > 0  and $numresults >= (($page-1)*20)) {
601                     $show_next = 1 if $numresults >= ($page*20);
602                     $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
603                     for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
604                         my $rec = $oResult[$k]->record($i);
605                         if ($rec) {
606                             my $marcrecord;
607                             my $marcdata;
608                             $marcdata   = $rec->raw();
609
610                             my ($charset_result, $charset_errors);
611                             if( $servers[$k]->{servertype} eq 'sru' ) {
612                                 $marcrecord = MARC::Record->new_from_xml( $marcdata, 'UTF-8', $servers[$k]->{syntax} );
613                                 $marcrecord->encoding('UTF-8');
614                             } else {
615                                 ( $marcrecord, $charset_result, $charset_errors ) = MarcToUTF8Record( $marcdata, $marc_type, $encoding[$k] );
616                             }
617                             my $heading;
618                             my $heading_authtype_code;
619                             $heading_authtype_code = GuessAuthTypeCode($marcrecord);
620                             next if ( not defined $heading_authtype_code ) ;
621
622                             $heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord });
623
624                             my $breedingid = ImportBreedingAuth( $marcrecord, $serverhost[$k], $encoding[$k], $heading );
625                             my %row_data;
626                             $row_data{server}       = $servers[$k]->{'servername'};
627                             $row_data{breedingid}   = $breedingid;
628                             $row_data{heading}      = $heading;
629                             $row_data{authid}       = $authid;
630                             $row_data{heading_code}      = $heading_authtype_code;
631                             push( @breeding_loop, \%row_data );
632                         }
633                         else {
634                             push(@breeding_loop,{'server'=>$servers[$k]->{'servername'},'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'authid'=>-1});
635                         }
636                     }
637                 }    #if $numresults
638             }
639         }    # if $k !=0
640
641         $template->param(
642             numberpending => $nremaining,
643             current_page => $page,
644             total_pages => $total_pages,
645             show_nextbutton => $show_next?1:0,
646             show_prevbutton => $page!=1,
647         );
648     } # while nremaining
649
650     #close result sets and connections
651     foreach(0..$s-1) {
652         $oResult[$_]->destroy();
653         $oConnection[$_]->destroy();
654     }
655
656     @servers = ();
657     foreach my $id (@id) {
658         push @servers, {id => $id};
659     }
660     $template->param(
661         breeding_loop => \@breeding_loop,
662         servers => \@servers,
663         errconn       => \@errconn
664     );
665 }
666
667 1;
668 __END__
669