Bug 12443 - Initial re-factoring of buildQuery
[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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
43 use C4::Koha;
44 use C4::Biblio;
45 use C4::Items;
46 use C4::Members; # to use GetMember
47 use C4::Branch;     # GetBranchDetail
48 use C4::Serials;    # CountSubscriptionFromBiblionumber
49 use C4::Search;         # enabled_staff_search_views
50 use C4::Acquisition qw(GetOrdersByBiblionumber);
51
52
53 #---- Internal function
54
55
56 my $query = new CGI;
57 my $dbh = C4::Context->dbh;
58
59 my $biblionumber = $query->param('biblionumber');
60
61 # open template
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63     {
64         template_name => "catalogue/ISBDdetail.tmpl",
65         query         => $query,
66         type          => "intranet",
67         authnotrequired => 0,
68         flagsrequired   => { catalogue => 1 },
69     }
70 );
71
72 my $res = GetISBDView($biblionumber, "intranet");
73 if ( not defined $res ) {
74        # biblionumber invalid -> report and exit
75        $template->param( unknownbiblionumber => 1,
76                                biblionumber => $biblionumber
77        );
78        output_html_with_http_headers $query, $cookie, $template->output;
79        exit;
80 }
81
82 if($query->cookie("holdfor")){ 
83     my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
84     $template->param(
85         holdfor => $query->cookie("holdfor"),
86         holdfor_surname => $holdfor_patron->{'surname'},
87         holdfor_firstname => $holdfor_patron->{'firstname'},
88         holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
89     );
90 }
91
92 # count of item linked with biblio
93 my $itemcount = GetItemsCount($biblionumber);
94 $template->param( count => $itemcount);
95 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
96  
97 if ($subscriptionsnumber) {
98     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
99     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
100     $template->param(
101         subscriptionsnumber => $subscriptionsnumber,
102         subscriptiontitle   => $subscriptiontitle,
103     );
104 }
105 my $record = GetMarcBiblio($biblionumber);
106
107 $template->param (
108     ISBD                => $res,
109     biblionumber        => $biblionumber,
110     isbdview            => 1,
111     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
112     ocoins => GetCOinSBiblio($record),
113     C4::Search::enabled_staff_search_views,
114     searchid            => $query->param('searchid'),
115 );
116
117 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
118 my @deletedorders_using_biblio;
119 my @orders_using_biblio;
120 my @baskets_orders;
121 my @baskets_deletedorders;
122
123 foreach my $myorder (@allorders_using_biblio) {
124     my $basket = $myorder->{'basketno'};
125     if ((defined $myorder->{'datecancellationprinted'}) and  ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
126         push @deletedorders_using_biblio, $myorder;
127         unless (grep(/^$basket$/, @baskets_deletedorders)){
128             push @baskets_deletedorders,$myorder->{'basketno'};
129         }
130     }
131     else {
132         push @orders_using_biblio, $myorder;
133         unless (grep(/^$basket$/, @baskets_orders)){
134             push @baskets_orders,$myorder->{'basketno'};
135             }
136     }
137 }
138
139 my $count_orders_using_biblio = scalar @orders_using_biblio ;
140 $template->param (countorders => $count_orders_using_biblio);
141
142 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
143 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
144
145 my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
146 my $holdcount = scalar( @$holds );
147 $template->param( holdcount => scalar ( @$holds ) );
148
149 output_html_with_http_headers $query, $cookie, $template->output;
150