Lines 34-39
use C4::Koha; #marc2csv
Link Here
|
34 |
use C4::XSLT (); |
34 |
use C4::XSLT (); |
35 |
use YAML; #marcrecords2csv |
35 |
use YAML; #marcrecords2csv |
36 |
use Text::CSV::Encoded; #marc2csv |
36 |
use Text::CSV::Encoded; #marc2csv |
|
|
37 |
use Koha::SimpleMARC qw(read_field); |
37 |
|
38 |
|
38 |
use vars qw($VERSION @ISA @EXPORT); |
39 |
use vars qw($VERSION @ISA @EXPORT); |
39 |
|
40 |
|
Lines 326-333
sub marc2endnote {
Link Here
|
326 |
} |
327 |
} |
327 |
my $fields = { |
328 |
my $fields = { |
328 |
DB => C4::Context->preference("LibraryName"), |
329 |
DB => C4::Context->preference("LibraryName"), |
329 |
Title => $marc_rec_obj->title(), |
330 |
Title => $marc_rec_obj->title(), |
330 |
Author => $marc_rec_obj->author(), |
331 |
Author => $marc_rec_obj->author(), |
331 |
Publisher => $f710a, |
332 |
Publisher => $f710a, |
332 |
City => $f260a, |
333 |
City => $f260a, |
333 |
Year => $marc_rec_obj->publication_date, |
334 |
Year => $marc_rec_obj->publication_date, |
Lines 345-351
sub marc2endnote {
Link Here
|
345 |
$template.="AB - Abstract\n" if $abstract; |
346 |
$template.="AB - Abstract\n" if $abstract; |
346 |
my ($text, $errmsg) = $style->format($template, $fields); |
347 |
my ($text, $errmsg) = $style->format($template, $fields); |
347 |
return ($text); |
348 |
return ($text); |
348 |
|
349 |
|
349 |
} |
350 |
} |
350 |
|
351 |
|
351 |
=head2 marc2csv - Convert several records from UNIMARC to CSV |
352 |
=head2 marc2csv - Convert several records from UNIMARC to CSV |
Lines 464-470
sub marcrecord2csv {
Link Here
|
464 |
foreach (@marcfieldsarray) { |
465 |
foreach (@marcfieldsarray) { |
465 |
my @result = split('=', $_); |
466 |
my @result = split('=', $_); |
466 |
if (scalar(@result) == 2) { |
467 |
if (scalar(@result) == 2) { |
467 |
push @marcfields, { header => $result[0], field => $result[1] }; |
468 |
push @marcfields, { header => $result[0], field => $result[1] }; |
468 |
} else { |
469 |
} else { |
469 |
push @marcfields, { field => $result[0] } |
470 |
push @marcfields, { field => $result[0] } |
470 |
} |
471 |
} |
Lines 480-486
sub marcrecord2csv {
Link Here
|
480 |
|
481 |
|
481 |
my $field = $_->{field}; |
482 |
my $field = $_->{field}; |
482 |
# Remove any blank char that might have unintentionally insered into the tag name |
483 |
# Remove any blank char that might have unintentionally insered into the tag name |
483 |
$field =~ s/\s+//g; |
484 |
$field =~ s/\s+//g; |
484 |
|
485 |
|
485 |
# If we have a user-supplied header, we use it |
486 |
# If we have a user-supplied header, we use it |
486 |
if (exists $_->{header}) { |
487 |
if (exists $_->{header}) { |
Lines 504-510
sub marcrecord2csv {
Link Here
|
504 |
} |
505 |
} |
505 |
} |
506 |
} |
506 |
$csv->combine(@marcfieldsheaders); |
507 |
$csv->combine(@marcfieldsheaders); |
507 |
$output = $csv->string() . "\n"; |
508 |
$output = $csv->string() . "\n"; |
508 |
} |
509 |
} |
509 |
|
510 |
|
510 |
# For each marcfield to export |
511 |
# For each marcfield to export |
Lines 529-535
sub marcrecord2csv {
Link Here
|
529 |
push @tmpfields, (defined $authvalues->{$subfield}) ? $authvalues->{$subfield} : $subfield; |
530 |
push @tmpfields, (defined $authvalues->{$subfield}) ? $authvalues->{$subfield} : $subfield; |
530 |
} |
531 |
} |
531 |
} |
532 |
} |
532 |
push (@fieldstab, join($subfieldseparator, @tmpfields)); |
533 |
push (@fieldstab, join($subfieldseparator, @tmpfields)); |
533 |
# Or a field |
534 |
# Or a field |
534 |
} else { |
535 |
} else { |
535 |
my @fields = ($record->field($marcfield)); |
536 |
my @fields = ($record->field($marcfield)); |
Lines 557-563
sub marcrecord2csv {
Link Here
|
557 |
|
558 |
|
558 |
push @valuesarray, $value; |
559 |
push @valuesarray, $value; |
559 |
} |
560 |
} |
560 |
push (@fieldstab, join($fieldseparator, @valuesarray)); |
561 |
push (@fieldstab, join($fieldseparator, @valuesarray)); |
561 |
} |
562 |
} |
562 |
}; |
563 |
}; |
563 |
|
564 |
|
Lines 599-605
sub changeEncoding {
Link Here
|
599 |
my $error; |
600 |
my $error; |
600 |
unless($flavour) {$flavour = C4::Context->preference("marcflavour")}; |
601 |
unless($flavour) {$flavour = C4::Context->preference("marcflavour")}; |
601 |
unless($to_encoding) {$to_encoding = "UTF-8"}; |
602 |
unless($to_encoding) {$to_encoding = "UTF-8"}; |
602 |
|
603 |
|
603 |
# ISO-2709 Record (MARC21 or UNIMARC) |
604 |
# ISO-2709 Record (MARC21 or UNIMARC) |
604 |
if (lc($format) =~ /^marc$/o) { |
605 |
if (lc($format) =~ /^marc$/o) { |
605 |
# if we're converting encoding of an ISO2709 file, we need to roundtrip through XML |
606 |
# if we're converting encoding of an ISO2709 file, we need to roundtrip through XML |
Lines 610-616
sub changeEncoding {
Link Here
|
610 |
unless ($error) { |
611 |
unless ($error) { |
611 |
($error,$newrecord) = marcxml2marc($marcxml,$to_encoding,$flavour); |
612 |
($error,$newrecord) = marcxml2marc($marcxml,$to_encoding,$flavour); |
612 |
} |
613 |
} |
613 |
|
614 |
|
614 |
# MARCXML Record |
615 |
# MARCXML Record |
615 |
} elsif (lc($format) =~ /^marcxml$/o) { # MARCXML Record |
616 |
} elsif (lc($format) =~ /^marcxml$/o) { # MARCXML Record |
616 |
my $marc; |
617 |
my $marc; |
Lines 708-721
sub marc2bibtex {
Link Here
|
708 |
); |
709 |
); |
709 |
} |
710 |
} |
710 |
|
711 |
|
711 |
$tex .= "\@book{"; |
712 |
my $BibtexExportAdditionalFields = C4::Context->preference('BibtexExportAdditionalFields'); |
|
|
713 |
my $additional_fields; |
714 |
if ($BibtexExportAdditionalFields) { |
715 |
$BibtexExportAdditionalFields = "$BibtexExportAdditionalFields\n\n"; |
716 |
$additional_fields = eval { YAML::Load($BibtexExportAdditionalFields); }; |
717 |
if ($@) { |
718 |
warn "Unable to parse BibtexExportAdditionalFields : $@"; |
719 |
$additional_fields = undef; |
720 |
} |
721 |
} |
722 |
|
723 |
if ( $additional_fields && $additional_fields->{'@'} ) { |
724 |
my ( $f, $sf ) = split( /\$/, $additional_fields->{'@'} ); |
725 |
my ( $type ) = read_field( { record => $record, field => $f, subfield => $sf, field_numbers => [1] } ); |
726 |
|
727 |
if ($type) { |
728 |
$tex .= '@' . $type . '{'; |
729 |
} |
730 |
else { |
731 |
$tex .= "\@book{"; |
732 |
} |
733 |
} |
734 |
else { |
735 |
$tex .= "\@book{"; |
736 |
} |
737 |
|
712 |
my @elt; |
738 |
my @elt; |
713 |
for ( my $i = 0 ; $i < scalar( @bh ) ; $i = $i + 2 ) { |
739 |
for ( my $i = 0 ; $i < scalar( @bh ) ; $i = $i + 2 ) { |
714 |
next unless $bh[$i+1]; |
740 |
next unless $bh[$i+1]; |
715 |
push @elt, qq|\t$bh[$i] = {$bh[$i+1]}|; |
741 |
push @elt, qq|\t$bh[$i] = {$bh[$i+1]}|; |
716 |
} |
742 |
} |
717 |
$tex .= join(",\n", $id, @elt); |
743 |
$tex .= join(",\n", $id, @elt); |
718 |
$tex .= "\n}\n"; |
744 |
$tex .= "\n"; |
|
|
745 |
|
746 |
if ($additional_fields) { |
747 |
foreach my $bibtex_tag ( keys %$additional_fields ) { |
748 |
next if $bibtex_tag eq '@'; |
749 |
|
750 |
my @fields = |
751 |
ref( $additional_fields->{$bibtex_tag} ) eq 'ARRAY' |
752 |
? @{ $additional_fields->{$bibtex_tag} } |
753 |
: $additional_fields->{$bibtex_tag}; |
754 |
|
755 |
for my $tag (@fields) { |
756 |
my ( $f, $sf ) = split( /\$/, $tag ); |
757 |
my @values = read_field( { record => $record, field => $f, subfield => $sf } ); |
758 |
foreach my $v (@values) { |
759 |
$tex .= qq(\t$bibtex_tag = {$v}\n); |
760 |
} |
761 |
} |
762 |
} |
763 |
} |
764 |
|
765 |
$tex .= "}\n"; |
719 |
|
766 |
|
720 |
return $tex; |
767 |
return $tex; |
721 |
} |
768 |
} |