use C4::Record;
use C4::Auth;
use C4::Output;
-use C4::Biblio;
+use C4::Biblio qw(
+ GetFrameworkCode
+ GetISBDView
+ GetMarcControlnumber
+);
use CGI qw ( -utf8 );
use C4::Auth;
-use C4::Ris;
+use C4::Ris qw( marc2ris );
+use Koha::Biblios;
use Koha::RecordProcessor;
my $query = CGI->new;
# Determine logged in user's patron category.
# Blank if not logged in.
my $userenv = C4::Context->userenv;
-my $borcat = q{};
+my $patron;
if ($userenv) {
my $borrowernumber = $userenv->{'number'};
if ($borrowernumber) {
- my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
- $borcat = $borrower ? $borrower->categorycode : $borcat;
+ $patron = Koha::Patrons->find( $borrowernumber );
}
}
my $include_items = ($format =~ /bibtex/) ? 0 : 1;
-my $marc = $biblionumber
- ? GetMarcBiblio({
- biblionumber => $biblionumber,
- embed_items => $include_items,
- opac => 1,
- borcat => $borcat })
- : undef;
+my $biblio = Koha::Biblios->find($biblionumber);
+my $marc = $biblio
+ ? $biblio->metadata->record(
+ {
+ embed_items => 1,
+ opac => 1,
+ patron => $patron,
+ }
+ )
+ : undef;
if(!$marc) {
print $query->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
-# ASSERT: There is a biblionumber, because GetMarcBiblio returned something.
-my $framework = GetFrameworkCode( $biblionumber );
+my $file_id = $biblionumber;
+my $file_pre = "bib-";
+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-";
+ }
+}
+
+my $framework = $biblio->frameworkcode;
my $record_processor = Koha::RecordProcessor->new({
filters => 'ViewPolicy',
options => {
print $query->header(
-type => 'application/marc',
-charset=>'ISO-2022',
- -attachment=>"bib-$biblionumber.$format");
+ -attachment=>"$file_pre$file_id.$format");
}
elsif ( $format eq 'isbd' ) {
print $query->header(
-type => 'text/plain',
-charset => 'utf-8',
- -attachment => "bib-$biblionumber.txt"
+ -attachment => "$file_pre$file_id.txt"
+ );
+ }
+ elsif ( $format eq 'ris' ) {
+ print $query->header(
+ -type => 'text/plain',
+ -charset => 'utf-8',
+ -attachment => "$file_pre$file_id.$format"
);
} else {
binmode STDOUT, ':encoding(UTF-8)';
print $query->header(
-type => 'application/octet-stream',
-charset => 'utf-8',
- -attachment => "bib-$biblionumber.$format"
+ -attachment => "$file_pre$file_id.$format"
);
}
print $marc;