bug 1909: add delete field/subfield button to MARC editor
[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 with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use C4::Biblio;
26 use C4::Items;
27 use CGI;
28 use C4::Output;
29 use C4::Reserves;
30 use C4::Circulation;
31 use C4::Members;
32
33 my $input = new CGI;
34 #print $input->header;
35
36 my @bibitems=$input->param('biblioitem');
37 # FIXME I think reqbib does not exist anymore, it's used in line 82, to AddReserve of contraint type 'o'
38 #       I bet it's a 2.x feature, reserving a given biblioitem, that is useless in Koha 3.0
39 #       we can remove this line, the AddReserve of constrainttype 'o',
40 #       and probably remove the reserveconstraint table as well, I never could fill anything in this table.
41 my @reqbib=$input->param('reqbib'); 
42 my $biblionumber=$input->param('biblionumber');
43 my $borrower=$input->param('member');
44 my $notes=$input->param('notes');
45 my $branch=$input->param('pickup');
46 my @rank=$input->param('rank-request');
47 my $type=$input->param('type');
48 my $title=$input->param('title');
49 my $borrowernumber=GetMember($borrower,'cardnumber');
50 my $checkitem=$input->param('checkitem');
51 my $found;
52
53 #if we have an item selectionned, and the pickup branch is the same as the holdingbranch of the document, we force the value $rank and $found .
54 if ($checkitem ne ''){
55     $rank[0] = '0' unless C4::Context->preference('ReservesNeedReturns');
56     my $item = $checkitem;
57     $item = GetItem($item);
58     if ( $item->{'holdingbranch'} eq $branch ){
59         $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
60     }
61 }
62
63 if ($type eq 'str8' && $borrowernumber ne ''){
64         my $count=@bibitems;
65         @bibitems=sort @bibitems;
66         my $i2=1;
67         my @realbi;
68         $realbi[0]=$bibitems[0];
69         for (my $i=1;$i<$count;$i++) {
70                 my $i3=$i2-1;
71                 if ($realbi[$i3] ne $bibitems[$i]) {
72                         $realbi[$i2]=$bibitems[$i];
73                         $i2++;
74                 }
75         }
76         my $const;
77         if ($input->param('request') eq 'any'){
78             # place a request on 1st available
79             AddReserve($branch,$borrowernumber->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$notes,$title,$checkitem,$found);
80         } elsif ($reqbib[0] ne ''){
81             # FIXME : elsif probably never reached, (see top of the script)
82             # place a request on a given item
83             AddReserve($branch,$borrowernumber->{'borrowernumber'},$biblionumber,'o',\@reqbib,$rank[0],$notes,$title,$checkitem, $found);
84         } else {
85             AddReserve($branch,$borrowernumber->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$notes,$title,$checkitem, $found);
86         }
87         
88 print $input->redirect("request.pl?biblionumber=$biblionumber");
89 } elsif ($borrowernumber eq ''){
90         print $input->header();
91         print "Invalid card number please try again";
92         print $input->Dump;
93 }