View | Details | Raw Unified | Return to bug 12357
Collapse All | Expand All

(-)a/C4/Record.pm (-12 / +59 lines)
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
}
(-)a/C4/Ris.pm (-24 / +73 lines)
Lines 59-70 package C4::Ris; Link Here
59
#
59
#
60
#
60
#
61
61
62
#use strict;
62
use Modern::Perl;
63
#use warnings;
64
63
65
use List::MoreUtils qw/uniq/;
64
use List::MoreUtils qw/uniq/;
66
use vars qw($VERSION @ISA @EXPORT);
65
use vars qw($VERSION @ISA @EXPORT);
67
66
67
use C4::Biblio qw(GetMarcSubfieldStructureFromKohaField);
68
use Koha::SimpleMARC qw(read_field);
69
68
# set the version for version checking
70
# set the version for version checking
69
$VERSION = 3.07.00.049;
71
$VERSION = 3.07.00.049;
70
72
Lines 76-81 $VERSION = 3.07.00.049; Link Here
76
  &marc2ris
78
  &marc2ris
77
);
79
);
78
80
81
our $utf;
82
our $intype;
83
our $marcprint;
84
our $protoyear;
85
79
86
80
=head1 marc2bibtex - Convert from UNIMARC to RIS
87
=head1 marc2bibtex - Convert from UNIMARC to RIS
81
88
Lines 101-125 sub marc2ris { Link Here
101
    close STDOUT;
108
    close STDOUT;
102
    open STDOUT,'>', \$outvar;
109
    open STDOUT,'>', \$outvar;
103
110
111
    ## First we should check the character encoding. This may be
112
    ## MARC-8 or UTF-8. The former is indicated by a blank, the latter
113
    ## by 'a' at position 09 (zero-based) of the leader
114
    my $leader = $record->leader();
115
    if ( $intype eq "marc21" ) {
116
        if ( $leader =~ /^.{9}a/ ) {
117
            print "<marc>---\r\n<marc>UTF-8 data\r\n" if $marcprint;
118
            $utf = 1;
119
        }
120
        else {
121
            print "<marc>---\r\n<marc>MARC-8 data\r\n" if $marcprint;
122
        }
123
    }
124
    ## else: other MARC formats do not specify the character encoding
125
    ## we assume it's *not* UTF-8
126
127
    my $RisExportAdditionalFields = C4::Context->preference('RisExportAdditionalFields');
128
    my $ris_additional_fields;
129
    if ($RisExportAdditionalFields) {
130
        $RisExportAdditionalFields = "$RisExportAdditionalFields\n\n";
131
        $ris_additional_fields = eval { YAML::Load($RisExportAdditionalFields); };
132
        if ($@) {
133
            warn "Unable to parse RisExportAdditionalFields : $@";
134
            $ris_additional_fields = undef;
135
        }
136
    }
104
137
105
	## First we should check the character encoding. This may be
138
    ## start RIS dataset
106
	## MARC-8 or UTF-8. The former is indicated by a blank, the latter
139
    if ( $ris_additional_fields && $ris_additional_fields->{TY} ) {
107
	## by 'a' at position 09 (zero-based) of the leader
140
        my ( $f, $sf ) = split( /\$/, $ris_additional_fields->{TY} );
108
	my $leader = $record->leader();
141
        my ( $type ) = read_field( { record => $record, field => $f, subfield => $sf, field_numbers => [1] } );
109
	if ($intype eq "marc21") {
142
        if ($type) {
110
	    if ($leader =~ /^.{9}a/) {
143
            print "TY  - $type\r\n";
111
		print "<marc>---\r\n<marc>UTF-8 data\r\n" if $marcprint;
144
        }
112
		$utf = 1;
145
        else {
113
	    }
146
            &print_typetag($leader);
114
	    else {
147
        }
115
		print "<marc>---\r\n<marc>MARC-8 data\r\n" if $marcprint;
148
    }
116
	    }
149
    else {
117
	}
150
        &print_typetag($leader);
118
	## else: other MARC formats do not specify the character encoding
151
    }
119
	## we assume it's *not* UTF-8
120
121
	## start RIS dataset
122
	&print_typetag($leader);
123
152
124
	## retrieve all author fields and collect them in a list
153
	## retrieve all author fields and collect them in a list
125
	my @author_fields;
154
	my @author_fields;
Lines 285-290 sub marc2ris { Link Here
285
        print_uri($record->field('856'));
314
        print_uri($record->field('856'));
286
    }
315
    }
287
316
317
    if ($ris_additional_fields) {
318
        foreach my $ris_tag ( keys %$ris_additional_fields ) {
319
            next if $ris_tag eq 'TY';
320
321
            my @fields =
322
              ref( $ris_additional_fields->{$ris_tag} ) eq 'ARRAY'
323
              ? @{ $ris_additional_fields->{$ris_tag} }
324
              : $ris_additional_fields->{$ris_tag};
325
326
            for my $tag (@fields) {
327
                my ( $f, $sf ) = split( /\$/, $tag );
328
                my @values = read_field( { record => $record, field => $f, subfield => $sf } );
329
                foreach my $v (@values) {
330
                    print "$ris_tag  - $v\r\n";
331
                }
332
            }
333
        }
334
    }
335
288
	## end RIS dataset
336
	## end RIS dataset
289
	print "ER  - \r\n";
337
	print "ER  - \r\n";
290
338
Lines 497-502 sub print_title { Link Here
497
	my $clean_title = $titlefield->subfield('a');
545
	my $clean_title = $titlefield->subfield('a');
498
546
499
	my $clean_subtitle = $titlefield->subfield('b');
547
	my $clean_subtitle = $titlefield->subfield('b');
548
$clean_subtitle ||= q{};
500
	$clean_title =~ s% *[/:;.]$%%;
549
	$clean_title =~ s% *[/:;.]$%%;
501
	$clean_subtitle =~ s%^ *(.*) *[/:;.]$%$1%;
550
	$clean_subtitle =~ s%^ *(.*) *[/:;.]$%$1%;
502
551
Lines 777-783 sub get_keywords { Link Here
777
	    }
826
	    }
778
	    else {
827
	    else {
779
		## retrieve all available subfields
828
		## retrieve all available subfields
780
		@kwsubfields = $kwfield->subfields();
829
		my @kwsubfields = $kwfield->subfields();
781
		
830
		
782
		## loop over all available subfield tuples
831
		## loop over all available subfield tuples
783
        foreach my $kwtuple (@kwsubfields) {
832
        foreach my $kwtuple (@kwsubfields) {
Lines 891-899 sub pool_subx { Link Here
891
940
892
    ## loop over all notefields
941
    ## loop over all notefields
893
    foreach my $notefield (@notefields) {
942
    foreach my $notefield (@notefields) {
894
	if ($notefield != undef) {
943
	if (defined $notefield) {
895
	    ## retrieve all available subfield tuples
944
	    ## retrieve all available subfield tuples
896
	    @notesubfields = $notefield->subfields();
945
	    my @notesubfields = $notefield->subfields();
897
946
898
	    ## loop over all subfield tuples
947
	    ## loop over all subfield tuples
899
        foreach my $notetuple (@notesubfields) {
948
        foreach my $notetuple (@notesubfields) {
Lines 967-973 sub charconv { Link Here
967
	## return unaltered if already utf-8
1016
	## return unaltered if already utf-8
968
	return @_;
1017
	return @_;
969
    }
1018
    }
970
    elsif ($uniout eq "t") {
1019
    elsif (my $uniout eq "t") {
971
	## convert to utf-8
1020
	## convert to utf-8
972
	return marc8_to_utf8("@_");
1021
	return marc8_to_utf8("@_");
973
    }
1022
    }
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 66-71 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
66
('BasketConfirmations','1','always ask for confirmation.|do not ask for confirmation.','When closing or reopening a basket,','Choice'),
66
('BasketConfirmations','1','always ask for confirmation.|do not ask for confirmation.','When closing or reopening a basket,','Choice'),
67
('BiblioAddsAuthorities','0',NULL,'If ON, adding a new biblio will check for an existing authority record and create one on the fly if one doesn\'t exist','YesNo'),
67
('BiblioAddsAuthorities','0',NULL,'If ON, adding a new biblio will check for an existing authority record and create one on the fly if one doesn\'t exist','YesNo'),
68
('BiblioDefaultView','normal','normal|marc|isbd','Choose the default detail view in the catalog; choose between normal, marc or isbd','Choice'),
68
('BiblioDefaultView','normal','normal|marc|isbd','Choose the default detail view in the catalog; choose between normal, marc or isbd','Choice'),
69
('BibtexExportAdditionalFields',  '', NULL ,  'Define additional BibTex tags to export from MARC records in YAML format as an associative array with either a marc tag/subfield combination as the value, or a list of tag/subfield combinations.',  'textarea'),
69
('BlockExpiredPatronOpacActions','1',NULL,'Set whether an expired patron can perform opac actions such as placing holds or renew books, can be overridden on a per patron-type basis','YesNo'),
70
('BlockExpiredPatronOpacActions','1',NULL,'Set whether an expired patron can perform opac actions such as placing holds or renew books, can be overridden on a per patron-type basis','YesNo'),
70
('BlockReturnOfWithdrawnItems','1','0','If enabled, items that are marked as withdrawn cannot be returned.','YesNo'),
71
('BlockReturnOfWithdrawnItems','1','0','If enabled, items that are marked as withdrawn cannot be returned.','YesNo'),
71
('BorrowerMandatoryField','surname|cardnumber',NULL,'Choose the mandatory fields for a patron\'s account','free'),
72
('BorrowerMandatoryField','surname|cardnumber',NULL,'Choose the mandatory fields for a patron\'s account','free'),
Lines 361-366 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
361
('ReturnLog','1',NULL,'If ON, enables the circulation (returns) log','YesNo'),
362
('ReturnLog','1',NULL,'If ON, enables the circulation (returns) log','YesNo'),
362
('ReturnToShelvingCart','0','','If set, when any item is \'checked in\', it\'s location code will be changed to CART.','YesNo'),
363
('ReturnToShelvingCart','0','','If set, when any item is \'checked in\', it\'s location code will be changed to CART.','YesNo'),
363
('reviewson','1','','If ON, enables patron reviews of bibliographic records in the OPAC','YesNo'),
364
('reviewson','1','','If ON, enables patron reviews of bibliographic records in the OPAC','YesNo'),
365
('RisExportAdditionalFields',  '', NULL ,  'Define additional RIS tags to export from MARC records in YAML format as an associative array with either a marc tag/subfield combination as the value, or a list of tag/subfield combinations.',  'textarea'),
364
('RoutingListAddReserves','1','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
366
('RoutingListAddReserves','1','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
365
('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'),
367
('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'),
366
('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'),
368
('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+16 lines)
Lines 9759-9764 if ( CheckVersion($DBversion) ) { Link Here
9759
    SetVersion ($DBversion);
9759
    SetVersion ($DBversion);
9760
}
9760
}
9761
9761
9762
$DBversion = "3.17.00.XXX";
9763
if ( CheckVersion($DBversion) ) {
9764
    $dbh->do(q{
9765
        INSERT INTO systempreferences (variable,value,options,explanation,type)
9766
        VALUES ('RisExportAdditionalFields',  '', NULL ,  'Define additional RIS tags to export from MARC records in YAML format as an associative array with either a marc tag/subfield combination as the value, or a list of tag/subfield combinations.',  'textarea')
9767
    });
9768
9769
    $dbh->do(q{
9770
        INSERT INTO systempreferences (variable,value,options,explanation,type)
9771
        VALUES ('BibtexExportAdditionalFields',  '', NULL ,  'Define additional BibTex tags to export from MARC records in YAML format as an associative array with either a marc tag/subfield combination as the value, or a list of tag/subfield combinations.',  'textarea')
9772
    });
9773
9774
    print "Upgrade to $DBversion done (Bug XXX - Add ability to export arbitrary MARC fields for RIS and BibTex)\n";
9775
    SetVersion($DBversion);
9776
}
9777
9762
=head1 FUNCTIONS
9778
=head1 FUNCTIONS
9763
9779
9764
=head2 TableExists($table)
9780
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-1 / +23 lines)
Lines 215-217 Cataloging: Link Here
215
                  yes: "do"
215
                  yes: "do"
216
                  no: "don't"
216
                  no: "don't"
217
            - attempt to match aggressively by trying all variations of the ISBNs in the imported record as a phrase in the ISBN fields of already cataloged records.  Note that this preference has no effect if UseQueryParser is on.
217
            - attempt to match aggressively by trying all variations of the ISBNs in the imported record as a phrase in the ISBN fields of already cataloged records.  Note that this preference has no effect if UseQueryParser is on.
218
- 
218
    Exporting:
219
        -
220
            - Include following fields when exporting BibTeX,
221
            - pref: BibtexExportAdditionalFields
222
              type: textarea
223
            - "Use one line per tag in the format BT_TAG: TAG$SUBFIELD ( e.g. lccn: 010$a )"
224
            - "<br/>"
225
            - "To specificy multiple marc tags/subfields as targets for a repeating BibTex tag, use the following format: BT_TAG: [TAG2$SUBFIELD1, TAG2$SUBFIELD2] ( e.g. notes: [501$a, 505$g] )"
226
            - "<br/>"
227
            - "All values of repeating tags and subfields will be printed with the given BibTeX tag."
228
            - "<br/>"
229
            - "Use '@' ( with quotes ) as the BT_TAG to replace the bibtex record type with a field value of your choosing."
230
        -
231
            - Include following fields when exporting RIS,
232
            - pref: RisExportAdditionalFields
233
              type: textarea
234
            - "Use one line per tag in the format RIS_TAG: TAG$SUBFIELD ( e.g. LC: 010$a )"
235
            - "<br/>"
236
            - "To specificy multiple marc tags/subfields as targets for a repeating RIS tag, use the following format: RIS_TAG: [TAG2$SUBFIELD1, TAG2$SUBFIELD2] ( e.g. NT: [501$a, 505$g] )"
237
            - "<br/>"
238
            - "All values of repeating tags and subfields will be printed with the given RIS tag."
239
            - "<br/>"
240
            - "Use of TY ( record type ) as a key will <i>replace</i> the default TY with the field value of your choosing."

Return to bug 12357