2 # WARNING: This file uses 4-character tabs!
4 #written 11/3/2002 by Finlay
5 #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
32 use C4
::Auth qw
/:DEFAULT get_session/;
33 use C4
::Branch
; # GetBranches
37 ###############################################
42 if (!C4
::Context
->userenv){
43 my $sessionID = $query->cookie("CGISESSID");
45 $session = get_session
($sessionID) if $sessionID;
46 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
47 # no branch set we can't transfer
48 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
53 #######################################################################################
55 my ($template, $user, $cookie) = get_template_and_user
(
57 template_name
=> "circ/branchtransfers.tmpl",
61 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
65 my $branches = GetBranches
;
75 my $request = $query->param('request') || '';
76 my $borrowernumber = $query->param('borrowernumber') || 0;
77 my $tobranchcd = $query->param('tobranchcd') || '';
81 # Deal with the requests....
82 if ( $request eq "KillWaiting" ) {
83 my $item = $query->param('itemnumber');
84 CancelReserve
( 0, $item, $borrowernumber );
88 elsif ( $request eq "SetWaiting" ) {
89 my $item = $query->param('itemnumber');
90 ModReserveAffect
( $item, $borrowernumber );
95 elsif ( $request eq 'KillReserved' ) {
96 my $biblio = $query->param('biblionumber');
97 CancelReserve
( $biblio, 0, $borrowernumber );
102 # collect the stack of books already transfered so they can printed...
106 my $barcode = $query->param('barcode');
108 defined $barcode and $barcode =~ s/\s*//g; # FIXME: barcodeInputFilter
109 # warn "barcode : $barcode";
113 ( $transfered, $messages, $iteminformation ) =
114 transferbook
( $tobranchcd, $barcode, $ignoreRs );
116 # warn "Transfered : $transfered / ".Dumper($messages);
117 $found = $messages->{'ResFound'};
120 my $frbranchcd = C4
::Context
->userenv->{'branch'};
121 # if ( not($found) ) {
122 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
123 $item{'title'} = $iteminformation->{'title'};
124 $item{'author'} = $iteminformation->{'author'};
125 $item{'itemtype'} = $iteminformation->{'itemtype'};
126 $item{'ccode'} = $iteminformation->{'ccode'};
127 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
128 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
131 $item{barcode
} = $barcode;
132 $item{frombrcd
} = $frbranchcd;
133 $item{tobrcd
} = $tobranchcd;
134 push( @trsfitemloop, \
%item );
135 # warn Dumper(@trsfitemloop);
139 foreach ( $query->param ) {
140 (next) unless (/bc-(\d*)/);
143 my $bc = $query->param("bc-$counter");
144 my $frbcd = $query->param("fb-$counter");
145 my $tobcd = $query->param("tb-$counter");
147 $item{counter
} = $counter;
148 $item{barcode
} = $bc;
149 $item{frombrcd
} = $frbcd;
150 $item{tobrcd
} = $tobcd;
151 my ($iteminformation) = GetBiblioFromItemNumber
( GetItemnumberFromBarcode
($bc) );
152 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
153 $item{'title'} = $iteminformation->{'title'};
154 $item{'author'} = $iteminformation->{'author'};
155 $item{'itemtype'} = $iteminformation->{'itemtype'};
156 $item{'ccode'} = $iteminformation->{'ccode'};
157 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
158 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
159 push( @trsfitemloop, \
%item );
165 #####################
168 my $res = $messages->{'ResFound'};
169 $itemnumber = $res->{'itemnumber'};
171 if ( $res->{'ResFound'} eq "Waiting" ) {
174 elsif ( $res->{'ResFound'} eq "Reserved" ) {
176 $biblionumber = $res->{'biblionumber'};
180 #####################
182 # Used for branch transfer limits error messages.
183 my $codeTypeDescription = 'Collection Code';
184 my $codeType = C4
::Context
->preference("BranchTransferLimitsType");
185 if ( $codeType eq 'itemtype' ) {
186 $codeTypeDescription = 'Item Type';
190 foreach my $code ( keys %$messages ) {
192 if ( $code eq 'BadBarcode' ) {
193 $err{msg
} = $messages->{'BadBarcode'};
194 $err{errbadcode
} = 1;
196 elsif ( $code eq "NotAllowed" ) {
197 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
198 # Do we really want a error log message here? --atz
199 $err{errnotallowed
} = 1;
200 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
201 $err{tbr
} = $branches->{ $tbr }->{'branchname'};
202 $err{code
} = $typecode;
203 $err{codeType
} = $codeTypeDescription;
205 elsif ( $code eq 'IsPermanent' ) {
206 $err{errispermanent
} = 1;
207 $err{msg
} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
209 elsif ( $code eq 'WasReturned' ) {
210 $err{errwasreturned
} = 1;
211 $err{borrowernumber
} = $messages->{'WasReturned'};
212 my $borrower = GetMember
('borrowernumber'=>$messages->{'WasReturned'});
213 $err{title
} = $borrower->{'title'};
214 $err{firstname
} = $borrower->{'firstname'};
215 $err{surname
} = $borrower->{'surname'};
216 $err{cardnumber
} = $borrower->{'cardnumber'};
218 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
219 push( @errmsgloop, \
%err );
223 # warn "FINAL ============= ".Dumper(@trsfitemloop);
226 reserved
=> $reserved,
228 borrowernumber
=> $borrowernumber,
229 itemnumber
=> $itemnumber,
231 biblionumber
=> $biblionumber,
232 tobranchcd
=> $tobranchcd,
233 reqmessage
=> $reqmessage,
234 cancelled
=> $cancelled,
235 setwaiting
=> $setwaiting,
236 trsfitemloop
=> \
@trsfitemloop,
237 branchoptionloop
=> GetBranchesLoop
($tobranchcd),
238 errmsgloop
=> \
@errmsgloop,
239 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
241 output_html_with_http_headers
$query, $cookie, $template->output;