Bug 36792: Limit POSIX imports
[koha.git] / opac / opac-renew.pl
1 #!/usr/bin/perl
2
3 #written 18/1/2000 by chris@katipo.co.nz
4 # adapted for use in the hlt opac by finlay@katipo.co.nz 29/11/2002
5 # script to renew items from the web
6 # Parts Copyright 2010,2011 Catalyst IT
7
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23
24 use Modern::Perl;
25
26 use CGI qw ( -utf8 );
27 use C4::Circulation qw( CanBookBeRenewed AddRenewal );
28 use C4::Auth qw( get_template_and_user );
29 use C4::Context;
30 use C4::Members;
31 use Koha::Items;
32 use Koha::Patrons;
33 my $query = CGI->new;
34
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36         {
37         template_name   => "opac-user.tt",
38         query           => $query,
39         type            => "opac",
40         }
41 );
42 my @issues = $query->multi_param('issue');
43
44 my $opacrenew = C4::Context->preference("OpacRenewalAllowed");
45
46 my $errorstring = q{};
47 my $renewed     = q{};
48
49 my $patron = Koha::Patrons->find( $borrowernumber );
50
51 if (   $patron->category->effective_BlockExpiredPatronOpacActions
52     && $patron->is_expired )
53 {
54     $errorstring = 'card_expired';
55 }
56 else {
57     my @renewed;
58     my $issues = Koha::Checkouts->search(
59         {
60             issue_id => { -in => \@issues }
61         }, {
62             prefetch => 'item'
63         }
64     );
65     while( my $issue = $issues->next) {
66         my ( $status, $error ) =
67           CanBookBeRenewed( $patron, $issue );
68         if ( $status == 1 && $opacrenew == 1 ) {
69             AddRenewal( $borrowernumber, $issue->itemnumber, undef, undef, undef, undef, 0 );
70             push( @renewed, $issue->itemnumber );
71         }
72         else {
73             $errorstring .= $error . "|";
74         }
75     }
76     $renewed = join( ':', @renewed );
77 }
78
79 print $query->redirect("/cgi-bin/koha/opac-user.pl?renew_error=$errorstring&renewed=$renewed");
80