* graphic bugfixes
[koha.git] / request.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to place reserves/requests
6 #writen 2/1/00 by chris@katipo.oc.nz
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26 use strict;
27 use C4::Search;
28 use C4::Output;
29 use C4::Auth;
30 use C4::Reserves2;
31 use C4::Biblio;
32 use C4::Koha;
33 use C4::Circulation::Circ2;
34 use HTML::Template;
35 use C4::Catalogue;
36 use CGI;
37 my $input = new CGI;
38
39 # get biblio information....
40 my $bib = $input->param('bib');
41 my $dat = bibdata($bib);
42
43 # get existing reserves .....
44 my ($count,$reserves) = FindReserves($bib);
45 my $totalcount = $count;
46 foreach my $res (@$reserves) {
47     if ($res->{'found'} eq 'W') {
48         $count--;
49     }
50 }
51
52 # make priorities options
53 my $num = $count + 1;
54
55 #priorityoptions building
56 my @optionloop;
57 for (my $i=1; $i<=$num; $i++){
58         my %option;
59         $option{num}=$i;
60         $option{selected}=($i==$num);
61         push(@optionloop, \%option);
62 }
63
64
65 # get branch information
66 my $branch = $input->cookie('branch');
67 ($branch) || ($branch = 'L');
68 my $branches = getbranches();
69 # make branch selection options...
70 my @branchloop;
71 foreach my $br (keys %$branches) {
72         (next) unless $branches->{$br}->{'IS'};
73                         # Only branches with the 'IS' branchrelation
74                         # can issue books
75         my %abranch;
76         $abranch{'selected'}=($br eq $branch);
77         $abranch{'branch'}=$br;
78         $abranch{'branchname'}=$branches->{$br}->{'branchname'};
79         push(@branchloop,\%abranch);
80 }
81
82
83 # todays date
84 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
85 $year=$year+1900;
86 $mon++;
87 my $date="$mday/$mon/$year";
88
89
90 # get biblioitem information and build rows for form
91 my ($count2,@data) = bibitems($bib);
92
93 my @bibitemloop;
94 foreach my $dat (sort {$b->{'dateaccessioned'} cmp $a->{'dateaccessioned'}} @data) {
95     $dat->{'dewey'}="" if ($dat->{'dewey'} == 0);
96     $dat->{'volumeddesc'} = "&nbsp;" unless $dat->{'volumeddesc'};
97     $dat->{'dewey'}=~ s/\.0000$//;
98     $dat->{'dewey'}=~ s/00$//;
99
100         my %abibitem;
101         my @barcodeloop;
102     my @barcodes = barcodes($dat->{'biblioitemnumber'});
103     foreach my $num (@barcodes) {
104                 my %barcode;
105                 $barcode{'barcode'}=$num->{'barcode'};
106                 $barcode{'message'}=$num->{'itemlost'} == 1 ? "(lost)" :
107             $num->{'itemlost'} == 2 ? "(long overdue)" : "";
108                 push(@barcodeloop, \%barcode);
109     }
110         $abibitem{'barcodeloop'}=\@barcodeloop;
111     $abibitem{'class'}="$dat->{'classification'}$dat->{'dewey'}$dat->{'subclass'}";
112     my $select;
113     $abibitem{'itemlost'}=(($dat->{'notforloan'})|| ($dat->{'itemlost'} == 1)) ;
114         $abibitem{'biblioitemnumber'}=$dat->{'biblioitemnumber'};
115         $abibitem{'description'}=$dat->{'description'};
116         $abibitem{'volumeddesc'}=$dat->{'volumeddesc'};
117         $abibitem{'publicationyear'}=$dat->{'publicationyear'};
118         push(@bibitemloop,\%abibitem);
119 }
120
121
122
123 #existingreserves building
124 my @reserveloop;
125 foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
126         my %reserve;
127 #    my $prioropt = priorityoptions($totalcount, $res->{'priority'});
128         my @optionloop;
129         for (my $i=1; $i<=$totalcount; $i++){
130                 my %option;
131                 $option{num}=$i;
132                 $option{selected}=($i==$res->{'priority'});
133                 push(@optionloop, \%option);
134         }
135 #    my $bropt = branchoptions($res->{'branchcode'});
136         my @branchloop;
137         foreach my $br (keys %$branches) {
138                 (next) unless $branches->{$br}->{'IS'};
139                                 # Only branches with the 'IS' branchrelation
140                                 # can issue books
141                 my %abranch;
142                 $abranch{'selected'}=($br eq $res->{'branchcode'});
143                 $abranch{'branch'}=$br;
144                 $abranch{'branchname'}=$branches->{$br}->{'branchname'};
145                 push(@branchloop,\%abranch);
146         }
147
148     if ($res->{'found'} eq 'W') {
149                 my %env;
150                 my $item = $res->{'itemnumber'};
151                 $item = getiteminformation(\%env,$item);
152                 $reserve{'barcode'}=$item->{'barcode'};
153                 $reserve{'biblionumber'}=$item->{'biblionumber'};
154                 $reserve{'wbrcode'} = $res->{'branchcode'};
155                 $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
156     }
157     $reserve{'date'} = slashifyDate($res->{'reservedate'});
158         $reserve{'borrowernumber'}=$res->{'borrowernumber'};
159         $reserve{'biblionumber'}=$res->{'biblionumber'};
160         $reserve{'bornum'}=$res->{'borrowernumber'};
161         $reserve{'firstname'}=$res->{'firstname'};
162         $reserve{'bornum'}=$res->{'borrowernumber'};
163         $reserve{'notes'}=$res->{'reservenotes'};
164         $reserve{'wait'}=($res->{'found'} eq 'W');
165         $reserve{'constrainttypea'}=($res->{'constrainttype'} eq 'a');
166         $reserve{'constrainttypeo'}=($res->{'constrainttype'} eq 'o');
167         $reserve{'voldesc'}=$res->{'volumeddesc'};
168         $reserve{'itemtype'}=$res->{'itemtype'};
169         $reserve{'branchloop'}=\@branchloop;
170         $reserve{'optionloop'}=\@optionloop;
171         push(@reserveloop,\%reserve);
172 }
173
174 my @branches;
175 my @select_branch;
176 my %select_branches;
177 my ($count2,@branches)=branches();
178 for (my $i=0;$i<$count2;$i++){
179         push @select_branch, $branches[$i]->{'branchcode'};#
180         $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
181 }
182 my $CGIbranch=CGI::scrolling_list( -name     => 'pickup',
183                         -values   => \@select_branch,
184                         -labels   => \%select_branches,
185                         -size     => 1,
186                         -multiple => 0 );
187
188 #get the time for the form name...
189 my $time = time();
190
191 #setup colours
192 my ($template, $borrowernumber, $cookie)
193     = get_template_and_user({template_name => "request.tmpl",
194                                                         query => $input,
195                             type => "intranet",
196                             authnotrequired => 0,
197                             flagsrequired => {parameters => 1},
198                          });
199 $template->param(       optionloop =>\@optionloop,
200                                                                 CGIbranch => $CGIbranch,
201                                                                 reserveloop => \@reserveloop,
202                                                                 'time' => $time,
203                                                                 bibitemloop => \@bibitemloop,
204                                                                 date => $date,
205                                                                 bib => $bib,
206                                                                 title =>$dat->{title});
207 # printout the page
208 print $input->header(-expires=>'now'), $template->output;