Bug 11629: (follow-up) Add message for librarian that status was updated
[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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23
24 use strict;
25 use warnings;
26
27 use CGI;
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.tmpl",
39                   query           => $query,
40                   type            => "opac",
41                   authnotrequired => 0,
42                   flagsrequired   => { borrow => 1 },
43                   debug           => 1,
44         }
45 ); 
46 my @items          = $query->param('item');
47
48 my $opacrenew = C4::Context->preference("OpacRenewalAllowed");
49
50 my $errorstring='';
51 my $member_details = GetMemberDetails($borrowernumber);
52
53 if (   $member_details->{'BlockExpiredPatronOpacActions'}
54     && $member_details->{'is_expired'} )
55 {
56     $errorstring = 'card_expired';
57 }
58 else {
59     for my $itemnumber (@items) {
60         my ( $status, $error ) =
61           CanBookBeRenewed( $borrowernumber, $itemnumber );
62         if ( $status == 1 && $opacrenew == 1 ) {
63             my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
64             my $branchcode;
65             if ( $renewalbranch eq 'itemhomebranch' ) {
66                 my $item = GetItem($itemnumber);
67                 $branchcode = $item->{'homebranch'};
68             }
69             elsif ( $renewalbranch eq 'patronhomebranch' ) {
70                 my $borrower = GetMemberDetails($borrowernumber);
71                 $branchcode = $borrower->{'branchcode'};
72             }
73             elsif ( $renewalbranch eq 'checkoutbranch' ) {
74                 my $issue = GetOpenIssue($itemnumber);
75                 $branchcode = $issue->{'branchcode'};
76             }
77             elsif ( $renewalbranch eq 'NULL' ) {
78                 $branchcode = '';
79             }
80             else {
81                 $branchcode = 'OPACRenew';
82             }
83             AddRenewal( $borrowernumber, $itemnumber, $branchcode );
84         }
85         else {
86             $errorstring .= $error . "|";
87         }
88     }
89 }
90
91 print $query->redirect("/cgi-bin/koha/opac-user.pl?renew_error=$errorstring");
92