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>.
29 use Koha
::RecordProcessor
;
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);
38 my $include_items = ($format =~ /bibtex/) ?
0 : 1;
39 my $marc = GetMarcBiblio
($biblionumber, $include_items)
43 print $query->redirect("/cgi-bin/koha/errors/404.pl");
47 # ASSERT: There is a biblionumber, because GetMarcBiblio returned something.
48 my $framework = GetFrameworkCode
( $biblionumber );
49 my $record_processor = Koha
::RecordProcessor
->new({
50 filters
=> 'ViewPolicy',
53 frameworkcode
=> $framework
56 $record_processor->process($marc);
58 if ($format =~ /endnote/) {
59 $marc = marc2endnote
($marc);
62 elsif ($format =~ /marcxml/) {
63 $marc = marc2marcxml
($marc);
66 elsif ($format=~ /mods/) {
67 $marc = marc2modsxml
($marc);
70 elsif ($format =~ /ris/) {
71 $marc = marc2ris
($marc);
74 elsif ($format =~ /bibtex/) {
75 $marc = marc2bibtex
($marc,$biblionumber);
78 elsif ($format =~ /dc$/) {
79 # TODO: Dublin Core leaks fields marked hidden by framework.
80 $marc = marc2dcxml
($marc, undef, $biblionumber, $format);
81 $format = "dublin-core.xml";
83 elsif ($format =~ /marc8/) {
84 ($error,$marc) = changeEncoding
($marc,"MARC","MARC21","MARC-8");
85 $marc = $marc->as_usmarc() unless $error;
88 elsif ($format =~ /utf8/) {
89 C4
::Charset
::SetUTF8Flag
($marc,1);
90 $marc = $marc->as_usmarc();
93 elsif ($format =~ /marcstd/) {
94 C4
::Charset
::SetUTF8Flag
($marc,1);
95 ($error,$marc) = marc2marc
($marc, 'marcstd', C4
::Context
->preference('marcflavour'));
98 elsif ( $format =~ /isbd/ ) {
101 'template' => 'opac',
102 'framework' => $framework,
107 $error= "Format $format is not supported.";
111 print $query->header();
112 print $query->start_html();
113 print "<h1>An error occurred </h1>";
114 print $query->escapeHTML("$error");
115 print $query->end_html();
118 if ($format eq 'marc8'){
119 print $query->header(
120 -type
=> 'application/marc',
121 -charset
=>'ISO-2022',
122 -attachment
=>"bib-$biblionumber.$format");
124 elsif ( $format eq 'isbd' ) {
125 print $query->header(
126 -type
=> 'text/plain',
128 -attachment
=> "bib-$biblionumber.txt"
131 binmode STDOUT
, ':encoding(UTF-8)';
132 print $query->header(
133 -type
=> 'application/octet-stream',
135 -attachment
=> "bib-$biblionumber.$format"