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
35 ###############################################
40 if (!C4::Context->userenv){
41 my $sessionID = $query->cookie("CGISESSID");
42 my $session = get_session($sessionID);
43 if ($session->param('branch') eq 'NO_LIBRARY_SET'){
44 # no branch set we can't transfer
45 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
51 #######################################################################################
53 my ( $template, $cookie );
55 ( $template, $user, $cookie ) = get_template_and_user(
57 template_name => "circ/branchtransfers.tmpl",
61 flagsrequired => { circulate => 1 },
65 my $branches = GetBranches;
66 my $branch = GetBranch( $query, $branches );
76 my $request = $query->param('request');
77 my $borrowernumber = $query->param('borrowernumber');
78 my $tobranchcd = $query->param('tobranchcd');
81 # Deal with the requests....
82 if ( $request eq "KillWaiting" ) {
83 my $item = $query->param('itemnumber');
85 CancelReserve( 0, $item, $borrowernumber );
91 if ( $request eq "SetWaiting" ) {
92 my $item = $query->param('itemnumber');
93 ModReserveAffect( $item, $borrowernumber );
98 if ( $request eq 'KillReserved' ) {
99 my $biblio = $query->param('biblionumber');
100 CancelReserve( $biblio, 0, $borrowernumber );
105 # set up the branchselect options....
106 my @branchoptionloop;
107 foreach my $br ( keys %$branches ) {
109 $branch{selected} = ( $br eq $tobranchcd );
111 $branch{name} = $branches->{$br}->{'branchname'};
112 push( @branchoptionloop, \%branch );
115 # collect the stack of books already transfered so they can printed...
119 my $barcode = $query->param('barcode');
121 $barcode =~ s/\s*//g;
122 # warn "barcode : $barcode";
126 ( $transfered, $messages, $iteminformation ) =
127 transferbook( $tobranchcd, $barcode, $ignoreRs );
129 # warn "Transfered : $transfered / ".Dumper($messages);
130 $found = $messages->{'ResFound'};
133 my $frbranchcd = C4::Context->userenv->{'branch'};
134 # if ( not($found) ) {
135 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
136 $item{'title'} = $iteminformation->{'title'};
137 $item{'author'} = $iteminformation->{'author'};
138 $item{'itemtype'} = $iteminformation->{'itemtype'};
139 $item{'ccode'} = $iteminformation->{'ccode'};
140 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
141 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
144 $item{barcode} = $barcode;
145 $item{frombrcd} = $frbranchcd;
146 $item{tobrcd} = $tobranchcd;
147 push( @trsfitemloop, \%item );
148 # warn Dumper(@trsfitemloop);
152 foreach ( $query->param ) {
153 (next) unless (/bc-(\d*)/);
156 my $bc = $query->param("bc-$counter");
157 my $frbcd = $query->param("fb-$counter");
158 my $tobcd = $query->param("tb-$counter");
160 $item{counter} = $counter;
161 $item{barcode} = $bc;
162 $item{frombrcd} = $frbcd;
163 $item{tobrcd} = $tobcd;
164 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
165 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
166 $item{'title'} = $iteminformation->{'title'};
167 $item{'author'} = $iteminformation->{'author'};
168 $item{'itemtype'} = $iteminformation->{'itemtype'};
169 $item{'ccode'} = $iteminformation->{'ccode'};
170 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
171 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
172 push( @trsfitemloop, \%item );
178 #####################
181 my $res = $messages->{'ResFound'};
182 $itemnumber = $res->{'itemnumber'};
184 if ( $res->{'ResFound'} eq "Waiting" ) {
187 if ( $res->{'ResFound'} eq "Reserved" ) {
189 $biblionumber = $res->{'biblionumber'};
193 #####################
196 foreach my $code ( keys %$messages ) {
199 if ( $code eq 'BadBarcode' ) {
200 $err{msg} = $messages->{'BadBarcode'};
201 $err{errbadcode} = 1;
204 if ( $code eq 'IsPermanent' ) {
205 $err{errispermanent} = 1;
206 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
208 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
210 if ( $code eq 'WasReturned' ) {
211 $err{errwasreturned} = 1;
213 push( @errmsgloop, \%err );
217 # warn "FINAL ============= ".Dumper(@trsfitemloop);
220 reserved => $reserved,
222 borrowernumber => $borrowernumber,
223 itemnumber => $itemnumber,
225 biblionumber => $biblionumber,
226 tobranchcd => $tobranchcd,
227 reqmessage => $reqmessage,
228 cancelled => $cancelled,
229 setwaiting => $setwaiting,
230 trsfitemloop => \@trsfitemloop,
231 branchoptionloop => \@branchoptionloop,
232 errmsgloop => \@errmsgloop,
233 CircAutocompl => C4::Context->preference("CircAutocompl")
235 output_html_with_http_headers $query, $cookie, $template->output;
239 return $borinfo->{'surname'} . " "
240 . $borinfo->{'title'} . " "
241 . $borinfo->{'firstname'};