Adding 'even' variable to pass to template to facilitate alternating row colors in...
[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::Interface::CGI::Output;
30 use C4::Auth;
31 use C4::Reserves2;
32 use C4::Biblio;
33 use C4::Koha;
34 use C4::Circulation::Circ2;
35 use HTML::Template;
36 use C4::Catalogue;
37 use CGI;
38 use C4::Date;
39
40 my $input = new CGI;
41
42 # get biblio information....
43 my $bib = $input->param('bib');
44 my $dat = bibdata($bib);
45
46 # get existing reserves .....
47 my ($count,$reserves) = FindReserves($bib);
48 my $totalcount = $count;
49 foreach my $res (@$reserves) {
50     if ($res->{'found'} eq 'W') {
51         $count--;
52     }
53 }
54
55 # make priorities options
56 my $num = $count + 1;
57
58 #priorityoptions building
59 my @optionloop;
60 for (my $i=1; $i<=$num; $i++){
61         my %option;
62         $option{num}=$i;
63         $option{selected}=($i==$num);
64         push(@optionloop, \%option);
65 }
66
67 # todays date
68 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
69 $year=$year+1900;
70 $mon++;
71 my $date=format_date("$year-$mon-$mday");
72
73
74 # get biblioitem information and build rows for form
75 my ($count2,@data) = bibitems($bib);
76
77 my @bibitemloop;
78 foreach my $dat (sort {$b->{'dateaccessioned'} cmp $a->{'dateaccessioned'}} @data) {
79     $dat->{'dewey'}="" if ($dat->{'dewey'} == 0);
80     $dat->{'volumeddesc'} = "&nbsp;" unless $dat->{'volumeddesc'};
81     $dat->{'dewey'}=~ s/\.0000$//;
82     $dat->{'dewey'}=~ s/00$//;
83
84         my %abibitem;
85         my @barcodeloop;
86     my @barcodes = barcodes($dat->{'biblioitemnumber'});
87     foreach my $num (@barcodes) {
88                 my %barcode;
89                 $barcode{'barcode'}=$num->{'barcode'};
90                 $barcode{'message'}=$num->{'itemlost'} == 1 ? "(lost)" :
91             $num->{'itemlost'} == 2 ? "(long overdue)" : "";
92                 push(@barcodeloop, \%barcode);
93     }
94         $abibitem{'barcodeloop'}=\@barcodeloop;
95     $abibitem{'class'}="$dat->{'classification'}$dat->{'dewey'}$dat->{'subclass'}";
96     my $select;
97     $abibitem{'itemlost'}=(($dat->{'notforloan'})|| ($dat->{'itemlost'} == 1)) ;
98         $abibitem{'biblioitemnumber'}=$dat->{'biblioitemnumber'};
99         $abibitem{'description'}=$dat->{'description'};
100         $abibitem{'volumeddesc'}=$dat->{'volumeddesc'};
101         $abibitem{'publicationyear'}=$dat->{'publicationyear'};
102         push(@bibitemloop,\%abibitem);
103 }
104
105
106
107 #existingreserves building
108 my @reserveloop;
109 my $branches = getbranches();
110 foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
111         my %reserve;
112 #    my $prioropt = priorityoptions($totalcount, $res->{'priority'});
113         my @optionloop;
114         for (my $i=1; $i<=$totalcount; $i++){
115                 my %option;
116                 $option{num}=$i;
117                 $option{selected}=($i==$res->{'priority'});
118                 push(@optionloop, \%option);
119         }
120         my @branchloop;
121         foreach my $br (keys %$branches) {
122 #               (next) unless $branches->{$br}->{'IS'};
123                                 # Only branches with the 'IS' branchrelation
124                                 # can issue books
125                 my %abranch;
126                 $abranch{'selected'}=($br eq $res->{'branchcode'});
127                 $abranch{'branch'}=$br;
128                 $abranch{'branchname'}=$branches->{$br}->{'branchname'};
129                 push(@branchloop,\%abranch);
130         }
131
132     if ($res->{'found'} eq 'W') {
133                 my %env;
134                 my $item = $res->{'itemnumber'};
135                 $item = getiteminformation(\%env,$item);
136                 $reserve{'barcode'}=$item->{'barcode'};
137                 $reserve{'biblionumber'}=$item->{'biblionumber'};
138                 $reserve{'wbrcode'} = $res->{'branchcode'};
139                 $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
140     }
141     $reserve{'date'} = format_date($res->{'reservedate'});
142         $reserve{'borrowernumber'}=$res->{'borrowernumber'};
143         $reserve{'biblionumber'}=$res->{'biblionumber'};
144         $reserve{'bornum'}=$res->{'borrowernumber'};
145         $reserve{'firstname'}=$res->{'firstname'};
146         $reserve{'surname'}=$res->{'surname'};
147         $reserve{'bornum'}=$res->{'borrowernumber'};
148         $reserve{'notes'}=$res->{'reservenotes'};
149         $reserve{'wait'}=($res->{'found'} eq 'W');
150         $reserve{'constrainttypea'}=($res->{'constrainttype'} eq 'a');
151         $reserve{'constrainttypeo'}=($res->{'constrainttype'} eq 'o');
152         $reserve{'voldesc'}=$res->{'volumeddesc'};
153         $reserve{'itemtype'}=$res->{'itemtype'};
154         $reserve{'branchloop'}=\@branchloop;
155         $reserve{'optionloop'}=\@optionloop;
156         push(@reserveloop,\%reserve);
157 }
158
159 my @branches;
160 my @select_branch;
161 my %select_branches;
162 my ($count2,@branches)=branches();
163 for (my $i=0;$i<$count2;$i++){
164         push @select_branch, $branches[$i]->{'branchcode'};#
165         $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
166 }
167 my $CGIbranch=CGI::scrolling_list( -name     => 'pickup',
168                         -values   => \@select_branch,
169                         -labels   => \%select_branches,
170                         -size     => 1,
171                         -multiple => 0 );
172
173 #get the time for the form name...
174 my $time = time();
175
176 #setup colours
177 my ($template, $borrowernumber, $cookie)
178     = get_template_and_user({template_name => "request.tmpl",
179                                                         query => $input,
180                             type => "intranet",
181                             authnotrequired => 0,
182                             flagsrequired => {parameters => 1},
183                          });
184 $template->param(       optionloop =>\@optionloop,
185                                                                 CGIbranch => $CGIbranch,
186                                                                 reserveloop => \@reserveloop,
187                                                                 'time' => $time,
188                                                                 bibitemloop => \@bibitemloop,
189                                                                 date => $date,
190                                                                 bib => $bib,
191                                                                 title =>$dat->{title});
192 # printout the page
193 print $input->header(
194         -type => C4::Interface::CGI::Output::guesstype($template->output),
195         -expires=>'now'
196 ), $template->output;