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