Bug 6554 - make Koha internally utf-8 clean
[koha.git] / reserve / renewscript.pl
1 #!/usr/bin/perl
2
3 #written 18/1/2000 by chris@katipo.co.nz
4 #script to renew items from the web
5
6 # Copyright 2000-2002 Katipo Communications
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 use strict;
23 use warnings;
24 use CGI;
25 use C4::Circulation;
26 use C4::Context;
27 use C4::Items;
28 use C4::Auth;
29 use URI::Escape;
30 use Koha::DateUtils;
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 }
63 else {
64     @barcodes = $input->param('barcodes[]');
65 }
66
67 my $branch = $input->param('branch');
68 my $datedue;
69 if ( $input->param('newduedate') ) {
70     $datedue = dt_from_string( $input->param('newduedate') );
71     $datedue->set_hour(23);
72     $datedue->set_minute(59);
73 }
74
75 # warn "barcodes : @barcodes";
76 #
77 # renew items
78 #
79 my $cardnumber     = $input->param("cardnumber");
80 my $borrowernumber = $input->param("borrowernumber");
81 my $exemptfine     = $input->param("exemptfine") || 0;
82 my $override_limit = $input->param("override_limit") || 0;
83 my $failedrenews   = q{};
84 foreach my $itemno (@data) {
85
86     # check status before renewing issue
87     my ( $renewokay, $error ) =
88       CanBookBeRenewed( $borrowernumber, $itemno, $override_limit );
89     if ($renewokay) {
90         AddRenewal( $borrowernumber, $itemno, $branch, $datedue );
91     }
92     else {
93         $failedrenews .= "&failedrenew=$itemno";
94     }
95 }
96 my $failedreturn = q{};
97 foreach my $barcode (@barcodes) {
98
99     # check status before renewing issue
100
101     #System Preference Handling During Check-in In Patron Module
102     my $itemnumber;
103     $itemnumber = GetItemnumberFromBarcode($barcode);
104     if ($itemnumber) {
105         if ( C4::Context->preference("InProcessingToShelvingCart") ) {
106             my $item = GetItem($itemnumber);
107             if ( $item->{'location'} eq 'PROC' ) {
108                 $item->{'location'} = 'CART';
109                 ModItem( $item, $item->{'biblionumber'},
110                     $item->{'itemnumber'} );
111             }
112         }
113
114         if ( C4::Context->preference("ReturnToShelvingCart") ) {
115             my $item = GetItem($itemnumber);
116             $item->{'location'} = 'CART';
117             ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
118         }
119     }
120
121     my ( $returned, $messages, $issueinformation, $borrower ) =
122       AddReturn( $barcode, $branch, $exemptfine );
123     $failedreturn .= "&failedreturn=$barcode" unless ($returned);
124 }
125
126 #
127 # redirection to the referrer page
128 #
129 if ( $input->param('destination') eq "circ" ) {
130     $cardnumber = uri_escape_utf8($cardnumber);
131     print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?findborrower='
132           . $cardnumber
133           . $failedrenews
134           . $failedreturn );
135 }
136 else {
137     print $input->redirect(
138             '/cgi-bin/koha/members/moremember.pl?borrowernumber='
139           . $borrowernumber
140           . $failedrenews
141           . $failedreturn );
142 }