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