Bug 25642: Fix description of new feature in update_dbix_class_files.pl
[koha.git] / reserve / placerequest.pl
blob0b4a12c20624afec773afa968a504bb416b4f3e3
1 #!/usr/bin/perl
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>.
24 use Modern::Perl;
26 use CGI qw ( -utf8 );
27 use C4::Biblio;
28 use C4::Items;
29 use C4::Output;
30 use C4::Reserves;
31 use C4::Circulation;
32 use C4::Members;
33 use C4::Auth qw/checkauth/;
35 use Koha::Items;
36 use Koha::Patrons;
38 my $input = CGI->new();
40 checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
42 my @bibitems = $input->multi_param('biblioitem');
43 my @reqbib = $input->multi_param('reqbib');
44 my $biblionumber = $input->param('biblionumber');
45 my $borrowernumber = $input->param('borrowernumber');
46 my $notes = $input->param('notes');
47 my $branch = $input->param('pickup');
48 my $startdate = $input->param('reserve_date') || '';
49 my @rank = $input->multi_param('rank-request');
50 my $type = $input->param('type');
51 my $title = $input->param('title');
52 my $checkitem = $input->param('checkitem');
53 my $expirationdate = $input->param('expiration_date');
54 my $itemtype = $input->param('itemtype') || undef;
56 my $borrower = Koha::Patrons->find( $borrowernumber );
57 $borrower = $borrower->unblessed if $borrower;
59 my $biblionumbers = $input->param('biblionumbers');
60 $biblionumbers ||= $biblionumber . '/';
62 my $bad_bibs = $input->param('bad_bibs');
63 my $holds_to_place_count = $input->param('holds_to_place_count') || 1;
65 my %bibinfos = ();
66 my @biblionumbers = split '/', $biblionumbers;
67 foreach my $bibnum (@biblionumbers) {
68 my %bibinfo = ();
69 $bibinfo{title} = $input->param("title_$bibnum");
70 $bibinfo{rank} = $input->param("rank_$bibnum");
71 $bibinfos{$bibnum} = \%bibinfo;
74 my $found;
76 if ( $type eq 'str8' && $borrower ) {
78 foreach my $biblionumber ( keys %bibinfos ) {
79 my $count = @bibitems;
80 @bibitems = sort @bibitems;
81 my $i2 = 1;
82 my @realbi;
83 $realbi[0] = $bibitems[0];
84 for ( my $i = 1 ; $i < $count ; $i++ ) {
85 my $i3 = $i2 - 1;
86 if ( $realbi[$i3] ne $bibitems[$i] ) {
87 $realbi[$i2] = $bibitems[$i];
88 $i2++;
92 my $can_override = C4::Context->preference('AllowHoldPolicyOverride');
93 if ( defined $checkitem && $checkitem ne '' ) {
95 my $item = Koha::Items->find($checkitem);
97 if ( $item->biblionumber ne $biblionumber ) {
98 $biblionumber = $item->biblionumber;
101 my $can_item_be_reserved = CanItemBeReserved($borrower->{'borrowernumber'}, $item->itemnumber, $branch)->{status};
103 if ( $can_item_be_reserved eq 'OK' || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) ) {
104 AddReserve(
106 branchcode => $branch,
107 borrowernumber => $borrower->{'borrowernumber'},
108 biblionumber => $biblionumber,
109 priority => $rank[0],
110 reservation_date => $startdate,
111 expiration_date => $expirationdate,
112 notes => $notes,
113 title => $title,
114 itemnumber => $checkitem,
115 found => $found,
116 itemtype => $itemtype,
122 } elsif (@biblionumbers > 1) {
123 my $bibinfo = $bibinfos{$biblionumber};
124 if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) {
125 AddReserve(
127 branchcode => $branch,
128 borrowernumber => $borrower->{'borrowernumber'},
129 biblionumber => $biblionumber,
130 priority => $bibinfo->{rank},
131 reservation_date => $startdate,
132 expiration_date => $expirationdate,
133 notes => $notes,
134 title => $bibinfo->{title},
135 itemnumber => $checkitem,
136 found => $found,
137 itemtype => $itemtype,
141 } else {
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' ) {
145 AddReserve(
147 branchcode => $branch,
148 borrowernumber => $borrower->{'borrowernumber'},
149 biblionumber => $biblionumber,
150 priority => $rank[0],
151 reservation_date => $startdate,
152 expiration_date => $expirationdate,
153 notes => $notes,
154 title => $title,
155 itemnumber => $checkitem,
156 found => $found,
157 itemtype => $itemtype,
165 if ($bad_bibs) {
166 $biblionumbers .= $bad_bibs;
168 print $input->redirect("request.pl?biblionumbers=$biblionumbers");
170 elsif ( $borrowernumber eq '' ) {
171 print $input->header();
172 print "Invalid borrower number please try again";
174 # Not sure that Dump() does HTML escaping. Use firebug or something to trace
175 # instead.
176 #print $input->Dump;