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