Merge branch 'new/bug_6479' into kcmaster
[wip/koha-chris_n.git] / catalogue / export.pl
1 #!/usr/bin/perl
2 use HTML::Template::Pro;
3 use strict;
4 #use warnings; FIXME - Bug 2505
5
6 use C4::Record;
7 use C4::Auth;
8 use C4::Output;
9 use C4::Biblio;
10 use CGI;
11
12
13
14 my $query = new CGI;
15 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
16                                                                      template_name   => "tools/export.tt",
17                                                                      query           => $query,
18                                                                      type            => "intranet",
19                                                                      authnotrequired => 0,
20                                                                      flagsrequired   => { tools => 'export_catalog' },
21                                                                      debug           => 1,
22                                                                      });
23
24 my $op=$query->param("op");
25 my $format=$query->param("format");
26 if ($op eq "export") {
27         my $biblionumber = $query->param("bib");
28                 if ($biblionumber){
29
30                         my $marc = GetMarcBiblio($biblionumber, 1);
31
32                         if ($format =~ /endnote/) {
33                                 $marc = marc2endnote($marc);
34                                 $format = 'endnote';
35                         }
36                         elsif ($format =~ /marcxml/) {
37                                 $marc = marc2marcxml($marc);
38                         }
39                         elsif ($format=~ /mods/) {
40                                 $marc = marc2modsxml($marc);
41                         }
42                         elsif ($format =~ /dc/) {
43                                 my $error;
44                                 ($error,$marc) = marc2dcxml($marc,1);
45                                 $format = "dublin-core.xml";
46                         }
47                         elsif ($format =~ /marc8/) {
48                                 $marc = changeEncoding($marc,"MARC","MARC21","MARC-8");
49                                 $marc = $marc->as_usmarc();
50                         }
51                         elsif ($format =~ /utf8/) {
52                                 C4::Charset::SetUTF8Flag($marc, 1);
53                                 $marc = $marc->as_usmarc();
54                         }
55                         print $query->header(
56                                 -type => 'application/octet-stream',
57                 -attachment=>"bib-$biblionumber.$format");
58                         print $marc;
59                 }
60 }