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

(-)a/C4/Record.pm (-35 / +78 lines)
Lines 2-7 package C4::Record; Link Here
2
#
2
#
3
# Copyright 2006 (C) LibLime
3
# Copyright 2006 (C) LibLime
4
# Parts copyright 2010 BibLibre
4
# Parts copyright 2010 BibLibre
5
# Part copyright 2015 Universidad de El Salvador
5
#
6
#
6
# This file is part of Koha.
7
# This file is part of Koha.
7
#
8
#
Lines 25-31 use strict; Link Here
25
# please specify in which methods a given module is used
26
# please specify in which methods a given module is used
26
use MARC::Record; # marc2marcxml, marcxml2marc, changeEncoding
27
use MARC::Record; # marc2marcxml, marcxml2marc, changeEncoding
27
use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding
28
use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding
28
use MARC::Crosswalk::DublinCore; # marc2dcxml
29
use Biblio::EndnoteStyle;
29
use Biblio::EndnoteStyle;
30
use Unicode::Normalize; # _entity_encode
30
use Unicode::Normalize; # _entity_encode
31
use C4::Biblio; #marc2bibtex
31
use C4::Biblio; #marc2bibtex
Lines 36-41 use YAML; #marcrecords2csv Link Here
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
use Koha::SimpleMARC qw(read_field);
39
use Koha::XSLT_Handler;
40
use Carp;
39
41
40
use vars qw($VERSION @ISA @EXPORT);
42
use vars qw($VERSION @ISA @EXPORT);
41
43
Lines 220-270 sub marcxml2marc { Link Here
220
222
221
=head2 marc2dcxml - Convert from ISO-2709 to Dublin Core
223
=head2 marc2dcxml - Convert from ISO-2709 to Dublin Core
222
224
223
  my ($error,$dcxml) = marc2dcxml($marc,$qualified);
225
    my dcxml = marc2dcxml ($marc, $xml, $biblionumber, $format);
224
226
225
Returns a DublinCore::Record object, will eventually return a Dublin Core scalar
227
EXAMPLE
226
228
227
FIXME: should return actual XML, not just an object
229
    my dcxml = marc2dcxml (undef, undef, 1, "oaidc");
230
231
Convert MARC or MARCXML to Dublin Core metadata (XSLT Transformation),
232
optionally can get an XML directly from database (biblioitems.marcxml)
233
without item information. This method take into consideration the syspref
234
'marcflavour' (UNIMARC, MARC21 and NORMARC).
235
Return an XML file with the format defined in C<$format>
228
236
229
C<$marc> - an ISO-2709 scalar or MARC::Record object
237
C<$marc> - an ISO-2709 scalar or MARC::Record object
230
238
231
C<$qualified> - specify whether qualified Dublin Core should be used in the input or output [0]
239
C<$xml> - a MARCXML file
240
241
C<$biblionumber> - obtain the record directly from database (biblioitems.marcxml)
242
243
C<$format> - accept three type of DC formats (oaidc, srwdc, and rdfdc )
232
244
233
=cut
245
=cut
234
246
235
sub marc2dcxml {
247
sub marc2dcxml {
236
	my ($marc,$qualified) = @_;
248
    my ( $marc, $xml, $biblionumber, $format ) = @_;
237
	my $error;
249
238
    # test if it's already a MARC::Record object, if not, make it one
250
    # global variables
239
    my $marc_record_obj;
251
    my ( $marcxml, $record, $output );
240
    if ($marc =~ /^MARC::Record/) { # it's already a MARC::Record object
252
241
        $marc_record_obj = $marc;
253
    # set the default path for intranet xslts
242
    } else { # it's not a MARC::Record object, make it one
254
    # differents xslts to process (OAIDC, SRWDC and RDFDC)
243
		eval { $marc_record_obj = MARC::Record->new_from_usmarc($marc) }; # handle exceptions
255
    my $xsl = C4::Context->config('intrahtdocs') . '/prog/en/xslt/' .
256
              C4::Context->preference('marcflavour') . 'slim2' . uc ( $format ) . '.xsl';
257
258
    if ( defined $marc ) {
259
        # no need to catch errors or warnings marc2marcxml do it instead
260
        $marcxml = C4::Record::marc2marcxml( $marc );
261
    } elsif ( not defined $xml and defined $biblionumber ) {
262
        # get MARCXML biblio directly from biblioitems.marcxml without item information
263
        $marcxml = C4::Biblio::GetXmlBiblio( $biblionumber );
264
    } else {
265
        $marcxml = $xml;
266
    }
244
267
245
		# conversion to MARC::Record object failed, populate $error
268
    # only proceed if MARC21 or UNIMARC; else clause is executed if marcflavour set it to NORMARC
246
		if ($@) {
269
    # generate MARC::Record object to see if not a marcxml record
247
			$error .="\nCreation of MARC::Record object failed: ".$MARC::File::ERROR;
270
    unless ( C4::Context->preference('marcflavour') eq 'NORMARC' ) {
248
		}
271
        eval { $record = MARC::Record->new_from_xml(
249
	}
272
                         $marcxml,
250
	my $crosswalk = MARC::Crosswalk::DublinCore->new;
273
                         'UTF-8',
251
	if ($qualified) {
274
                         C4::Context->preference('marcflavour')
252
		$crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 1 );
275
               );
253
	}
276
        };
254
	my $dcxml = $crosswalk->as_dublincore($marc_record_obj);
277
    } else {
255
	my $dcxmlfinal = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
278
        eval { $record = MARC::Record->new_from_xml(
256
	$dcxmlfinal .= "<metadata
279
                         $marcxml,
257
  xmlns=\"http://example.org/myapp/\"
280
                        'UTF-8',
258
  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
281
                        'MARC21'
259
  xsi:schemaLocation=\"http://example.org/myapp/ http://example.org/myapp/schema.xsd\"
282
               );
260
  xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
283
        };
261
  xmlns:dcterms=\"http://purl.org/dc/terms/\">";
284
    }
262
285
263
	foreach my $element ( $dcxml->elements() ) {
286
    # conversion to MARC::Record object failed
264
                $dcxmlfinal.="<"."dc:".$element->name().">".$element->content()."</"."dc:".$element->name().">\n";
287
    if ( $@ ) {
288
        croak "Creation of MARC::Record object failed.";
289
    } elsif ( $record->warnings() ) {
290
        carp "Warnings encountered while processing ISO-2709 record.\n";
291
        my @warnings = $record->warnings();
292
        foreach my $warn (@warnings) {
293
            carp "\t". $warn;
294
        };
295
    } elsif ( $record =~ /^MARC::Record/ ) { # if OK makes xslt transformation
296
        my $xslt_engine = Koha::XSLT_Handler->new;
297
        if ( $format =~ /oaidc|srwdc|rdfdc/ ) {
298
            $output = $xslt_engine->transform( $marcxml, $xsl );
299
        } else {
300
            croak "The format argument ($format) not accepted.\n" .
301
                  "Please pass a valid format (oaidc, srwdc, or rdfdc)\n";
302
        }
303
        my $err = $xslt_engine->err; # error number
304
        my $errstr = $xslt_engine->errstr; # error message
305
        if ( $err ) {
306
            croak "Error when processing $errstr Error number: $err\n";
307
        } else {
308
            return $output;
309
        }
265
    }
310
    }
266
	$dcxmlfinal .= "\n</metadata>";
267
	return ($error,$dcxmlfinal);
268
}
311
}
269
312
270
=head2 marc2modsxml - Convert from ISO-2709 to MODS
313
=head2 marc2modsxml - Convert from ISO-2709 to MODS
(-)a/catalogue/export.pl (-2 / +2 lines)
Lines 50-57 if ($op eq "export") { Link Here
50
                $marc = marc2bibtex($marc);
50
                $marc = marc2bibtex($marc);
51
                $format = "bibtex";
51
                $format = "bibtex";
52
            }
52
            }
53
            elsif ($format =~ /dc/) {
53
            elsif ($format =~ /dc$/) {
54
                ($error,$marc) = marc2dcxml($marc,1);
54
                $marc = marc2dcxml(undef, undef, $biblionumber, $format);
55
                $format = "dublin-core.xml";
55
                $format = "dublin-core.xml";
56
            }
56
            }
57
            elsif ($format =~ /marc8/) {
57
            elsif ($format =~ /marc8/) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc (-1 / +29 lines)
Lines 217-223 CAN_user_serials_create_subscription ) %] Link Here
217
    <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-download"></i> Save <span class="caret"></span></button>
217
    <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-download"></i> Save <span class="caret"></span></button>
218
    <ul class="dropdown-menu">
218
    <ul class="dropdown-menu">
219
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=bibtex&amp;op=export&amp;bib=[% biblionumber %]">BIBTEX</a></li>
219
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=bibtex&amp;op=export&amp;bib=[% biblionumber %]">BIBTEX</a></li>
220
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=dc&amp;op=export&amp;bib=[% biblionumber %]">Dublin Core (XML)</a></li>
220
        <li><a href="#" data-toggle="modal" data-target="#exportModal_">Dublin Core</a></li>
221
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=marcxml&amp;op=export&amp;bib=[% biblionumber %]">MARCXML</a></li>
221
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=marcxml&amp;op=export&amp;bib=[% biblionumber %]">MARCXML</a></li>
222
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=marc8&amp;op=export&amp;bib=[% biblionumber %]">MARC (non-Unicode/MARC-8)</a></li>
222
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=marc8&amp;op=export&amp;bib=[% biblionumber %]">MARC (non-Unicode/MARC-8)</a></li>
223
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=utf8&amp;op=export&amp;bib=[% biblionumber %]">MARC (Unicode/UTF-8)</a></li>
223
        <li><a href="/cgi-bin/koha/catalogue/export.pl?format=utf8&amp;op=export&amp;bib=[% biblionumber %]">MARC (Unicode/UTF-8)</a></li>
Lines 266-268 CAN_user_serials_create_subscription ) %] Link Here
266
</form>
266
</form>
267
</div>
267
</div>
268
268
269
    <!--Modal for Dublin Core-->
270
    <div class="modal hide" id="exportModal_" tabindex="-1" role="dialog" aria-labelledby="exportLabelexportModal_" aria-hidden="true">
271
        <div class="modal-header">
272
            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">&times;</button>
273
            <h3 id="exportLabelexportModal_">Exporting to Dublin Core...</h3>
274
        </div>
275
        <form method="get" action="/cgi-bin/koha/catalogue/export.pl">
276
        <div class="modal-body">
277
            <fieldset>
278
                <input id="input-simple" type="radio" name="format" value="rdfdc">
279
                <label for="input-simple">Simple DC-RDF</label>
280
                <br>
281
                <input id="input-oai" type="radio" name="format" value="oaidc" checked>
282
                <label for="input-oai">OAI-DC</label>
283
                <br>
284
                <input id="input-srw" type="radio" name="format" value="srwdc">
285
                <label for="input-srw">SRW-DC</label>
286
                <br>
287
            </fieldset>
288
        </div>
289
        <div class="modal-footer">
290
            <button type="submit" class="btn">Export</button>
291
            <button class="btn btn-link" data-dismiss="modal" aria-hidden="true">Cancel</button>
292
        </div>
293
        <input type="hidden" name="op" value="export" />
294
        <input type="hidden" name="bib" value="[% biblionumber %]" />
295
        </form>
296
    </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-1 / +2 lines)
Lines 1054-1060 function verify_images() { Link Here
1054
      <th>Save Record</th>   </tr>
1054
      <th>Save Record</th>   </tr>
1055
    <tr><td> Select download format:    <select name="format">
1055
    <tr><td> Select download format:    <select name="format">
1056
        <option value="mods">MODS (XML)</option>
1056
        <option value="mods">MODS (XML)</option>
1057
        <option value="dc">Dublin Core (XML)</option>
1057
        <option data-toggle="modal" data-target="#exportModal_">Dublin Core</option>
1058
        <option value="marcxml">MARCXML</option>
1058
        <option value="marcxml">MARCXML</option>
1059
        <option value="marc8">MARC (non-Unicode/MARC-8)</option>
1059
        <option value="marc8">MARC (non-Unicode/MARC-8)</option>
1060
        <option value="utf8">MARC (Unicode/UTF-8)</option>    </select>
1060
        <option value="utf8">MARC (Unicode/UTF-8)</option>    </select>
Lines 1087-1090 function verify_images() { Link Here
1087
</div>
1087
</div>
1088
[% END %]
1088
[% END %]
1089
</div>
1089
</div>
1090
1090
[% INCLUDE 'intranet-bottom.inc' %]
1091
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-1 / +1 lines)
Lines 2-8 Link Here
2
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Catalog &rsaquo; Item details for [% title %] [% FOREACH subtitl IN subtitle %] [% subtitl.subfield %][% END %]</title>
3
<title>Koha &rsaquo; Catalog &rsaquo; Item details for [% title %] [% FOREACH subtitl IN subtitle %] [% subtitl.subfield %][% END %]</title>
4
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
5
<style type="text/css">h3{padding-top: 1em; border-top: 2px solid #CCCCCC;}</style>
5
<style type="text/css">h3{padding-top: 1em; border-top: 2px solid #CCCCCC;}#exportLabelexportModal_{border-top: 0px;}</style>
6
[% INCLUDE 'browser-strings.inc' %]
6
[% INCLUDE 'browser-strings.inc' %]
7
<!--[if lt IE 9]>
7
<!--[if lt IE 9]>
8
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
8
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc (-1 / +4 lines)
Lines 38-48 Link Here
38
                    <a id="format" class="dropdown-toggle" data-toggle="dropdown" href="#">Save record <b class="caret"></b></a>
38
                    <a id="format" class="dropdown-toggle" data-toggle="dropdown" href="#">Save record <b class="caret"></b></a>
39
                        <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="format">
39
                        <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="format">
40
                            [% FOREACH option IN export_options %]
40
                            [% FOREACH option IN export_options %]
41
                                [% IF option == 'dc' %]
42
                                    <li><a role="menuitem" href="#" data-toggle="modal" data-target="#exportModal_">Dublin Core</a></li>
43
                                [% ELSE %]
41
                                <li>
44
                                <li>
42
                                    <a role="menuitem" href="/cgi-bin/koha/opac-export.pl?op=export&amp;bib=[% biblionumber %]&amp;format=[% option %]">
45
                                    <a role="menuitem" href="/cgi-bin/koha/opac-export.pl?op=export&amp;bib=[% biblionumber %]&amp;format=[% option %]">
43
                                        [% SWITCH option %]
46
                                        [% SWITCH option %]
44
                                            [% CASE 'bibtex' %]BIBTEX
47
                                            [% CASE 'bibtex' %]BIBTEX
45
                                            [% CASE 'dc' %]Dublin Core (XML)
46
                                            [% CASE 'endnote' %]EndNote
48
                                            [% CASE 'endnote' %]EndNote
47
                                            [% CASE 'marcxml' %]MARCXML
49
                                            [% CASE 'marcxml' %]MARCXML
48
                                            [% CASE 'marc8' %]MARC (non-Unicode/MARC-8)
50
                                            [% CASE 'marc8' %]MARC (non-Unicode/MARC-8)
Lines 54-59 Link Here
54
                                        [% END %]
56
                                        [% END %]
55
                                    </a>
57
                                    </a>
56
                                </li>
58
                                </li>
59
                                [% END %]
57
                            [% END %]
60
                            [% END %]
58
                        </ul>
61
                        </ul>
59
                </div>
62
                </div>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (+29 lines)
Lines 1154-1159 Link Here
1154
</div> <!-- / .container-fluid -->
1154
</div> <!-- / .container-fluid -->
1155
</div> <!-- / .main -->
1155
</div> <!-- / .main -->
1156
1156
1157
<!-- Dublin Core Modal Form -->
1158
<div class="modal hide" id="exportModal_" tabindex="-1" role="dialog" aria-labelledby="exportLabelexportModal_" aria-hidden="true">
1159
    <div class="modal-header">
1160
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">&times;</button>
1161
        <h3 class="modal-title" id="exportModalLabel">Exporting to Dublin Core...</h3>
1162
    </div>
1163
    <form method="get" action="/cgi-bin/koha/opac-export.pl">
1164
    <div class="modal-body">
1165
        <fieldset id="dc_fieldset">
1166
                <input id="input-simple" type="radio" name="format" value="rdfdc">
1167
                <label class="label_dc" for="input-simple">Simple DC-RDF</label>
1168
                <br>
1169
                <input id="input-oai" type="radio" name="format" value="oaidc">
1170
                <label class="label_dc" for="input-oai">OAI-DC</label>
1171
                <br>
1172
                <input id="input-srw" type="radio" name="format" value="srwdc">
1173
                <label class="label_dc" for="input-srw">SRW-DC</label>
1174
                <br>
1175
        <input type="hidden" name="op" value="export">
1176
        <input type="hidden" name="bib" value="[% biblionumber %]">
1177
        </fieldset>
1178
    </div>
1179
    <div class="modal-footer">
1180
        <button type="submit" class="btn">Export</button>
1181
        <button class="btn btn-link" data-dismiss="modal" aria-hidden="true">Cancel</button>
1182
    </div>
1183
    </form>
1184
</div>
1185
1157
[% INCLUDE 'opac-bottom.inc' %]
1186
[% INCLUDE 'opac-bottom.inc' %]
1158
1187
1159
[%# End of template %]
1188
[%# End of template %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less (+14 lines)
Lines 2490-2493 a.reviewlink:visited { Link Here
2490
    font-size: 90%;
2490
    font-size: 90%;
2491
}
2491
}
2492
2492
2493
#dc_fieldset {
2494
    border: 1px solid #dddddd;
2495
    border-width: 1px;
2496
    padding: 5px;
2497
    border-radius: 10px
2498
}
2499
2500
.label_dc{
2501
    display: inline;
2502
    padding: 0px;
2503
    margin: 0px;
2504
    cursor: pointer;
2505
}
2506
2493
@import "responsive.less";
2507
@import "responsive.less";
(-)a/opac/opac-export.pl (-3 / +2 lines)
Lines 60-67 elsif ($format =~ /bibtex/) { Link Here
60
    $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
60
    $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
61
    $format = 'bibtex';
61
    $format = 'bibtex';
62
}
62
}
63
elsif ($format =~ /dc/) {
63
elsif ($format =~ /dc$/) {
64
    ($error,$marc) = marc2dcxml($marc,1);
64
    $marc = marc2dcxml(undef, undef, $biblionumber, $format);
65
    $format = "dublin-core.xml";
65
    $format = "dublin-core.xml";
66
}
66
}
67
elsif ($format =~ /marc8/) {
67
elsif ($format =~ /marc8/) {
68
- 

Return to bug 13642