3 #written 11/3/2002 by Finlay
4 #script to execute branch transfers of books
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
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
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.
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
26 use C4::Circulation::Circ2;
32 ###############################################
36 my $headerbackgroundcolor='#99cc33';
37 my $circbackgroundcolor='#ffffcc';
38 my $circbackgroundcolor='white';
39 my $linecolor1='#ffffcc';
40 my $linecolor2='white';
41 my $backgroundimage="/images/background-mem.gif";
43 my $branches = getbranches();
44 my $printers = getprinters(\%env);
47 ###############################################
51 my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($query);
54 my $branch = $query->param("branch");
55 my $printer = $query->param("printer");
57 ($branch) || ($branch=$query->cookie('branch')) ;
58 ($printer) || ($printer=$query->cookie('printer')) ;
60 ($branches->{$branch}) || ($branch=(keys %$branches)[0]);
61 ($printers->{$printer}) || ($printer=(keys %$printers)[0]);
63 my $genbrname = $branches->{$branch}->{'branchname'} ;
64 my $genprname = $printers->{$printer}->{'printername'};
75 my $request=$query->param('request');
76 my $borrnum = $query->param('borrowernumber');
78 my $tobranchcd=$query->param('tobranchcd');
82 # Deal with the requests....
83 if ($request eq "KillWaiting") {
84 my $item = $query->param('itemnumber');
85 CancelReserve(0, $item, $borrnum);
91 if ($request eq "SetWaiting") {
92 my $item = $query->param('itemnumber');
93 $tobranchcd = ReserveWaiting($item, $borrnum);
94 $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
99 if ($request eq 'KillReserved'){
100 my $biblio = $query->param('biblionumber');
101 CancelReserve($biblio, 0, $borrnum);
108 # set up the branchselect options....
109 my @branchoptionloop;
110 foreach my $br (keys %$branches) {
111 (next) unless $branches->{$br}->{'CU'};
113 $branch{selected}=($br eq $tobranchcd);
115 $branch{name}=$branches->{$br}->{'branchname'};
116 push (@branchoptionloop, \%branch);
120 # collect the stack of books already transfered so they can printed...
125 my $color=$linecolor2;
127 my $barcode = $query->param('barcode');
131 ($transfered, $messages, $iteminformation)
132 = transferbook($tobranchcd, $barcode, $ignoreRs);
133 $found = $messages->{'ResFound'};
136 my $frbranchcd = $iteminformation->{'holdingbranch'};
138 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
139 $item{'color'}=$color;
140 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
141 $item{'title'}=$iteminformation->{'title'};
142 $item{'author'}=$iteminformation->{'author'};
143 $item{'itemtype'}=$iteminformation->{'itemtype'};
144 $item{'frbrname'}=$branches->{$frbranchcd}->{'branchname'};
145 $item{'tobrname'}=$branches->{$tobranchcd}->{'branchname'};
148 $item{barcode}=$barcode;
149 $item{frombrcd}=$frbranchcd;
150 $item{tobrcd}=$tobranchcd;
152 #Are these lines still useful ???
153 $transfereditems{0}=$barcode;
154 $frbranchcds{0}=$frbranchcd;
155 $tobranchcds{0}=$tobranchcd;
157 push (@trsfitemloop, \%item);
161 foreach ($query->param){
162 (next) unless (/bc-(\d*)/);
165 my $bc=$query->param("bc-$counter");
166 my $frbcd=$query->param("fb-$counter");
167 my $tobcd=$query->param("tb-$counter");
169 $item{counter}=$counter;
171 $item{frombrcd}=$frbcd;
172 $item{tobrcd}=$tobcd;
173 my ($iteminformation) = getiteminformation(\%env, 0, $bc);
174 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
175 $item{'color'}=$color;
176 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
177 $item{'title'}=$iteminformation->{'title'};
178 $item{'author'}=$iteminformation->{'author'};
179 $item{'itemtype'}=$iteminformation->{'itemtype'};
180 $item{'frbrname'}=$branches->{$frbcd}->{'branchname'};
181 $item{'tobrname'}=$branches->{$tobcd}->{'branchname'};
183 #Are these lines still useful ???
184 $transfereditems{$counter}=$bc;
185 $frbranchcds{$counter}=$frbcd;
186 $tobranchcds{$counter}=$tobcd;
188 push (@trsfitemloop, \%item);
200 #####################
203 my $res = $messages->{'ResFound'};
204 $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
205 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
207 $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
208 $borcnum = $borr->{'cardnumber'};
209 $itemnumber = $res->{'itemnumber'};
211 if ($res->{'ResFound'} eq "Waiting") {
214 if ($res->{'ResFound'} eq "Reserved") {
216 $biblionum = $res->{'biblionumber'};
220 #####################
223 foreach my $code (keys %$messages) {
225 $err{errbadcode} = ($code eq 'BadBarcode');
226 if ($code eq 'BadBarcode') {
227 $err{msg}=$messages->{'BadBarcode'};
230 $err{errispermanent} = ($code eq 'IsPermanent');
231 if ($code eq 'IsPermanent'){
232 $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
233 # Here, msg contains the branchname
234 # Not so satisfied with this... But should work
236 $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
238 $err{errwasreturned} = ($code eq 'WasReturned');
239 if ($code eq 'WasReturned') {
240 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
241 $name =name($borrowerinfo);
242 $bornum =$borrowerinfo->{'borrowernumber'};
243 $borcnum =$borrowerinfo->{'cardnumber'};
245 if ($code eq 'WasTransfered'){
246 # Put code here if you want to notify the user that item was transfered...
248 push (@errmsgloop, \%err);
252 #######################################################################################
253 # Make the page .....
254 my ($template, $borrowernumber, $cookie)
255 = get_template_and_user({template_name => "circ/branchtransfers.tmpl",
258 authnotrequired => 0,
259 flagsrequired => {parameters => 1},
261 $template->param( genbrname => $genbrname,
262 genprname => $genprname,
266 hdrbckgdcolor => $headerbackgroundcolor,
267 bckgdimg => $backgroundimage,
268 reserved => $reserved,
273 branchname => $branchname,
274 itemnumber => $itemnumber,
276 biblionumber => $biblionum,
277 tobranchcd => $tobranchcd,
278 reqmessage => $reqmessage,
279 cancelled => $cancelled,
280 setwaiting => $setwaiting,
281 trsfitemloop => \@trsfitemloop,
282 branchoptionloop => \@branchoptionloop,
283 errmsgloop => \@errmsgloop
285 output_html_with_http_headers $query, $sessioncookie, $template->output;
290 return $borinfo->{'surname'}." ".$borinfo->{'title'}." ".$borinfo->{'firstname'};