Bug 10527: remove disused routine C4::Branch::get_branch_code_from_name
[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::Context;
29 use C4::Items;
30 use C4::Auth;
31 use URI::Escape;
32 use Koha::DateUtils;
33 my $input = new CGI;
34
35 #Set Up User_env
36 # And assures user is loggedin  and has correct accreditations.
37
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39     {
40         template_name   => "members/moremember.tmpl",
41         query           => $input,
42         type            => "intranet",
43         authnotrequired => 0,
44         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
45         debug           => 0,
46     }
47 );
48
49 #
50 # find items to renew, all items or a selection of items
51 #
52
53 my @data;
54 if ($input->param('renew_all')) {
55     @data = $input->param('all_items[]');
56 }
57 else {
58     @data = $input->param('items[]');
59 }
60
61 my @barcodes;
62 if ($input->param('return_all')) {
63     @barcodes = $input->param('all_barcodes[]');
64 } else {
65     @barcodes = $input->param('barcodes[]');
66 }
67
68 my $branch=$input->param('branch');
69 my $datedue;
70 if ( $input->param('newduedate') ) {
71     $datedue = dt_from_string( $input->param('newduedate') );
72     $datedue->set_hour(23);
73     $datedue->set_minute(59);
74 }
75
76 # warn "barcodes : @barcodes";
77 #
78 # renew items
79 #
80 my $cardnumber = $input->param("cardnumber");
81 my $borrowernumber = $input->param("borrowernumber");
82 my $exemptfine = $input->param("exemptfine") || 0;
83 my $override_limit = $input->param("override_limit") || 0;
84 my $failedrenews = q{};
85 foreach my $itemno (@data) {
86     # check status before renewing issue
87         my ($renewokay,$error) = CanBookBeRenewed($borrowernumber,$itemno,$override_limit);
88     if ($renewokay){
89         AddRenewal($borrowernumber,$itemno,$branch,$datedue);
90     }
91         else {
92                 $failedrenews.="&failedrenew=$itemno";        
93         }
94 }
95 my $failedreturn = q{};
96 foreach my $barcode (@barcodes) {
97     # check status before renewing issue
98
99     #System Preference Handling During Check-in In Patron Module
100     my $itemnumber;
101     $itemnumber = GetItemnumberFromBarcode($barcode);
102     if ($itemnumber) {
103         if ( C4::Context->preference("InProcessingToShelvingCart") ) {
104             my $item = GetItem( $itemnumber );
105             if ( $item->{'location'} eq 'PROC' ) {
106                 $item->{'location'} = 'CART';
107                 ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
108             }
109         }
110
111         if ( C4::Context->preference("ReturnToShelvingCart") ) {
112             my $item = GetItem( $itemnumber );
113             $item->{'location'} = 'CART';
114             ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
115         }
116     }
117
118    my ( $returned, $messages, $issueinformation, $borrower ) = 
119     AddReturn($barcode, $branch, $exemptfine);
120    $failedreturn.="&failedreturn=$barcode" unless ($returned);
121 }
122
123 #
124 # redirection to the referrer page
125 #
126 if ($input->param('destination') eq "circ"){
127     $cardnumber = uri_escape($cardnumber);
128     print $input->redirect(
129         '/cgi-bin/koha/circ/circulation.pl?findborrower='.$cardnumber.$failedrenews.$failedreturn
130     );
131 }
132 else {
133     print $input->redirect(
134         '/cgi-bin/koha/members/moremember.pl?borrowernumber='.$borrowernumber.$failedrenews.$failedreturn
135     );
136 }