1 package C4::AuthoritiesMarc;
2 # Copyright 2000-2002 Katipo Communications
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
27 use vars qw($VERSION @ISA @EXPORT);
29 # set the version for version checking
36 &AUTHfind_authtypecode
43 &AUTHfind_marc_from_kohafield
56 sub AUTHfind_marc_from_kohafield {
57 my ( $dbh, $kohafield,$authtypecode ) = @_;
58 return 0, 0 unless $kohafield;
59 $authtypecode="" unless $authtypecode;
60 my $marcfromkohafield;
61 my $sth = $dbh->prepare("select tagfield,tagsubfield from auth_subfield_structure where kohafield= ? and authtypecode=? ");
62 $sth->execute($kohafield,$authtypecode);
63 my ($tagfield,$tagsubfield) = $sth->fetchrow;
65 return ($tagfield,$tagsubfield);
68 my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode) = @_;
71 # the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
72 # the authtypecode. Then, search on $a of this tag_to_report
73 # also store main entry MARC tag, to extract it at end of search
75 ##first set the authtype search and may be multiple authorities
78 my @auths=split / /,$authtypecode ;
79 foreach my $auth (@auths){
80 $query .=" \@attr 1=1013 \@attr 5=100 ".$auth; ##No truncation on authtype
81 push @authtypecode ,$auth;
85 $query= "\@or ".$query;
91 for(my $i = 0 ; $i <= $#{$value} ; $i++)
95 ##If mainentry search $a tag
96 if (@$tags[$i] eq "mainentry") {
97 $attr =" \@attr 1=21 ";
99 $attr =" \@attr 1=47 ";
105 if (@$operator[$i] eq 'phrase') {
106 $attr.=" \@attr 4=1 \@attr 5=100 \@attr 6=2 ";##Phrase, No truncation,all of subfield field must match
110 $attr .=" \@attr 4=6 \@attr 5=1 ";## Word list, right truncated, anywhere
115 $attr =$attr."\"".@$value[$i]."\"";
121 ##Add how many queries generated
122 $query= $and.$query.$q2;
125 $offset=0 unless $offset;
126 my $counter = $offset;
127 $length=10 unless $length;
130 $oAuth[0]=C4::Context->Zconnauth("authorityserver");
132 my $Anewq= new ZOOM::Query::PQF($query);
133 $Anewq->sortby("1=21 i< 1=47 i< ");
135 $oAResult= $oAuth[0]->search($Anewq) ;
136 while (($i = ZOOM::event(\@oAuth)) != 0) {
137 my $ev = $oAuth[$i-1]->last_event();
138 # warn("Authority ", $i-1, ": event $ev (", ZOOM::event_str($ev), ")\n");
139 last if $ev == ZOOM::Event::ZEND;
141 my($error, $errmsg, $addinfo, $diagset) = $oAuth[0]->error_x();
143 warn "oAuth error: $errmsg ($error) $addinfo $diagset\n";
149 $nbresults=$oAResult->size();
150 my $nremains=$nbresults;
152 my @finalresult = ();
157 ##Find authid and linkid fields
158 ##we may be searching multiple authoritytypes.
159 ##Fix me this assumes that all authid and linkid fields are the same for all authority types
160 my ($authidfield,$authidsubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.authid",$authtypecode[0]);
161 my ($linkidfield,$linkidsubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.linkid",$authtypecode[0]);
162 while (($counter < $nbresults) && ($counter < ($offset + $length))) {
164 ##Here we have to extract MARC record and $authid from ZEBRA AUTHORITIES
165 my $rec=$oAResult->record($counter);
166 my $marcdata=$rec->raw();
170 my $separator=C4::Context->preference('authoritysep');
171 my $linksummary=" ".$separator;
173 $authrecord = MARC::File::USMARC::decode($marcdata);
175 my $authid=$authrecord->field($authidfield)->subfield($authidsubfield);
176 if ($authrecord->field($linkidfield)){
177 my @fields=$authrecord->field($linkidfield);
179 foreach my $field (@fields){
180 $linkid=$field->subfield($linkidsubfield) ;
181 if ($linkid){ ##There is a linked record add fields to produce summary
182 my $linktype=AUTHfind_authtypecode($dbh,$linkid);
183 my $linkrecord=AUTHgetauthority($dbh,$linkid);
184 $linksummary.="<br> <a href='detail.pl?authid=$linkid'>".getsummary($dbh,$linkrecord,$linkid,$linktype).".</a>".$separator;
189 my $summary=getsummary($dbh,$authrecord,$authid,$authtypecode);
190 $summary="<a href='detail.pl?authid=$authid'>".$summary.".</a>";
191 if ($linkid && $linksummary ne " ".$separator){
192 $summary="<b>".$summary."</b>".$linksummary;
195 $newline{summary} = $summary;
196 $newline{authid} = $authid;
197 $newline{linkid} = $linkid;
199 # $newline{biblio_fields} = $tags_using_authtype;
200 $newline{even} = $counter % 2;
202 push @finalresult, \%newline;
211 $oConnection[0]=C4::Context->Zconnauth("biblioserver");
212 for (my $z=0; $z<@finalresult; $z++){
215 $nquery= "\@attr GILS 1=2057 ".$finalresult[$z]{authid};
216 $nquery="\@or ".$nquery." \@attr GILS 1=2057 ".$finalresult[$z]{linkid} if $finalresult[$z]{linkid};
217 $oResult[$z] = $oConnection[0]->search_pqf($nquery);
221 while (($i = ZOOM::event(\@oConnection)) != 0) {
222 my $ev = $oConnection[0]->last_event();
223 # warn("connection ", $i-1, ": event $ev (", ZOOM::event_str($ev), ")\n");
224 last if $ev == ZOOM::Event::ZEND;
227 my($error, $errmsg, $addinfo, $diagset) = $oConnection[0]->error_x();
229 warn "oConnection $ error: $errmsg ($error) $addinfo\n";
230 ##In fact its an error. Should we inform at least the librarian?
234 my $count=$oResult[$z]->size() ;
235 $finalresult[$z]{used}=$count;
236 # $oResult->destroy();
237 # $oConnection[$i-1]->destroy();
244 $oAResult->destroy();
245 $oAuth[0]->destroy();
247 return (\@finalresult, $nbresults);
250 # Creates the SQL Request
253 my ($dbh,$tags, $and_or, $operator, $value) = @_;
255 my $sql_tables; # will contain marc_subfield_table as m1,...
256 my $sql_where1; # will contain the "true" where
257 my $sql_where2 = "("; # will contain m1.authid=m2.authid
258 my $nb_active=0; # will contain the number of "active" entries. and entry is active is a value is provided.
259 my $nb_table=1; # will contain the number of table. ++ on each entry EXCEPT when an OR is provided.
262 for(my $i=0; $i<=@$value;$i++) {
267 $sql_tables = "auth_subfield_table as m$nb_table,";
268 $sql_where1 .= "( m$nb_table.subfieldvalue like '@$value[$i]' ";
270 $sql_where1 .=" and concat(m$nb_table.tag,m$nb_table.subfieldcode) IN (@$tags[$i])";
280 $sql_tables .= "auth_subfield_table as m$nb_table,";
281 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue like '@$value[$i]' ";
283 $sql_where1 .=" and concat(m$nb_table.tag,m$nb_table.subfieldcode) IN (@$tags[$i])";
286 $sql_where2.="m1.authid=m$nb_table.authid and ";
293 if($sql_where2 ne "(") # some datas added to sql_where2, processing
295 $sql_where2 = substr($sql_where2, 0, (length($sql_where2)-5)); # deletes the trailing ' and '
298 else # no sql_where2 statement, deleting '('
302 chop $sql_tables; # deletes the trailing ','
304 return ($sql_tables, $sql_where1, $sql_where2);
308 sub AUTHcount_usage {
310 ### try ZOOM search here
311 my $oConnection=C4::Context->Zconn("biblioserver");
313 $query= "\@attr GILS 1=2057 ".$authid;
315 my $oResult = $oConnection->search_pqf($query);
317 my $result=$oResult->size() if ($oResult);
324 sub AUTHfind_authtypecode {
325 my ($dbh,$authid) = @_;
326 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
327 $sth->execute($authid);
328 my ($authtypecode) = $sth->fetchrow;
329 return $authtypecode;
334 my ($dbh,$forlibrarian,$authtypecode)= @_;
335 $authtypecode="" unless $authtypecode;
337 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
340 # check that authority exists
341 $sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
342 $sth->execute($authtypecode);
343 my ($total) = $sth->fetchrow;
344 $authtypecode="" unless ($total >0);
346 "select tagfield,liblibrarian,libopac,mandatory,repeatable from auth_tag_structure where authtypecode=? order by tagfield"
349 $sth->execute($authtypecode);
350 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
352 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) = $sth->fetchrow ) {
353 $res->{$tag}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
354 $res->{$tab}->{tab} = ""; # XXX
355 $res->{$tag}->{mandatory} = $mandatory;
356 $res->{$tag}->{repeatable} = $repeatable;
358 $sth= $dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link from auth_subfield_structure where authtypecode=? order by tagfield,tagsubfield"
360 $sth->execute($authtypecode);
363 my $authorised_value;
373 ( $tag, $subfield, $liblibrarian, , $libopac, $tab,
374 $mandatory, $repeatable, $authorised_value, $authtypecode,
375 $value_builder, $kohafield, $seealso, $hidden,
380 $res->{$tag}->{$subfield}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
381 $res->{$tag}->{$subfield}->{tab} = $tab;
382 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
383 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
384 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
385 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
386 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
387 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
388 $res->{$tag}->{$subfield}->{seealso} = $seealso;
389 $res->{$tag}->{$subfield}->{hidden} = $hidden;
390 $res->{$tag}->{$subfield}->{isurl} = $isurl;
391 $res->{$tag}->{$subfield}->{link} = $link;
396 sub AUTHaddauthority {
397 # pass the MARC::Record to this function, and it will create the records in the authority table
398 my ($dbh,$record,$authid,$authtypecode) = @_;
400 #my $leadercode=AUTHfind_leader($dbh,$authtypecode);
401 my $leader=' a ';##Fixme correct leader as this one just adds utf8 to MARC21
402 #substr($leader,8,1)=$leadercode;
403 # $record->leader($leader);
404 my ($authfield,$authidsubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.authid",$authtypecode);
405 my ($authfield2,$authtypesubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.authtypecode",$authtypecode);
406 my ($linkidfield,$linkidsubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.linkid",$authtypecode);
408 # if authid empty => true add, find a new authid number
410 my $sth=$dbh->prepare("select max(authid) from auth_header");
412 ($authid)=$sth->fetchrow;
415 ##Insert the recordID in MARC record
417 ##Both authid and authtypecode is expected to be in the same field. Modify if other requirements arise
418 $record->add_fields($authfield,'','',$authidsubfield=>$authid,$authtypesubfield=>$authtypecode);
420 $dbh->do("lock tables auth_header WRITE");
421 $sth=$dbh->prepare("insert into auth_header (authid,datecreated,authtypecode,marc) values (?,now(),?,?)");
422 $sth->execute($authid,$authtypecode,$record->as_usmarc);
426 ##Modified record reinsertid
427 my $idfield=$record->field($authfield);
428 $record->delete_field($idfield);
429 $record->add_fields($authfield,'','',$authtypesubfield=>$authtypecode,$authidsubfield=>$authid);
431 $dbh->do("lock tables auth_header WRITE");
432 my $sth=$dbh->prepare("update auth_header set marc=? where authid=?");
433 $sth->execute($record->as_usmarc,$authid);
436 $dbh->do("unlock tables");
437 zebraop($dbh,$authid,'specialUpdate',"authorityserver");
439 if ($record->field($linkidfield)){
440 my @fields=$record->field($linkidfield);
442 foreach my $field (@fields){
443 my $linkid=$field->subfield($linkidsubfield) ;
445 ##Modify the record of linked
446 AUTHaddlink($dbh,$linkid,$authid);
454 my ($dbh,$linkid,$authid)=@_;
455 my $record=AUTHgetauthority($dbh,$linkid);
456 my $authtypecode=AUTHfind_authtypecode($dbh,$linkid);
457 #warn "adding l:$linkid,a:$authid,auth:$authtypecode";
458 $record=AUTH2marcOnefieldlink($dbh,$record,"auth_header.linkid",$authid,$authtypecode);
459 $dbh->do("lock tables auth_header WRITE");
460 my $sth=$dbh->prepare("update auth_header set marc=? where authid=?");
461 $sth->execute($record->as_usmarc,$linkid);
463 $dbh->do("unlock tables");
464 zebraop($dbh,$linkid,'specialUpdate',"authorityserver");
467 sub AUTH2marcOnefieldlink {
468 my ( $dbh, $record, $kohafieldname, $newvalue,$authtypecode ) = @_;
469 my $sth = $dbh->prepare(
470 "select tagfield,tagsubfield from auth_subfield_structure where authtypecode=? and kohafield=?"
472 $sth->execute($authtypecode,$kohafieldname);
473 my ($tagfield,$tagsubfield)=$sth->fetchrow;
474 $record->add_fields( $tagfield, " ", " ", $tagsubfield => $newvalue );
478 sub XMLgetauthority {
480 # Returns MARC::XML of the authority passed in parameter.
481 my ( $dbh, $authid ) = @_;
485 $dbh->prepare("select marc from auth_header where authid=? " );
487 $sth->execute($authid);
488 my ($marc)=$sth->fetchrow;
489 $marc=MARC::File::USMARC::decode($marc);
490 my $marcxml=$marc->as_xml_record();
497 ##Hard coded for NEU auth types
498 my($dbh,$authtypecode)=@_;
501 if ($authtypecode eq "AUTH"){
503 }elsif ($authtypecode eq "ESUB"){
505 }elsif ($authtypecode eq "TSUB"){
513 sub AUTHgetauthority {
514 # Returns MARC::Record of the biblio passed in parameter.
515 my ($dbh,$authid)=@_;
516 my $sth=$dbh->prepare("select marc from auth_header where authid=?");
517 $sth->execute($authid);
518 my ($marc) = $sth->fetchrow;
519 my $record=MARC::File::USMARC::decode($marc);
524 sub AUTHgetauth_type {
525 my ($authtypecode) = @_;
526 my $dbh=C4::Context->dbh;
527 my $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
528 $sth->execute($authtypecode);
529 return $sth->fetchrow_hashref;
531 sub AUTHmodauthority {
533 my ($dbh,$authid,$record,$authtypecode,$merge)=@_;
534 my ($oldrecord)=&AUTHgetauthority($dbh,$authid);
535 if ($oldrecord eq $record) {
538 my $sth=$dbh->prepare("update auth_header set marc=? where authid=?");
539 #warn find if linked records exist and delete them
540 my($linkidfield,$linkidsubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.linkid",$authtypecode);
542 if ($oldrecord->field($linkidfield)){
543 my @fields=$oldrecord->field($linkidfield);
544 foreach my $field (@fields){
545 my $linkid=$field->subfield($linkidsubfield) ;
547 ##Modify the record of linked
548 my $linkrecord=AUTHgetauthority($dbh,$linkid);
549 my $linktypecode=AUTHfind_authtypecode($dbh,$linkid);
550 my ( $linkidfield2,$linkidsubfield2)=AUTHfind_marc_from_kohafield($dbh,"auth_header.linkid",$linktypecode);
551 my @linkfields=$linkrecord->field($linkidfield2);
552 foreach my $linkfield (@linkfields){
553 if ($linkfield->subfield($linkidsubfield2) eq $authid){
554 $linkrecord->delete_field($linkfield);
555 $sth->execute($linkrecord->as_usmarc,$linkid);
556 zebraop($dbh,$linkid,'specialUpdate',"authorityserver");
562 #Now rewrite the $record to table with an add
563 $authid=AUTHaddauthority($dbh,$record,$authid,$authtypecode);
566 ### If a library thinks that updating all biblios is a long process and wishes to leave that to a cron job to use merge_authotities.p
567 ### they should have a system preference "dontmerge=1" otherwise by default biblios will be updated
568 ### the $merge flag is now depreceated and will be removed at code cleaning
570 if (C4::Context->preference('dontmerge') ){
571 # save the file in localfile/modified_authorities
572 my $cgidir = C4::Context->intranetdir ."/cgi-bin";
573 unless (opendir(DIR, "$cgidir")) {
574 $cgidir = C4::Context->intranetdir."/";
577 my $filename = $cgidir."/localfile/modified_authorities/$authid.authid";
578 open AUTH, "> $filename";
582 &merge($dbh,$authid,$record,$authid,$record);
587 sub AUTHdelauthority {
588 my ($dbh,$authid,$keep_biblio) = @_;
589 # if the keep_biblio is set to 1, then authority entries in biblio are preserved.
591 zebraop($dbh,$authid,"recordDelete","authorityserver");
592 $dbh->do("delete from auth_header where authid=$authid") ;
594 # FIXME : delete or not in biblio tables (depending on $keep_biblio flag)
599 sub AUTHfind_authtypecode {
600 my ($dbh,$authid) = @_;
601 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
602 $sth->execute($authid);
603 my ($authtypecode) = $sth->fetchrow;
604 return $authtypecode;
610 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
612 my $record = MARC::Record->new();
613 #---- TODO : the leader is missing
615 # my %subfieldlist=();
616 my $prevvalue; # if tag <10
617 my $field; # if tag >=10
618 for (my $i=0; $i< @$rtags; $i++) {
619 # rebuild MARC::Record
620 if (@$rtags[$i] ne $prevtag) {
623 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
627 $record->add_fields($field);
630 $indicators{@$rtags[$i]}.=' ';
631 if (@$rtags[$i] <10) {
632 $prevvalue= @$rvalues[$i];
636 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
638 $prevtag = @$rtags[$i];
640 if (@$rtags[$i] <10) {
641 $prevvalue=@$rvalues[$i];
643 if (length(@$rvalues[$i])>0) {
644 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
647 $prevtag= @$rtags[$i];
650 # the last has not been included inside the loop... do it now !
651 $record->add_fields($field) if $field;
660 my ($record,$authtypecode)=@_;
661 # warn "IN for ".$record->as_formatted;
662 my $dbh = C4::Context->dbh;
663 # warn "".$record->as_formatted;
664 my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
665 $sth->execute($authtypecode);
666 my ($auth_tag_to_report) = $sth->fetchrow;
668 # build a request for authoritysearch
669 my (@tags, @and_or, @excluding, @operator, @value, $offset, $length);
670 if ($record->field($auth_tag_to_report)) {
671 push @tags, $auth_tag_to_report;
674 push @operator, "all";
675 push @value, $record->field($auth_tag_to_report)->as_string();
678 my ($finalresult,$nbresult) = authoritysearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10,$authtypecode);
679 # there is at least 1 result => return the 1st one
681 return @$finalresult[0]->{authid},@$finalresult[0]->{summary};
683 # no result, returns nothing
688 ## give this a Marc record to return summary
689 my ($dbh,$record,$authid,$authtypecode)=@_;
691 # my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
692 my $authref = getauthtype($authtypecode);
693 my $summary = $authref->{summary};
694 my @fields = $record->fields();
695 # chop $tags_using_authtype;
696 # if the library has a summary defined, use it. Otherwise, build a standard one
698 my @fields = $record->fields();
699 foreach my $field (@fields) {
700 my $tag = $field->tag();
701 my $tagvalue = $field->as_string();
702 $summary =~ s/\[(.?.?.?.?)$tag\*(.*?)]/$1$tagvalue$2\[$1$tag$2]/g;
705 my @subf = $field->subfields;
706 for my $i (0..$#subf) {
707 my $subfieldcode = $subf[$i][0];
708 my $subfieldvalue = $subf[$i][1];
709 my $tagsubf = $tag.$subfieldcode;
710 $summary =~ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
714 $summary =~ s/\[(.*?)]//g;
715 $summary =~ s/\n/<br>/g;
717 my $heading; # = $authref->{summary};
721 my @fields = $record->fields();
722 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
723 # construct UNIMARC summary, that is quite different from MARC21 one
725 foreach my $field ($record->field('2..')) {
726 $heading.= $field->as_string();
729 foreach my $field ($record->field('4..')) {
730 $summary.= " <i>".$field->as_string()."</i><br/>";
731 $summary.= " <i>see:</i> ".$heading."<br/>";
734 foreach my $field ($record->field('5..')) {
735 $summary.= " <i>".$field->as_string()."</i><br/>";
736 $summary.= " <i>see:</i> ".$heading."<br/>";
739 foreach my $field ($record->field('7..')) {
740 $seeheading.= " <i>see also:</i> ".$field->as_string()."<br />";
741 $altheading.= " ".$field->as_string()."<br />";
742 $altheading.= " <i>see also:</i> ".$heading."<br />";
744 $summary = "<b>".$heading."</b><br />".$seeheading.$altheading.$summary;
746 # construct MARC21 summary
747 foreach my $field ($record->field('1..')) {
748 if ($record->field('100')) {
749 $heading.= $field->as_string('abcdefghjklmnopqrstvxyz68');
750 } elsif ($record->field('110')) {
751 $heading.= $field->as_string('abcdefghklmnoprstvxyz68');
752 } elsif ($record->field('111')) {
753 $heading.= $field->as_string('acdefghklnpqstvxyz68');
754 } elsif ($record->field('130')) {
755 $heading.= $field->as_string('adfghklmnoprstvxyz68');
756 } elsif ($record->field('148')) {
757 $heading.= $field->as_string('abvxyz68');
758 } elsif ($record->field('150')) {
759 # $heading.= $field->as_string('abvxyz68');
760 $heading.= $field->as_formatted();
761 my $tag=$field->tag();
762 $heading=~s /^$tag//g;
763 $heading =~s /\_/\$/g;
764 } elsif ($record->field('151')) {
765 $heading.= $field->as_string('avxyz68');
766 } elsif ($record->field('155')) {
767 $heading.= $field->as_string('abvxyz68');
768 } elsif ($record->field('180')) {
769 $heading.= $field->as_string('vxyz68');
770 } elsif ($record->field('181')) {
771 $heading.= $field->as_string('vxyz68');
772 } elsif ($record->field('182')) {
773 $heading.= $field->as_string('vxyz68');
774 } elsif ($record->field('185')) {
775 $heading.= $field->as_string('vxyz68');
777 $heading.= $field->as_string();
780 foreach my $field ($record->field('4..')) {
781 $seeheading.= " ".$field->as_string()."<br />";
782 $seeheading.= " <i>see:</i> ".$seeheading."<br />";
784 foreach my $field ($record->field('5..')) {
785 $altheading.= " <i>see also:</i> ".$field->as_string()."<br />";
786 $altheading.= " ".$field->as_string()."<br />";
787 $altheading.= " <i>see also:</i> ".$altheading."<br />";
789 $summary.=$heading.$seeheading.$altheading;
795 my ($dbh,$mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
796 my $authtypecodefrom = AUTHfind_authtypecode($dbh,$mergefrom);
797 my $authtypecodeto = AUTHfind_authtypecode($dbh,$mergeto);
798 # return if authority does not exist
799 my @X = $MARCfrom->fields();
801 my @X = $MARCto->fields();
805 # search the tag to report
806 my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
807 $sth->execute($authtypecodefrom);
808 my ($auth_tag_to_report) = $sth->fetchrow;
811 @record_to = $MARCto->field($auth_tag_to_report)->subfields() if $MARCto->field($auth_tag_to_report);
813 @record_from = $MARCfrom->field($auth_tag_to_report)->subfields() if $MARCfrom->field($auth_tag_to_report);
815 # search all biblio tags using this authority.
816 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
817 $sth->execute($authtypecodefrom);
818 my @tags_using_authtype;
819 while (my ($tagfield) = $sth->fetchrow) {
820 push @tags_using_authtype,$tagfield."9" ;
823 # now, find every biblio using this authority
824 ### try ZOOM search here
825 my $oConnection=C4::Context->Zconn("biblioserver");
827 $query= "\@attr GILS 1=2057 ".$mergefrom;
828 my $oResult = $oConnection->search_pqf($query);
829 my $count=$oResult->size() if ($oResult);
832 while ( $z<$count ) {
834 $rec=$oResult->record($z);
835 my $marcdata = $rec->raw();
836 push @reccache, $marcdata;
840 foreach my $marc(@reccache){
844 $marcrecord = MARC::File::USMARC::decode($marc);
845 foreach my $tagfield (@tags_using_authtype){
846 $tagfield=substr($tagfield,0,3);
847 my @tags = $marcrecord->field($tagfield);
848 foreach my $tag (@tags){
849 my $tagsubs=$tag->subfield("9");
850 #warn "$tagfield:$tagsubs:$mergefrom";
851 if ($tagsubs== $mergefrom) {
853 $tag->update("9" =>$mergeto);
854 foreach my $subfield (@record_to) {
855 # warn "$subfield,$subfield->[0],$subfield->[1]";
856 $tag->update($subfield->[0] =>$subfield->[1]);
859 $marcrecord->delete_field($tag);
860 $marcrecord->add_fields($tag);
864 my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,"") ;
866 &NEWmodbiblio($dbh,$marcrecord,$oldbiblio->{'biblionumber'},undef,"0000") ;
871 END { } # module clean-up code here (global destructor)
877 Koha Developement team <info@koha.org>
879 Paul POULAIN paul.poulain@free.fr
885 # Revision 1.28 2006/08/02 16:40:23 kados
886 # rolling back previous merge, will do manually
888 # Revision 1.9.2.17.2.1 2006/05/28 18:49:12 tgarip1957
889 # This is an unusual commit. The main purpose is a working model of Zebra on a modified rel2_2.
890 # Any questions regarding these commits should be asked to Joshua Ferraro unless you are Joshua whom I'll report to
892 # Revision 1.9.2.6 2005/06/07 10:02:00 tipaul
893 # porting dictionnary search from head to 2.2. there is now a ... facing titles, author & subject, to search in biblio & authorities existing values.
895 # Revision 1.9.2.5 2005/05/31 14:50:46 tipaul
896 # fix for authority merging. There was a bug on official installs
898 # Revision 1.9.2.4 2005/05/30 11:24:15 tipaul
899 # fixing a bug : when a field was repeated, the last field was also repeated. (Was due to the "empty" field in html between fields : to separate fields, in html, an empty field is automatically added. in AUTHhtml2marc, this empty field was not discarded correctly)
901 # Revision 1.9.2.3 2005/04/28 08:45:33 tipaul
902 # porting FindDuplicate feature for authorities from HEAD to rel_2_2, works correctly now.
904 # Revision 1.9.2.2 2005/02/28 14:03:13 tipaul
905 # * adding search on "main entry" (ie $a subfield) on a given authority (the "search everywhere" field is still here).
906 # * adding a select box to requet "contain" or "begin with" search.
907 # * fixing some bug in authority search (related to "main entry" search)
909 # Revision 1.9.2.1 2005/02/24 13:12:13 tipaul
910 # saving authority modif in a text file. This will be used soon with another script (in crontab). The script in crontab will retrieve every authorityid in the directory localfile/authorities and modify every biblio using this authority. Those modifs may be long. So they can't be done through http, because we may encounter a webserver timeout, and kill the process before end of the job.
911 # So, it will be done through a cron job.
912 # (/me agree we need some doc for command line scripts)
914 # Revision 1.9 2004/12/23 09:48:11 tipaul
915 # Minor changes in summary "exploding" (the 3 digits AFTER the subfield were not on the right place).
917 # Revision 1.8 2004/11/05 10:11:39 tipaul
918 # export auth_count_usage (bugfix)
920 # Revision 1.7 2004/09/23 16:13:00 tipaul
921 # Bugfix in modification
923 # Revision 1.6 2004/08/18 16:00:24 tipaul
924 # fixes for authorities management
926 # Revision 1.5 2004/07/05 13:37:22 doxulting
927 # First step for working authorities
929 # Revision 1.4 2004/06/22 11:35:37 tipaul
930 # removing % at the beginning of a string to avoid loooonnnngggg searchs
932 # Revision 1.3 2004/06/17 08:02:13 tipaul
933 # merging tag & subfield in auth_word for better perfs
935 # Revision 1.2 2004/06/10 08:29:01 tipaul
936 # MARC authority management (continued)
938 # Revision 1.1 2004/06/07 07:35:01 tipaul
939 # MARC authority management package