Merge remote branch 'kc/new/bug_6162' into kcmaster
[koha.git] / opac / opac-export.pl
blobf9d3c253d39b658be7716430bb21dc664278ac14
1 #!/usr/bin/perl
3 # Parts Copyright Catalyst IT 2011
5 # This file is part of Koha.
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.
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.
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
22 use strict;
23 use warnings;
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;
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 $dbh=C4::Context->dbh;
39 my $sth;
40 if ($biblionumber) {
41 $sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?");
42 $sth->execute($biblionumber);
44 my $error;
45 while (my ($marc) = $sth->fetchrow) {
46 if ($marc){
48 if ($format =~ /endnote/) {
49 $marc = marc2endnote($marc);
50 $format = 'endnote';
52 elsif ($format =~ /marcxml/) {
53 $marc = marc2marcxml($marc);
55 elsif ($format=~ /mods/) {
56 $marc = marc2modsxml($marc);
58 elsif ($format =~ /ris/) {
59 $marc = marc2ris(MARC::Record->new_from_usmarc($marc));
61 elsif ($format =~ /bibtex/) {
62 $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
63 }elsif ($format =~ /dc/) {
64 ($error,$marc) = marc2dcxml($marc,1);
65 $format = "dublin-core.xml";
67 elsif ($format =~ /marc8/) {
68 ($error,$marc) = changeEncoding($marc,"MARC","MARC21","MARC-8");
69 if (! $error){
70 $marc = $marc->as_usmarc();
73 elsif ($format =~ /utf8/) {
74 #default
76 if ($error){
77 print $query->header();
78 print $query->start_html();
79 print "<h1>An error occured </h1>";
80 print $error;
81 print $query->end_html();
83 else {
84 print $query->header(
85 -type => 'application/octet-stream',
86 -attachment=>"bib-$biblionumber.$format");
87 print $marc;