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