Fix for renewals not working at circulation
[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 with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use CGI;
26 use C4::Circulation;
27 use C4::Auth;
28 use C4::Dates qw/format_date_in_iso/;
29 use strict;
30 my $input = new CGI;
31
32 #Set Up User_env
33 # And assures user is loggedin  and has correct accreditations.
34
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36     {
37         template_name   => "members/moremember.tmpl",
38         query           => $input,
39         type            => "intranet",
40         authnotrequired => 0,
41         flagsrequired   => { borrowers => 1 },
42         debug           => 1,
43     }
44 );
45
46 #
47 # find items to renew, all items or a selection of items
48 #
49
50 my @data;
51 if ($input->param('renew_all')) {
52     @data = $input->param('all_items[]');
53 }
54 else {
55     @data = $input->param('items[]');
56 }
57 my @barcodes = $input->param('barcodes[]');
58 my $branch=$input->param('branch');
59 my $datedue;
60 if ($input->param('newduedate')){
61     $datedue=C4::Dates->new($input->param('newduedate'));
62 }
63
64 # warn "barcodes : @barcodes";
65 #
66 # renew items
67 #
68 my $cardnumber = $input->param("cardnumber");
69 my $borrowernumber = $input->param("borrowernumber");
70 my $failedrenews;
71 foreach my $itemno (@data) {
72     # check status before renewing issue
73         my ($renewokay,$error) = CanBookBeRenewed($borrowernumber,$itemno);
74     if ($renewokay){
75         AddRenewal($borrowernumber,$itemno,$branch,$datedue);
76     }
77         else {
78                 $failedrenews.="&failedrenew=$itemno";        
79         }
80 }
81 my $failedreturn;
82 foreach my $barcode (@barcodes) {
83     # check status before renewing issue  
84    my ( $returned, $messages, $issueinformation, $borrower ) = 
85     AddReturn($barcode,$branch,1);
86    $failedreturn.="&failedreturn=$barcode" unless ($returned);
87 }
88
89 #
90 # redirection to the referrer page
91 #
92 if ($input->param('destination') eq "circ"){
93     print $input->redirect(
94         '/cgi-bin/koha/circ/circulation.pl?findborrower='.$cardnumber.$failedrenews.$failedreturn
95     );
96 }
97 else {
98     print $input->redirect(
99         '/cgi-bin/koha/members/moremember.pl?borrowernumber='.$borrowernumber.$failedrenews.$failedreturn
100     );
101 }