Adding feature : multiple returns via moremember page.
[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
29 my $input = new CGI;
30
31 #Set Up User_env
32 # And assures user is loggedin  and has correct accreditations.
33
34 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35     {
36         template_name   => "members/moremember.tmpl",
37         query           => $input,
38         type            => "intranet",
39         authnotrequired => 0,
40         flagsrequired   => { borrowers => 1 },
41         debug           => 1,
42     }
43 );
44
45 #
46 # find items to renew, all items or a selection of items
47 #
48
49 my @data;
50 if ($input->param('renew_all')) {
51     @data = $input->param('all_items[]');
52 }
53 else {
54     @data = $input->param('items[]');
55 }
56 my @barcodes = $input->param('barcodes[]');
57 my $branch=$input->param('branch');
58
59 # warn "barcodes : @barcodes";
60 #
61 # renew items
62 #
63 my $cardnumber = $input->param("cardnumber");
64 my $borrowernumber = $input->param("borrowernumber");
65 my $failedrenews;
66 foreach my $itemno (@data) {
67     # check status before renewing issue
68     if (CanBookBeRenewed($borrowernumber,$itemno)){
69         AddRenewal($borrowernumber,$itemno,$branch);
70     }
71         else {
72                 $failedrenews.="&failedrenew=$itemno";        
73         }
74 }
75 my $failedreturn;
76 foreach my $barcode (@barcodes) {
77     # check status before renewing issue  
78    my ( $returned, $messages, $issueinformation, $borrower ) = 
79     AddReturn($barcode,$branch,1);
80    $failedreturn.="&failedreturn=$barcode" unless ($returned);
81 }
82
83 #
84 # redirection to the referrer page
85 #
86 if ($input->param('destination') eq "circ"){
87     print $input->redirect(
88         '/cgi-bin/koha/circ/circulation.pl?findborrower='.$cardnumber.$failedrenews.$failedreturn
89     );
90 }
91 else {
92     print $input->redirect(
93         '/cgi-bin/koha/members/moremember.pl?borrowernumber='.$borrowernumber.$failedrenews.$failedreturn
94     );
95 }