Bug 27770: ES: Deprecated aggregation order key [_term] used, replaced by [_key]
[koha.git] / catalogue / labeledMARCdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008-2009 LibLime
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use CGI qw ( -utf8 ); 
22 use HTML::Entities;
23 use MARC::Record;
24 use C4::Auth;
25 use C4::Context;
26 use C4::Output;
27 use C4::Biblio;
28 use C4::Items;
29 use C4::Search;         # enabled_staff_search_views
30 use C4::Serials;
31 use C4::Acquisition qw(GetOrdersByBiblionumber);
32
33 use Koha::Biblios;
34 use Koha::BiblioFrameworks;
35 use Koha::Patrons;
36
37 my $query        = new CGI;
38 my $dbh          = C4::Context->dbh;
39 my $biblionumber = $query->param('biblionumber');
40 $biblionumber = HTML::Entities::encode($biblionumber);
41 my $frameworkcode = $query->param('frameworkcode') // GetFrameworkCode( $biblionumber );
42 my $popup        =
43   $query->param('popup')
44   ;    # if set to 1, then don't insert links, it's just to show the biblio
45
46 # open template
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48     {
49         template_name   => "catalogue/labeledMARCdetail.tt",
50         query           => $query,
51         type            => "intranet",
52         flagsrequired   => { catalogue => 1 },
53         debug           => 1,
54     }
55 );
56
57 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
58 if ( not defined $record ) {
59     # biblionumber invalid -> report and exit
60     $template->param( unknownbiblionumber => 1,
61                 biblionumber => $biblionumber
62     );
63     output_html_with_http_headers $query, $cookie, $template->output;
64     exit;
65 }
66
67 my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
68 my $tagslib = GetMarcStructure(1,$frameworkcode);
69 my $biblio = GetBiblioData($biblionumber);
70
71 if($query->cookie("holdfor")){ 
72     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
73     $template->param(
74         holdfor => $query->cookie("holdfor"),
75         holdfor_surname => $holdfor_patron->surname,
76         holdfor_firstname => $holdfor_patron->firstname,
77         holdfor_cardnumber => $holdfor_patron->cardnumber,
78     );
79 }
80
81 #count of item linked
82 my $itemcount = $biblio_object->items->count;
83 $template->param( count => $itemcount,
84                                         bibliotitle => $biblio->{title}, );
85
86 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
87 $template->param(
88     frameworks    => $frameworks,
89     frameworkcode => $frameworkcode,
90 );
91
92 my @marc_data;
93 my $prevlabel = '';
94 for my $field ($record->fields)
95 {
96         my $tag = $field->tag;
97         next if ! exists $tagslib->{$tag}->{lib};
98         my $label = $tagslib->{$tag}->{lib};
99         if ($label eq $prevlabel)
100         {
101                 $label = '';
102         }
103         else
104         {
105                 $prevlabel = $label;
106         }
107         my $value = $tag < 10
108                 ? $field->data
109                 : join ' ', map { $_->[1] } $field->subfields;
110         push @marc_data, {
111                 label => $label,
112                 value => $value,
113         };
114 }
115
116 $template->param (
117         marc_data                               => \@marc_data,
118     biblionumber            => $biblionumber,
119     popup                   => $popup,
120         labeledmarcview => 1,
121         z3950_search_params             => C4::Search::z3950_search_args($biblio),
122         C4::Search::enabled_staff_search_views,
123     subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber),
124     searchid            => scalar $query->param('searchid'),
125 );
126
127 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
128 my @deletedorders_using_biblio;
129 my @orders_using_biblio;
130 my @baskets_orders;
131 my @baskets_deletedorders;
132
133 foreach my $myorder (@allorders_using_biblio) {
134     my $basket = $myorder->{'basketno'};
135     if ((defined $myorder->{'datecancellationprinted'}) and  ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
136         push @deletedorders_using_biblio, $myorder;
137         unless (grep(/^$basket$/, @baskets_deletedorders)){
138             push @baskets_deletedorders,$myorder->{'basketno'};
139         }
140     }
141     else {
142         push @orders_using_biblio, $myorder;
143         unless (grep(/^$basket$/, @baskets_orders)){
144             push @baskets_orders,$myorder->{'basketno'};
145             }
146     }
147 }
148
149 my $count_orders_using_biblio = scalar @orders_using_biblio ;
150 $template->param (countorders => $count_orders_using_biblio);
151
152 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
153 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
154
155 $biblio = Koha::Biblios->find( $biblionumber );
156 my $holds = $biblio->holds;
157 $template->param( holdcount => $holds->count );
158
159 output_html_with_http_headers $query, $cookie, $template->output;