Bug 11629: (follow-up) Add message for librarian that status was updated
[koha.git] / reserve / placerequest.pl
1 #!/usr/bin/perl
2
3 #script to place reserves/requests
4 #writen 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 under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 use strict;
25 use warnings;
26
27 use CGI;
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 # FIXME I think reqbib does not exist anymore, it's used in line 82, to AddReserve of contraint type 'o'
42 #       I bet it's a 2.x feature, reserving a given biblioitem, that is useless in Koha 3.0
43 #       we can remove this line, the AddReserve of constrainttype 'o',
44 #       and probably remove the reserveconstraint table as well, I never could fill anything in this table.
45 my @reqbib=$input->param('reqbib'); 
46 my $biblionumber=$input->param('biblionumber');
47 my $borrowernumber=$input->param('borrowernumber');
48 my $notes=$input->param('notes');
49 my $branch=$input->param('pickup');
50 my $startdate=$input->param('reserve_date') || '';
51 my @rank=$input->param('rank-request');
52 my $type=$input->param('type');
53 my $title=$input->param('title');
54 my $borrower=GetMember('borrowernumber'=>$borrowernumber);
55 my $checkitem=$input->param('checkitem');
56 my $expirationdate = $input->param('expiration_date');
57
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
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 we have an item selectionned, and the pickup branch is the same as the holdingbranch
74 # of the document, we force the value $rank and $found .
75 if ($checkitem ne ''){
76     $rank[0] = '0' unless C4::Context->preference('ReservesNeedReturns');
77     my $item = $checkitem;
78     $item = GetItem($item);
79     if ( $item->{'holdingbranch'} eq $branch ){
80         $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
81     }
82 }
83
84 if ($type eq 'str8' && $borrower){
85
86     foreach my $biblionumber (keys %bibinfos) {
87         my $count=@bibitems;
88         @bibitems=sort @bibitems;
89         my $i2=1;
90         my @realbi;
91         $realbi[0]=$bibitems[0];
92         for (my $i=1;$i<$count;$i++) {
93             my $i3=$i2-1;
94             if ($realbi[$i3] ne $bibitems[$i]) {
95                 $realbi[$i2]=$bibitems[$i];
96                 $i2++;
97             }
98         }
99         my $const;
100
101         if ($checkitem ne ''){
102                 my $item = GetItem($checkitem);
103                 if ($item->{'biblionumber'} ne $biblionumber) {
104                         $biblionumber = $item->{'biblionumber'};
105                 }
106         }
107
108
109
110         if ($multi_hold) {
111             my $bibinfo = $bibinfos{$biblionumber};
112             AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',[$biblionumber],
113                        $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
114         } else {
115             if ($input->param('request') eq 'any'){
116                 # place a request on 1st available
117                 AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem,$found);
118             } elsif ($reqbib[0] ne ''){
119                 # FIXME : elsif probably never reached, (see top of the script)
120                 # place a request on a given item
121                 AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'o',\@reqbib,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
122             } else {
123                 AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
124             }
125         }
126     }
127
128     if ($multi_hold) {
129         if ($bad_bibs) {
130             $biblionumbers .= $bad_bibs;
131         }
132         print $input->redirect("request.pl?biblionumbers=$biblionumbers&multi_hold=1");
133     } else {
134         print $input->redirect("request.pl?biblionumber=$biblionumber");
135     }
136 } elsif ($borrower eq ''){
137         print $input->header();
138         print "Invalid borrower number please try again";
139 # Not sure that Dump() does HTML escaping. Use firebug or something to trace
140 # instead.
141 #       print $input->Dump;
142 }