Bug 14111 - More t/Auth_with_shibboleth.t silencing
[koha.git] / opac / opac-export.pl
blobbf040db0a10573483e1ad9d74a37ef03c9321714
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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use strict;
21 use warnings;
23 use C4::Record;
24 use C4::Auth;
25 use C4::Output;
26 use C4::Biblio;
27 use CGI qw ( -utf8 );
28 use C4::Auth;
29 use C4::Ris;
31 my $query = new CGI;
32 my $op=$query->param("op")||''; #op=export is currently the only use
33 my $format=$query->param("format")||'utf8';
34 my $biblionumber = $query->param("bib")||0;
35 $biblionumber = int($biblionumber);
36 my ($marc, $error)= ('','');
38 $marc = GetMarcBiblio($biblionumber, 1) if $biblionumber;
39 if(!$marc) {
40 print $query->redirect("/cgi-bin/koha/errors/404.pl");
41 exit;
43 elsif ($format =~ /endnote/) {
44 $marc = marc2endnote($marc);
45 $format = 'endnote';
47 elsif ($format =~ /marcxml/) {
48 $marc = marc2marcxml($marc);
49 $format = 'marcxml';
51 elsif ($format=~ /mods/) {
52 $marc = marc2modsxml($marc);
53 $format = 'mods';
55 elsif ($format =~ /ris/) {
56 $marc = marc2ris($marc);
57 $format = 'ris';
59 elsif ($format =~ /bibtex/) {
60 $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
61 $format = 'bibtex';
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 $marc = $marc->as_usmarc() unless $error;
70 $format = 'marc8';
72 elsif ($format =~ /utf8/) {
73 C4::Charset::SetUTF8Flag($marc,1);
74 $marc = $marc->as_usmarc();
75 $format = 'utf8';
77 elsif ($format =~ /marcstd/) {
78 C4::Charset::SetUTF8Flag($marc,1);
79 ($error,$marc) = marc2marc($marc, 'marcstd', C4::Context->preference('marcflavour'));
80 $format = 'marcstd';
82 elsif ( $format =~ /isbd/ ) {
83 $marc = GetISBDView($biblionumber, "opac");
84 $format = 'isbd';
86 else {
87 $error= "Format $format is not supported.";
90 if ($error){
91 print $query->header();
92 print $query->start_html();
93 print "<h1>An error occurred </h1>";
94 print $query->escapeHTML("$error");
95 print $query->end_html();
97 else {
98 if ($format eq 'marc8'){
99 print $query->header(
100 -type => 'application/marc',
101 -charset=>'ISO-2022',
102 -attachment=>"bib-$biblionumber.$format");
104 elsif ( $format eq 'isbd' ) {
105 print $query->header(
106 -type => 'text/plain',
107 -charset => 'utf-8',
108 -attachment => "bib-$biblionumber.txt"
110 }else{
111 print $query->header(
112 -type => 'application/octet-stream',
113 -charset=>'utf-8',
114 -attachment=>"bib-$biblionumber.$format");
116 print $marc;