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