Koha/catalogue/export.pl
Nick Clemens 234cced91d Bug 24108: Make export file names consistent
This patch renames the systempreference to be a bit clearer and uses
explicit options rather than a yes/no

Additionally it standardizes the export from the advanced cataloging editor
with that from the details page

To test:
 1 - Apply patches
 2 - Update database and restart all the things
 3 - Open a record in the advanced editor and save it as marc and xml
 4 - Note the file name is 'bib-{biblionumber.{format}'
 5 - Edit the syspref 'DefaultSaveRecordFileID' to be control number
 6 - Repeate 3-4 on a record with and without a control number
 7 - If control number present fiule name should be 'record-{controlnumber}.{format}'
 8 - Otherwise it should be as above
 9 - Repeat tests from the details page of a record
10 - Repeat tests from the opac details page of a record

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-02-17 16:28:25 +01:00

91 lines
3 KiB
Perl
Executable file

#!/usr/bin/perl
use Modern::Perl;
use C4::Record;
use C4::Auth;
use C4::Output;
use C4::Biblio;
use CGI qw ( -utf8 );
use C4::Ris;
my $query = CGI->new;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
template_name => "tools/export.tt",
query => $query,
type => "intranet",
flagsrequired => { catalogue => 1 },
debug => 1,
});
my $op=$query->param("op");
my $format=$query->param("format");
my $error = '';
if ($op eq "export") {
my $biblionumber = $query->param("bib");
if ($biblionumber){
my $file_id = $biblionumber;
my $file_pre = "bib-";
my $marc = GetMarcBiblio({
biblionumber => $biblionumber,
embed_items => 1 });
if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){
my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour
my $control_num = GetMarcControlnumber( $marc, $marcflavour );
if( $control_num ){
$file_id = $control_num;
$file_pre = "record-";
}
}
if ($format =~ /endnote/) {
$marc = marc2endnote($marc);
$format = 'endnote';
}
elsif ($format =~ /marcxml/) {
$marc = marc2marcxml($marc);
$format = "marcxml";
}
elsif ($format=~ /mods/) {
$marc = marc2modsxml($marc);
$format = "mods";
}
elsif ($format =~ /ris/) {
$marc = marc2ris($marc);
$format = "ris";
}
elsif ($format =~ /bibtex/) {
$marc = marc2bibtex($marc);
$format = "bibtex";
}
elsif ($format =~ /dc$/) {
$marc = marc2dcxml(undef, undef, $biblionumber, $format);
$format = "dublin-core.xml";
}
elsif ($format =~ /marc8/) {
$marc = changeEncoding($marc,"MARC","MARC21","MARC-8");
$marc = $marc->as_usmarc();
$format = "marc8";
}
elsif ($format =~ /utf8/) {
C4::Charset::SetUTF8Flag($marc, 1);
$marc = $marc->as_usmarc();
$format = "utf8";
}
elsif ($format =~ /marcstd/) {
C4::Charset::SetUTF8Flag($marc,1);
($error, $marc) = marc2marc($marc, 'marcstd', C4::Context->preference('marcflavour'));
$format = "marcstd";
}
if ( $format =~ /utf8/ or $format =~ /marcstd/ ) {
binmode STDOUT, ':encoding(UTF-8)';
}
print $query->header(
-type => 'application/octet-stream',
-attachment=>"$file_pre$file_id.$format");
print $marc;
}
}