Bug 22104: Clean up patron API keys template
[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 Modern::Perl;
25
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/;
34 use Koha::Patrons;
35
36 my $input = CGI->new();
37
38 checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
39
40 my @bibitems       = $input->multi_param('biblioitem');
41 my @reqbib         = $input->multi_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->multi_param('rank-request');
48 my $type           = $input->param('type');
49 my $title          = $input->param('title');
50 my $checkitem      = $input->param('checkitem');
51 my $expirationdate = $input->param('expiration_date');
52 my $itemtype       = $input->param('itemtype') || undef;
53
54 my $borrower = Koha::Patrons->find( $borrowernumber );
55 $borrower = $borrower->unblessed if $borrower;
56
57 my $multi_hold = $input->param('multi_hold');
58 my $biblionumbers = $multi_hold ? $input->param('biblionumbers') : ($biblionumber . '/');
59 my $bad_bibs = $input->param('bad_bibs');
60 my $holds_to_place_count = $input->param('holds_to_place_count') || 1;
61
62 my %bibinfos = ();
63 my @biblionumbers = split '/', $biblionumbers;
64 foreach my $bibnum (@biblionumbers) {
65     my %bibinfo = ();
66     $bibinfo{title} = $input->param("title_$bibnum");
67     $bibinfo{rank} = $input->param("rank_$bibnum");
68     $bibinfos{$bibnum} = \%bibinfo;
69 }
70
71 my $found;
72
73 if ( $type eq 'str8' && $borrower ) {
74
75     foreach my $biblionumber ( keys %bibinfos ) {
76         my $count = @bibitems;
77         @bibitems = sort @bibitems;
78         my $i2 = 1;
79         my @realbi;
80         $realbi[0] = $bibitems[0];
81         for ( my $i = 1 ; $i < $count ; $i++ ) {
82             my $i3 = $i2 - 1;
83             if ( $realbi[$i3] ne $bibitems[$i] ) {
84                 $realbi[$i2] = $bibitems[$i];
85                 $i2++;
86             }
87         }
88
89         if ( defined $checkitem && $checkitem ne '' ) {
90             my $item = GetItem($checkitem);
91             if ( $item->{'biblionumber'} ne $biblionumber ) {
92                 $biblionumber = $item->{'biblionumber'};
93             }
94         }
95
96         if ($multi_hold) {
97             my $bibinfo = $bibinfos{$biblionumber};
98             AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,[$biblionumber],
99                        $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
100         } else {
101             # place a request on 1st available
102             for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
103                 AddReserve( $branch, $borrower->{'borrowernumber'},
104                     $biblionumber, \@realbi, $rank[0], $startdate, $expirationdate, $notes, $title,
105                     $checkitem, $found, $itemtype );
106             }
107         }
108     }
109
110     if ($multi_hold) {
111         if ($bad_bibs) {
112             $biblionumbers .= $bad_bibs;
113         }
114         print $input->redirect("request.pl?biblionumbers=$biblionumbers&multi_hold=1");
115     }
116     else {
117         print $input->redirect("request.pl?biblionumber=$biblionumber");
118     }
119 }
120 elsif ( $borrowernumber eq '' ) {
121     print $input->header();
122     print "Invalid borrower number please try again";
123
124     # Not sure that Dump() does HTML escaping. Use firebug or something to trace
125     # instead.
126     #print $input->Dump;
127 }