2 # WARNING: This file uses 4-character tabs!
4 #written 11/3/2002 by Finlay
5 #script to execute branch transfers of books
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Circulation::Circ2;
31 use C4::Interface::CGI::Output;
34 ###############################################
38 my $headerbackgroundcolor='#99cc33';
39 my $circbackgroundcolor='#ffffcc';
40 my $circbackgroundcolor='white';
41 my $linecolor1='#ffffcc';
42 my $linecolor2='white';
43 my $backgroundimage="/images/background-mem.gif";
45 my $branches = getbranches();
46 my $printers = getprinters(\%env);
49 ###############################################
53 my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($query);
56 my $branch = $query->param("branch");
57 my $printer = $query->param("printer");
59 ($branch) || ($branch=$query->cookie('branch')) ;
60 ($printer) || ($printer=$query->cookie('printer')) ;
62 ($branches->{$branch}) || ($branch=(keys %$branches)[0]);
63 ($printers->{$printer}) || ($printer=(keys %$printers)[0]);
65 my $genbrname = $branches->{$branch}->{'branchname'} ;
66 my $genprname = $printers->{$printer}->{'printername'};
77 my $request=$query->param('request');
78 my $borrnum = $query->param('borrowernumber');
80 my $tobranchcd=$query->param('tobranchcd');
84 # Deal with the requests....
85 if ($request eq "KillWaiting") {
86 my $item = $query->param('itemnumber');
87 CancelReserve(0, $item, $borrnum);
93 if ($request eq "SetWaiting") {
94 my $item = $query->param('itemnumber');
95 $tobranchcd = ReserveWaiting($item, $borrnum);
96 $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
101 if ($request eq 'KillReserved'){
102 my $biblio = $query->param('biblionumber');
103 CancelReserve($biblio, 0, $borrnum);
110 # set up the branchselect options....
111 my @branchoptionloop;
112 foreach my $br (keys %$branches) {
113 (next) unless $branches->{$br}->{'CU'};
115 $branch{selected}=($br eq $tobranchcd);
117 $branch{name}=$branches->{$br}->{'branchname'};
118 push (@branchoptionloop, \%branch);
122 # collect the stack of books already transfered so they can printed...
127 my $color=$linecolor2;
129 my $barcode = $query->param('barcode');
133 ($transfered, $messages, $iteminformation)
134 = transferbook($tobranchcd, $barcode, $ignoreRs);
135 $found = $messages->{'ResFound'};
138 my $frbranchcd = $iteminformation->{'holdingbranch'};
140 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
141 $item{'color'}=$color;
142 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
143 $item{'title'}=$iteminformation->{'title'};
144 $item{'author'}=$iteminformation->{'author'};
145 $item{'itemtype'}=$iteminformation->{'itemtype'};
146 $item{'frbrname'}=$branches->{$frbranchcd}->{'branchname'};
147 $item{'tobrname'}=$branches->{$tobranchcd}->{'branchname'};
150 $item{barcode}=$barcode;
151 $item{frombrcd}=$frbranchcd;
152 $item{tobrcd}=$tobranchcd;
154 #Are these lines still useful ???
155 $transfereditems{0}=$barcode;
156 $frbranchcds{0}=$frbranchcd;
157 $tobranchcds{0}=$tobranchcd;
159 push (@trsfitemloop, \%item);
163 foreach ($query->param){
164 (next) unless (/bc-(\d*)/);
167 my $bc=$query->param("bc-$counter");
168 my $frbcd=$query->param("fb-$counter");
169 my $tobcd=$query->param("tb-$counter");
171 $item{counter}=$counter;
173 $item{frombrcd}=$frbcd;
174 $item{tobrcd}=$tobcd;
175 my ($iteminformation) = getiteminformation(\%env, 0, $bc);
176 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
177 $item{'color'}=$color;
178 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
179 $item{'title'}=$iteminformation->{'title'};
180 $item{'author'}=$iteminformation->{'author'};
181 $item{'itemtype'}=$iteminformation->{'itemtype'};
182 $item{'frbrname'}=$branches->{$frbcd}->{'branchname'};
183 $item{'tobrname'}=$branches->{$tobcd}->{'branchname'};
185 #Are these lines still useful ???
186 $transfereditems{$counter}=$bc;
187 $frbranchcds{$counter}=$frbcd;
188 $tobranchcds{$counter}=$tobcd;
190 push (@trsfitemloop, \%item);
202 #####################
205 my $res = $messages->{'ResFound'};
206 $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
207 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
209 $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
210 $borcnum = $borr->{'cardnumber'};
211 $itemnumber = $res->{'itemnumber'};
213 if ($res->{'ResFound'} eq "Waiting") {
216 if ($res->{'ResFound'} eq "Reserved") {
218 $biblionum = $res->{'biblionumber'};
222 #####################
225 foreach my $code (keys %$messages) {
227 $err{errbadcode} = ($code eq 'BadBarcode');
228 if ($code eq 'BadBarcode') {
229 $err{msg}=$messages->{'BadBarcode'};
232 $err{errispermanent} = ($code eq 'IsPermanent');
233 if ($code eq 'IsPermanent'){
234 $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
235 # Here, msg contains the branchname
236 # Not so satisfied with this... But should work
238 $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
240 $err{errwasreturned} = ($code eq 'WasReturned');
241 if ($code eq 'WasReturned') {
242 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
243 $name =name($borrowerinfo);
244 $bornum =$borrowerinfo->{'borrowernumber'};
245 $borcnum =$borrowerinfo->{'cardnumber'};
247 if ($code eq 'WasTransfered'){
248 # Put code here if you want to notify the user that item was transfered...
250 push (@errmsgloop, \%err);
254 #######################################################################################
255 # Make the page .....
256 my ($template, $borrowernumber, $cookie)
257 = get_template_and_user({template_name => "circ/branchtransfers.tmpl",
260 authnotrequired => 0,
261 flagsrequired => {parameters => 1},
263 $template->param( genbrname => $genbrname,
264 genprname => $genprname,
268 hdrbckgdcolor => $headerbackgroundcolor,
269 bckgdimg => $backgroundimage,
270 reserved => $reserved,
275 branchname => $branchname,
276 itemnumber => $itemnumber,
278 biblionumber => $biblionum,
279 tobranchcd => $tobranchcd,
280 reqmessage => $reqmessage,
281 cancelled => $cancelled,
282 setwaiting => $setwaiting,
283 trsfitemloop => \@trsfitemloop,
284 branchoptionloop => \@branchoptionloop,
285 errmsgloop => \@errmsgloop
287 output_html_with_http_headers $query, $sessioncookie, $template->output;
292 return $borinfo->{'surname'}." ".$borinfo->{'title'}." ".$borinfo->{'firstname'};