Bug 27894: Adapt /holds/:hold_id/pickup_locations
[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
32 use Koha::Biblios;
33 use Koha::BiblioFrameworks;
34 use Koha::Patrons;
35 use Koha::Virtualshelves;
36
37 my $query        = CGI->new;
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 if( $query->cookie("searchToOrder") ){
82     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
83     $template->param(
84         searchtoorder_basketno => $basketno,
85         searchtoorder_vendorid => $vendorid
86     );
87 }
88
89 #count of item linked
90 my $itemcount = $biblio_object->items->count;
91 $template->param( count => $itemcount,
92                                         bibliotitle => $biblio->{title}, );
93
94 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
95 $template->param(
96     frameworks    => $frameworks,
97     frameworkcode => $frameworkcode,
98 );
99
100 my @marc_data;
101 my $prevlabel = '';
102 for my $field ($record->fields)
103 {
104         my $tag = $field->tag;
105         next if ! exists $tagslib->{$tag}->{lib};
106         my $label = $tagslib->{$tag}->{lib};
107         if ($label eq $prevlabel)
108         {
109                 $label = '';
110         }
111         else
112         {
113                 $prevlabel = $label;
114         }
115         my $value = $tag < 10
116                 ? $field->data
117                 : join ' ', map { $_->[1] } $field->subfields;
118         push @marc_data, {
119                 label => $label,
120                 value => $value,
121         };
122 }
123
124 # get biblionumbers stored in the cart
125 my @cart_list;
126
127 if($query->cookie("intranet_bib_list")){
128     my $cart_list = $query->cookie("intranet_bib_list");
129     @cart_list = split(/\//, $cart_list);
130     if ( grep {$_ eq $biblionumber} @cart_list) {
131         $template->param( incart => 1 );
132     }
133 }
134
135 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
136     {
137         borrowernumber => $loggedinuser,
138         add_allowed    => 1,
139         category       => 1,
140     }
141 );
142 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
143     {
144         borrowernumber => $loggedinuser,
145         add_allowed    => 1,
146         category       => 2,
147     }
148 );
149
150
151 $template->param(
152     add_to_some_private_shelves => $some_private_shelves,
153     add_to_some_public_shelves  => $some_public_shelves,
154 );
155
156 $template->param (
157         marc_data                               => \@marc_data,
158     biblionumber            => $biblionumber,
159     popup                   => $popup,
160         labeledmarcview => 1,
161         z3950_search_params             => C4::Search::z3950_search_args($biblio),
162         C4::Search::enabled_staff_search_views,
163     subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber),
164     searchid            => scalar $query->param('searchid'),
165 );
166
167 $biblio = Koha::Biblios->find( $biblionumber );
168 my $holds = $biblio->holds;
169 $template->param( biblio => $biblio, holdcount => $holds->count );
170
171 output_html_with_http_headers $query, $cookie, $template->output;