e392f75e8595306c4202f113842647f630fc0cb1
[koha.git] / request.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::Output;
28 use C4::Reserves2;
29 use C4::Acquisitions;
30 use C4::Koha;
31 use C4::Circulation::Circ2;
32
33 use CGI;
34 my $input = new CGI;
35
36 # get biblio information....
37 my $bib = $input->param('bib');
38 my $dat = bibdata($bib);
39
40 # get existing reserves .....
41 my ($count,$reserves) = FindReserves($bib);
42 foreach my $res (@$reserves) {
43     if ($res->{'found'} eq 'W') {
44         $count--;
45     }
46 }
47
48 # make priorities options
49 my $num = $count + 1;
50 my $priorityoptions = priorityoptions($num, $num);
51
52
53 # get branch information
54 my $branch = $input->cookie('branch');
55 ($branch) || ($branch = 'L');
56 my $branches = getbranches();
57 my $branchoptions = branchoptions($branch);
58
59
60 # todays date
61 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
62 $year=$year+1900;
63 $mon++;
64 my $date="$mday/$mon/$year";
65
66
67
68
69 # get biblioitem information and build rows for form
70 my ($count2,@data) = bibitems($bib);
71 my $bibitemrows = "";
72
73
74 for (my $i=0; $i<$count2; $i++) {
75     my @barcodes = barcodes($data[$i]->{'biblioitemnumber'});
76     my $barcodestext = "";
77     foreach my $num (@barcodes) {
78         my $message = $num->{'itemlost'} == 1 ? "(lost)" :
79             $num->{'itemlost'} == 2 ? "(long overdue)" : "";
80         $barcodestext .= "$num->{'barcode'} $message <br>";
81     }
82     $barcodestext = substr($barcodestext, 0, -4);
83
84     $data[$i]->{'dewey'}="" if ($data[$i]->{'dewey'} == 0);
85
86     warn "Itemlost: $data[$i]->{itemlost} \n";
87     $data[$i]->{'volumeddesc'} = "&nbsp;" unless $data[$i]->{'volumeddesc'};
88     $data[$i]->{'dewey'}=~ s/\.0000$//;
89     $data[$i]->{'dewey'}=~ s/00$//;
90     my $class="$data[$i]->{'classification'}$data[$i]->{'dewey'}$data[$i]->{'subclass'}";
91     my $select;
92     if (($data[$i]->{'notforloan'}) 
93         || ($data[$i]->{'itemlost'} == 1)
94         || ($data[$i]->{'itemlost'} == 2))  {
95         $select = "Cannot be reserved.";
96     } else {
97         $select = " <input type=checkbox name=reqbib value=$data[$i]->{'biblioitemnumber'}><input type=hidden name=biblioitem value=$data[$i]->{'biblioitemnumber'}>";
98     }
99     $bibitemrows .= <<"EOF";
100 <tr VALIGN=TOP>
101 <TD>$select</td>
102 <TD>$data[$i]->{'description'}</td>
103 <TD>$class</td>
104 <td>$data[$i]->{'volumeddesc'}</td>
105 <td>$data[$i]->{'publicationyear'}</td>
106 <td>$barcodestext</td>
107 </tr>
108 EOF
109 }
110
111
112
113
114 my $existingreserves = "";
115 foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
116     my $prioropt = priorityoptions($count, $res->{'priority'});
117     my $bropt = branchoptions($res->{'branchcode'});
118     my $bor=$res->{'borrowernumber'};
119     $date = slashifyDate($res->{'reservedate'});
120
121     my $type=$res->{'constrainttype'};
122     if ($type eq 'a'){
123         $type='Next Available';
124     } elsif ($type eq 'o'){
125         $type="This type only $res->{'volumeddesc'} $res->{'itemtype'}";
126     }
127
128     my $notes = $res->{'reservenotes'}." ";
129     my $rank;
130     my $pickup;
131     my $change;
132     if ($res->{'found'} eq 'W') {
133         my %env;
134         my $item = $res->{'itemnumber'};
135         $item = getiteminformation(\%env,$item);
136         $item = "<a href=/cgi-bin/koha/detail.pl?bib=$item->{'biblionumber'} &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$item->{'barcode'}</a>";
137         my $wbra = $branches->{$res->{'branchcode'}}->{'branchname'};
138         $rank = "Item waiting";
139         $type = $item;
140         $pickup = "at <b>".$wbra."</b>";
141         $change = "<input type=checkbox name=rank-request value=del>delete";
142     } else {
143         $rank = "<select name=rank-request>$prioropt<option value=del>Del</select>";
144         $pickup = "<select name=pickup>$bropt</select>";
145     }
146     $existingreserves .= <<"EOF";
147 <input type=hidden name=borrower value=$res->{'borrowernumber'}>
148 <input type=hidden name=biblio value=$res->{'biblionumber'}>
149 <tr VALIGN=TOP>
150 <TD>$rank</td>
151 <TD>
152 <a href=/cgi-bin/koha/moremember.pl?bornum=$bor>$res->{'firstname'} $res->{'surname'}</a>
153 </td>
154 <td>$notes</td>
155 <TD>$date</td>
156 <TD>$pickup</td>
157 <TD>$type</td>
158 </tr>
159 EOF
160 }
161
162
163
164 sub priorityoptions {
165     my ($count, $sel) = @_;
166     my $out = "";
167     for (my $i=1; $i<=$count; $i++){
168         $out .= "<option value=$i";
169         if ($sel == $i){
170             $out .= " selected";
171         }
172         $out .= ">$i\n";
173     }
174     return $out;
175 }
176
177 # make branch selection options...
178 sub branchoptions {
179     my ($selbr) = @_;
180     my $out = "";
181     foreach my $br (keys %$branches) {
182         (next) unless $branches->{$br}->{'IS'};
183         my $selected = "";
184         if ($br eq $selbr) {
185             $selected = "selected";
186         }
187         $out .= "<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
188     }
189     return $out;
190 }
191
192
193
194 # printout the page
195
196
197 print $input->header;
198
199
200 #setup colours
201 print startpage();
202 print startmenu('catalogue');
203
204
205
206
207 print <<printend
208
209 <form action="placerequest.pl" method=post>
210 <INPUT TYPE="image" name="submit"  VALUE="request" height=42  WIDTH=187 BORDER=0 src="/images/place-request.gif" align=right >
211 <input type=hidden name=biblio value=$bib>
212 <input type=hidden name=type value=str8>
213 <input type=hidden name=title value="$dat->{'title'}">
214 <FONT SIZE=6><em>Requesting: <br>
215 <a href=/cgi-bin/koha/detail.pl?bib=$bib>$dat->{'title'}</a> 
216 ($dat->{'author'})</em></FONT><P>
217 <p>
218
219
220 <!----------------BIBLIO RESERVE TABLE-------------->
221
222
223 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
224 <TR VALIGN=TOP>
225 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Rank</b></TD>
226 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Member Number</b></TD>
227 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Notes</b></TD>
228 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Date</b></TD>
229 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Pickup</b></TD>
230 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Request</b></TD>
231 </TR>
232 <tr VALIGN=TOP  >
233 <td><select name=rank-request>
234 $priorityoptions
235 </select></td>
236 <td><input type=text size=10 name=member></td>
237 <td><input type=text size=20 name=notes></td>
238 <td>$date</td>
239 <td><select name=pickup>
240 $branchoptions
241 </select></td>
242 <td><input type=checkbox name=request value=any>Next Available, 
243 <br>(or choose from list below)</td>
244 </tr></table>
245 </p>
246
247
248 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
249 <TR VALIGN=TOP>
250
251 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Request</b></TD>
252 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Item Type</b></TD>
253 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Classification</b></TD>
254 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Volume</b></TD>
255 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Pubdate</b></TD>
256 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Copies</b></TD>
257 </TR>
258 $bibitemrows
259 </table>
260 </p>
261 </form>
262 <p>&nbsp;</p>
263
264
265
266 <!-----------MODIFY EXISTING REQUESTS----------------->
267
268 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
269
270 <TR VALIGN=TOP>
271
272 <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=7><B>MODIFY EXISTING REQUESTS </b></TD>
273 </TR>
274 <form action=modrequest.pl method=post>
275 <TR VALIGN=TOP>
276
277 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Rank</b></TD>
278 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Member</b></TD>
279 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Notes</b></TD>
280 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Date</b></TD>
281 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Pickup</b></TD>
282 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Request</b></TD>
283 </TR>
284 $existingreserves
285 <tr VALIGN=TOP>
286 <TD colspan=6 align=right>
287 Delete a request by selecting "del" from the rank list.
288 <INPUT TYPE="image" name="submit"  VALUE="request" height=42  WIDTH=64 BORDER=0 src="/images/ok.gif"></td>
289 </tr>
290 </table>
291 <P>
292 <br>
293 </form>
294
295 printend
296 ;
297
298 print endmenu();
299 print endpage();