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
30 use C4::Interface::CGI::Output;
31 use C4::Branch; # GetBranches
34 ###############################################
38 my $branches = GetBranches;
39 my $printers = GetPrinters( \%env );
41 ###############################################
46 my $branch = GetBranch( $query, $branches );
47 my $printer = GetPrinter( $query, $printers );
49 my $genbrname = $branches->{$branch}->{'branchname'};
50 my $genprname = $printers->{$printer}->{'printername'};
62 my $request = $query->param('request');
63 my $borrowernumber = $query->param('borrowernumber');
65 my $tobranchcd = $query->param('tobranchcd');
69 # Deal with the requests....
70 if ( $request eq "KillWaiting" ) {
71 my $item = $query->param('itemnumber');
73 CancelReserve( 0, $item, $borrowernumber );
80 if ( $request eq "SetWaiting" ) {
81 my $item = $query->param('itemnumber');
82 $tobranchcd = ReserveWaiting( $item, $borrowernumber );
83 $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
89 if ( $request eq 'KillReserved' ) {
90 my $biblio = $query->param('biblionumber');
91 CancelReserve( $biblio, 0, $borrowernumber );
97 # set up the branchselect options....
99 foreach my $br ( keys %$branches ) {
101 #(next) unless $branches->{$br}->{'CU'}; #FIXME disabled to fix bug 202
103 $branch{selected} = ( $br eq $tobranchcd );
105 $branch{name} = $branches->{$br}->{'branchname'};
106 push( @branchoptionloop, \%branch );
109 # collect the stack of books already transfered so they can printed...
115 my $barcode = $query->param('barcode');
119 ( $transfered, $messages, $iteminformation ) =
120 transferbook( $tobranchcd, $barcode, $ignoreRs );
121 $found = $messages->{'ResFound'};
124 my $frbranchcd = $iteminformation->{'frbranchcd'};
126 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
127 $item{'title'} = $iteminformation->{'title'};
128 $item{'author'} = $iteminformation->{'author'};
129 $item{'itemtype'} = $iteminformation->{'itemtype'};
130 $item{'ccode'} = $iteminformation->{'ccode'};
131 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
132 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
135 $item{barcode} = $barcode;
136 $item{frombrcd} = $frbranchcd;
137 $item{tobrcd} = $tobranchcd;
139 #Are these lines still useful ???
140 $transfereditems{0} = $barcode;
141 $frbranchcds{0} = $frbranchcd;
142 $tobranchcds{0} = $tobranchcd;
144 push( @trsfitemloop, \%item );
148 foreach ( $query->param ) {
149 (next) unless (/bc-(\d*)/);
152 my $bc = $query->param("bc-$counter");
153 my $frbcd = $query->param("fb-$counter");
154 my $tobcd = $query->param("tb-$counter");
156 $item{counter} = $counter;
157 $item{barcode} = $bc;
158 $item{frombrcd} = $frbcd;
159 $item{tobrcd} = $tobcd;
160 my ($iteminformation) = GetBiblioFromItemNumer( 0, $bc );
161 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
162 $item{'title'} = $iteminformation->{'title'};
163 $item{'author'} = $iteminformation->{'author'};
164 $item{'itemtype'} = $iteminformation->{'itemtype'};
165 $item{'ccode'} = $iteminformation->{'ccode'};
166 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
167 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
169 #Are these lines still useful ???
170 $transfereditems{$counter} = $bc;
171 $frbranchcds{$counter} = $frbcd;
172 $tobranchcds{$counter} = $tobcd;
174 push( @trsfitemloop, \%item );
191 #####################
194 my $res = $messages->{'ResFound'};
195 $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
196 my ($borr) = GetMemberDetails( $res->{'borrowernumber'}, 0 );
197 $title = $borr->{'title'};
198 $surname = $borr->{'surname'};
199 $firstname = $borr->{'firstname'};
200 $borrowernumber = $borr->{'borrowernumber'};
201 $borphone = $borr->{'phone'};
202 $borstraddress = $borr->{'streetaddress'};
203 $borcity = $borr->{'city'};
204 $borzip = $borr->{'zipcode'};
205 $boremail = $borr->{'emailadress'};
207 #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
208 $borcnum = $borr->{'cardnumber'};
209 $itemnumber = $res->{'itemnumber'};
211 if ( $res->{'ResFound'} eq "Waiting" ) {
214 if ( $res->{'ResFound'} eq "Reserved" ) {
216 $biblionum = $res->{'biblionumber'};
220 #####################
223 foreach my $code ( keys %$messages ) {
226 if ( $code eq 'BadBarcode' ) {
227 $err{msg} = $messages->{'BadBarcode'};
228 $err{errbadcode} = 1;
232 if ( $code eq 'IsPermanent' ) {
233 $err{errispermanent} = 1;
234 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
236 # Here, msg contains the branchname
237 # Not so satisfied with this... But should work
240 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
242 if ( $code eq 'WasReturned' ) {
243 $err{errwasreturned} = 1;
246 GetMemberDetails( $messages->{'WasReturned'}, 0 );
247 $title = $borrowerinfo->{'title'};
248 $surname = $borrowerinfo->{'surname'};
249 $firstname = $borrowerinfo->{'firstname'};
250 $borrowernumber = $borrowerinfo->{'borrowernumber'};
251 $borcnum = $borrowerinfo->{'cardnumber'};
254 # if ($code eq 'WasTransfered'){
255 # Put code here if you want to notify the user that item was transfered...
256 # $wastransferred = 1;
258 push( @errmsgloop, \%err );
261 #######################################################################################
262 # Make the page .....
263 my ( $template, $cookie );
264 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
266 template_name => "circ/branchtransfers.tmpl",
269 authnotrequired => 0,
270 flagsrequired => { circulate => 1 },
274 $template->param( allmessages => 1 );
278 genbrname => $genbrname,
279 genprname => $genprname,
283 reserved => $reserved,
287 firstname => $firstname,
288 borphone => $borphone,
289 borstraddress => $borstraddress,
292 boremail => $boremail,
293 borrowernumber => $borrowernumber,
295 branchname => $branchname,
296 itemnumber => $itemnumber,
298 biblionumber => $biblionum,
299 tobranchcd => $tobranchcd,
300 reqmessage => $reqmessage,
301 cancelled => $cancelled,
302 setwaiting => $setwaiting,
303 wastransferred => $wastransferred,
304 trsfitemloop => \@trsfitemloop,
305 branchoptionloop => \@branchoptionloop,
306 errmsgloop => \@errmsgloop,
307 intranetcolorstylesheet =>
308 C4::Context->preference("intranetcolorstylesheet"),
309 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
310 IntranetNav => C4::Context->preference("IntranetNav"),
312 output_html_with_http_headers $query, $cookie, $template->output;
316 return $borinfo->{'surname'} . " "
317 . $borinfo->{'title'} . " "
318 . $borinfo->{'firstname'};