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

(-)a/C4/Record.pm (-7 / +54 lines)
Lines 35-40 use C4::XSLT (); Link Here
35
use YAML; #marcrecords2csv
35
use YAML; #marcrecords2csv
36
use Template;
36
use Template;
37
use Text::CSV::Encoded; #marc2csv
37
use Text::CSV::Encoded; #marc2csv
38
use Koha::SimpleMARC qw(read_field);
38
39
39
use vars qw($VERSION @ISA @EXPORT);
40
use vars qw($VERSION @ISA @EXPORT);
40
41
Lines 327-334 sub marc2endnote { Link Here
327
    }
328
    }
328
	my $fields = {
329
	my $fields = {
329
		DB => C4::Context->preference("LibraryName"),
330
		DB => C4::Context->preference("LibraryName"),
330
		Title => $marc_rec_obj->title(),	
331
		Title => $marc_rec_obj->title(),
331
		Author => $marc_rec_obj->author(),	
332
		Author => $marc_rec_obj->author(),
332
		Publisher => $f710a,
333
		Publisher => $f710a,
333
		City => $f260a,
334
		City => $f260a,
334
		Year => $marc_rec_obj->publication_date,
335
		Year => $marc_rec_obj->publication_date,
Lines 346-352 sub marc2endnote { Link Here
346
	$template.="AB - Abstract\n" if $abstract;
347
	$template.="AB - Abstract\n" if $abstract;
347
	my ($text, $errmsg) = $style->format($template, $fields);
348
	my ($text, $errmsg) = $style->format($template, $fields);
348
	return ($text);
349
	return ($text);
349
	
350
350
}
351
}
351
352
352
=head2 marc2csv - Convert several records from UNIMARC to CSV
353
=head2 marc2csv - Convert several records from UNIMARC to CSV
Lines 640-646 sub changeEncoding { Link Here
640
	my $error;
641
	my $error;
641
	unless($flavour) {$flavour = C4::Context->preference("marcflavour")};
642
	unless($flavour) {$flavour = C4::Context->preference("marcflavour")};
642
	unless($to_encoding) {$to_encoding = "UTF-8"};
643
	unless($to_encoding) {$to_encoding = "UTF-8"};
643
	
644
644
	# ISO-2709 Record (MARC21 or UNIMARC)
645
	# ISO-2709 Record (MARC21 or UNIMARC)
645
	if (lc($format) =~ /^marc$/o) {
646
	if (lc($format) =~ /^marc$/o) {
646
		# if we're converting encoding of an ISO2709 file, we need to roundtrip through XML
647
		# if we're converting encoding of an ISO2709 file, we need to roundtrip through XML
Lines 651-657 sub changeEncoding { Link Here
651
		unless ($error) {
652
		unless ($error) {
652
			($error,$newrecord) = marcxml2marc($marcxml,$to_encoding,$flavour);
653
			($error,$newrecord) = marcxml2marc($marcxml,$to_encoding,$flavour);
653
		}
654
		}
654
	
655
655
	# MARCXML Record
656
	# MARCXML Record
656
	} elsif (lc($format) =~ /^marcxml$/o) { # MARCXML Record
657
	} elsif (lc($format) =~ /^marcxml$/o) { # MARCXML Record
657
		my $marc;
658
		my $marc;
Lines 749-762 sub marc2bibtex { Link Here
749
        );
750
        );
750
    }
751
    }
751
752
752
    $tex .= "\@book{";
753
    my $BibtexExportAdditionalFields = C4::Context->preference('BibtexExportAdditionalFields');
754
    my $additional_fields;
755
    if ($BibtexExportAdditionalFields) {
756
        $BibtexExportAdditionalFields = "$BibtexExportAdditionalFields\n\n";
757
        $additional_fields = eval { YAML::Load($BibtexExportAdditionalFields); };
758
        if ($@) {
759
            warn "Unable to parse BibtexExportAdditionalFields : $@";
760
            $additional_fields = undef;
761
        }
762
    }
763
764
    if ( $additional_fields && $additional_fields->{'@'} ) {
765
        my ( $f, $sf ) = split( /\$/, $additional_fields->{'@'} );
766
        my ( $type ) = read_field( { record => $record, field => $f, subfield => $sf, field_numbers => [1] } );
767
768
        if ($type) {
769
            $tex .= '@' . $type . '{';
770
        }
771
        else {
772
            $tex .= "\@book{";
773
        }
774
    }
775
    else {
776
        $tex .= "\@book{";
777
    }
778
753
    my @elt;
779
    my @elt;
754
    for ( my $i = 0 ; $i < scalar( @bh ) ; $i = $i + 2 ) {
780
    for ( my $i = 0 ; $i < scalar( @bh ) ; $i = $i + 2 ) {
755
        next unless $bh[$i+1];
781
        next unless $bh[$i+1];
756
        push @elt, qq|\t$bh[$i] = {$bh[$i+1]}|;
782
        push @elt, qq|\t$bh[$i] = {$bh[$i+1]}|;
757
    }
783
    }
758
    $tex .= join(",\n", $id, @elt);
784
    $tex .= join(",\n", $id, @elt);
759
    $tex .= "\n}\n";
785
    $tex .= "\n";
786
787
    if ($additional_fields) {
788
        foreach my $bibtex_tag ( keys %$additional_fields ) {
789
            next if $bibtex_tag eq '@';
790
791
            my @fields =
792
              ref( $additional_fields->{$bibtex_tag} ) eq 'ARRAY'
793
              ? @{ $additional_fields->{$bibtex_tag} }
794
              : $additional_fields->{$bibtex_tag};
795
796
            for my $tag (@fields) {
797
                my ( $f, $sf ) = split( /\$/, $tag );
798
                my @values = read_field( { record => $record, field => $f, subfield => $sf } );
799
                foreach my $v (@values) {
800
                    $tex .= qq(\t$bibtex_tag = {$v}\n);
801
                }
802
            }
803
        }
804
    }
805
806
    $tex .= "}\n";
760
807
761
    return $tex;
808
    return $tex;
762
}
809
}
(-)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/atomicupdate/bug_12357.sql (+5 lines)
Line 0 Link Here
1
INSERT INTO systempreferences (variable,value,options,explanation,type)
2
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');
3
4
INSERT INTO systempreferences (variable,value,options,explanation,type)
5
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');
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 64-69 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
64
('BasketConfirmations','1','always ask for confirmation.|do not ask for confirmation.','When closing or reopening a basket,','Choice'),
64
('BasketConfirmations','1','always ask for confirmation.|do not ask for confirmation.','When closing or reopening a basket,','Choice'),
65
('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'),
65
('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'),
66
('BiblioDefaultView','normal','normal|marc|isbd','Choose the default detail view in the catalog; choose between normal, marc or isbd','Choice'),
66
('BiblioDefaultView','normal','normal|marc|isbd','Choose the default detail view in the catalog; choose between normal, marc or isbd','Choice'),
67
('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'),
67
('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'),
68
('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'),
68
('BlockReturnOfWithdrawnItems','1','0','If enabled, items that are marked as withdrawn cannot be returned.','YesNo'),
69
('BlockReturnOfWithdrawnItems','1','0','If enabled, items that are marked as withdrawn cannot be returned.','YesNo'),
69
('BorrowerMandatoryField','surname|cardnumber',NULL,'Choose the mandatory fields for a patron\'s account','free'),
70
('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/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