Bug 23363: (QA follow-up) Fix indentation
[koha.git] / opac / opac-basket.pl
blobc2d57f2f5eefe45fe1a1e9c63aa06ba21f6f33d7
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
20 use CGI qw ( -utf8 );
21 use List::Util qw/none/; # well just one :)
23 use C4::Koha;
24 use C4::Biblio;
25 use C4::Items;
26 use C4::Circulation;
27 use C4::Auth;
28 use C4::Output;
29 use Koha::RecordProcessor;
31 use Koha::AuthorisedValues;
33 my $query = new CGI;
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
37 template_name => "opac-basket.tt",
38 query => $query,
39 type => "opac",
40 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
44 my $bib_list = $query->param('bib_list');
45 my $verbose = $query->param('verbose');
47 if ($verbose) { $template->param( verbose => 1 ); }
49 my @bibs = split( /\//, $bib_list );
50 my @results;
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);
61 my $borcat = q{};
62 if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
63 # we need to fetch the borrower info here, so we can pass the category
64 my $patron = Koha::Patrons->find($borrowernumber);
65 $borcat = $patron ? $patron->categorycode : $borcat;
68 my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
69 foreach my $biblionumber ( @bibs ) {
70 $template->param( biblionumber => $biblionumber );
72 my $dat = &GetBiblioData($biblionumber);
73 next unless $dat;
75 # No filtering on the item records needed for the record itself
76 # since the only reason item information is grabbed is because of branchcodes.
77 my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
78 my $framework = &GetFrameworkCode( $biblionumber );
79 $record_processor->options({
80 interface => 'opac',
81 frameworkcode => $framework
82 });
83 $record_processor->process($record);
84 next unless $record;
85 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
86 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
87 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
88 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
89 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
91 # grab all the items...
92 my @all_items = &GetItemsInfo( $biblionumber );
94 # determine which ones should be hidden / visible
95 my @hidden_items = GetHiddenItemnumbers({ items => \@all_items, borcat => $borcat });
97 # If every item is hidden, then the biblio should be hidden too.
98 next if (scalar @all_items >= 1 && scalar @hidden_items == scalar @all_items);
100 # copy the visible ones into the items array.
101 my @items;
102 foreach my $item (@all_items) {
103 if ( none { $item->{itemnumber} ne $_ } @hidden_items ) {
104 my $reserve_status = C4::Reserves::GetReserveStatus($item->{itemnumber});
105 if( $reserve_status eq "Waiting"){ $item->{'waiting'} = 1; }
106 if( $reserve_status eq "Reserved"){ $item->{'onhold'} = 1; }
107 push @items, $item;
111 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
113 my $hasauthors = 0;
114 if($dat->{'author'} || @$marcauthorsarray) {
115 $hasauthors = 1;
117 my $collections =
118 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
119 my $shelflocations =
120 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
122 # COinS format FIXME: for books Only
123 my $coins_format;
124 my $fmt = substr $record->leader(), 6,2;
125 my $fmts;
126 $fmts->{'am'} = 'book';
127 $dat->{ocoins_format} = $fmts->{$fmt};
129 if ( $num % 2 == 1 ) {
130 $dat->{'even'} = 1;
133 for my $itm (@items) {
134 if ($itm->{'location'}){
135 $itm->{'location_opac'} = $shelflocations->{$itm->{'location'} };
137 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
138 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
139 $itm->{transfertwhen} = $transfertwhen;
140 $itm->{transfertfrom} = $transfertfrom;
141 $itm->{transfertto} = $transfertto;
144 $num++;
145 $dat->{biblionumber} = $biblionumber;
146 $dat->{ITEM_RESULTS} = \@items;
147 $dat->{MARCNOTES} = $marcnotesarray;
148 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
149 $dat->{MARCAUTHORS} = $marcauthorsarray;
150 $dat->{MARCSERIES} = $marcseriesarray;
151 $dat->{MARCURLS} = $marcurlsarray;
152 $dat->{HASAUTHORS} = $hasauthors;
153 $dat->{subtitle} = $subtitle;
155 if ( C4::Context->preference("BiblioDefaultView") eq "normal" ) {
156 $dat->{dest} = "opac-detail.pl";
158 elsif ( C4::Context->preference("BiblioDefaultView") eq "marc" ) {
159 $dat->{dest} = "opac-MARCdetail.pl";
161 else {
162 $dat->{dest} = "opac-ISBDdetail.pl";
164 push( @results, $dat );
167 my $resultsarray = \@results;
169 # my $itemsarray=\@items;
171 $template->param(
172 bib_list => $bib_list,
173 BIBLIO_RESULTS => $resultsarray,
176 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };