Bug 7143: Update about page for new dev - Victor Grousset
[koha.git] / reserve / placerequest.pl
blob403321c818407aadd19901cc8c92b4f11bdaa0e7
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 strict;
25 use warnings;
27 use CGI qw ( -utf8 );
28 use C4::Biblio;
29 use C4::Items;
30 use C4::Output;
31 use C4::Reserves;
32 use C4::Circulation;
33 use C4::Members;
34 use C4::Auth qw/checkauth/;
35 use Koha::Patrons;
37 my $input = CGI->new();
39 checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
41 my @bibitems = $input->multi_param('biblioitem');
42 my @reqbib = $input->multi_param('reqbib');
43 my $biblionumber = $input->param('biblionumber');
44 my $borrowernumber = $input->param('borrowernumber');
45 my $notes = $input->param('notes');
46 my $branch = $input->param('pickup');
47 my $startdate = $input->param('reserve_date') || '';
48 my @rank = $input->multi_param('rank-request');
49 my $type = $input->param('type');
50 my $title = $input->param('title');
51 my $checkitem = $input->param('checkitem');
52 my $expirationdate = $input->param('expiration_date');
53 my $itemtype = $input->param('itemtype') || undef;
55 my $borrower = Koha::Patrons->find( $borrowernumber );
56 $borrower = $borrower->unblessed if $borrower;
58 my $multi_hold = $input->param('multi_hold');
59 my $biblionumbers = $multi_hold ? $input->param('biblionumbers') : ($biblionumber . '/');
60 my $bad_bibs = $input->param('bad_bibs');
61 my $holds_to_place_count = $input->param('holds_to_place_count') || 1;
63 my %bibinfos = ();
64 my @biblionumbers = split '/', $biblionumbers;
65 foreach my $bibnum (@biblionumbers) {
66 my %bibinfo = ();
67 $bibinfo{title} = $input->param("title_$bibnum");
68 $bibinfo{rank} = $input->param("rank_$bibnum");
69 $bibinfos{$bibnum} = \%bibinfo;
72 my $found;
74 # if we have an item selectionned, and the pickup branch is the same as the holdingbranch
75 # of the document, we force the value $rank and $found .
76 if (defined $checkitem && $checkitem ne ''){
77 $holds_to_place_count = 1;
78 $rank[0] = '0' unless C4::Context->preference('ReservesNeedReturns');
79 my $item = $checkitem;
80 $item = GetItem($item);
81 if ( $item->{'holdingbranch'} eq $branch ){
82 $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
86 if ( $type eq 'str8' && $borrower ) {
88 foreach my $biblionumber ( keys %bibinfos ) {
89 my $count = @bibitems;
90 @bibitems = sort @bibitems;
91 my $i2 = 1;
92 my @realbi;
93 $realbi[0] = $bibitems[0];
94 for ( my $i = 1 ; $i < $count ; $i++ ) {
95 my $i3 = $i2 - 1;
96 if ( $realbi[$i3] ne $bibitems[$i] ) {
97 $realbi[$i2] = $bibitems[$i];
98 $i2++;
102 if ( defined $checkitem && $checkitem ne '' ) {
103 my $item = GetItem($checkitem);
104 if ( $item->{'biblionumber'} ne $biblionumber ) {
105 $biblionumber = $item->{'biblionumber'};
109 if ($multi_hold) {
110 my $bibinfo = $bibinfos{$biblionumber};
111 AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,[$biblionumber],
112 $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
113 } else {
114 # place a request on 1st available
115 for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
116 AddReserve( $branch, $borrower->{'borrowernumber'},
117 $biblionumber, \@realbi, $rank[0], $startdate, $expirationdate, $notes, $title,
118 $checkitem, $found, $itemtype );
123 if ($multi_hold) {
124 if ($bad_bibs) {
125 $biblionumbers .= $bad_bibs;
127 print $input->redirect("request.pl?biblionumbers=$biblionumbers&multi_hold=1");
129 else {
130 print $input->redirect("request.pl?biblionumber=$biblionumber");
133 elsif ( $borrowernumber eq '' ) {
134 print $input->header();
135 print "Invalid borrower number please try again";
137 # Not sure that Dump() does HTML escaping. Use firebug or something to trace
138 # instead.
139 #print $input->Dump;