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 <Katrin.Fischer.83@web.de>
Works nicely, tested different export options on different records.
This commit is contained in:
Jared Camins-Esakov 2012-05-30 10:04:20 -04:00 committed by Paul Poulain
parent ba7ac6d3ec
commit 13cbbb79dd
4 changed files with 1502 additions and 15 deletions

View File

@ -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 {

52
authorities/export.pl Executable file
View File

@ -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;
}
}

View File

@ -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 ) %]
<span id="delAuthc"><a id="delAuth" href="javascript:confirm_deletion()">Delete</a></span>
[% END %][% ELSE %]&nbsp;[% END %]
[% END %]
<span id="savemenuc">Save</span>
[% ELSE %]&nbsp;[% END %]
<span id="newmenuc">
<label for="add_authtypecode">New: </label>

File diff suppressed because it is too large Load Diff