Bug 29407: Make the pickup locations dropdown JS reusable
[koha.git] / basket / 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 Modern::Perl;
20 use CGI qw ( -utf8 );
21 use C4::Koha;
22 use C4::Biblio qw(
23     GetBiblioData
24     GetMarcAuthors
25     GetMarcBiblio
26     GetMarcSeries
27     GetMarcSubjects
28     GetMarcUrls
29 );
30 use C4::Items qw( GetItemsInfo );
31 use C4::Auth qw( get_template_and_user );
32 use C4::Output qw( output_html_with_http_headers );
33
34 use Koha::AuthorisedValues;
35 use Koha::Biblios;
36 use Koha::CsvProfiles;
37
38 my $query = CGI->new;
39
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
41     {
42         template_name   => "basket/basket.tt",
43         query           => $query,
44         type            => "intranet",
45         flagsrequired   => { catalogue => 1 },
46     }
47 );
48
49 my $bib_list     = $query->param('bib_list');
50 my $verbose      = $query->param('verbose');
51
52 if ($verbose)      { $template->param( verbose      => 1 ); }
53
54 my @bibs = split( /\//, $bib_list );
55 my @results;
56
57 my $num = 1;
58 my $marcflavour = C4::Context->preference('marcflavour');
59 if (C4::Context->preference('TagsEnabled')) {
60         $template->param(TagsEnabled => 1);
61         foreach (qw(TagsShowOnList TagsInputOnList)) {
62                 C4::Context->preference($_) and $template->param($_ => 1);
63         }
64 }
65
66
67 foreach my $biblionumber ( @bibs ) {
68     $template->param( biblionumber => $biblionumber );
69
70     my $dat              = &GetBiblioData($biblionumber);
71     next unless $dat;
72     my $biblio           = Koha::Biblios->find( $biblionumber );
73     my $record           = &GetMarcBiblio({ biblionumber => $biblionumber });
74     my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $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
81     my $hasauthors = 0;
82     if($dat->{'author'} || @$marcauthorsarray) {
83       $hasauthors = 1;
84     }
85         
86     my $shelflocations =
87       { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
88
89         for my $itm (@items) {
90             if ($itm->{'location'}){
91             $itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
92                 }
93         }
94         # COinS format FIXME: for books Only
95         my $fmt = substr $record->leader(), 6,2;
96         my $fmts;
97         $fmts->{'am'} = 'book';
98         $dat->{ocoins_format} = $fmts->{$fmt};
99
100     if ( $num % 2 == 1 ) {
101         $dat->{'even'} = 1;
102     }
103
104     $num++;
105     $dat->{biblionumber} = $biblionumber;
106     $dat->{ITEM_RESULTS}   = \@items;
107     $dat->{MARCNOTES}      = $marcnotesarray;
108     $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
109     $dat->{MARCAUTHORS}    = $marcauthorsarray;
110     $dat->{MARCSERIES}  = $marcseriesarray;
111     $dat->{MARCURLS}    = $marcurlsarray;
112     $dat->{HASAUTHORS}  = $hasauthors;
113
114     if ( C4::Context->preference("IntranetBiblioDefaultView") eq "normal" ) {
115         $dat->{dest} = "/cgi-bin/koha/catalogue/detail.pl";
116     }
117     elsif ( C4::Context->preference("IntranetBiblioDefaultView") eq "marc" ) {
118         $dat->{dest} = "/cgi-bin/koha/catalogue/MARCdetail.pl";
119     }
120     else {
121         $dat->{dest} = "/cgi-bin/koha/catalogue/ISBDdetail.pl";
122     }
123     push( @results, $dat );
124 }
125
126 my $resultsarray = \@results;
127
128 # my $itemsarray=\@items;
129
130 $template->param(
131     BIBLIO_RESULTS => $resultsarray,
132     csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
133     bib_list => $bib_list,
134 );
135
136 output_html_with_http_headers $query, $cookie, $template->output;