Bug 6739: make it possible to block expired patrons from OPAC actions
[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::Items;
31 use C4::Members;
32 use Date::Calc qw( Today Date_to_Days );
33 my $query = new CGI;
34
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36         {
37                   template_name   => "opac-user.tmpl",
38                   query           => $query,
39                   type            => "opac",
40                   authnotrequired => 0,
41                   flagsrequired   => { borrow => 1 },
42                   debug           => 1,
43         }
44 ); 
45 my @items          = $query->param('item');
46
47 my $opacrenew = C4::Context->preference("OpacRenewalAllowed");
48
49 my $errorstring='';
50 my $member_details = GetMemberDetails($borrowernumber);
51 # BlockExpiredPatronOpacActions syspref 0 is false, 1 is true. BlockExpiredPatronOpacActions for categories (from GetMemberDetails) -1 means use syspref, 0 is false, 1 is true (where false means dont block, true means block)
52 if( ($member_details->{'BlockExpiredPatronOpacActions'} == -1 ? C4::Conext->preference('BlockExpiredPatronOpacActions') : $member_details->{'BlockExpiredPatronOpacActions'})
53     && Date_to_Days( Today() ) > Date_to_Days( split /-/, $member_details->{'dateexpiry'} ) ){
54    $errorstring='unable to renew as your card has expired';
55 } else {
56     for my $itemnumber ( @items ) {
57         my ($status,$error) = CanBookBeRenewed( $borrowernumber, $itemnumber );
58         if ( $status == 1 && $opacrenew == 1 ) {
59             my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
60             my $branchcode;
61             if ($renewalbranch eq 'itemhomebranch'){
62                 my $item = GetItem($itemnumber);
63                 $branchcode=$item->{'homebranch'};
64             }
65             elsif ($renewalbranch eq 'patronhomebranch'){
66                 my $borrower = GetMemberDetails($borrowernumber);
67                 $branchcode = $borrower->{'branchcode'};
68             }
69             elsif ($renewalbranch eq 'checkoutbranch'){
70                 my $issue = GetOpenIssue($itemnumber);
71                 $branchcode = $issue->{'branchcode'};
72             }
73             elsif ($renewalbranch eq 'NULL'){
74                 $branchcode='';
75             }
76             else {
77                 $branchcode='OPACRenew'
78             }
79             AddRenewal( $borrowernumber, $itemnumber, $branchcode);
80         }
81         else {
82             $errorstring .= $error ."|";
83         }
84     }
85 }
86
87 print $query->redirect("/cgi-bin/koha/opac-user.pl?renew_error=$errorstring");
88