Bumping database version
[koha.git] / opac / opac-export.pl
1 #!/usr/bin/perl
2
3 # Parts Copyright Catalyst IT 2011
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19 #
20
21
22 use strict;
23 use warnings;
24
25 use C4::Record;
26 use C4::Auth;
27 use C4::Output;
28 use C4::Biblio;
29 use CGI;
30 use C4::Auth;
31 use C4::Ris;
32
33 my $query = new CGI;
34 my $op=$query->param("op");
35 my $format=$query->param("format");
36 if ($op eq "export") {
37         my $biblionumber = $query->param("bib");
38         my $error;
39
40                 if ($biblionumber){
41
42                         my $marc = GetMarcBiblio($biblionumber, 1);
43
44                         if ($format =~ /endnote/) {
45                                 $marc = marc2endnote($marc);
46                                 $format = 'endnote';
47                         }
48                         elsif ($format =~ /marcxml/) {
49                                 $marc = marc2marcxml($marc);
50                         }
51                         elsif ($format=~ /mods/) {
52                                 $marc = marc2modsxml($marc);
53                         }
54                         elsif ($format =~ /ris/) {
55                                 $marc = marc2ris(MARC::Record->new_from_usmarc($marc));
56                         }
57                         elsif ($format =~ /bibtex/) {
58                                 $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
59                         }
60                         elsif ($format =~ /dc/) {
61                                 ($error,$marc) = marc2dcxml($marc,1);
62                                 $format = "dublin-core.xml";
63                         }
64                         elsif ($format =~ /marc8/) {
65                                 ($error,$marc) = changeEncoding($marc,"MARC","MARC21","MARC-8");
66                                 if (! $error){
67                                     $marc = $marc->as_usmarc();
68                                 }
69                         }
70                         elsif ($format =~ /utf8/) {
71                                 C4::Charset::SetUTF8Flag($marc,1);
72                                 $marc = $marc->as_usmarc();
73                         }
74
75                 if ($error){
76                     print $query->header();
77                     print $query->start_html();
78                     print "<h1>An error occured </h1>";
79                     print $error;
80                     print $query->end_html();
81                 }
82                 else {
83                     print $query->header(
84                                     -type => 'application/octet-stream',
85                     -attachment=>"bib-$biblionumber.$format");
86                     print $marc;
87                 }
88             }
89 }