Bug 27668: Improve validation of patron entry form in the OPAC
[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
49 use Koha::Biblios;
50 use Koha::Patrons;
51 use Koha::RecordProcessor;
52 use Koha::Virtualshelves;
53
54
55 my $query = CGI->new;
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         flagsrequired   => { catalogue => 1 },
68     }
69 );
70
71 if ( not defined $biblionumber ) {
72        # biblionumber invalid -> report and exit
73        $template->param( unknownbiblionumber => 1,
74                                 biblionumber => $biblionumber
75        );
76        output_html_with_http_headers $query, $cookie, $template->output;
77        exit;
78 }
79
80 my $record = GetMarcBiblio({
81     biblionumber => $biblionumber,
82     embed_items  => 1 });
83
84 if ( not defined $record ) {
85        # biblionumber invalid -> report and exit
86        $template->param( unknownbiblionumber => 1,
87                                 biblionumber => $biblionumber
88        );
89        output_html_with_http_headers $query, $cookie, $template->output;
90        exit;
91 }
92
93 my $biblio = Koha::Biblios->find( $biblionumber );
94 my $framework = GetFrameworkCode( $biblionumber );
95 my $record_processor = Koha::RecordProcessor->new({
96     filters => 'ViewPolicy',
97     options => {
98         interface => 'intranet',
99         frameworkcode => $framework
100     },
101 });
102 $record_processor->process($record);
103
104 my $res = GetISBDView({
105     'record'    => $record,
106     'template'  => 'intranet',
107     'framework' => $framework,
108 });
109
110 if($query->cookie("holdfor")){ 
111     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
112     $template->param(
113         holdfor => $query->cookie("holdfor"),
114         holdfor_surname => $holdfor_patron->surname,
115         holdfor_firstname => $holdfor_patron->firstname,
116         holdfor_cardnumber => $holdfor_patron->cardnumber,
117     );
118 }
119
120 if( $query->cookie("searchToOrder") ){
121     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
122     $template->param(
123         searchtoorder_basketno => $basketno,
124         searchtoorder_vendorid => $vendorid
125     );
126 }
127
128 # count of item linked with biblio
129 my $itemcount = $biblio->items->count;
130 $template->param( count => $itemcount);
131 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
132  
133 if ($subscriptionsnumber) {
134     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
135     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
136     $template->param(
137         subscriptionsnumber => $subscriptionsnumber,
138         subscriptiontitle   => $subscriptiontitle,
139     );
140 }
141
142 # get biblionumbers stored in the cart
143 my @cart_list;
144
145 if($query->cookie("intranet_bib_list")){
146     my $cart_list = $query->cookie("intranet_bib_list");
147     @cart_list = split(/\//, $cart_list);
148     if ( grep {$_ eq $biblionumber} @cart_list) {
149         $template->param( incart => 1 );
150     }
151 }
152
153 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
154     {
155         borrowernumber => $loggedinuser,
156         add_allowed    => 1,
157         category       => 1,
158     }
159 );
160 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
161     {
162         borrowernumber => $loggedinuser,
163         add_allowed    => 1,
164         category       => 2,
165     }
166 );
167
168
169 $template->param(
170     add_to_some_private_shelves => $some_private_shelves,
171     add_to_some_public_shelves  => $some_public_shelves,
172 );
173
174 $template->param (
175     ISBD                => $res,
176     biblionumber        => $biblionumber,
177     isbdview            => 1,
178     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
179     ocoins => $biblio->get_coins,
180     C4::Search::enabled_staff_search_views,
181     searchid            => scalar $query->param('searchid'),
182     biblio              => $biblio,
183 );
184
185 my $holds = $biblio->holds;
186 $template->param( holdcount => $holds->count );
187
188 output_html_with_http_headers $query, $cookie, $template->output;
189