Bug 11592: (QA followup) Simplify code
[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;
40 use C4::Context;
41 use C4::Output;
42 use CGI qw ( -utf8 );
43 use C4::Koha;
44 use C4::Biblio;
45 use C4::Items;
46 use C4::Members; # to use GetMember
47 use C4::Serials;    # CountSubscriptionFromBiblionumber
48 use C4::Search;         # enabled_staff_search_views
49 use C4::Acquisition qw(GetOrdersByBiblionumber);
50 use Koha::RecordProcessor;
51
52
53 my $query = new CGI;
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         authnotrequired => 0,
66         flagsrequired   => { catalogue => 1 },
67     }
68 );
69
70 if ( not defined $biblionumber ) {
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 = GetMarcBiblio($biblionumber,1);
80 my $record_processor = Koha::RecordProcessor->new({
81     filters => 'ViewPolicy',
82     options => {
83         interface => 'intranet',
84     },
85 });
86 $record_processor->process($record);
87
88 if ( not defined $record ) {
89        # biblionumber invalid -> report and exit
90        $template->param( unknownbiblionumber => 1,
91                                 biblionumber => $biblionumber
92        );
93        output_html_with_http_headers $query, $cookie, $template->output;
94        exit;
95 }
96
97 my $framework = GetFrameworkCode( $biblionumber );
98 my $res = GetISBDView({
99     'record'    => $record,
100     'template'  => 'intranet',
101     'framework' => $framework,
102 });
103
104 if($query->cookie("holdfor")){ 
105     my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
106     $template->param(
107         holdfor => $query->cookie("holdfor"),
108         holdfor_surname => $holdfor_patron->{'surname'},
109         holdfor_firstname => $holdfor_patron->{'firstname'},
110         holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
111     );
112 }
113
114 # count of item linked with biblio
115 my $itemcount = GetItemsCount($biblionumber);
116 $template->param( count => $itemcount);
117 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
118  
119 if ($subscriptionsnumber) {
120     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
121     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
122     $template->param(
123         subscriptionsnumber => $subscriptionsnumber,
124         subscriptiontitle   => $subscriptiontitle,
125     );
126 }
127
128 $template->param (
129     ISBD                => $res,
130     biblionumber        => $biblionumber,
131     isbdview            => 1,
132     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
133     ocoins => GetCOinSBiblio($record),
134     C4::Search::enabled_staff_search_views,
135     searchid            => scalar $query->param('searchid'),
136 );
137
138 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
139 my @deletedorders_using_biblio;
140 my @orders_using_biblio;
141 my @baskets_orders;
142 my @baskets_deletedorders;
143
144 foreach my $myorder (@allorders_using_biblio) {
145     my $basket = $myorder->{'basketno'};
146     if ((defined $myorder->{'datecancellationprinted'}) and  ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
147         push @deletedorders_using_biblio, $myorder;
148         unless (grep(/^$basket$/, @baskets_deletedorders)){
149             push @baskets_deletedorders,$myorder->{'basketno'};
150         }
151     }
152     else {
153         push @orders_using_biblio, $myorder;
154         unless (grep(/^$basket$/, @baskets_orders)){
155             push @baskets_orders,$myorder->{'basketno'};
156             }
157     }
158 }
159
160 my $count_orders_using_biblio = scalar @orders_using_biblio ;
161 $template->param (countorders => $count_orders_using_biblio);
162
163 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
164 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
165
166 my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
167 my $holdcount = scalar( @$holds );
168 $template->param( holdcount => scalar ( @$holds ) );
169
170 output_html_with_http_headers $query, $cookie, $template->output;
171