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>.
30 use C4::Items qw( GetHiddenItemnumbers GetItemsInfo );
31 use C4::Circulation qw( GetTransfers );
32 use C4::Auth qw( get_template_and_user );
33 use C4::Output qw( output_html_with_http_headers );
34 use Koha::RecordProcessor;
35 use Koha::CsvProfiles;
36 use Koha::AuthorisedValues;
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
43 template_name => "opac-basket.tt",
46 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
50 my $bib_list = $query->param('bib_list');
51 my $verbose = $query->param('verbose');
53 if ($verbose) { $template->param( verbose => 1 ); }
55 my @bibs = split( /\//, $bib_list );
59 my $marcflavour = C4::Context->preference('marcflavour');
60 if (C4::Context->preference('TagsEnabled')) {
61 $template->param(TagsEnabled => 1);
62 foreach (qw(TagsShowOnList TagsInputOnList)) {
63 C4::Context->preference($_) and $template->param($_ => 1);
68 if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
69 # we need to fetch the borrower info here, so we can pass the category
70 my $patron = Koha::Patrons->find($borrowernumber);
71 $borcat = $patron ? $patron->categorycode : $borcat;
74 my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
75 my $rules = C4::Context->yaml_preference('OpacHiddenItems');
77 foreach my $biblionumber ( @bibs ) {
78 $template->param( biblionumber => $biblionumber );
80 my $biblio = Koha::Biblios->find( $biblionumber ) or next;
81 my $dat = $biblio->unblessed;
83 # No filtering on the item records needed for the record itself
84 # since the only reason item information is grabbed is because of branchcodes.
85 my $record = &GetMarcBiblio({ biblionumber => $biblionumber });
86 my $framework = &GetFrameworkCode( $biblionumber );
87 $record_processor->options({
89 frameworkcode => $framework
91 $record_processor->process($record);
93 my $marcnotesarray = $biblio->get_marc_notes({ opac => 1 });
94 my $marcauthorsarray = $biblio->get_marc_authors;
95 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
96 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
97 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
99 # grab all the items...
100 my @all_items = &GetItemsInfo( $biblionumber );
102 # determine which ones should be hidden / visible
103 my @hidden_items = GetHiddenItemnumbers({ items => \@all_items, borcat => $borcat });
105 # If every item is hidden, then the biblio should be hidden too.
107 if $biblio->hidden_in_opac({ rules => $rules });
109 # copy the visible ones into the items array.
111 foreach my $item (@all_items) {
113 # next if item is hidden
114 next if grep { $item->{itemnumber} eq $_ } @hidden_items ;
116 my $reserve_status = C4::Reserves::GetReserveStatus($item->{itemnumber});
117 if( $reserve_status eq "Waiting"){ $item->{'waiting'} = 1; }
118 if( $reserve_status eq "Reserved"){ $item->{'onhold'} = 1; }
123 if($dat->{'author'} || @$marcauthorsarray) {
127 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
129 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
131 # COinS format FIXME: for books Only
132 my $fmt = substr $record->leader(), 6,2;
134 $fmts->{'am'} = 'book';
135 $dat->{ocoins_format} = $fmts->{$fmt};
137 if ( $num % 2 == 1 ) {
141 for my $itm (@items) {
142 if ($itm->{'location'}){
143 $itm->{'location_opac'} = $shelflocations->{$itm->{'location'} };
145 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
146 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
147 $itm->{transfertwhen} = $transfertwhen;
148 $itm->{transfertfrom} = $transfertfrom;
149 $itm->{transfertto} = $transfertto;
153 $dat->{biblionumber} = $biblionumber;
154 $dat->{ITEM_RESULTS} = \@items;
155 $dat->{MARCNOTES} = $marcnotesarray;
156 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
157 $dat->{MARCAUTHORS} = $marcauthorsarray;
158 $dat->{MARCSERIES} = $marcseriesarray;
159 $dat->{MARCURLS} = $marcurlsarray;
160 $dat->{HASAUTHORS} = $hasauthors;
162 push( @results, $dat );
165 my $resultsarray = \@results;
167 # my $itemsarray=\@items;
170 csv_profiles => Koha::CsvProfiles->search(
171 { type => 'marc', used_for => 'export_records', staff_only => 0 } ),
172 bib_list => $bib_list,
173 BIBLIO_RESULTS => $resultsarray,
176 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };