Bug 27266: (follow-up) Remove instances of GetMarcAuthors
[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
22 use C4::Koha;
23 use C4::Biblio qw(
24     GetBiblioData
25     GetFrameworkCode
26     GetMarcBiblio
27     GetMarcSeries
28     GetMarcSubjects
29     GetMarcUrls
30 );
31 use C4::Items qw( GetHiddenItemnumbers GetItemsInfo );
32 use C4::Circulation qw( GetTransfers );
33 use C4::Auth qw( get_template_and_user );
34 use C4::Output qw( output_html_with_http_headers );
35 use Koha::RecordProcessor;
36 use Koha::CsvProfiles;
37 use Koha::AuthorisedValues;
38 use Koha::Biblios;
39
40 my $query = CGI->new;
41
42 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
43     {
44         template_name   => "opac-basket.tt",
45         query           => $query,
46         type            => "opac",
47         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
48     }
49 );
50
51 my $bib_list     = $query->param('bib_list');
52 my $verbose      = $query->param('verbose');
53
54 if ($verbose)      { $template->param( verbose      => 1 ); }
55
56 my @bibs = split( /\//, $bib_list );
57 my @results;
58
59 my $num = 1;
60 my $marcflavour = C4::Context->preference('marcflavour');
61 if (C4::Context->preference('TagsEnabled')) {
62         $template->param(TagsEnabled => 1);
63         foreach (qw(TagsShowOnList TagsInputOnList)) {
64                 C4::Context->preference($_) and $template->param($_ => 1);
65         }
66 }
67
68 my $borcat = q{};
69 if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
70     # we need to fetch the borrower info here, so we can pass the category
71     my $patron = Koha::Patrons->find($borrowernumber);
72     $borcat = $patron ? $patron->categorycode : $borcat;
73 }
74
75 my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
76 my $rules = C4::Context->yaml_preference('OpacHiddenItems');
77
78 foreach my $biblionumber ( @bibs ) {
79     $template->param( biblionumber => $biblionumber );
80
81     my $dat              = &GetBiblioData($biblionumber);
82     next unless $dat;
83     my $biblio           = Koha::Biblios->find( $biblionumber );
84
85     # No filtering on the item records needed for the record itself
86     # since the only reason item information is grabbed is because of branchcodes.
87     my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
88     my $framework = &GetFrameworkCode( $biblionumber );
89     $record_processor->options({
90         interface => 'opac',
91         frameworkcode => $framework
92     });
93     $record_processor->process($record);
94     next unless $record;
95     my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
96     my $marcauthorsarray = $biblio->get_marc_authors;
97     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
98     my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
99     my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
100
101     # grab all the items...
102     my @all_items        = &GetItemsInfo( $biblionumber );
103
104     # determine which ones should be hidden / visible
105     my @hidden_items     = GetHiddenItemnumbers({ items => \@all_items, borcat => $borcat });
106
107     # If every item is hidden, then the biblio should be hidden too.
108     next
109       if $biblio->hidden_in_opac({ rules => $rules });
110
111     # copy the visible ones into the items array.
112     my @items;
113     foreach my $item (@all_items) {
114
115             # next if item is hidden
116             next  if  grep  { $item->{itemnumber} eq $_  } @hidden_items ;
117
118             my $reserve_status = C4::Reserves::GetReserveStatus($item->{itemnumber});
119             if( $reserve_status eq "Waiting"){ $item->{'waiting'} = 1; }
120             if( $reserve_status eq "Reserved"){ $item->{'onhold'} = 1; }
121             push @items, $item;
122     }
123
124     my $hasauthors = 0;
125     if($dat->{'author'} || @$marcauthorsarray) {
126       $hasauthors = 1;
127     }
128     my $collections =
129       { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
130     my $shelflocations =
131       { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
132
133         # COinS format FIXME: for books Only
134         my $fmt = substr $record->leader(), 6,2;
135         my $fmts;
136         $fmts->{'am'} = 'book';
137         $dat->{ocoins_format} = $fmts->{$fmt};
138
139     if ( $num % 2 == 1 ) {
140         $dat->{'even'} = 1;
141     }
142
143     for my $itm (@items) {
144         if ($itm->{'location'}){
145             $itm->{'location_opac'} = $shelflocations->{$itm->{'location'} };
146         }
147         my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
148         if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
149              $itm->{transfertwhen} = $transfertwhen;
150              $itm->{transfertfrom} = $transfertfrom;
151              $itm->{transfertto}   = $transfertto;
152         }
153     }
154     $num++;
155     $dat->{biblionumber} = $biblionumber;
156     $dat->{ITEM_RESULTS}   = \@items;
157     $dat->{MARCNOTES}      = $marcnotesarray;
158     $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
159     $dat->{MARCAUTHORS}    = $marcauthorsarray;
160     $dat->{MARCSERIES}  = $marcseriesarray;
161     $dat->{MARCURLS}    = $marcurlsarray;
162     $dat->{HASAUTHORS}  = $hasauthors;
163
164     if ( C4::Context->preference("BiblioDefaultView") eq "normal" ) {
165         $dat->{dest} = "opac-detail.pl";
166     }
167     elsif ( C4::Context->preference("BiblioDefaultView") eq "marc" ) {
168         $dat->{dest} = "opac-MARCdetail.pl";
169     }
170     else {
171         $dat->{dest} = "opac-ISBDdetail.pl";
172     }
173     push( @results, $dat );
174 }
175
176 my $resultsarray = \@results;
177
178 # my $itemsarray=\@items;
179
180 $template->param(
181     csv_profiles => [
182         Koha::CsvProfiles->search(
183             { type => 'marc', used_for => 'export_records', staff_only => 0 }
184         )
185     ],
186     bib_list => $bib_list,
187     BIBLIO_RESULTS => $resultsarray,
188 );
189
190 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };