Bug 17301 - Add callnumber to label-edit-batch.pl
[koha.git] / C4 / Breeding.pm
blobee14c81d7c13a6d5218f913b6c60b5e1e38eb0bf
1 package C4::Breeding;
3 # Copyright 2000-2002 Katipo Communications
4 # Parts Copyright 2013 Prosentient Systems
6 # This file is part of Koha.
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.
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.
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>.
21 use strict;
22 use warnings;
24 use C4::Biblio;
25 use C4::Koha;
26 use C4::Charset;
27 use MARC::File::USMARC;
28 use C4::ImportBatch;
29 use C4::AuthoritiesMarc; #GuessAuthTypeCode, FindDuplicateAuthority
30 use C4::Languages;
31 use Koha::Database;
32 use Koha::XSLT_Handler;
34 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
36 BEGIN {
37 require Exporter;
38 @ISA = qw(Exporter);
39 @EXPORT = qw(&BreedingSearch &Z3950Search &Z3950SearchAuth);
42 =head1 NAME
44 C4::Breeding : module to add biblios to import_records via
45 the breeding/reservoir API.
47 =head1 SYNOPSIS
49 Z3950Search($pars, $template);
50 ($count, @results) = &BreedingSearch($title,$isbn,$random);
52 =head1 DESCRIPTION
54 This module contains routines related to Koha's Z39.50 search into
55 cataloguing reservoir features.
57 =head2 BreedingSearch
59 ($count, @results) = &BreedingSearch($title,$isbn,$random);
60 C<$title> contains the title,
61 C<$isbn> contains isbn or issn,
62 C<$random> contains the random seed from a z3950 search.
64 C<$count> is the number of items in C<@results>. C<@results> is an
65 array of references-to-hash; the keys are the items from the C<import_records> and
66 C<import_biblios> tables of the Koha database.
68 =cut
70 sub BreedingSearch {
71 my ($search,$isbn,$z3950random) = @_;
72 my $dbh = C4::Context->dbh;
73 my $count = 0;
74 my ($query,@bind);
75 my $sth;
76 my @results;
78 # normalise ISBN like at import
79 $isbn = C4::Koha::GetNormalizedISBN($isbn);
81 $query = "SELECT import_record_id, file_name, isbn, title, author
82 FROM import_biblios
83 JOIN import_records USING (import_record_id)
84 JOIN import_batches USING (import_batch_id)
85 WHERE ";
86 if ($z3950random) {
87 $query .= "z3950random = ?";
88 @bind=($z3950random);
89 } else {
90 @bind=();
91 if (defined($search) && length($search)>0) {
92 $search =~ s/(\s+)/\%/g;
93 $query .= "title like ? OR author like ?";
94 push(@bind,"%$search%", "%$search%");
96 if ($#bind!=-1 && defined($isbn) && length($isbn)>0) {
97 $query .= " and ";
99 if (defined($isbn) && length($isbn)>0) {
100 $query .= "isbn like ?";
101 push(@bind,"$isbn%");
104 $sth = $dbh->prepare($query);
105 $sth->execute(@bind);
106 while (my $data = $sth->fetchrow_hashref) {
107 $results[$count] = $data;
108 # FIXME - hack to reflect difference in name
109 # of columns in old marc_breeding and import_records
110 # There needs to be more separation between column names and
111 # field names used in the templates </soapbox>
112 $data->{'file'} = $data->{'file_name'};
113 $data->{'id'} = $data->{'import_record_id'};
114 $count++;
115 } # while
117 $sth->finish;
118 return($count, @results);
119 } # sub breedingsearch
122 =head2 Z3950Search
124 Z3950Search($pars, $template);
126 Parameters for Z3950 search are all passed via the $pars hash. It may contain isbn, title, author, dewey, subject, lccall, controlnumber, stdid, srchany.
127 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).
128 This code is used in acqui/z3950_search and cataloging/z3950_search.
129 The second parameter $template is a Template object. The routine uses this parameter to store the found values into the template.
131 =cut
133 sub Z3950Search {
134 my ($pars, $template)= @_;
136 my @id= @{$pars->{id}};
137 my $page= $pars->{page};
138 my $biblionumber= $pars->{biblionumber};
140 my $show_next = 0;
141 my $total_pages = 0;
142 my @results;
143 my @breeding_loop = ();
144 my @oConnection;
145 my @oResult;
146 my @errconn;
147 my $s = 0;
148 my $imported=0;
150 my ( $zquery, $squery ) = _build_query( $pars );
152 my $schema = Koha::Database->new()->schema();
153 my $rs = $schema->resultset('Z3950server')->search(
154 { id => [ @id ] },
155 { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
157 my @servers = $rs->all;
158 foreach my $server ( @servers ) {
159 $oConnection[$s] = _create_connection( $server );
160 $oResult[$s] =
161 $server->{servertype} eq 'zed'?
162 $oConnection[$s]->search_pqf( $zquery ):
163 $oConnection[$s]->search(new ZOOM::Query::CQL(
164 _translate_query( $server, $squery )));
165 $s++;
167 my $xslh = Koha::XSLT_Handler->new;
169 my $nremaining = $s;
170 while ( $nremaining-- ) {
171 my $k;
172 my $event;
173 while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
174 $event = $oConnection[ $k - 1 ]->last_event();
175 last if $event == ZOOM::Event::ZEND;
178 if ( $k != 0 ) {
179 $k--;
180 my ($error)= $oConnection[$k]->error_x(); #ignores errmsg, addinfo, diagset
181 if ($error) {
182 if ($error =~ m/^(10000|10007)$/ ) {
183 push(@errconn, { server => $servers[$k]->{host}, error => $error } );
186 else {
187 my $numresults = $oResult[$k]->size();
188 my $i;
189 my $res;
190 if ( $numresults > 0 and $numresults >= (($page-1)*20)) {
191 $show_next = 1 if $numresults >= ($page*20);
192 $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
193 for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
194 if ( $oResult[$k]->record($i) ) {
195 undef $error;
196 ( $res, $error ) = _handle_one_result( $oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber, $xslh ); #ignores error in sequence numbering
197 push @breeding_loop, $res if $res;
198 push @errconn, { server => $servers[$k]->{servername}, error => $error, seq => $i+1 } if $error;
200 else {
201 push @errconn, { 'server' => $servers[$k]->{servername}, error => ( ( $oConnection[$k]->error_x() )[0] ), seq => $i+1 };
204 } #if $numresults
206 } # if $k !=0
208 $template->param(
209 numberpending => $nremaining,
210 current_page => $page,
211 total_pages => $total_pages,
212 show_nextbutton => $show_next?1:0,
213 show_prevbutton => $page!=1,
215 } # while nremaining
217 #close result sets and connections
218 foreach(0..$s-1) {
219 $oResult[$_]->destroy();
220 $oConnection[$_]->destroy();
223 $template->param(
224 breeding_loop => \@breeding_loop,
225 servers => \@servers,
226 errconn => \@errconn
230 sub _build_query {
231 my ( $pars ) = @_;
233 my $qry_build = {
234 isbn => '@attr 1=7 @attr 5=1 "#term" ',
235 issn => '@attr 1=8 @attr 5=1 "#term" ',
236 title => '@attr 1=4 "#term" ',
237 author => '@attr 1=1003 "#term" ',
238 dewey => '@attr 1=16 "#term" ',
239 subject => '@attr 1=21 "#term" ',
240 lccall => '@attr 1=16 @attr 2=3 @attr 3=1 @attr 4=1 @attr 5=1 '.
241 '@attr 6=1 "#term" ',
242 controlnumber => '@attr 1=12 "#term" ',
243 srchany => '@attr 1=1016 "#term" ',
244 stdid => '@attr 1=1007 "#term" ',
247 my $zquery='';
248 my $squery='';
249 my $nterms=0;
250 foreach my $k ( sort keys %$pars ) {
251 #note that the sort keys forces an identical result under Perl 5.18
252 #one of the unit tests is based on that assumption
253 if( ( my $val=$pars->{$k} ) && $qry_build->{$k} ) {
254 $qry_build->{$k} =~ s/#term/$val/g;
255 $zquery .= $qry_build->{$k};
256 $squery .= "[$k]=\"$val\" and ";
257 $nterms++;
260 $zquery = "\@and " . $zquery for 2..$nterms;
261 $squery =~ s/ and $//;
262 return ( $zquery, $squery );
265 sub _handle_one_result {
266 my ( $zoomrec, $servhref, $seq, $bib, $xslh )= @_;
268 my $raw= $zoomrec->raw();
269 my $marcrecord;
270 if( $servhref->{servertype} eq 'sru' ) {
271 $marcrecord= MARC::Record->new_from_xml( $raw, 'UTF-8',
272 $servhref->{syntax} );
273 } else {
274 ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encoding} // "iso-5426" ); #ignores charset return values
276 SetUTF8Flag($marcrecord);
277 my $error;
278 ( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh);
280 my $batch_id = GetZ3950BatchId($servhref->{servername});
281 my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0);
282 #FIXME passing 0 for z3950random
283 #Will eliminate this unused field in a followup report
284 #Last zero indicates: no update for batch record counts
287 #call to TransformMarcToKoha replaced by next call
288 #we only need six fields from the marc record
289 my $row;
290 $row = _add_rowdata(
292 biblionumber => $bib,
293 server => $servhref->{servername},
294 breedingid => $breedingid,
295 }, $marcrecord) if $breedingid;
296 return ( $row, $error );
299 sub _do_xslt_proc {
300 my ( $marc, $server, $xslh ) = @_;
301 return $marc if !$server->{add_xslt};
303 my $htdocs = C4::Context->config('intrahtdocs');
304 my $theme = C4::Context->preference("template"); #staff
305 my $lang = C4::Languages::getlanguage() || 'en';
307 my @files= split ',', $server->{add_xslt};
308 my $xml = $marc->as_xml;
309 foreach my $f ( @files ) {
310 $f =~ s/^\s+//; $f =~ s/\s+$//; next if !$f;
311 $f = C4::XSLT::_get_best_default_xslt_filename(
312 $htdocs, $theme, $lang, $f ) unless $f =~ /^\//;
313 $xml = $xslh->transform( $xml, $f );
314 last if $xslh->err; #skip other files
316 if( !$xslh->err ) {
317 return MARC::Record->new_from_xml($xml, 'UTF-8');
318 } else {
319 return ( $marc, 'xslt_err' ); #original record in case of errors
323 sub _add_rowdata {
324 my ($row, $record)=@_;
325 my %fetch= (
326 title => 'biblio.title',
327 author => 'biblio.author',
328 isbn =>'biblioitems.isbn',
329 lccn =>'biblioitems.lccn', #LC control number (not call number)
330 edition =>'biblioitems.editionstatement',
331 date => 'biblio.copyrightdate', #MARC21
332 date2 => 'biblioitems.publicationyear', #UNIMARC
334 foreach my $k (keys %fetch) {
335 my ($t, $f)= split '\.', $fetch{$k};
336 $row= C4::Biblio::TransformMarcToKohaOneField($t, $f, $record, $row);
337 $row->{$k}= $row->{$f} if $k ne $f;
339 $row->{date}//= $row->{date2};
340 $row->{isbn}=_isbn_replace($row->{isbn});
341 return $row;
344 sub _isbn_replace {
345 my ($isbn) = @_;
346 return unless defined $isbn;
347 $isbn =~ s/ |-|\.//g;
348 $isbn =~ s/\|/ \| /g;
349 $isbn =~ s/\(/ \(/g;
350 return $isbn;
353 sub _create_connection {
354 my ( $server ) = @_;
355 my $option1= new ZOOM::Options();
356 $option1->option( 'async' => 1 );
357 $option1->option( 'elementSetName', 'F' );
358 $option1->option( 'preferredRecordSyntax', $server->{syntax} );
359 $option1->option( 'timeout', $server->{timeout} ) if $server->{timeout};
361 if( $server->{servertype} eq 'sru' ) {
362 foreach( split ',', $server->{sru_options}//'' ) {
363 #first remove surrounding spaces at comma and equals-sign
364 s/^\s+|\s+$//g;
365 my @temp= split '=', $_, 2;
366 @temp= map { my $c=$_; $c=~s/^\s+|\s+$//g; $c; } @temp;
367 $option1->option( $temp[0] => $temp[1] ) if @temp;
369 } elsif( $server->{servertype} eq 'zed' ) {
370 $option1->option( 'databaseName', $server->{db} );
371 $option1->option( 'user', $server->{userid} ) if $server->{userid};
372 $option1->option( 'password', $server->{password} ) if $server->{password};
375 my $obj= ZOOM::Connection->create($option1);
376 if( $server->{servertype} eq 'sru' ) {
377 my $host= $server->{host};
378 if( $host !~ /^https?:\/\// ) {
379 #Normally, host will not be prefixed by protocol.
380 #In that case we can (safely) assume http.
381 #In case someone prefixed with https, give it a try..
382 $host = 'http://' . $host;
384 $obj->connect( $host.':'.$server->{port}.'/'.$server->{db} );
385 } else {
386 $obj->connect( $server->{host}, $server->{port} );
388 return $obj;
391 sub _translate_query { #SRU query adjusted per server cf. srufields column
392 my ($server, $query) = @_;
394 #sru_fields is in format title=field,isbn=field,...
395 #if a field doesn't exist, try anywhere or remove [field]=
396 my @parts= split(',', $server->{sru_fields} );
397 my %trans= map { if( /=/ ) { ( $`,$' ) } else { () } } @parts;
398 my $any= $trans{srchany}?$trans{srchany}.'=':'';
400 my $q=$query;
401 foreach my $key (keys %trans) {
402 my $f=$trans{$key};
403 if( $f ) {
404 $q=~s/\[$key\]/$f/g;
405 } else {
406 $q=~s/\[$key\]=/$any/g;
409 $q=~s/\[\w+\]=/$any/g; # remove remaining fields (not found in field list)
410 return $q;
413 =head2 ImportBreedingAuth
415 ImportBreedingAuth($marcrecords,$overwrite_auth,$filename,$encoding,$z3950random,$batch_type);
417 ImportBreedingAuth imports MARC records in the reservoir (import_records table).
418 ImportBreedingAuth is based on the ImportBreeding subroutine.
420 =cut
422 sub ImportBreedingAuth {
423 my ($marcrecords,$overwrite_auth,$filename,$encoding,$z3950random,$batch_type) = @_;
424 my @marcarray = split /\x1D/, $marcrecords;
426 my $dbh = C4::Context->dbh;
428 my $batch_id = GetZ3950BatchId($filename);
429 my $searchbreeding = $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?");
431 my $marcflavour = C4::Context->preference('marcflavour');
432 my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
434 # fields used for import results
435 my $imported=0;
436 my $alreadyindb = 0;
437 my $alreadyinfarm = 0;
438 my $notmarcrecord = 0;
439 my $breedingid;
440 for (my $i=0;$i<=$#marcarray;$i++) {
441 my ($marcrecord, $charset_result, $charset_errors);
442 ($marcrecord, $charset_result, $charset_errors) =
443 MarcToUTF8Record($marcarray[$i]."\x1D", $marc_type, $encoding);
445 # Normalize the record so it doesn't have separated diacritics
446 SetUTF8Flag($marcrecord);
448 if (scalar($marcrecord->fields()) == 0) {
449 $notmarcrecord++;
450 } else {
451 my $heading;
452 $heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord });
454 my $heading_authtype_code;
455 $heading_authtype_code = GuessAuthTypeCode($marcrecord);
457 my $controlnumber;
458 $controlnumber = $marcrecord->field('001')->data;
460 #Check if the authority record already exists in the database...
461 my ($duplicateauthid,$duplicateauthvalue);
462 if ($marcrecord && $heading_authtype_code) {
463 ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority( $marcrecord, $heading_authtype_code);
466 if ($duplicateauthid && $overwrite_auth ne 2) {
467 #If the authority record exists and $overwrite_auth doesn't equal 2, then mark it as already in the DB
468 $alreadyindb++;
469 } else {
470 if ($controlnumber && $heading) {
471 $searchbreeding->execute($controlnumber,$heading);
472 ($breedingid) = $searchbreeding->fetchrow;
474 if ($breedingid && $overwrite_auth eq '0') {
475 $alreadyinfarm++;
476 } else {
477 if ($breedingid && $overwrite_auth eq '1') {
478 ModAuthorityInBatch($breedingid, $marcrecord);
479 } else {
480 my $import_id = AddAuthToBatch($batch_id, $imported, $marcrecord, $encoding, $z3950random);
481 $breedingid = $import_id;
483 $imported++;
488 return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid);
491 =head2 Z3950SearchAuth
493 Z3950SearchAuth($pars, $template);
495 Parameters for Z3950 search are all passed via the $pars hash. It may contain nameany, namepersonal, namecorp, namemeetingcon,
496 title, uniform title, subject, subjectsubdiv, srchany.
497 Also it should contain an arrayref id that points to a list of IDs of the z3950 targets to be queried (see z3950servers table).
498 This code is used in cataloging/z3950_auth_search.
499 The second parameter $template is a Template object. The routine uses this parameter to store the found values into the template.
501 =cut
503 sub Z3950SearchAuth {
504 my ($pars, $template)= @_;
506 my $dbh = C4::Context->dbh;
507 my @id= @{$pars->{id}};
508 my $random= $pars->{random};
509 my $page= $pars->{page};
511 my $nameany= $pars->{nameany};
512 my $authorany= $pars->{authorany};
513 my $authorpersonal= $pars->{authorpersonal};
514 my $authorcorp= $pars->{authorcorp};
515 my $authormeetingcon= $pars->{authormeetingcon};
516 my $title= $pars->{title};
517 my $uniformtitle= $pars->{uniformtitle};
518 my $subject= $pars->{subject};
519 my $subjectsubdiv= $pars->{subjectsubdiv};
520 my $srchany= $pars->{srchany};
521 my $authid= $pars->{authid};
523 my $show_next = 0;
524 my $total_pages = 0;
525 my $attr = '';
526 my $host;
527 my $server;
528 my $database;
529 my $port;
530 my $marcdata;
531 my @encoding;
532 my @results;
533 my $count;
534 my $record;
535 my @serverhost;
536 my @servername;
537 my @breeding_loop = ();
539 my @oConnection;
540 my @oResult;
541 my @errconn;
542 my $s = 0;
543 my $query;
544 my $nterms=0;
546 my $marcflavour = C4::Context->preference('marcflavour');
547 my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
549 if ($nameany) {
550 $query .= " \@attr 1=1002 \"$nameany\" "; #Any name (this includes personal, corporate, meeting/conference authors, and author names in subject headings)
551 #This attribute is supported by both the Library of Congress and Libraries Australia 08/05/2013
552 $nterms++;
555 if ($authorany) {
556 $query .= " \@attr 1=1003 \"$authorany\" "; #Author-name (this includes personal, corporate, meeting/conference authors, but not author names in subject headings)
557 #This attribute is not supported by the Library of Congress, but is supported by Libraries Australia 08/05/2013
558 $nterms++;
561 if ($authorcorp) {
562 $query .= " \@attr 1=2 \"$authorcorp\" "; #1005 is another valid corporate author attribute...
563 $nterms++;
566 if ($authorpersonal) {
567 $query .= " \@attr 1=1 \"$authorpersonal\" "; #1004 is another valid personal name attribute...
568 $nterms++;
571 if ($authormeetingcon) {
572 $query .= " \@attr 1=3 \"$authormeetingcon\" "; #1006 is another valid meeting/conference name attribute...
573 $nterms++;
576 if ($subject) {
577 $query .= " \@attr 1=21 \"$subject\" ";
578 $nterms++;
581 if ($subjectsubdiv) {
582 $query .= " \@attr 1=47 \"$subjectsubdiv\" ";
583 $nterms++;
586 if ($title) {
587 $query .= " \@attr 1=4 \"$title\" "; #This is a regular title search. 1=6 will give just uniform titles
588 $nterms++;
591 if ($uniformtitle) {
592 $query .= " \@attr 1=6 \"$uniformtitle\" "; #This is the uniform title search
593 $nterms++;
596 if($srchany) {
597 $query .= " \@attr 1=1016 \"$srchany\" ";
598 $nterms++;
601 for my $i (1..$nterms-1) {
602 $query = "\@and " . $query;
605 foreach my $servid (@id) {
606 my $sth = $dbh->prepare("select * from z3950servers where id=?");
607 $sth->execute($servid);
608 while ( $server = $sth->fetchrow_hashref ) {
609 my $option1 = new ZOOM::Options();
610 $option1->option( 'async' => 1 );
611 $option1->option( 'elementSetName', 'F' );
612 $option1->option( 'databaseName', $server->{db} );
613 $option1->option( 'user', $server->{userid} ) if $server->{userid};
614 $option1->option( 'password', $server->{password} ) if $server->{password};
615 $option1->option( 'preferredRecordSyntax', $server->{syntax} );
616 $option1->option( 'timeout', $server->{timeout} ) if $server->{timeout};
617 $oConnection[$s] = create ZOOM::Connection($option1);
618 $oConnection[$s]->connect( $server->{host}, $server->{port} );
619 $serverhost[$s] = $server->{host};
620 $servername[$s] = $server->{servername};
621 $encoding[$s] = ($server->{encoding}?$server->{encoding}:"iso-5426");
622 $s++;
623 } ## while fetch
624 } # foreach
625 my $nremaining = $s;
627 for ( my $z = 0 ; $z < $s ; $z++ ) {
628 $oResult[$z] = $oConnection[$z]->search_pqf($query);
631 while ( $nremaining-- ) {
632 my $k;
633 my $event;
634 while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
635 $event = $oConnection[ $k - 1 ]->last_event();
636 last if $event == ZOOM::Event::ZEND;
639 if ( $k != 0 ) {
640 $k--;
641 my ($error, $errmsg, $addinfo, $diagset)= $oConnection[$k]->error_x();
642 if ($error) {
643 if ($error =~ m/^(10000|10007)$/ ) {
644 push(@errconn, {'server' => $serverhost[$k]});
647 else {
648 my $numresults = $oResult[$k]->size();
649 my $i;
650 my $result = '';
651 if ( $numresults > 0 and $numresults >= (($page-1)*20)) {
652 $show_next = 1 if $numresults >= ($page*20);
653 $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
654 for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
655 my $rec = $oResult[$k]->record($i);
656 if ($rec) {
657 my $marcrecord;
658 my $marcdata;
659 $marcdata = $rec->raw();
661 my ($charset_result, $charset_errors);
662 ($marcrecord, $charset_result, $charset_errors)= MarcToUTF8Record($marcdata, $marc_type, $encoding[$k]);
664 my $heading;
665 my $heading_authtype_code;
666 $heading_authtype_code = GuessAuthTypeCode($marcrecord);
667 $heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord });
669 my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreedingAuth( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
670 my %row_data;
671 $row_data{server} = $servername[$k];
672 $row_data{breedingid} = $breedingid;
673 $row_data{heading} = $heading;
674 $row_data{authid} = $authid;
675 $row_data{heading_code} = $heading_authtype_code;
676 push( @breeding_loop, \%row_data );
678 else {
679 push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'authid'=>-1});
682 } #if $numresults
684 } # if $k !=0
686 $template->param(
687 numberpending => $nremaining,
688 current_page => $page,
689 total_pages => $total_pages,
690 show_nextbutton => $show_next?1:0,
691 show_prevbutton => $page!=1,
693 } # while nremaining
695 #close result sets and connections
696 foreach(0..$s-1) {
697 $oResult[$_]->destroy();
698 $oConnection[$_]->destroy();
701 my @servers = ();
702 foreach my $id (@id) {
703 push @servers, {id => $id};
705 $template->param(
706 breeding_loop => \@breeding_loop,
707 servers => \@servers,
708 errconn => \@errconn
713 __END__