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>.
28 use Koha::RecordProcessor;
29 use Koha::CsvProfiles;
30 use Koha::AuthorisedValues;
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
36 template_name => "opac-basket.tt",
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 );
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);
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);
73 my $biblio = Koha::Biblios->find( $biblionumber );
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({
81 frameworkcode => $framework
83 $record_processor->process($record);
85 my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
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.
102 foreach my $item (@all_items) {
104 # next if item is hidden
105 next if grep { $item->{itemnumber} eq $_ } @hidden_items ;
107 my $reserve_status = C4::Reserves::GetReserveStatus($item->{itemnumber});
108 if( $reserve_status eq "Waiting"){ $item->{'waiting'} = 1; }
109 if( $reserve_status eq "Reserved"){ $item->{'onhold'} = 1; }
114 if($dat->{'author'} || @$marcauthorsarray) {
118 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
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 $fmt = substr $record->leader(), 6,2;
125 $fmts->{'am'} = 'book';
126 $dat->{ocoins_format} = $fmts->{$fmt};
128 if ( $num % 2 == 1 ) {
132 for my $itm (@items) {
133 if ($itm->{'location'}){
134 $itm->{'location_opac'} = $shelflocations->{$itm->{'location'} };
136 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
137 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
138 $itm->{transfertwhen} = $transfertwhen;
139 $itm->{transfertfrom} = $transfertfrom;
140 $itm->{transfertto} = $transfertto;
144 $dat->{biblionumber} = $biblionumber;
145 $dat->{ITEM_RESULTS} = \@items;
146 $dat->{MARCNOTES} = $marcnotesarray;
147 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
148 $dat->{MARCAUTHORS} = $marcauthorsarray;
149 $dat->{MARCSERIES} = $marcseriesarray;
150 $dat->{MARCURLS} = $marcurlsarray;
151 $dat->{HASAUTHORS} = $hasauthors;
153 if ( C4::Context->preference("BiblioDefaultView") eq "normal" ) {
154 $dat->{dest} = "opac-detail.pl";
156 elsif ( C4::Context->preference("BiblioDefaultView") eq "marc" ) {
157 $dat->{dest} = "opac-MARCdetail.pl";
160 $dat->{dest} = "opac-ISBDdetail.pl";
162 push( @results, $dat );
165 my $resultsarray = \@results;
167 # my $itemsarray=\@items;
171 Koha::CsvProfiles->search(
172 { type => 'marc', used_for => 'export_records', staff_only => 0 }
175 bib_list => $bib_list,
176 BIBLIO_RESULTS => $resultsarray,
179 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };