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