3 #script to place reserves/requests
4 #written 2/1/00 by chris@katipo.oc.nz
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
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.
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.
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>.
27 use C4::Reserves qw( CanItemBeReserved AddReserve CanBookBeReserved );
28 use C4::Auth qw( checkauth );
33 my $input = CGI->new();
35 checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
37 my @bibitems = $input->multi_param('biblioitem');
38 my @reqbib = $input->multi_param('reqbib');
39 my @holdable_bibs = $input->multi_param('holdable_bibs');
40 my $biblionumber = $input->param('biblionumber');
41 my $borrowernumber = $input->param('borrowernumber');
42 my $notes = $input->param('notes');
43 my $branch = $input->param('pickup');
44 my $startdate = $input->param('reserve_date') || '';
45 my @rank = $input->multi_param('rank-request');
46 my $title = $input->param('title');
47 my $checkitem = $input->param('checkitem');
48 my $expirationdate = $input->param('expiration_date');
49 my $itemtype = $input->param('itemtype') || undef;
50 my $non_priority = $input->param('non_priority');
52 my $borrower = Koha::Patrons->find( $borrowernumber );
53 $borrower = $borrower->unblessed if $borrower;
55 my $biblionumbers = $input->param('biblionumbers');
56 $biblionumbers ||= $biblionumber . '/';
58 my $holds_to_place_count = $input->param('holds_to_place_count') || 1;
61 my @biblionumbers = split '/', $biblionumbers;
62 foreach my $bibnum (@biblionumbers) {
64 $bibinfo{title} = $input->param("title_$bibnum");
65 $bibinfo{rank} = $input->param("rank_$bibnum");
66 $bibinfo{pickup} = $input->param("pickup_$bibnum");
67 $bibinfos{$bibnum} = \%bibinfo;
74 foreach my $biblionumber ( keys %bibinfos ) {
75 my $count = @bibitems;
76 @bibitems = sort @bibitems;
79 $realbi[0] = $bibitems[0];
80 for ( my $i = 1 ; $i < $count ; $i++ ) {
82 if ( $realbi[$i3] ne $bibitems[$i] ) {
83 $realbi[$i2] = $bibitems[$i];
88 my $can_override = C4::Context->preference('AllowHoldPolicyOverride');
89 if ( defined $checkitem && $checkitem ne '' ) {
91 my $item_pickup_location = $input->param("item_pickup_$checkitem");
93 my $item = Koha::Items->find($checkitem);
95 if ( $item->biblionumber ne $biblionumber ) {
96 $biblionumber = $item->biblionumber;
99 my $can_item_be_reserved = CanItemBeReserved($borrower->{'borrowernumber'}, $item->itemnumber, $item_pickup_location)->{status};
101 if ( $can_item_be_reserved eq 'OK' || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) ) {
104 branchcode => $item_pickup_location,
105 borrowernumber => $borrower->{'borrowernumber'},
106 biblionumber => $biblionumber,
107 priority => $rank[0],
108 reservation_date => $startdate,
109 expiration_date => $expirationdate,
112 itemnumber => $checkitem,
114 itemtype => $itemtype,
115 non_priority => $non_priority,
121 } elsif (@biblionumbers > 1) {
122 my $bibinfo = $bibinfos{$biblionumber};
123 if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) {
126 branchcode => $bibinfo->{pickup},
127 borrowernumber => $borrower->{'borrowernumber'},
128 biblionumber => $biblionumber,
129 priority => $bibinfo->{rank},
130 reservation_date => $startdate,
131 expiration_date => $expirationdate,
133 title => $bibinfo->{title},
134 itemnumber => $checkitem,
136 itemtype => $itemtype,
137 non_priority => $non_priority,
142 # place a request on 1st available
143 for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
144 if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) {
147 branchcode => $branch,
148 borrowernumber => $borrower->{'borrowernumber'},
149 biblionumber => $biblionumber,
150 priority => $rank[0],
151 reservation_date => $startdate,
152 expiration_date => $expirationdate,
155 itemnumber => $checkitem,
157 itemtype => $itemtype,
158 non_priority => $non_priority,
166 print $input->redirect("request.pl?biblionumbers=$biblionumbers");
168 elsif ( $borrowernumber eq '' ) {
169 print $input->header();
170 print "Invalid borrower number please try again";
172 # Not sure that Dump() does HTML escaping. Use firebug or something to trace