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
31 use C4::Auth qw/:DEFAULT get_session/;
32 use C4::Branch; # GetBranches
36 ###############################################
41 if (!C4::Context->userenv){
42 my $sessionID = $query->cookie("CGISESSID");
43 my $session = get_session($sessionID);
44 if ($session->param('branch') eq 'NO_LIBRARY_SET'){
45 # no branch set we can't transfer
46 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
52 #######################################################################################
54 my ( $template, $cookie );
56 ( $template, $user, $cookie ) = get_template_and_user(
58 template_name => "circ/branchtransfers.tmpl",
62 flagsrequired => { circulate => "circulate_remaining_permissions" },
66 my $branches = GetBranches;
67 my $branch = GetBranch( $query, $branches );
77 my $request = $query->param('request');
78 my $borrowernumber = $query->param('borrowernumber');
79 my $tobranchcd = $query->param('tobranchcd');
82 # Deal with the requests....
83 if ( $request eq "KillWaiting" ) {
84 my $item = $query->param('itemnumber');
86 CancelReserve( 0, $item, $borrowernumber );
92 if ( $request eq "SetWaiting" ) {
93 my $item = $query->param('itemnumber');
94 ModReserveAffect( $item, $borrowernumber );
99 if ( $request eq 'KillReserved' ) {
100 my $biblio = $query->param('biblionumber');
101 CancelReserve( $biblio, 0, $borrowernumber );
106 # set up the branchselect options....
107 my @branchoptionloop;
108 foreach my $br ( keys %$branches ) {
110 $branch{selected} = ( $br eq $tobranchcd );
112 $branch{name} = $branches->{$br}->{'branchname'};
113 push( @branchoptionloop, \%branch );
116 # collect the stack of books already transfered so they can printed...
120 my $barcode = $query->param('barcode');
122 $barcode =~ s/\s*//g;
123 # warn "barcode : $barcode";
127 ( $transfered, $messages, $iteminformation ) =
128 transferbook( $tobranchcd, $barcode, $ignoreRs );
130 # warn "Transfered : $transfered / ".Dumper($messages);
131 $found = $messages->{'ResFound'};
134 my $frbranchcd = C4::Context->userenv->{'branch'};
135 # if ( not($found) ) {
136 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
137 $item{'title'} = $iteminformation->{'title'};
138 $item{'author'} = $iteminformation->{'author'};
139 $item{'itemtype'} = $iteminformation->{'itemtype'};
140 $item{'ccode'} = $iteminformation->{'ccode'};
141 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
142 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
145 $item{barcode} = $barcode;
146 $item{frombrcd} = $frbranchcd;
147 $item{tobrcd} = $tobranchcd;
148 push( @trsfitemloop, \%item );
149 # warn Dumper(@trsfitemloop);
153 foreach ( $query->param ) {
154 (next) unless (/bc-(\d*)/);
157 my $bc = $query->param("bc-$counter");
158 my $frbcd = $query->param("fb-$counter");
159 my $tobcd = $query->param("tb-$counter");
161 $item{counter} = $counter;
162 $item{barcode} = $bc;
163 $item{frombrcd} = $frbcd;
164 $item{tobrcd} = $tobcd;
165 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
166 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
167 $item{'title'} = $iteminformation->{'title'};
168 $item{'author'} = $iteminformation->{'author'};
169 $item{'itemtype'} = $iteminformation->{'itemtype'};
170 $item{'ccode'} = $iteminformation->{'ccode'};
171 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
172 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
173 push( @trsfitemloop, \%item );
179 #####################
182 my $res = $messages->{'ResFound'};
183 $itemnumber = $res->{'itemnumber'};
185 if ( $res->{'ResFound'} eq "Waiting" ) {
188 if ( $res->{'ResFound'} eq "Reserved" ) {
190 $biblionumber = $res->{'biblionumber'};
194 #####################
196 # Used for branch transfer limits error messages.
197 my $codeTypeDescription = 'Collection Code';
198 my $codeType = C4::Context->preference("BranchTransferLimitsType");
199 if ( $codeType eq 'itemtype' ) {
200 $codeTypeDescription = 'Item Type';
205 foreach my $code ( keys %$messages ) {
208 if ( $code eq 'BadBarcode' ) {
209 $err{msg} = $messages->{'BadBarcode'};
210 $err{errbadcode} = 1;
213 if ( $code eq "NotAllowed" ) {
214 warn $messages->{'NotAllowed'};
215 warn $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
216 $err{errnotallowed} = 1;
217 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
218 $err{tbr} = $branches->{ $tbr }->{'branchname'};
219 $err{code} = $typecode;
220 $err{codeType} = $codeTypeDescription;
223 if ( $code eq 'IsPermanent' ) {
224 $err{errispermanent} = 1;
225 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
227 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
229 if ( $code eq 'WasReturned' ) {
230 $err{errwasreturned} = 1;
231 $err{borrowernumber}=$messages->{'WasReturned'};
232 my $borrower = GetMember($messages->{'WasReturned'},'borrowernumber');
233 $err{title}=$borrower->{'title'};
234 $err{firstname}=$borrower->{'firstname'};
235 $err{surname}=$borrower->{'surname'};
236 $err{cardnumber} =$borrower->{'cardnumber'};
238 push( @errmsgloop, \%err );
242 # warn "FINAL ============= ".Dumper(@trsfitemloop);
245 reserved => $reserved,
247 borrowernumber => $borrowernumber,
248 itemnumber => $itemnumber,
250 biblionumber => $biblionumber,
251 tobranchcd => $tobranchcd,
252 reqmessage => $reqmessage,
253 cancelled => $cancelled,
254 setwaiting => $setwaiting,
255 trsfitemloop => \@trsfitemloop,
256 branchoptionloop => \@branchoptionloop,
257 errmsgloop => \@errmsgloop,
258 CircAutocompl => C4::Context->preference("CircAutocompl")
260 output_html_with_http_headers $query, $cookie, $template->output;
264 return $borinfo->{'surname'} . " "
265 . $borinfo->{'title'} . " "
266 . $borinfo->{'firstname'};