Bug 30860: Cache CanItemBeReserved return value
[koha.git] / reserve / modrequest.pl
1 #!/usr/bin/perl
2
3 #script to modify reserves/requests
4 #written 2/1/00 by chris@katipo.oc.nz
5 #last update 27/1/2000 by chris@katipo.co.nz
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
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24
25 use Modern::Perl;
26 use CGI qw ( -utf8 );
27 use URI;
28 use List::MoreUtils qw( uniq );
29 use Try::Tiny;
30
31 use C4::Output;
32 use C4::Reserves qw( ModReserve ModReserveCancelAll );
33 use C4::Auth qw( checkauth );
34 use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
35
36 my $query = CGI->new;
37
38 checkauth($query, 0, { reserveforothers => '*' }, 'intranet');
39
40 my @reserve_id = $query->multi_param('reserve_id');
41 my @rank = $query->multi_param('rank-request');
42 my @borrower = $query->multi_param('borrowernumber');
43 my @reservedates = $query->multi_param('reservedate');
44 my @expirationdates = $query->multi_param('expirationdate');
45 my @branch = $query->multi_param('pickup');
46 my @itemnumber = $query->multi_param('itemnumber');
47 my @biblionumber = $query->multi_param('biblionumber');
48 my $count=@rank;
49
50 @biblionumber = uniq @biblionumber;
51
52 my $CancelBiblioNumber = $query->param('CancelBiblioNumber');
53 my $CancelBorrowerNumber = $query->param('CancelBorrowerNumber');
54 my $CancelItemnumber = $query->param('CancelItemnumber');
55
56 # 2 possibilitys : cancel an item reservation, or modify or cancel the queded list
57
58 # 1) cancel an item reservation by function ModReserveCancelAll (in reserves.pm)
59 if ($CancelBorrowerNumber) {
60     ModReserveCancelAll($CancelItemnumber, $CancelBorrowerNumber);
61     $biblionumber[0] = $CancelBiblioNumber,
62 }
63
64 # 2) Cancel or modify the queue list of reserves (without item linked)
65 else {
66     for (my $i=0;$i<$count;$i++){
67         undef $itemnumber[$i] if !$itemnumber[$i];
68         my $suspend_until = $query->param( "suspend_until_" . $reserve_id[$i] );
69         my $cancellation_reason = $query->param("cancellation-reason");
70         my $params = {
71             rank => $rank[$i],
72             reserve_id => $reserve_id[$i],
73             expirationdate => $expirationdates[$i] || undef,
74             branchcode => $branch[$i],
75             itemnumber => $itemnumber[$i],
76             defined $suspend_until ? ( suspend_until => $suspend_until ) : (),
77             cancellation_reason => $cancellation_reason,
78         };
79         if (C4::Context->preference('AllowHoldDateInFuture')) {
80             $params->{reservedate} = $reservedates[$i] || undef;
81         }
82
83         try {
84             ModReserve($params);
85         } catch {
86             if ($_->isa('Koha::Exceptions::ObjectNotFound')){
87                 warn $_;
88             } else {
89                 $_->rethrow;
90             }
91         }
92     }
93     my @biblio_ids = uniq @biblionumber;
94     Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
95         {
96             biblio_ids => \@biblio_ids
97         }
98     );
99 }
100
101 my $from=$query->param('from');
102 $from ||= q{};
103 if ( $from eq 'borrower'){
104     print $query->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrower[0]");
105 } elsif ( $from eq 'circ'){
106     print $query->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrower[0]");
107 } else {
108      my $url = URI->new("/cgi-bin/koha/reserve/request.pl");
109      $url->query_form( biblionumber => [@biblionumber]);
110      print $query->redirect($url);
111 }