Bug 17600: Standardize our EXPORT_OK
[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 C4::Auth qw( get_template_and_user );
24 use C4::Context;
25 use C4::Output qw( output_html_with_http_headers );
26 use C4::Biblio qw(
27     GetBiblioData
28     GetFrameworkCode
29     GetMarcBiblio
30     GetMarcStructure
31 );
32 use C4::Search qw( z3950_search_args enabled_staff_search_views );
33 use C4::Serials qw( CountSubscriptionFromBiblionumber );
34
35 use Koha::Biblios;
36 use Koha::BiblioFrameworks;
37 use Koha::Patrons;
38 use Koha::Virtualshelves;
39
40 my $query        = CGI->new;
41 my $dbh          = C4::Context->dbh;
42 my $biblionumber = $query->param('biblionumber');
43 $biblionumber = HTML::Entities::encode($biblionumber);
44 my $frameworkcode = $query->param('frameworkcode') // GetFrameworkCode( $biblionumber );
45 my $popup        =
46   $query->param('popup')
47   ;    # if set to 1, then don't insert links, it's just to show the biblio
48
49 # open template
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51     {
52         template_name   => "catalogue/labeledMARCdetail.tt",
53         query           => $query,
54         type            => "intranet",
55         flagsrequired   => { catalogue => 1 },
56     }
57 );
58
59 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
60 if ( not defined $record ) {
61     # biblionumber invalid -> report and exit
62     $template->param( unknownbiblionumber => 1,
63                 biblionumber => $biblionumber
64     );
65     output_html_with_http_headers $query, $cookie, $template->output;
66     exit;
67 }
68
69 my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
70 my $tagslib = GetMarcStructure(1,$frameworkcode);
71 my $biblio = GetBiblioData($biblionumber);
72
73 if($query->cookie("holdfor")){ 
74     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
75     $template->param(
76         holdfor => $query->cookie("holdfor"),
77         holdfor_surname => $holdfor_patron->surname,
78         holdfor_firstname => $holdfor_patron->firstname,
79         holdfor_cardnumber => $holdfor_patron->cardnumber,
80     );
81 }
82
83 if( $query->cookie("searchToOrder") ){
84     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
85     $template->param(
86         searchtoorder_basketno => $basketno,
87         searchtoorder_vendorid => $vendorid
88     );
89 }
90
91 #count of item linked
92 my $itemcount = $biblio_object->items->count;
93 $template->param( count => $itemcount,
94                                         bibliotitle => $biblio->{title}, );
95
96 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
97 $template->param(
98     frameworks    => $frameworks,
99     frameworkcode => $frameworkcode,
100 );
101
102 my @marc_data;
103 my $prevlabel = '';
104 for my $field ($record->fields)
105 {
106         my $tag = $field->tag;
107         next if ! exists $tagslib->{$tag}->{lib};
108         my $label = $tagslib->{$tag}->{lib};
109         if ($label eq $prevlabel)
110         {
111                 $label = '';
112         }
113         else
114         {
115                 $prevlabel = $label;
116         }
117         my $value = $tag < 10
118                 ? $field->data
119                 : join ' ', map { $_->[1] } $field->subfields;
120         push @marc_data, {
121                 label => $label,
122                 value => $value,
123         };
124 }
125
126 # get biblionumbers stored in the cart
127 my @cart_list;
128
129 if($query->cookie("intranet_bib_list")){
130     my $cart_list = $query->cookie("intranet_bib_list");
131     @cart_list = split(/\//, $cart_list);
132     if ( grep {$_ eq $biblionumber} @cart_list) {
133         $template->param( incart => 1 );
134     }
135 }
136
137 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
138     {
139         borrowernumber => $loggedinuser,
140         add_allowed    => 1,
141         category       => 1,
142     }
143 );
144 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
145     {
146         borrowernumber => $loggedinuser,
147         add_allowed    => 1,
148         category       => 2,
149     }
150 );
151
152
153 $template->param(
154     add_to_some_private_shelves => $some_private_shelves,
155     add_to_some_public_shelves  => $some_public_shelves,
156 );
157
158 $template->param (
159         marc_data                               => \@marc_data,
160     biblionumber            => $biblionumber,
161     popup                   => $popup,
162         labeledmarcview => 1,
163         z3950_search_params             => C4::Search::z3950_search_args($biblio),
164         C4::Search::enabled_staff_search_views,
165     subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber),
166     searchid            => scalar $query->param('searchid'),
167 );
168
169 $biblio = Koha::Biblios->find( $biblionumber );
170 my $holds = $biblio->holds;
171 $template->param( biblio => $biblio, holdcount => $holds->count );
172
173 output_html_with_http_headers $query, $cookie, $template->output;