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>.
29 use C4::Circulation qw( GetTransfers );
30 use C4::Auth qw( get_template_and_user );
31 use C4::Output qw( output_html_with_http_headers );
32 use Koha::RecordProcessor;
33 use Koha::CsvProfiles;
34 use Koha::AuthorisedValues;
39 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
41 template_name => "opac-basket.tt",
44 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
48 my $bib_list = $query->param('bib_list');
49 my $verbose = $query->param('verbose');
51 if ($verbose) { $template->param( verbose => 1 ); }
53 my @bibs = split( /\//, $bib_list );
57 my $marcflavour = C4::Context->preference('marcflavour');
58 if (C4::Context->preference('TagsEnabled')) {
59 $template->param(TagsEnabled => 1);
60 foreach (qw(TagsShowOnList TagsInputOnList)) {
61 C4::Context->preference($_) and $template->param($_ => 1);
65 my $logged_in_user = Koha::Patrons->find($borrowernumber);
67 my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
68 my $rules = C4::Context->yaml_preference('OpacHiddenItems');
70 foreach my $biblionumber ( @bibs ) {
71 $template->param( biblionumber => $biblionumber );
73 my $biblio = Koha::Biblios->find( $biblionumber ) or next;
74 my $dat = $biblio->unblessed;
76 # No filtering on the item records needed for the record itself
77 # since the only reason item information is grabbed is because of branchcodes.
78 my $record = $biblio->metadata->record;
79 my $framework = &GetFrameworkCode( $biblionumber );
80 $record_processor->options({
82 frameworkcode => $framework
84 $record_processor->process($record);
86 my $marcnotesarray = $biblio->get_marc_notes({ opac => 1 });
87 my $marcauthorsarray = $biblio->get_marc_contributors;
88 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
89 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
90 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
92 # If every item is hidden, then the biblio should be hidden too.
94 if $biblio->hidden_in_opac({ rules => $rules });
96 # grab all the items...
97 my $items = $biblio->items->filter_by_visible_in_opac({ patron => $logged_in_user })->unblessed;
98 foreach my $item (@$items) {
99 my $reserve_status = C4::Reserves::GetReserveStatus($item->{itemnumber});
100 if( $reserve_status eq "Waiting"){ $item->{'waiting'} = 1; }
101 if( $reserve_status eq "Reserved"){ $item->{'onhold'} = 1; }
105 if($dat->{'author'} || @$marcauthorsarray) {
109 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
111 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
113 # COinS format FIXME: for books Only
114 my $fmt = substr $record->leader(), 6,2;
116 $fmts->{'am'} = 'book';
117 $dat->{ocoins_format} = $fmts->{$fmt};
119 if ( $num % 2 == 1 ) {
123 for my $itm (@$items) {
124 if ($itm->{'location'}){
125 $itm->{'location_opac'} = $shelflocations->{$itm->{'location'} };
127 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
128 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
129 $itm->{transfertwhen} = $transfertwhen;
130 $itm->{transfertfrom} = $transfertfrom;
131 $itm->{transfertto} = $transfertto;
135 $dat->{biblionumber} = $biblionumber;
136 $dat->{ITEM_RESULTS} = $items;
137 $dat->{MARCNOTES} = $marcnotesarray;
138 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
139 $dat->{MARCAUTHORS} = $marcauthorsarray;
140 $dat->{MARCSERIES} = $marcseriesarray;
141 $dat->{MARCURLS} = $marcurlsarray;
142 $dat->{HASAUTHORS} = $hasauthors;
144 push( @results, $dat );
147 my $resultsarray = \@results;
149 # my $itemsarray=\@items;
152 csv_profiles => Koha::CsvProfiles->search(
153 { type => 'marc', used_for => 'export_records', staff_only => 0 } ),
154 bib_list => $bib_list,
155 BIBLIO_RESULTS => $resultsarray,
158 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };