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