Bug 16154: CGI->multi_param - Force scalar context
[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 strict;
37 #use warnings; FIXME - Bug 2505
38
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
51
52 #---- Internal function
53
54
55 my $query = new CGI;
56 my $dbh = C4::Context->dbh;
57
58 my $biblionumber = $query->param('biblionumber');
59
60 # open template
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62     {
63         template_name => "catalogue/ISBDdetail.tt",
64         query         => $query,
65         type          => "intranet",
66         authnotrequired => 0,
67         flagsrequired   => { catalogue => 1 },
68     }
69 );
70
71 my $res = GetISBDView($biblionumber, "intranet");
72 if ( not defined $res ) {
73        # biblionumber invalid -> report and exit
74        $template->param( unknownbiblionumber => 1,
75                                biblionumber => $biblionumber
76        );
77        output_html_with_http_headers $query, $cookie, $template->output;
78        exit;
79 }
80
81 if($query->cookie("holdfor")){ 
82     my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
83     $template->param(
84         holdfor => $query->cookie("holdfor"),
85         holdfor_surname => $holdfor_patron->{'surname'},
86         holdfor_firstname => $holdfor_patron->{'firstname'},
87         holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
88     );
89 }
90
91 # count of item linked with biblio
92 my $itemcount = GetItemsCount($biblionumber);
93 $template->param( count => $itemcount);
94 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
95  
96 if ($subscriptionsnumber) {
97     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
98     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
99     $template->param(
100         subscriptionsnumber => $subscriptionsnumber,
101         subscriptiontitle   => $subscriptiontitle,
102     );
103 }
104 my $record = GetMarcBiblio($biblionumber);
105
106 $template->param (
107     ISBD                => $res,
108     biblionumber        => $biblionumber,
109     isbdview            => 1,
110     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
111     ocoins => GetCOinSBiblio($record),
112     C4::Search::enabled_staff_search_views,
113     searchid            => scalar $query->param('searchid'),
114 );
115
116 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
117 my @deletedorders_using_biblio;
118 my @orders_using_biblio;
119 my @baskets_orders;
120 my @baskets_deletedorders;
121
122 foreach my $myorder (@allorders_using_biblio) {
123     my $basket = $myorder->{'basketno'};
124     if ((defined $myorder->{'datecancellationprinted'}) and  ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
125         push @deletedorders_using_biblio, $myorder;
126         unless (grep(/^$basket$/, @baskets_deletedorders)){
127             push @baskets_deletedorders,$myorder->{'basketno'};
128         }
129     }
130     else {
131         push @orders_using_biblio, $myorder;
132         unless (grep(/^$basket$/, @baskets_orders)){
133             push @baskets_orders,$myorder->{'basketno'};
134             }
135     }
136 }
137
138 my $count_orders_using_biblio = scalar @orders_using_biblio ;
139 $template->param (countorders => $count_orders_using_biblio);
140
141 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
142 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
143
144 my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
145 my $holdcount = scalar( @$holds );
146 $template->param( holdcount => scalar ( @$holds ) );
147
148 output_html_with_http_headers $query, $cookie, $template->output;
149