Bug 23536: Remove obsolete category markup from patron entry
[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::Serials;    # CountSubscriptionFromBiblionumber
47 use C4::Search;         # enabled_staff_search_views
48 use C4::Acquisition qw(GetOrdersByBiblionumber);
49
50 use Koha::Biblios;
51 use Koha::Patrons;
52 use Koha::RecordProcessor;
53
54
55 my $query = new CGI;
56 my $dbh = C4::Context->dbh;
57
58 my $biblionumber = $query->param('biblionumber');
59 $biblionumber = HTML::Entities::encode($biblionumber);
60
61 # open template
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63     {
64         template_name => "catalogue/ISBDdetail.tt",
65         query         => $query,
66         type          => "intranet",
67         authnotrequired => 0,
68         flagsrequired   => { catalogue => 1 },
69     }
70 );
71
72 if ( not defined $biblionumber ) {
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 my $record = GetMarcBiblio({
82     biblionumber => $biblionumber,
83     embed_items  => 1 });
84
85 if ( not defined $record ) {
86        # biblionumber invalid -> report and exit
87        $template->param( unknownbiblionumber => 1,
88                                 biblionumber => $biblionumber
89        );
90        output_html_with_http_headers $query, $cookie, $template->output;
91        exit;
92 }
93
94 my $biblio = Koha::Biblios->find( $biblionumber );
95 my $framework = GetFrameworkCode( $biblionumber );
96 my $record_processor = Koha::RecordProcessor->new({
97     filters => 'ViewPolicy',
98     options => {
99         interface => 'intranet',
100         frameworkcode => $framework
101     },
102 });
103 $record_processor->process($record);
104
105 my $res = GetISBDView({
106     'record'    => $record,
107     'template'  => 'intranet',
108     'framework' => $framework,
109 });
110
111 if($query->cookie("holdfor")){ 
112     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
113     $template->param(
114         holdfor => $query->cookie("holdfor"),
115         holdfor_surname => $holdfor_patron->surname,
116         holdfor_firstname => $holdfor_patron->firstname,
117         holdfor_cardnumber => $holdfor_patron->cardnumber,
118     );
119 }
120
121 if( $query->cookie("searchToOrder") ){
122     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
123     $template->param(
124         searchtoorder_basketno => $basketno,
125         searchtoorder_vendorid => $vendorid
126     );
127 }
128
129 # count of item linked with biblio
130 my $itemcount = $biblio->items->count;
131 $template->param( count => $itemcount);
132 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
133  
134 if ($subscriptionsnumber) {
135     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
136     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
137     $template->param(
138         subscriptionsnumber => $subscriptionsnumber,
139         subscriptiontitle   => $subscriptiontitle,
140     );
141 }
142
143 $template->param (
144     ISBD                => $res,
145     biblionumber        => $biblionumber,
146     isbdview            => 1,
147     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
148     ocoins => $biblio->get_coins,
149     C4::Search::enabled_staff_search_views,
150     searchid            => scalar $query->param('searchid'),
151     biblio              => $biblio,
152 );
153
154 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
155 my @deletedorders_using_biblio;
156 my @orders_using_biblio;
157 my @baskets_orders;
158 my @baskets_deletedorders;
159
160 foreach my $myorder (@allorders_using_biblio) {
161     my $basket = $myorder->{'basketno'};
162     if ((defined $myorder->{'datecancellationprinted'}) and  ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
163         push @deletedorders_using_biblio, $myorder;
164         unless (grep{ $_ eq $basket } @baskets_deletedorders){
165             push @baskets_deletedorders,$myorder->{'basketno'};
166         }
167     }
168     else {
169         push @orders_using_biblio, $myorder;
170         unless (grep{ $_ eq $basket } @baskets_orders){
171             push @baskets_orders,$myorder->{'basketno'};
172             }
173     }
174 }
175
176 my $count_orders_using_biblio = scalar @orders_using_biblio ;
177 $template->param (countorders => $count_orders_using_biblio);
178
179 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
180 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
181
182 my $holds = $biblio->holds;
183 $template->param( holdcount => $holds->count );
184
185 output_html_with_http_headers $query, $cookie, $template->output;
186