14 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
15 template_name => "tools/export.tt",
18 flagsrequired => { catalogue => 1 },
21 my $op=$query->param("op");
22 my $format=$query->param("format");
24 if ($op eq "export") {
25 my $biblionumber = $query->param("bib");
27 my $file_id = $biblionumber;
28 my $file_pre = "bib-";
30 my $marc = GetMarcBiblio({
31 biblionumber => $biblionumber,
34 if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){
35 my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour
36 my $control_num = GetMarcControlnumber( $marc, $marcflavour );
38 $file_id = $control_num;
39 $file_pre = "record-";
43 if ($format =~ /endnote/) {
44 $marc = marc2endnote($marc);
47 elsif ($format =~ /marcxml/) {
48 $marc = marc2marcxml($marc);
51 elsif ($format=~ /mods/) {
52 $marc = marc2modsxml($marc);
55 elsif ($format =~ /ris/) {
56 $marc = marc2ris($marc);
59 elsif ($format =~ /bibtex/) {
60 $marc = marc2bibtex($marc);
63 elsif ($format =~ /dc$/) {
64 $marc = marc2dcxml(undef, undef, $biblionumber, $format);
65 $format = "dublin-core.xml";
67 elsif ($format =~ /marc8/) {
68 $marc = changeEncoding($marc,"MARC","MARC21","MARC-8");
69 $marc = $marc->as_usmarc();
72 elsif ($format =~ /utf8/) {
73 C4::Charset::SetUTF8Flag($marc, 1);
74 $marc = $marc->as_usmarc();
77 elsif ($format =~ /marcstd/) {
78 C4::Charset::SetUTF8Flag($marc,1);
79 ($error, $marc) = marc2marc($marc, 'marcstd', C4::Context->preference('marcflavour'));
82 if ( $format =~ /utf8/ or $format =~ /marcstd/ ) {
83 binmode STDOUT, ':encoding(UTF-8)';
86 -type => 'application/octet-stream',
87 -attachment=>"$file_pre$file_id.$format");