Bug 29660: Unused code in placerequest.pl
[koha.git] / reserve / placerequest.pl
1 #!/usr/bin/perl
2
3 #script to place reserves/requests
4 #written 2/1/00 by chris@katipo.oc.nz
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
15 #
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23
24 use Modern::Perl;
25
26 use CGI qw ( -utf8 );
27 use C4::Reserves qw( CanItemBeReserved AddReserve CanBookBeReserved );
28 use C4::Auth qw( checkauth );
29
30 use Koha::Items;
31 use Koha::Patrons;
32
33 my $input = CGI->new();
34
35 checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
36
37 my @reqbib         = $input->multi_param('reqbib');
38 my $biblionumber   = $input->param('biblionumber');
39 my $borrowernumber = $input->param('borrowernumber');
40 my $notes          = $input->param('notes');
41 my $branch         = $input->param('pickup');
42 my $startdate      = $input->param('reserve_date') || '';
43 my @rank           = $input->multi_param('rank-request');
44 my $type           = $input->param('type');
45 my $title          = $input->param('title');
46 my $checkitem      = $input->param('checkitem');
47 my $expirationdate = $input->param('expiration_date');
48 my $itemtype       = $input->param('itemtype') || undef;
49 my $non_priority   = $input->param('non_priority');
50
51 my $patron = Koha::Patrons->find( $borrowernumber );
52
53 my $biblionumbers = $input->param('biblionumbers');
54 $biblionumbers ||= $biblionumber . '/';
55
56 my $bad_bibs = $input->param('bad_bibs');
57 my $holds_to_place_count = $input->param('holds_to_place_count') || 1;
58
59 my %bibinfos = ();
60 my @biblionumbers = split '/', $biblionumbers;
61 foreach my $bibnum (@biblionumbers) {
62     my %bibinfo = ();
63     $bibinfo{title}  = $input->param("title_$bibnum");
64     $bibinfo{rank}   = $input->param("rank_$bibnum");
65     $bibinfo{pickup} = $input->param("pickup_$bibnum");
66     $bibinfos{$bibnum} = \%bibinfo;
67 }
68
69 my $found;
70
71 if ( $type eq 'str8' && $patron ) {
72
73     foreach my $biblionumber ( keys %bibinfos ) {
74
75         my $can_override = C4::Context->preference('AllowHoldPolicyOverride');
76         if ( defined $checkitem && $checkitem ne '' ) {
77
78             my $item_pickup_location = $input->param("item_pickup_$checkitem");
79
80             my $item = Koha::Items->find($checkitem);
81
82             if ( $item->biblionumber ne $biblionumber ) {
83                 $biblionumber = $item->biblionumber;
84             }
85
86             my $can_item_be_reserved = CanItemBeReserved($patron, $item, $item_pickup_location)->{status};
87
88             if ( $can_item_be_reserved eq 'OK' || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) ) {
89                 AddReserve(
90                     {
91                         branchcode       => $item_pickup_location,
92                         borrowernumber   => $patron->borrowernumber,
93                         biblionumber     => $biblionumber,
94                         priority         => $rank[0],
95                         reservation_date => $startdate,
96                         expiration_date  => $expirationdate,
97                         notes            => $notes,
98                         title            => $title,
99                         itemnumber       => $checkitem,
100                         found            => $found,
101                         itemtype         => $itemtype,
102                         non_priority     => $non_priority,
103                     }
104                 );
105
106             }
107
108         } elsif (@biblionumbers > 1) {
109             my $bibinfo = $bibinfos{$biblionumber};
110             if ( $can_override || CanBookBeReserved($patron->borrowernumber, $biblionumber)->{status} eq 'OK' ) {
111                 AddReserve(
112                     {
113                         branchcode       => $bibinfo->{pickup},
114                         borrowernumber   => $patron->borrowernumber,
115                         biblionumber     => $biblionumber,
116                         priority         => $bibinfo->{rank},
117                         reservation_date => $startdate,
118                         expiration_date  => $expirationdate,
119                         notes            => $notes,
120                         title            => $bibinfo->{title},
121                         itemnumber       => $checkitem,
122                         found            => $found,
123                         itemtype         => $itemtype,
124                         non_priority     => $non_priority,
125                     }
126                 );
127             }
128         } else {
129             # place a request on 1st available
130             for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
131                 if ( $can_override || CanBookBeReserved($patron->borrowernumber, $biblionumber)->{status} eq 'OK' ) {
132                     AddReserve(
133                         {
134                             branchcode       => $branch,
135                             borrowernumber   => $patron->borrowernumber,
136                             biblionumber     => $biblionumber,
137                             priority         => $rank[0],
138                             reservation_date => $startdate,
139                             expiration_date  => $expirationdate,
140                             notes            => $notes,
141                             title            => $title,
142                             itemnumber       => $checkitem,
143                             found            => $found,
144                             itemtype         => $itemtype,
145                             non_priority     => $non_priority,
146                         }
147                     );
148                 }
149             }
150         }
151     }
152
153     if ($bad_bibs) {
154         $biblionumbers .= $bad_bibs;
155     }
156     print $input->redirect("request.pl?biblionumbers=$biblionumbers");
157 }
158 elsif ( $borrowernumber eq '' ) {
159     print $input->header();
160     print "Invalid borrower number please try again";
161
162     # Not sure that Dump() does HTML escaping. Use firebug or something to trace
163     # instead.
164     #print $input->Dump;
165 }