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