Merge remote-tracking branch 'kc/new/enh/bug_5922' into kcmaster
[koha.git] / reserve / renewscript.pl
1 #!/usr/bin/perl
2
3
4 #written 18/1/2000 by chris@katipo.co.nz
5 #script to renew items from the web
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use strict;
25 use warnings;
26 use CGI;
27 use C4::Circulation;
28 use C4::Auth;
29 use URI::Escape;
30 use C4::Dates qw/format_date_in_iso/;
31 my $input = new CGI;
32
33 #Set Up User_env
34 # And assures user is loggedin  and has correct accreditations.
35
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37     {
38         template_name   => "members/moremember.tmpl",
39         query           => $input,
40         type            => "intranet",
41         authnotrequired => 0,
42         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
43         debug           => 0,
44     }
45 );
46
47 #
48 # find items to renew, all items or a selection of items
49 #
50
51 my @data;
52 if ($input->param('renew_all')) {
53     @data = $input->param('all_items[]');
54 }
55 else {
56     @data = $input->param('items[]');
57 }
58
59 my @barcodes;
60 if ($input->param('return_all')) {
61     @barcodes = $input->param('all_barcodes[]');
62 } else {
63     @barcodes = $input->param('barcodes[]');
64 }
65
66 my $branch=$input->param('branch');
67 my $datedue;
68 if ($input->param('newduedate')){
69     $datedue=C4::Dates->new($input->param('newduedate'));
70 }
71
72 # warn "barcodes : @barcodes";
73 #
74 # renew items
75 #
76 my $cardnumber = $input->param("cardnumber");
77 my $borrowernumber = $input->param("borrowernumber");
78 my $exemptfine = $input->param("exemptfine") || 0;
79 my $override_limit = $input->param("override_limit") || 0;
80 my $failedrenews = q{};
81 foreach my $itemno (@data) {
82     # check status before renewing issue
83         my ($renewokay,$error) = CanBookBeRenewed($borrowernumber,$itemno,$override_limit);
84     if ($renewokay){
85         AddRenewal($borrowernumber,$itemno,$branch,$datedue);
86     }
87         else {
88                 $failedrenews.="&failedrenew=$itemno";        
89         }
90 }
91 my $failedreturn = q{};
92 foreach my $barcode (@barcodes) {
93     # check status before renewing issue
94    my ( $returned, $messages, $issueinformation, $borrower ) = 
95     AddReturn($barcode, $branch, $exemptfine);
96    $failedreturn.="&failedreturn=$barcode" unless ($returned);
97 }
98
99 #
100 # redirection to the referrer page
101 #
102 if ($input->param('destination') eq "circ"){
103     $cardnumber = uri_escape($cardnumber);
104     print $input->redirect(
105         '/cgi-bin/koha/circ/circulation.pl?findborrower='.$cardnumber.$failedrenews.$failedreturn
106     );
107 }
108 else {
109     print $input->redirect(
110         '/cgi-bin/koha/members/moremember.pl?borrowernumber='.$borrowernumber.$failedrenews.$failedreturn
111     );
112 }