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>.
28 use C4::Reserves qw( CanItemBeReserved AddReserve CanBookBeReserved );
29 use C4::Auth qw( checkauth );
34 my $input = CGI->new();
36 checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
38 my @reqbib = $input->multi_param('reqbib');
39 my @biblionumbers = $input->multi_param('biblionumber');
40 my @holdable_bibs = $input->multi_param('holdable_bibs');
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 $item_group_id = $input->param('item_group_id');
49 my $expirationdate = $input->param('expiration_date');
50 my $itemtype = $input->param('itemtype') || undef;
51 my $non_priority = $input->param('non_priority');
52 my $op = $input->param('op') || q{};
54 my $patron = Koha::Patrons->find( $borrowernumber );
56 my $holds_to_place_count = $input->param('holds_to_place_count') || 1;
59 foreach my $bibnum ( @holdable_bibs ) {
61 $bibinfo{title} = $input->param("title_$bibnum");
62 $bibinfo{rank} = $input->param("rank_$bibnum");
63 $bibinfo{pickup} = $input->param("pickup_$bibnum");
64 $bibinfos{$bibnum} = \%bibinfo;
69 if ( $op eq 'cud-placerequest' && $patron ) {
71 foreach my $biblionumber ( keys %bibinfos ) {
73 my $can_override = C4::Context->preference('AllowHoldPolicyOverride');
74 if ( defined $checkitem && $checkitem ne '' ) {
76 if ( my $item_pickup_location = $input->param("item_pickup_$checkitem") ) {
78 my $item = Koha::Items->find($checkitem);
80 if ( $item->biblionumber ne $biblionumber ) {
81 $biblionumber = $item->biblionumber;
84 my $can_item_be_reserved = CanItemBeReserved($patron, $item, $item_pickup_location)->{status};
86 if ( $can_item_be_reserved eq 'OK' || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) ) {
89 branchcode => $item_pickup_location,
90 borrowernumber => $patron->borrowernumber,
91 biblionumber => $biblionumber,
93 reservation_date => $startdate,
94 expiration_date => $expirationdate,
97 itemnumber => $checkitem,
99 itemtype => $itemtype,
100 non_priority => $non_priority,
107 } elsif (@biblionumbers > 1) {
108 my $bibinfo = $bibinfos{$biblionumber};
109 if ( $can_override || CanBookBeReserved($patron->borrowernumber, $biblionumber)->{status} eq 'OK' ) {
112 branchcode => $bibinfo->{pickup},
113 borrowernumber => $patron->borrowernumber,
114 biblionumber => $biblionumber,
115 priority => $bibinfo->{rank},
116 reservation_date => $startdate,
117 expiration_date => $expirationdate,
119 title => $bibinfo->{title},
120 itemnumber => $checkitem,
122 itemtype => $itemtype,
123 non_priority => $non_priority,
128 # place a request on 1st available
129 for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
130 if ( $can_override || CanBookBeReserved($patron->borrowernumber, $biblionumber)->{status} eq 'OK' ) {
133 branchcode => $branch,
134 borrowernumber => $patron->borrowernumber,
135 biblionumber => $biblionumber,
136 priority => $rank[0],
137 reservation_date => $startdate,
138 expiration_date => $expirationdate,
141 itemnumber => $checkitem,
143 itemtype => $itemtype,
144 non_priority => $non_priority,
145 item_group_id => $item_group_id,
153 my $redirect_url = URI->new("request.pl");
154 $redirect_url->query_form( biblionumber => [@biblionumbers]);
155 print $input->redirect($redirect_url);
157 elsif ( $borrowernumber eq '' ) {
158 print $input->header();
159 print "Invalid borrower number please try again";
161 # Not sure that Dump() does HTML escaping. Use firebug or something to trace