Bug 15638: spelling mistake in ~/Koha/reserve/placerequest.pl:4
[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 strict;
25 use warnings;
26
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
36 my $input = CGI->new();
37
38 checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
39
40 my @bibitems=$input->param('biblioitem');
41 my @reqbib=$input->param('reqbib'); 
42 my $biblionumber=$input->param('biblionumber');
43 my $borrowernumber=$input->param('borrowernumber');
44 my $notes=$input->param('notes');
45 my $branch=$input->param('pickup');
46 my $startdate=$input->param('reserve_date') || '';
47 my @rank=$input->param('rank-request');
48 my $type=$input->param('type');
49 my $title=$input->param('title');
50 my $borrower=GetMember('borrowernumber'=>$borrowernumber);
51 my $checkitem=$input->param('checkitem');
52 my $expirationdate = $input->param('expiration_date');
53
54 my $multi_hold = $input->param('multi_hold');
55 my $biblionumbers = $multi_hold ? $input->param('biblionumbers') : ($biblionumber . '/');
56 my $bad_bibs = $input->param('bad_bibs');
57
58 my %bibinfos = ();
59 my @biblionumbers = split '/', $biblionumbers;
60 foreach my $bibnum (@biblionumbers) {
61     my %bibinfo = ();
62     $bibinfo{title} = $input->param("title_$bibnum");
63     $bibinfo{rank} = $input->param("rank_$bibnum");
64     $bibinfos{$bibnum} = \%bibinfo;
65 }
66
67 my $found;
68
69 # if we have an item selectionned, and the pickup branch is the same as the holdingbranch
70 # of the document, we force the value $rank and $found .
71 if (defined $checkitem && $checkitem ne ''){
72     $rank[0] = '0' unless C4::Context->preference('ReservesNeedReturns');
73     my $item = $checkitem;
74     $item = GetItem($item);
75     if ( $item->{'holdingbranch'} eq $branch ){
76         $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
77     }
78 }
79
80 if ($type eq 'str8' && $borrower){
81
82     foreach my $biblionumber (keys %bibinfos) {
83         my $count=@bibitems;
84         @bibitems=sort @bibitems;
85         my $i2=1;
86         my @realbi;
87         $realbi[0]=$bibitems[0];
88         for (my $i=1;$i<$count;$i++) {
89             my $i3=$i2-1;
90             if ($realbi[$i3] ne $bibitems[$i]) {
91                 $realbi[$i2]=$bibitems[$i];
92                 $i2++;
93             }
94         }
95
96     if (defined $checkitem && $checkitem ne ''){
97                 my $item = GetItem($checkitem);
98                 if ($item->{'biblionumber'} ne $biblionumber) {
99                         $biblionumber = $item->{'biblionumber'};
100                 }
101         }
102
103
104
105         if ($multi_hold) {
106             my $bibinfo = $bibinfos{$biblionumber};
107             AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,[$biblionumber],
108                        $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
109         } else {
110             # place a request on 1st available
111             AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem,$found);
112         }
113     }
114
115     if ($multi_hold) {
116         if ($bad_bibs) {
117             $biblionumbers .= $bad_bibs;
118         }
119         print $input->redirect("request.pl?biblionumbers=$biblionumbers&multi_hold=1");
120     } else {
121         print $input->redirect("request.pl?biblionumber=$biblionumber");
122     }
123 } elsif ($borrower eq ''){
124         print $input->header();
125         print "Invalid borrower number please try again";
126 # Not sure that Dump() does HTML escaping. Use firebug or something to trace
127 # instead.
128 #       print $input->Dump;
129 }