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");
44 $session = get_session($sessionID) if $sessionID;
45 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
46 # no branch set we can't transfer
47 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
53 #######################################################################################
55 my ( $template, $cookie );
57 ( $template, $user, $cookie ) = get_template_and_user(
59 template_name => "circ/branchtransfers.tmpl",
63 flagsrequired => { circulate => "circulate_remaining_permissions" },
67 my $branches = GetBranches;
68 my $branch = GetBranch( $query, $branches );
78 my $request = $query->param('request');
79 my $borrowernumber = $query->param('borrowernumber');
80 my $tobranchcd = $query->param('tobranchcd');
83 # Deal with the requests....
84 if ( $request eq "KillWaiting" ) {
85 my $item = $query->param('itemnumber');
87 CancelReserve( 0, $item, $borrowernumber );
93 if ( $request eq "SetWaiting" ) {
94 my $item = $query->param('itemnumber');
95 ModReserveAffect( $item, $borrowernumber );
100 if ( $request eq 'KillReserved' ) {
101 my $biblio = $query->param('biblionumber');
102 CancelReserve( $biblio, 0, $borrowernumber );
107 # set up the branchselect options....
108 my @branchoptionloop;
109 foreach my $br (sort {$branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}} keys %$branches ) {
111 $branch{selected} = ( $br eq $tobranchcd );
113 $branch{name} = $branches->{$br}->{'branchname'};
114 push( @branchoptionloop, \%branch );
117 # collect the stack of books already transfered so they can printed...
121 my $barcode = $query->param('barcode');
123 $barcode =~ s/\s*//g;
124 # warn "barcode : $barcode";
128 ( $transfered, $messages, $iteminformation ) =
129 transferbook( $tobranchcd, $barcode, $ignoreRs );
131 # warn "Transfered : $transfered / ".Dumper($messages);
132 $found = $messages->{'ResFound'};
135 my $frbranchcd = C4::Context->userenv->{'branch'};
136 # if ( not($found) ) {
137 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
138 $item{'title'} = $iteminformation->{'title'};
139 $item{'author'} = $iteminformation->{'author'};
140 $item{'itemtype'} = $iteminformation->{'itemtype'};
141 $item{'ccode'} = $iteminformation->{'ccode'};
142 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
143 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
146 $item{barcode} = $barcode;
147 $item{frombrcd} = $frbranchcd;
148 $item{tobrcd} = $tobranchcd;
149 push( @trsfitemloop, \%item );
150 # warn Dumper(@trsfitemloop);
154 foreach ( $query->param ) {
155 (next) unless (/bc-(\d*)/);
158 my $bc = $query->param("bc-$counter");
159 my $frbcd = $query->param("fb-$counter");
160 my $tobcd = $query->param("tb-$counter");
162 $item{counter} = $counter;
163 $item{barcode} = $bc;
164 $item{frombrcd} = $frbcd;
165 $item{tobrcd} = $tobcd;
166 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
167 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
168 $item{'title'} = $iteminformation->{'title'};
169 $item{'author'} = $iteminformation->{'author'};
170 $item{'itemtype'} = $iteminformation->{'itemtype'};
171 $item{'ccode'} = $iteminformation->{'ccode'};
172 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
173 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
174 push( @trsfitemloop, \%item );
180 #####################
183 my $res = $messages->{'ResFound'};
184 $itemnumber = $res->{'itemnumber'};
186 if ( $res->{'ResFound'} eq "Waiting" ) {
189 if ( $res->{'ResFound'} eq "Reserved" ) {
191 $biblionumber = $res->{'biblionumber'};
195 #####################
198 foreach my $code ( keys %$messages ) {
201 if ( $code eq 'BadBarcode' ) {
202 $err{msg} = $messages->{'BadBarcode'};
203 $err{errbadcode} = 1;
206 if ( $code eq 'IsPermanent' ) {
207 $err{errispermanent} = 1;
208 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
210 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
212 if ( $code eq 'WasReturned' ) {
213 $err{errwasreturned} = 1;
214 $err{borrowernumber}=$messages->{'WasReturned'};
215 my $borrower = GetMember($messages->{'WasReturned'},'borrowernumber');
216 $err{title}=$borrower->{'title'};
217 $err{firstname}=$borrower->{'firstname'};
218 $err{surname}=$borrower->{'surname'};
219 $err{cardnumber} =$borrower->{'cardnumber'};
221 push( @errmsgloop, \%err );
225 # warn "FINAL ============= ".Dumper(@trsfitemloop);
228 reserved => $reserved,
230 borrowernumber => $borrowernumber,
231 itemnumber => $itemnumber,
233 biblionumber => $biblionumber,
234 tobranchcd => $tobranchcd,
235 reqmessage => $reqmessage,
236 cancelled => $cancelled,
237 setwaiting => $setwaiting,
238 trsfitemloop => \@trsfitemloop,
239 branchoptionloop => \@branchoptionloop,
240 errmsgloop => \@errmsgloop,
241 CircAutocompl => C4::Context->preference("CircAutocompl")
243 output_html_with_http_headers $query, $cookie, $template->output;
247 return $borinfo->{'surname'} . " "
248 . $borinfo->{'title'} . " "
249 . $borinfo->{'firstname'};