Bug 11592: Updated License Text and use Modern::Perl
[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 strict;
25 use warnings;
26
27 use CGI qw ( -utf8 );
28 use C4::Circulation;
29 use C4::Auth;
30 use C4::Context;
31 use C4::Items;
32 use C4::Members;
33 use Date::Calc qw( Today Date_to_Days );
34 my $query = new CGI;
35
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37         {
38         template_name   => "opac-user.tt",
39         query           => $query,
40         type            => "opac",
41         authnotrequired => 0,
42         debug           => 1,
43         }
44 ); 
45 my @items = $query->multi_param('item');
46
47 my $opacrenew = C4::Context->preference("OpacRenewalAllowed");
48
49 my $errorstring = q{};
50 my $renewed     = q{};
51
52 my $member_details = GetMemberDetails($borrowernumber);
53
54 if (   $member_details->{'BlockExpiredPatronOpacActions'}
55     && $member_details->{'is_expired'} )
56 {
57     $errorstring = 'card_expired';
58 }
59 else {
60     my @renewed;
61     for my $itemnumber (@items) {
62         my ( $status, $error ) =
63           CanBookBeRenewed( $borrowernumber, $itemnumber );
64         if ( $status == 1 && $opacrenew == 1 ) {
65             my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
66             my $branchcode;
67             if ( $renewalbranch eq 'itemhomebranch' ) {
68                 my $item = GetItem($itemnumber);
69                 $branchcode = $item->{'homebranch'};
70             }
71             elsif ( $renewalbranch eq 'patronhomebranch' ) {
72                 my $borrower = GetMemberDetails($borrowernumber);
73                 $branchcode = $borrower->{'branchcode'};
74             }
75             elsif ( $renewalbranch eq 'checkoutbranch' ) {
76                 my $issue = GetOpenIssue($itemnumber);
77                 $branchcode = $issue->{'branchcode'};
78             }
79             elsif ( $renewalbranch eq 'NULL' ) {
80                 $branchcode = '';
81             }
82             else {
83                 $branchcode = 'OPACRenew';
84             }
85             AddRenewal( $borrowernumber, $itemnumber, $branchcode );
86             push( @renewed, $itemnumber );
87         }
88         else {
89             $errorstring .= $error . "|";
90         }
91     }
92     $renewed = join( ':', @renewed );
93 }
94
95 print $query->redirect("/cgi-bin/koha/opac-user.pl?renew_error=$errorstring&renewed=$renewed");
96