Lines 736-830
sub build_tabs {
Link Here
|
736 |
$template->param( BIG_LOOP => \@BIG_LOOP ); |
736 |
$template->param( BIG_LOOP => \@BIG_LOOP ); |
737 |
} |
737 |
} |
738 |
|
738 |
|
739 |
# |
|
|
740 |
# sub that tries to find authorities linked to the biblio |
741 |
# the sub : |
742 |
# - search in the authority DB for the same authid (in $9 of the biblio) |
743 |
# - search in the authority DB for the same 001 (in $3 of the biblio in UNIMARC) |
744 |
# - search in the authority DB for the same values (exactly) (in all subfields of the biblio) |
745 |
# if the authority is found, the biblio is modified accordingly to be connected to the authority. |
746 |
# if the authority is not found, it's added, and the biblio is then modified to be connected to the authority. |
747 |
# |
748 |
|
749 |
sub BiblioAddAuthorities{ |
750 |
my ( $record, $frameworkcode ) = @_; |
751 |
my $dbh=C4::Context->dbh; |
752 |
my $query=$dbh->prepare(qq| |
753 |
SELECT authtypecode,tagfield |
754 |
FROM marc_subfield_structure |
755 |
WHERE frameworkcode=? |
756 |
AND (authtypecode IS NOT NULL AND authtypecode<>\"\")|); |
757 |
# SELECT authtypecode,tagfield |
758 |
# FROM marc_subfield_structure |
759 |
# WHERE frameworkcode=? |
760 |
# AND (authtypecode IS NOT NULL OR authtypecode<>\"\")|); |
761 |
$query->execute($frameworkcode); |
762 |
my ($countcreated,$countlinked); |
763 |
while (my $data=$query->fetchrow_hashref){ |
764 |
foreach my $field ($record->field($data->{tagfield})){ |
765 |
next if ($field->subfield('3') || $field->subfield('9')); |
766 |
# No authorities id in the tag. |
767 |
# Search if there is any authorities to link to. |
768 |
my $query='at='.$data->{authtypecode}.' '; |
769 |
map {$query.= ' and he,ext="'.$_->[1].'"' if ($_->[0]=~/[A-z]/)} $field->subfields(); |
770 |
my ($error, $results, $total_hits)=SimpleSearch( $query, undef, undef, [ "authorityserver" ] ); |
771 |
# there is only 1 result |
772 |
if ( $error ) { |
773 |
warn "BIBLIOADDSAUTHORITIES: $error"; |
774 |
return (0,0) ; |
775 |
} |
776 |
if ( @{$results} == 1) { |
777 |
my $marcrecord = MARC::File::USMARC::decode($results->[0]); |
778 |
$field->add_subfields('9'=>$marcrecord->field('001')->data); |
779 |
$countlinked++; |
780 |
} elsif (@{$results} > 1) { |
781 |
#More than One result |
782 |
#This can comes out of a lack of a subfield. |
783 |
# my $marcrecord = MARC::File::USMARC::decode($results->[0]); |
784 |
# $record->field($data->{tagfield})->add_subfields('9'=>$marcrecord->field('001')->data); |
785 |
$countlinked++; |
786 |
} else { |
787 |
#There are no results, build authority record, add it to Authorities, get authid and add it to 9 |
788 |
###NOTICE : This is only valid if a subfield is linked to one and only one authtypecode |
789 |
###NOTICE : This can be a problem. We should also look into other types and rejected forms. |
790 |
my $authtypedata=GetAuthType($data->{authtypecode}); |
791 |
next unless $authtypedata; |
792 |
my $marcrecordauth=MARC::Record->new(); |
793 |
if (C4::Context->preference('marcflavour') eq 'MARC21') { |
794 |
$marcrecordauth->leader(' nz a22 o 4500'); |
795 |
SetMarcUnicodeFlag($marcrecordauth, 'MARC21'); |
796 |
} |
797 |
my $authfield=MARC::Field->new($authtypedata->{auth_tag_to_report},'','',"a"=>"".$field->subfield('a')); |
798 |
map { $authfield->add_subfields($_->[0]=>$_->[1]) if ($_->[0]=~/[A-z]/ && $_->[0] ne "a" )} $field->subfields(); |
799 |
$marcrecordauth->insert_fields_ordered($authfield); |
800 |
|
801 |
# bug 2317: ensure new authority knows it's using UTF-8; currently |
802 |
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles |
803 |
# automatically for UNIMARC (by not transcoding) |
804 |
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record |
805 |
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind |
806 |
# of change to a core API just before the 3.0 release. |
807 |
|
808 |
if (C4::Context->preference('marcflavour') eq 'MARC21') { |
809 |
$marcrecordauth->insert_fields_ordered(MARC::Field->new('667','','','a'=>"Machine generated authority record.")); |
810 |
my $cite = $record->author() . ", " . $record->title_proper() . ", " . $record->publication_date() . " "; |
811 |
$cite =~ s/^[\s\,]*//; |
812 |
$cite =~ s/[\s\,]*$//; |
813 |
$cite = "Work cat.: (" . C4::Context->preference('MARCOrgCode') . ")". $record->subfield('999','c') . ": " . $cite; |
814 |
$marcrecordauth->insert_fields_ordered(MARC::Field->new('670','','','a'=>$cite)); |
815 |
} |
816 |
|
817 |
# warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted; |
818 |
|
819 |
my $authid=AddAuthority($marcrecordauth,'',$data->{authtypecode}); |
820 |
$countcreated++; |
821 |
$field->add_subfields('9'=>$authid); |
822 |
} |
823 |
} |
824 |
} |
825 |
return ($countlinked,$countcreated); |
826 |
} |
827 |
|
828 |
# ======================== |
739 |
# ======================== |
829 |
# MAIN |
740 |
# MAIN |
830 |
#========================= |
741 |
#========================= |
Lines 957-963
if ( $op eq "addbiblio" ) {
Link Here
|
957 |
my $oldbibnum; |
868 |
my $oldbibnum; |
958 |
my $oldbibitemnum; |
869 |
my $oldbibitemnum; |
959 |
if (C4::Context->preference("BiblioAddsAuthorities")){ |
870 |
if (C4::Context->preference("BiblioAddsAuthorities")){ |
960 |
my ($countlinked,$countcreated)=BiblioAddAuthorities($record,$frameworkcode); |
871 |
my ($countlinked,$countcreated)=BiblioAutoLink($record,$frameworkcode); |
961 |
} |
872 |
} |
962 |
if ( $is_a_modif ) { |
873 |
if ( $is_a_modif ) { |
963 |
ModBiblioframework( $biblionumber, $frameworkcode ); |
874 |
ModBiblioframework( $biblionumber, $frameworkcode ); |