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