5 #script to place reserves/requests
6 #writen 2/1/00 by chris@katipo.oc.nz
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
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
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.
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
29 use C4::Interface::CGI::Output;
34 use C4::Circulation::Circ2;
40 my $dbh=C4::Context->dbh;
41 # get biblio information....
42 my $biblionumber = $input->param('biblionumber');
43 my ($record) = XMLgetbiblio($dbh,$biblionumber);
44 $record=XML_xml2hash_onerecord($record);
45 my $dat=XMLmarc2koha_onerecord($dbh,$record,"biblios");
46 # get existing reserves .....
47 my ($count,$reserves) = FindReserves($biblionumber);
48 my $totalcount = $count;
49 foreach my $res (@$reserves) {
50 if ($res->{'found'} eq 'W') {
55 # make priorities options
58 #priorityoptions building
60 for (my $i=1; $i<=$num; $i++){
63 $option{selected}=($i==$num);
64 push(@optionloop, \%option);
68 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
71 my $date=format_date("$year-$mon-$mday");
77 my @barcodes = barcodes($biblionumber);
79 foreach my $num (@barcodes) {
81 $barcode{'date_due'}=$num->{'date_due'} if $num->{'date_due'} gt "0000-00-00" ;
82 $barcode{'barcode'}=$num->{'barcode'};
83 $barcode{'itemnumber'}=$num->{'itemnumber'};
84 $barcode{'message'}=$num->{'itemlost'} == 1 ? "(lost)" :
85 $num->{'itemlost'} == 2 ? "(long overdue)" : "";
86 $barcode{'class'}=$num->{'itemcallnumber'};
87 $abibitem{'itemlost'}=(($num->{'notforloan'})|| ($num->{'itemlost'} == 1)) ;
88 $abibitem{'itemlost'}=($num->{'wthdrawn'}) ;
89 push(@barcodeloop, \%barcode);
92 $abibitem{'class'}="$dat->{'classification'}$dat->{'dewey'}$dat->{'subclass'}";
93 $abibitem{'biblionumber'}=$dat->{'biblionumber'};
94 $abibitem{'description'}=$dat->{'itemtype'};
95 $abibitem{'volumeddesc'}=$dat->{'volumeddesc'};
96 $abibitem{'publicationyear'}=$dat->{'publicationyear'};
98 $abibitem{'barcodeloop'}=\@barcodeloop;
99 push(@bibitemloop,\%abibitem);
104 #existingreserves building
106 my $branches = GetBranches();
108 foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
110 if ($res->{'priority'}>$totalcount){$totalcount=$res->{'priority'};}
111 # my $prioropt = priorityoptions($totalcount, $res->{'priority'});
113 for (my $i=1; $i<=$totalcount; $i++){
116 $option{selected}=($i==$res->{'priority'});
117 push(@optionloop, \%option);
121 foreach my $br (keys %$branches) {
125 (next) unless $branches->{$br}->{'IS'};
127 # Only branches with the 'IS' branchrelation
130 $abranch{'selected'}=($br eq $res->{'branchcode'});
131 $abranch{'branch'}=$br;
132 $abranch{'branchname'}=$branches->{$br}->{'branchname'};
133 push(@branchloop,\%abranch);
136 # my $item = $res->{'itemnumber'};
137 # $item = getiteminformation(\%env,$item);
139 if ($res->{'found'} eq 'W') {
141 $reserve{'holdingbranch'}=$res->{'holdingbranch'};
142 $reserve{'barcode'}=$res->{'barcode'};
143 $reserve{'biblionumber'}=$res->{'biblionumber'};
144 $reserve{'wbrcode'} = $res->{'branchcode'};
145 $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
146 if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){
147 $reserve{'atdestination'} = 1;
150 $reserve{'barcode'}=$res->{'barcode'};
151 $reserve{'date'} = format_date($res->{'reservedate'});
152 $reserve{'borrowernumber'}=$res->{'borrowernumber'};
153 $reserve{'biblionumber'}=$res->{'biblionumber'};
154 $reserve{'bornum'}=$res->{'borrowernumber'};
155 $reserve{'firstname'}=$res->{'firstname'};
156 $reserve{'surname'}=$res->{'surname'};
157 $reserve{'bornum'}=$res->{'borrowernumber'};
158 $reserve{'notes'}=$res->{'reservenotes'};
159 $reserve{'wait'}=($res->{'found'} eq 'W');
160 $reserve{'constrainttypea'}=($res->{'constrainttype'} eq 'a');
161 $reserve{'constrainttypeo'}=($res->{'constrainttype'} eq 'o');
162 $reserve{'voldesc'}=$res->{'volumeddesc'};
163 $reserve{'itemtype'}=$res->{'itemtype'};
164 $reserve{'branchloop'}=\@branchloop;
165 $reserve{'optionloop'}=\@optionloop;
166 push(@reserveloop,\%reserve);
172 my $branches=GetBranches;
173 #my $count2=scalar(@branches);
174 foreach my $br (keys %$branches) {
176 push @select_branch, $br;
177 $select_branches{$br}= $branches->{$br}->{'branchname'};
179 my $CGIbranch=CGI::scrolling_list( -name => 'pickup',
180 -values => \@select_branch,
181 -labels => \%select_branches,
185 #get the time for the form name...
189 my ($template, $borrowernumber, $cookie)
190 = get_template_and_user({template_name => "reserve/request.tmpl",
193 authnotrequired => 0,
194 flagsrequired => {borrowers => 1},
196 $template->param( optionloop =>\@optionloop,
197 CGIbranch => $CGIbranch,
198 reserveloop => \@reserveloop,
200 bibitemloop => \@bibitemloop,
202 biblionumber => $biblionumber,
203 title =>$dat->{title});
205 output_html_with_http_headers $input, $cookie, $template->output;