Bug 32482: (follow-up) Add markup comments
[koha.git] / catalogue / ISBDdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
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 =head1 NAME
21
22 ISBDdetail.pl : script to show a biblio in ISBD format
23
24 =head1 SYNOPSIS
25
26 =cut
27
28 =head1 DESCRIPTION
29
30 This script needs a biblionumber as parameter 
31
32 =head1 FUNCTIONS
33
34 =cut
35
36 use Modern::Perl;
37
38 use HTML::Entities;
39 use C4::Auth qw( get_template_and_user );
40 use C4::Context;
41 use C4::Output qw( output_html_with_http_headers );
42 use CGI qw ( -utf8 );
43 use C4::Biblio qw( GetBiblioData GetISBDView );
44 use C4::Serials qw( CountSubscriptionFromBiblionumber GetSubscription GetSubscriptionsFromBiblionumber );
45 use C4::Search qw( z3950_search_args enabled_staff_search_views );
46
47 use Koha::Biblios;
48 use Koha::Patrons;
49 use Koha::RecordProcessor;
50 use Koha::Virtualshelves;
51
52
53 my $query = CGI->new;
54 my $dbh = C4::Context->dbh;
55
56 my $biblionumber = $query->param('biblionumber');
57 $biblionumber = HTML::Entities::encode($biblionumber);
58
59 # open template
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61     {
62         template_name => "catalogue/ISBDdetail.tt",
63         query         => $query,
64         type          => "intranet",
65         flagsrequired   => { catalogue => 1 },
66     }
67 );
68
69 my $biblio = Koha::Biblios->find( $biblionumber );
70 unless ( $biblionumber && $biblio ) {
71    # biblionumber invalid -> report and exit
72    $template->param( unknownbiblionumber => 1,
73                             biblionumber => $biblionumber
74    );
75    output_html_with_http_headers $query, $cookie, $template->output;
76    exit;
77 }
78
79 my $record = $biblio->metadata->record({ embed_items => 1 });
80
81 if ( not defined $record ) {
82        # biblionumber invalid -> report and exit
83        $template->param( unknownbiblionumber => 1,
84                                 biblionumber => $biblionumber
85        );
86        output_html_with_http_headers $query, $cookie, $template->output;
87        exit;
88 }
89
90 my $framework = $biblio->frameworkcode;
91 my $record_processor = Koha::RecordProcessor->new({
92     filters => 'ViewPolicy',
93     options => {
94         interface => 'intranet',
95         frameworkcode => $framework
96     },
97 });
98 $record_processor->process($record);
99
100 my $res = GetISBDView({
101     'record'    => $record,
102     'template'  => 'intranet',
103     'framework' => $framework,
104 });
105
106 if($query->cookie("holdfor")){ 
107     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
108     $template->param(
109         holdfor        => $query->cookie("holdfor"),
110         holdfor_patron => $holdfor_patron,
111     );
112 }
113
114 if( $query->cookie("searchToOrder") ){
115     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
116     $template->param(
117         searchtoorder_basketno => $basketno,
118         searchtoorder_vendorid => $vendorid
119     );
120 }
121
122 # count of item linked with biblio
123 my $itemcount = $biblio->items->count;
124 $template->param( count => $itemcount);
125 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
126  
127 if ($subscriptionsnumber) {
128     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
129     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
130     $template->param(
131         subscriptionsnumber => $subscriptionsnumber,
132         subscriptiontitle   => $subscriptiontitle,
133     );
134 }
135
136 # get biblionumbers stored in the cart
137 my @cart_list;
138
139 if($query->cookie("intranet_bib_list")){
140     my $cart_list = $query->cookie("intranet_bib_list");
141     @cart_list = split(/\//, $cart_list);
142     if ( grep {$_ eq $biblionumber} @cart_list) {
143         $template->param( incart => 1 );
144     }
145 }
146
147 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
148     {
149         borrowernumber => $loggedinuser,
150         add_allowed    => 1,
151         public         => 0,
152     }
153 );
154 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
155     {
156         borrowernumber => $loggedinuser,
157         add_allowed    => 1,
158         public         => 1,
159     }
160 );
161
162
163 $template->param(
164     add_to_some_private_shelves => $some_private_shelves,
165     add_to_some_public_shelves  => $some_public_shelves,
166 );
167
168 $template->param (
169     ISBD                => $res,
170     biblionumber        => $biblionumber,
171     isbdview            => 1,
172     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
173     ocoins => $biblio->get_coins,
174     C4::Search::enabled_staff_search_views,
175     searchid            => scalar $query->param('searchid'),
176     biblio              => $biblio,
177 );
178
179 my $holds = $biblio->holds;
180 $template->param( holdcount => $holds->count );
181
182 output_html_with_http_headers $query, $cookie, $template->output;
183