Bug 26464: Code correction in opac-main when news_id passed
[koha.git] / catalogue / export.pl
blob80f3f156cf0ec9fe8d468839f0e5437a20261338
1 #!/usr/bin/perl
2 use Modern::Perl;
4 use C4::Record;
5 use C4::Auth;
6 use C4::Output;
7 use C4::Biblio;
8 use CGI qw ( -utf8 );
9 use C4::Ris;
13 my $query = new CGI;
14 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
15 template_name => "tools/export.tt",
16 query => $query,
17 type => "intranet",
18 flagsrequired => { catalogue => 1 },
19 debug => 1,
20 });
22 my $op=$query->param("op");
23 my $format=$query->param("format");
24 my $error = '';
25 if ($op eq "export") {
26 my $biblionumber = $query->param("bib");
27 if ($biblionumber){
29 my $marc = GetMarcBiblio({
30 biblionumber => $biblionumber,
31 embed_items => 1 });
33 if ($format =~ /endnote/) {
34 $marc = marc2endnote($marc);
35 $format = 'endnote';
37 elsif ($format =~ /marcxml/) {
38 $marc = marc2marcxml($marc);
39 $format = "marcxml";
41 elsif ($format=~ /mods/) {
42 $marc = marc2modsxml($marc);
43 $format = "mods";
45 elsif ($format =~ /ris/) {
46 $marc = marc2ris($marc);
47 $format = "ris";
49 elsif ($format =~ /bibtex/) {
50 $marc = marc2bibtex($marc);
51 $format = "bibtex";
53 elsif ($format =~ /dc$/) {
54 $marc = marc2dcxml(undef, undef, $biblionumber, $format);
55 $format = "dublin-core.xml";
57 elsif ($format =~ /marc8/) {
58 $marc = changeEncoding($marc,"MARC","MARC21","MARC-8");
59 $marc = $marc->as_usmarc();
60 $format = "marc8";
62 elsif ($format =~ /utf8/) {
63 C4::Charset::SetUTF8Flag($marc, 1);
64 $marc = $marc->as_usmarc();
65 $format = "utf8";
67 elsif ($format =~ /marcstd/) {
68 C4::Charset::SetUTF8Flag($marc,1);
69 ($error, $marc) = marc2marc($marc, 'marcstd', C4::Context->preference('marcflavour'));
70 $format = "marcstd";
72 if ( $format =~ /utf8/ or $format =~ /marcstd/ ) {
73 binmode STDOUT, ':encoding(UTF-8)';
75 print $query->header(
76 -type => 'application/octet-stream',
77 -attachment=>"bib-$biblionumber.$format");
78 print $marc;