From 13cbbb79dd6f726fa3b034c810e9b04c472de5a3 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Wed, 30 May 2012 10:04:20 -0400 Subject: [PATCH] Bug 8203: Add ability to save individual authorities Adds the ability to save individual authority records in MADS, MARCXML, or binary MARC format to the staff client. To test: 1. Apply patch 2. View authority record in staff client 3. Try saving record as MADS, MARCXML, and MARC, and confirm that the resulting files are what you expect Signed-off-by: Katrin Fischer Works nicely, tested different export options on different records. --- C4/Record.pm | 54 +- authorities/export.pl | 52 + .../prog/en/includes/authorities-toolbar.inc | 23 +- .../prog/en/xslt/MARC21slim2MADS.xsl | 1388 +++++++++++++++++ 4 files changed, 1502 insertions(+), 15 deletions(-) create mode 100755 authorities/export.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2MADS.xsl diff --git a/C4/Record.pm b/C4/Record.pm index ed91196922..a07fcfc6b3 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -52,6 +52,7 @@ $VERSION = 3.07.00.049; &marcxml2marc &marc2dcxml &marc2modsxml + &marc2madsxml &marc2bibtex &marc2csv &changeEncoding @@ -267,25 +268,52 @@ sub marc2dcxml { =head2 marc2modsxml - Convert from ISO-2709 to MODS - my ($error,$modsxml) = marc2modsxml($marc); + my $modsxml = marc2modsxml($marc); Returns a MODS scalar =cut sub marc2modsxml { - my ($marc) = @_; - # grab the XML, run it through our stylesheet, push it out to the browser - my $xmlrecord = marc2marcxml($marc); - my $xslfile = C4::Context->config('intrahtdocs')."/prog/en/xslt/MARC21slim2MODS3-1.xsl"; - my $parser = XML::LibXML->new(); - my $xslt = XML::LibXSLT->new(); - my $source = $parser->parse_string($xmlrecord); - my $style_doc = $parser->parse_file($xslfile); - my $stylesheet = $xslt->parse_stylesheet($style_doc); - my $results = $stylesheet->transform($source); - my $newxmlrecord = $stylesheet->output_string($results); - return ($newxmlrecord); + my ($marc) = @_; + return _transformWithStylesheet($marc, "/prog/en/xslt/MARC21slim2MODS3-1.xsl"); +} + +=head2 marc2madsxml - Convert from ISO-2709 to MADS + + my $madsxml = marc2madsxml($marc); + +Returns a MADS scalar + +=cut + +sub marc2madsxml { + my ($marc) = @_; + return _transformWithStylesheet($marc, "/prog/en/xslt/MARC21slim2MADS.xsl"); +} + +=head2 _transformWithStylesheet - Transform a MARC record with a stylesheet + + my $xml = _transformWithStylesheet($marc, $stylesheet) + +Returns the XML scalar result of the transformation. $stylesheet should +contain the path to a stylesheet under intrahtdocs. + +=cut + +sub _transformWithStylesheet { + my ($marc, $stylesheet) = @_; + # grab the XML, run it through our stylesheet, push it out to the browser + my $xmlrecord = marc2marcxml($marc); + my $xslfile = C4::Context->config('intrahtdocs') . $stylesheet; + my $parser = XML::LibXML->new(); + my $xslt = XML::LibXSLT->new(); + my $source = $parser->parse_string($xmlrecord); + my $style_doc = $parser->parse_file($xslfile); + my $stylesheet = $xslt->parse_stylesheet($style_doc); + my $results = $stylesheet->transform($source); + my $newxmlrecord = $stylesheet->output_string($results); + return ($newxmlrecord); } sub marc2endnote { diff --git a/authorities/export.pl b/authorities/export.pl new file mode 100755 index 0000000000..c6b83491de --- /dev/null +++ b/authorities/export.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use C4::Record; +use C4::Auth; +use C4::Output; +use C4::AuthoritiesMarc; +use CGI; + +my $query = new CGI; +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "tools/export.tt", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { editauthorities => 1 }, + debug => 1, + } +); + +my $op = $query->param("op"); +my $format = $query->param("format"); +my $error = ''; +if ( $op eq "export" ) { + my $authid = $query->param("authid"); + if ($authid) { + + my $marc = GetAuthority($authid); + + if ( $format =~ /marcxml/ ) { + $marc = marc2marcxml($marc); + } + elsif ($format=~ /mads/) { + $marc = marc2madsxml($marc); + } + elsif ( $format =~ /marc8/ ) { + $marc = changeEncoding( $marc, "MARC", "MARC21", "MARC-8" ); + $marc = $marc->as_usmarc(); + } + elsif ( $format =~ /utf8/ ) { + C4::Charset::SetUTF8Flag( $marc, 1 ); + $marc = $marc->as_usmarc(); + } + print $query->header( + -type => 'application/octet-stream', + -attachment => "auth-$authid.$format" + ); + print $marc; + } +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc index 120f079bc4..7315b29e03 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc @@ -7,6 +7,7 @@ $(document).ready(function() { $("#newmenuc").empty(); $("#delAuthc").empty(); + $("#savemenuc").empty(); yuiToolbar(); }); @@ -35,7 +36,23 @@ label: _("Delete"), container: "delAuthc", onclick: {fn: confirm_deletion } - }); + }); + + var savemenu = [ + { text: _("MADS (XML)"), url: "/cgi-bin/koha/authorities/export.pl?format=mads&op=export&authid=[% authid %]" }, + { text: _("MARCXML"), url: "/cgi-bin/koha/authorities/export.pl?format=marcxml&op=export&authid=[% authid %]" }, + { text: _("MARC (non-Unicode/MARC-8)"), url: "/cgi-bin/koha/authorities/export.pl?format=marc8&op=export&authid=[% authid %]" }, + { text: _("MARC (Unicode/UTF-8)"), url: "/cgi-bin/koha/authorities/export.pl?format=utf8&op=export&authid=[% authid %]" }, + ]; + + new YAHOO.widget.Button({ + type: "menu", + label: _("Save"), + id: "savemenuc", + name: "savemenubutton", + menu: savemenu, + container: "savemenuc" + }); } //]]> @@ -46,7 +63,9 @@ [% UNLESS ( count ) %] Delete - [% END %][% ELSE %] [% END %] + [% END %] + Save +[% ELSE %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2MADS.xsl b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2MADS.xsl new file mode 100644 index 0000000000..570eaaa2f5 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2MADS.xsl @@ -0,0 +1,1388 @@ + + + + + + + + + + + + + + + + + naf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + direct + + + + + indirect + + + + + not applicable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Converted from MARCXML to MADS version 2.0 (Revision 2.10) + + + + + + + + + + + earlier rules + + + + + aacr1 + + + + + aacr2 + + + + + aacr2 compatible + + + + + other rules + + + + + + + + + + + + + + + + + + + + + + + n + n + fghkdlmor + + + + + p + p + fghkdlmor + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + cdn + + + + + + + + + + + aq + + + + + + + + + + + + acdenq + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bc + + + + + + + + + + + + + + + + + + + + + + + yes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a + + - + + st + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ab + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nonpublic + + + source + + + notFound + + + history + + + subject example + + + deleted heading information + + + application history + + + + + + + + + + + ab + + + + + ai + + + + + + + + + + + + + + + z3 + + + + + + + + + + + + earlier + + + later + + + parentOrg + + + broader + + + narrower + + + other + + + other + + + + other + + + + equivalent + + + + + + + + + + acronym + + + other + + + other + + + + + other + + + + + + + + + + + + naf + + + + + lcsh + + + + + lacnaf + + + + + lcsh + + + + cash + + + naf + + + lcsh + + + + lacnaf + + + + + cash + + + + + lcshcl + + + + + nlmnaf + + + + + nalnaf + + + + + aat + + + + sears + + + rvm + + + + + + + + + naf + + + + + lcsh + + + + + lacnaf + + + + + lcsh + + + + + lcsh + + + + + mesh + + + + + nal + + + + + cash + + + + + naf + + + + lcsh + + + lacnaf + + + cash + + + lcsh + + + naf + + + lacnaf + + + lcsh + + + cash + + + lcshcl + + + nlmnaf + + + nalnaf + + + rvm + + + + + + + + lacnaf + + + naf + + + lcsh + + + mesh + + + nal + + + cash + + + + + -- 2.39.5