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