Bug 11592: MARCView and ISBD followup
[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
19 use strict;
20 use warnings;
21 use CGI qw ( -utf8 );
22 use C4::Koha;
23 use C4::Biblio;
24 use C4::Branch;
25 use C4::Items;
26 use C4::Circulation;
27 use C4::Auth;
28 use C4::Output;
29 use Koha::RecordProcessor;
30
31 my $query = new CGI;
32
33 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
34     {
35         template_name   => "opac-basket.tt",
36         query           => $query,
37         type            => "opac",
38         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
39     }
40 );
41
42 my $bib_list     = $query->param('bib_list');
43 my $print_basket = $query->param('print');
44 my $verbose      = $query->param('verbose');
45
46 if ($verbose)      { $template->param( verbose      => 1 ); }
47 if ($print_basket) { $template->param( print_basket => 1 ); }
48
49 my @bibs = split( /\//, $bib_list );
50 my @results;
51
52 my $num = 1;
53 my $marcflavour = C4::Context->preference('marcflavour');
54 if (C4::Context->preference('TagsEnabled')) {
55         $template->param(TagsEnabled => 1);
56         foreach (qw(TagsShowOnList TagsInputOnList)) {
57                 C4::Context->preference($_) and $template->param($_ => 1);
58         }
59 }
60
61 my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
62 foreach my $biblionumber ( @bibs ) {
63     $template->param( biblionumber => $biblionumber );
64
65     my $dat              = &GetBiblioData($biblionumber);
66     next unless $dat;
67     my $record_unfiltered = &GetMarcBiblio($biblionumber);
68     my $record_filtered   = $record_unfiltered->clone();
69     my $record            = $record_processor->process($record_filtered);
70     next unless $record;
71     my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
72     my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
73     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
74     my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
75     my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
76     my @items            = &GetItemsInfo( $biblionumber );
77     my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
78
79     my $hasauthors = 0;
80     if($dat->{'author'} || @$marcauthorsarray) {
81       $hasauthors = 1;
82     }
83     my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
84     my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
85
86         # COinS format FIXME: for books Only
87         my $coins_format;
88         my $fmt = substr $record->leader(), 6,2;
89         my $fmts;
90         $fmts->{'am'} = 'book';
91         $dat->{ocoins_format} = $fmts->{$fmt};
92
93     if ( $num % 2 == 1 ) {
94         $dat->{'even'} = 1;
95     }
96
97 my $branches = GetBranches();
98     for my $itm (@items) {
99         if ($itm->{'location'}){
100             $itm->{'location_opac'} = $shelflocations->{$itm->{'location'} };
101         }
102         my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
103         if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
104              $itm->{transfertwhen} = $transfertwhen;
105              $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
106              $itm->{transfertto}   = $branches->{$transfertto}{branchname};
107         }
108     }
109     $num++;
110     $dat->{biblionumber} = $biblionumber;
111     $dat->{ITEM_RESULTS}   = \@items;
112     $dat->{MARCNOTES}      = $marcnotesarray;
113     $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
114     $dat->{MARCAUTHORS}    = $marcauthorsarray;
115     $dat->{MARCSERIES}  = $marcseriesarray;
116     $dat->{MARCURLS}    = $marcurlsarray;
117     $dat->{HASAUTHORS}  = $hasauthors;
118     $dat->{subtitle} = $subtitle;
119
120     if ( C4::Context->preference("BiblioDefaultView") eq "normal" ) {
121         $dat->{dest} = "opac-detail.pl";
122     }
123     elsif ( C4::Context->preference("BiblioDefaultView") eq "marc" ) {
124         $dat->{dest} = "opac-MARCdetail.pl";
125     }
126     else {
127         $dat->{dest} = "opac-ISBDdetail.pl";
128     }
129     push( @results, $dat );
130 }
131
132 my $resultsarray = \@results;
133
134 # my $itemsarray=\@items;
135
136 $template->param(
137     bib_list => $bib_list,
138     BIBLIO_RESULTS => $resultsarray,
139 );
140
141 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };