Bug 19040: Refactor GetMarcBiblio parameters
[koha.git] / opac / opac-basket.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use CGI qw ( -utf8 );
21 use C4::Koha;
22 use C4::Biblio;
23 use C4::Items;
24 use C4::Circulation;
25 use C4::Auth;
26 use C4::Output;
27 use Koha::RecordProcessor;
28
29 use Koha::AuthorisedValues;
30
31 my $query = new CGI;
32
33 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
34     {
35         template_name   => "opac-basket.tt",
36         query           => $query,
37         type            => "opac",
38         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
39     }
40 );
41
42 my $bib_list     = $query->param('bib_list');
43 my $print_basket = $query->param('print');
44 my $verbose      = $query->param('verbose');
45
46 if ($verbose)      { $template->param( verbose      => 1 ); }
47 if ($print_basket) { $template->param( print_basket => 1 ); }
48
49 my @bibs = split( /\//, $bib_list );
50 my @results;
51
52 my $num = 1;
53 my $marcflavour = C4::Context->preference('marcflavour');
54 if (C4::Context->preference('TagsEnabled')) {
55         $template->param(TagsEnabled => 1);
56         foreach (qw(TagsShowOnList TagsInputOnList)) {
57                 C4::Context->preference($_) and $template->param($_ => 1);
58         }
59 }
60
61 my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
62 foreach my $biblionumber ( @bibs ) {
63     $template->param( biblionumber => $biblionumber );
64
65     my $dat              = &GetBiblioData($biblionumber);
66     next unless $dat;
67
68     my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
69     my $framework = &GetFrameworkCode( $biblionumber );
70     $record_processor->options({
71         interface => 'opac',
72         frameworkcode => $framework
73     });
74     $record_processor->process($record);
75     next unless $record;
76     my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
77     my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
78     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
79     my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
80     my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
81     my @items            = &GetItemsInfo( $biblionumber );
82     my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
83
84     my $hasauthors = 0;
85     if($dat->{'author'} || @$marcauthorsarray) {
86       $hasauthors = 1;
87     }
88     my $collections =
89       { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
90     my $shelflocations =
91       { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
92
93         # COinS format FIXME: for books Only
94         my $coins_format;
95         my $fmt = substr $record->leader(), 6,2;
96         my $fmts;
97         $fmts->{'am'} = 'book';
98         $dat->{ocoins_format} = $fmts->{$fmt};
99
100     if ( $num % 2 == 1 ) {
101         $dat->{'even'} = 1;
102     }
103
104     for my $itm (@items) {
105         if ($itm->{'location'}){
106             $itm->{'location_opac'} = $shelflocations->{$itm->{'location'} };
107         }
108         my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
109         if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
110              $itm->{transfertwhen} = $transfertwhen;
111              $itm->{transfertfrom} = $transfertfrom;
112              $itm->{transfertto}   = $transfertto;
113         }
114     }
115     $num++;
116     $dat->{biblionumber} = $biblionumber;
117     $dat->{ITEM_RESULTS}   = \@items;
118     $dat->{MARCNOTES}      = $marcnotesarray;
119     $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
120     $dat->{MARCAUTHORS}    = $marcauthorsarray;
121     $dat->{MARCSERIES}  = $marcseriesarray;
122     $dat->{MARCURLS}    = $marcurlsarray;
123     $dat->{HASAUTHORS}  = $hasauthors;
124     $dat->{subtitle} = $subtitle;
125
126     if ( C4::Context->preference("BiblioDefaultView") eq "normal" ) {
127         $dat->{dest} = "opac-detail.pl";
128     }
129     elsif ( C4::Context->preference("BiblioDefaultView") eq "marc" ) {
130         $dat->{dest} = "opac-MARCdetail.pl";
131     }
132     else {
133         $dat->{dest} = "opac-ISBDdetail.pl";
134     }
135     push( @results, $dat );
136 }
137
138 my $resultsarray = \@results;
139
140 # my $itemsarray=\@items;
141
142 $template->param(
143     bib_list => $bib_list,
144     BIBLIO_RESULTS => $resultsarray,
145 );
146
147 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };