Bug 16522: (follow-up) MARC display templates and get_marc_host fixes
[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     GetMarcSeries
24     GetMarcSubjects
25     GetMarcUrls
26 );
27 use C4::Auth qw( get_template_and_user );
28 use C4::Output qw( output_html_with_http_headers );
29
30 use Koha::AuthorisedValues;
31 use Koha::Biblios;
32 use Koha::CsvProfiles;
33
34 my $query = CGI->new;
35
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
37     {
38         template_name   => "basket/basket.tt",
39         query           => $query,
40         type            => "intranet",
41         flagsrequired   => { catalogue => 1 },
42     }
43 );
44
45 my $bib_list     = $query->param('bib_list');
46 my $verbose      = $query->param('verbose');
47
48 if ($verbose)      { $template->param( verbose      => 1 ); }
49
50 my @bibs = split( /\//, $bib_list );
51 my @results;
52
53 my $num = 1;
54 my $marcflavour = C4::Context->preference('marcflavour');
55 if (C4::Context->preference('TagsEnabled')) {
56         $template->param(TagsEnabled => 1);
57         foreach (qw(TagsShowOnList TagsInputOnList)) {
58                 C4::Context->preference($_) and $template->param($_ => 1);
59         }
60 }
61
62
63 foreach my $biblionumber ( @bibs ) {
64     $template->param( biblionumber => $biblionumber );
65
66     my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
67     my $dat              = $biblio->unblessed;
68     my $record           = $biblio->metadata->record;
69     my $marcnotesarray   = $biblio->get_marc_notes;
70     my $marcauthorsarray = $biblio->get_marc_contributors;
71     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
72     my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
73     my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
74
75     my $hasauthors = 0;
76     if($dat->{'author'} || @$marcauthorsarray) {
77       $hasauthors = 1;
78     }
79
80     # COinS format FIXME: for books Only
81     my $fmt = substr $record->leader(), 6,2;
82     my $fmts;
83     $fmts->{'am'} = 'book';
84     $dat->{ocoins_format} = $fmts->{$fmt};
85
86     if ( $num % 2 == 1 ) {
87         $dat->{'even'} = 1;
88     }
89
90     $num++;
91     $dat->{biblionumber} = $biblionumber;
92     $dat->{ITEM_RESULTS}   = $biblio->items->search_ordered;
93     $dat->{MARCNOTES}      = $marcnotesarray;
94     $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
95     $dat->{MARCAUTHORS}    = $marcauthorsarray;
96     $dat->{MARCSERIES}  = $marcseriesarray;
97     $dat->{MARCURLS}    = $marcurlsarray;
98     $dat->{HASAUTHORS}  = $hasauthors;
99     my ( $host, $relatedparts ) = $biblio->get_marc_host;
100     $dat->{HOSTITEMENTRIES} = $host;
101     $dat->{RELATEDPARTS} = $relatedparts;
102
103     push( @results, $dat );
104 }
105
106 my $resultsarray = \@results;
107
108 # my $itemsarray=\@items;
109
110 $template->param(
111     BIBLIO_RESULTS => $resultsarray,
112     csv_profiles => Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }),
113     bib_list => $bib_list,
114 );
115
116 output_html_with_http_headers $query, $cookie, $template->output;