Merge branch 'bug2505_patches' of git://git.catalyst.net.nz/koha into to-push
[koha.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 use C4::Auth;
12
13 my $query = new CGI;
14 my $op=$query->param("op");
15 my $format=$query->param("format");
16 if ($op eq "export") {
17         my $biblionumber = $query->param("bib");
18         my $dbh=C4::Context->dbh;
19         my $sth;
20         if ($biblionumber) {
21                 $sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?");
22                 $sth->execute($biblionumber);
23         }
24         while (my ($marc) = $sth->fetchrow) {
25                 if ($marc){
26
27                         if ($format =~ /endnote/) {
28                                 $marc = marc2endnote($marc);
29                                 $format = 'endnote';
30                         }
31                         elsif ($format =~ /marcxml/) {
32                                 $marc = marc2marcxml($marc);
33                         }
34                         elsif ($format=~ /mods/) {
35                                 $marc = marc2modsxml($marc);
36                         }
37                         elsif ($format =~ /dc/) {
38                                 my $error;
39                                 ($error,$marc) = marc2dcxml($marc,1);
40                                 $format = "dublin-core.xml";
41                         }
42                         elsif ($format =~ /marc8/) {
43                                 $marc = changeEncoding($marc,"MARC","MARC21","MARC-8");
44                                 $marc = $marc->as_usmarc();
45                         }
46                         elsif ($format =~ /utf8/) {
47                                 #default
48                         }
49                         print $query->header(
50                                 -type => 'application/octet-stream',
51                 -attachment=>"bib-$biblionumber.$format");
52                         print $marc;
53                 }
54         }
55 }