+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';
+}
+elsif ( $format =~ /isbd/ ) {
+ $marc = GetISBDView({
+ 'record' => $marc,
+ 'template' => 'opac',
+ 'framework' => $framework,
+ });
+ $format = 'isbd';
+}
+else {
+ $error= "Format $format is not supported.";
+}
+
+if ($error){
+ print $query->header();
+ print $query->start_html();
+ print "<h1>An error occurred </h1>";
+ print $query->escapeHTML("$error");
+ print $query->end_html();
+}
+else {
+ if ($format eq 'marc8'){
+ print $query->header(
+ -type => 'application/marc',
+ -charset=>'ISO-2022',
+ -attachment=>"bib-$biblionumber.$format");
+ }
+ elsif ( $format eq 'isbd' ) {
+ print $query->header(
+ -type => 'text/plain',
+ -charset => 'utf-8',
+ -attachment => "bib-$biblionumber.txt"
+ );
+ } else {
+ binmode STDOUT, ':encoding(UTF-8)';
+ print $query->header(
+ -type => 'application/octet-stream',
+ -charset => 'utf-8',
+ -attachment => "bib-$biblionumber.$format"
+ );
+ }
+ print $marc;
+}
+
+1;