improvement of reserves.pl with item - reservation
[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 DBI;
26 use C4::Search;
27 use C4::Biblio;
28 use CGI;
29 use C4::Output;
30 use C4::Reserves2;
31 use C4::Circulation::Circ2;
32 use C4::Members;
33
34 my $input = new CGI;
35 #print $input->header;
36
37 my @bibitems=$input->param('biblioitem');
38 my @reqbib=$input->param('reqbib');
39 my $biblio=$input->param('biblio');
40 my $borrower=$input->param('member');
41 my $notes=$input->param('notes');
42 my $branch=$input->param('pickup');
43 my @rank=$input->param('rank-request');
44 my $type=$input->param('type');
45 my $title=$input->param('title');
46 my $bornum=borrdata($borrower,'');
47 # Nouveau developpement
48 my $checkitem=$input->param('checkitem');
49 # my $priority;
50 my $found;
51
52 #new op : 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 .
53 if ($checkitem ne ''){
54                 $rank[0] = '0';
55                 my %env;
56                 my $item = $checkitem;
57                 $item = getiteminformation(\%env,$item);
58                 if ( $item->{'holdingbranch'} eq $branch ){
59                 $found = 'W';   
60                 }
61
62
63 }
64
65 # END of new op .
66
67 if ($type eq 'str8' && $bornum ne ''){
68         my $count=@bibitems;
69         @bibitems=sort @bibitems;
70         my $i2=1;
71         my @realbi;
72         $realbi[0]=$bibitems[0];
73         for (my $i=1;$i<$count;$i++) {
74                 my $i3=$i2-1;
75                 if ($realbi[$i3] ne $bibitems[$i]) {
76                         $realbi[$i2]=$bibitems[$i];
77                         $i2++;
78                 }
79         }
80         my $env;
81         my $const;
82         if ($input->param('request') eq 'any'){
83         $const='a';
84   CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblio,$const,\@realbi,$rank[0],$notes,$title,$checkitem,$found);
85         } elsif ($reqbib[0] ne ''){
86         $const='o';
87   CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblio,$const,\@reqbib,$rank[0],$notes,$title,$checkitem, $found);
88         } else {
89   CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblio,'a',\@realbi,$rank[0],$notes,$title,$checkitem, $found);
90         }
91         
92 print $input->redirect("request.pl?bib=$biblio");
93 } elsif ($bornum eq ''){
94         print $input->header();
95         print "Invalid card number please try again";
96         print $input->Dump;
97 }