Bug 14004: Add ability to temporarily disable JS/CSS sysprefs
[koha.git] / circ / renew.pl
1 #!/usr/bin/perl
2
3 # Copyright 2013 ByWater Solutions
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use CGI qw ( -utf8 );
23 use C4::Context;
24 use C4::Auth qw/:DEFAULT get_session/;
25 use C4::Output;
26 use C4::Circulation;
27 use C4::Koha;
28 use Koha::DateUtils;
29 use Koha::Database;
30 use Koha::BiblioFrameworks;
31
32 my $cgi = new CGI;
33
34 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
35     {
36         template_name   => "circ/renew.tt",
37         query           => $cgi,
38         type            => "intranet",
39         flagsrequired   => { circulate => "circulate_remaining_permissions" },
40     }
41 );
42
43 my $schema = Koha::Database->new()->schema();
44
45 my $barcode        = $cgi->param('barcode');
46 $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespae
47 $barcode = barcodedecode($barcode) if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
48 my $override_limit = $cgi->param('override_limit');
49 my $override_holds = $cgi->param('override_holds');
50
51 my ( $item, $issue, $borrower );
52 my $error = q{};
53 my ( $soonest_renew_date, $latest_auto_renew_date );
54
55 if ($barcode) {
56     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
57     $item = $schema->resultset("Item")->single( { barcode => $barcode } );
58
59     if ($item) {
60
61         $issue = $item->issue();
62
63         if ($issue) {
64
65             $borrower = $issue->borrower();
66             
67             if ( ( $borrower->debarred() || q{} ) lt dt_from_string()->ymd() ) {
68                 my $can_renew;
69                 ( $can_renew, $error ) =
70                   CanBookBeRenewed( $borrower->borrowernumber(),
71                     $item->itemnumber(), $override_limit );
72
73                 if ( $error && ($error eq 'on_reserve') ) {
74                     if ($override_holds) {
75                         $can_renew = 1;
76                         $error     = undef;
77                     }
78                     else {
79                         $can_renew = 0;
80                     }
81                 }
82
83                 if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
84                     $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
85                         $borrower->borrowernumber(),
86                         $item->itemnumber(),
87                     );
88                 }
89                 if ( $error && ( $error eq 'auto_too_late' ) ) {
90                     $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
91                         $borrower->borrowernumber(),
92                         $item->itemnumber(),
93                     );
94                 }
95                 if ($can_renew) {
96                     my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
97                     my $date_due;
98                     if ( $cgi->param('renewonholdduedate') ) {
99                         $date_due = dt_from_string( scalar $cgi->param('renewonholdduedate'));
100                     }
101                     $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode, $date_due );
102                     $template->param( date_due => $date_due );
103                 }
104             }
105             else {
106                 $error = "patron_restricted";
107             }
108         }
109         else {
110             $error = "no_checkout";
111         }
112     }
113     else {
114         $error = "no_item";
115     }
116
117     $template->param(
118         item     => $item,
119         issue    => $issue,
120         borrower => $borrower,
121         error    => $error,
122         soonestrenewdate => $soonest_renew_date,
123         latestautorenewdate => $latest_auto_renew_date,
124     );
125 }
126
127 # Checking if there is a Fast Cataloging Framework
128 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
129
130 output_html_with_http_headers( $cgi, $cookie, $template->output );