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