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