3 # Copyright 2009 BibLibre
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>.
24 use C4::Auth qw( get_template_and_user );
25 use C4::Biblio qw( GetFrameworkCode GetISBDView );
26 use C4::Output qw( output_html_with_http_headers );
28 use C4::Ris qw( marc2ris );
30 use Koha::CsvProfiles;
31 use Koha::RecordProcessor;
32 use Koha::Virtualshelves;
37 # if virtualshelves is disabled, leave immediately
38 if ( ! C4::Context->preference('virtualshelves') ) {
39 print $query->redirect("/cgi-bin/koha/errors/404.pl");
43 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
45 template_name => "opac-downloadshelf.tt",
48 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
52 my $patron = Koha::Patrons->find( $borrowernumber );
54 my $shelfnumber = $query->param('shelfnumber');
55 my $format = $query->param('format');
56 my $context = $query->param('context');
58 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
59 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
61 if ($shelfnumber && $format) {
64 my $contents = $shelf->get_contents;
65 my $marcflavour = C4::Context->preference('marcflavour');
71 if ($format =~ /^\d+$/) {
73 my $csv_profile = Koha::CsvProfiles->find($format);
74 if ( not $csv_profile or $csv_profile->staff_only ) {
75 print $query->redirect('/cgi-bin/koha/errors/404.pl');
80 while ( my $content = $contents->next ) {
81 push @biblios, $content->biblionumber;
83 $output = marc2csv(\@biblios, $format);
86 my $record_processor = Koha::RecordProcessor->new({
87 filters => 'ViewPolicy'
89 while ( my $content = $contents->next ) {
90 my $biblionumber = $content->biblionumber;
92 my $biblio = Koha::Biblios->find($biblionumber);
93 my $record = $biblio->metadata->record->(
100 my $framework = $biblio->frameworkcode;
101 $record_processor->options({
103 frameworkcode => $framework
105 $record_processor->process($record);
108 if ($format eq 'iso2709') {
109 $output .= $record->as_usmarc();
111 elsif ($format eq 'ris' ) {
112 $output .= marc2ris($record);
114 elsif ($format eq 'bibtex') {
115 $output .= marc2bibtex($record, $biblionumber);
117 elsif ( $format eq 'isbd' ) {
118 $output .= GetISBDView({
120 'template' => 'opac',
121 'framework' => $framework,
124 $type = "text/plain";
129 # If it was a CSV export we change the format after the export so the file extension is fine
130 $format = "csv" if ($format =~ m/^\d+$/);
132 print $query->header(
133 -type => ($type) ? $type : 'application/octet-stream',
134 -'Content-Transfer-Encoding' => 'binary',
135 -attachment => ($extension) ? "shelf.$format.$extension" : "shelf.$format"
141 # if modal context is passed set a variable so that page markup can be different
142 if($context eq "modal"){
143 $template->param(modal => 1);
145 $template->param(fullpage => 1);
148 csv_profiles => Koha::CsvProfiles->search(
151 used_for => 'export_records',
157 output_html_with_http_headers $query, $cookie, $template->output;
161 $template->param(invalidlist => 1);
162 output_html_with_http_headers $query, $cookie, $template->output;