fix for bug 2488: OPACItemsResultsDisplay/singlebranchmode
[koha.git] / circ / branchtransfers.pl
blob36f4da3e9596340dcdc4bc4ee04f79ae45a4cec0
1 #!/usr/bin/perl
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
14 # version.
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
24 use strict;
25 use CGI;
26 use C4::Circulation;
27 use C4::Output;
28 use C4::Reserves;
29 use C4::Biblio;
30 use C4::Items;
31 use C4::Auth qw/:DEFAULT get_session/;
32 use C4::Branch; # GetBranches
33 use C4::Koha;
34 use C4::Members;
36 ###############################################
37 # Getting state
39 my $query = new CGI;
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");
47 exit;
52 #######################################################################################
53 # Make the page .....
54 my ( $template, $cookie );
55 my $user;
56 ( $template, $user, $cookie ) = get_template_and_user(
58 template_name => "circ/branchtransfers.tmpl",
59 query => $query,
60 type => "intranet",
61 authnotrequired => 0,
62 flagsrequired => { circulate => 1 },
66 my $branches = GetBranches;
67 my $branch = GetBranch( $query, $branches );
69 my $messages;
70 my $found;
71 my $reserved;
72 my $waiting;
73 my $reqmessage;
74 my $cancelled;
75 my $setwaiting;
77 my $request = $query->param('request');
78 my $borrowernumber = $query->param('borrowernumber');
79 my $tobranchcd = $query->param('tobranchcd');
81 ############
82 # Deal with the requests....
83 if ( $request eq "KillWaiting" ) {
84 my $item = $query->param('itemnumber');
86 CancelReserve( 0, $item, $borrowernumber );
87 $cancelled = 1;
88 $reqmessage = 1;
91 my $ignoreRs = 0;
92 if ( $request eq "SetWaiting" ) {
93 my $item = $query->param('itemnumber');
94 ModReserveAffect( $item, $borrowernumber );
95 $ignoreRs = 1;
96 $setwaiting = 1;
97 $reqmessage = 1;
99 if ( $request eq 'KillReserved' ) {
100 my $biblio = $query->param('biblionumber');
101 CancelReserve( $biblio, 0, $borrowernumber );
102 $cancelled = 1;
103 $reqmessage = 1;
106 # set up the branchselect options....
107 my @branchoptionloop;
108 foreach my $br ( keys %$branches ) {
109 my %branch;
110 $branch{selected} = ( $br eq $tobranchcd );
111 $branch{code} = $br;
112 $branch{name} = $branches->{$br}->{'branchname'};
113 push( @branchoptionloop, \%branch );
116 # collect the stack of books already transfered so they can printed...
117 my @trsfitemloop;
118 my %transfereditems;
119 my $transfered;
120 my $barcode = $query->param('barcode');
121 # strip whitespace
122 $barcode =~ s/\s*//g;
123 # warn "barcode : $barcode";
124 if ($barcode) {
126 my $iteminformation;
127 ( $transfered, $messages, $iteminformation ) =
128 transferbook( $tobranchcd, $barcode, $ignoreRs );
129 # use Data::Dumper;
130 # warn "Transfered : $transfered / ".Dumper($messages);
131 $found = $messages->{'ResFound'};
132 if ($transfered) {
133 my %item;
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'};
144 $item{counter} = 0;
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*)/);
155 my $counter = $1;
156 my %item;
157 my $bc = $query->param("bc-$counter");
158 my $frbcd = $query->param("fb-$counter");
159 my $tobcd = $query->param("tb-$counter");
160 $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 );
176 my $itemnumber;
177 my $biblionumber;
179 #####################
181 if ($found) {
182 my $res = $messages->{'ResFound'};
183 $itemnumber = $res->{'itemnumber'};
185 if ( $res->{'ResFound'} eq "Waiting" ) {
186 $waiting = 1;
188 if ( $res->{'ResFound'} eq "Reserved" ) {
189 $reserved = 1;
190 $biblionumber = $res->{'biblionumber'};
194 #####################
196 my @errmsgloop;
197 foreach my $code ( keys %$messages ) {
198 my %err;
200 if ( $code eq 'BadBarcode' ) {
201 $err{msg} = $messages->{'BadBarcode'};
202 $err{errbadcode} = 1;
205 if ( $code eq 'IsPermanent' ) {
206 $err{errispermanent} = 1;
207 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
209 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
211 if ( $code eq 'WasReturned' ) {
212 $err{errwasreturned} = 1;
213 $err{borrowernumber}=$messages->{'WasReturned'};
214 my $borrower = GetMember($messages->{'WasReturned'},'borrowernumber');
215 $err{title}=$borrower->{'title'};
216 $err{firstname}=$borrower->{'firstname'};
217 $err{surname}=$borrower->{'surname'};
218 $err{cardnumber} =$borrower->{'cardnumber'};
220 push( @errmsgloop, \%err );
223 # use Data::Dumper;
224 # warn "FINAL ============= ".Dumper(@trsfitemloop);
225 $template->param(
226 found => $found,
227 reserved => $reserved,
228 waiting => $waiting,
229 borrowernumber => $borrowernumber,
230 itemnumber => $itemnumber,
231 barcode => $barcode,
232 biblionumber => $biblionumber,
233 tobranchcd => $tobranchcd,
234 reqmessage => $reqmessage,
235 cancelled => $cancelled,
236 setwaiting => $setwaiting,
237 trsfitemloop => \@trsfitemloop,
238 branchoptionloop => \@branchoptionloop,
239 errmsgloop => \@errmsgloop,
240 CircAutocompl => C4::Context->preference("CircAutocompl")
242 output_html_with_http_headers $query, $cookie, $template->output;
244 sub name {
245 my ($borinfo) = @_;
246 return $borinfo->{'surname'} . " "
247 . $borinfo->{'title'} . " "
248 . $borinfo->{'firstname'};
251 # Local Variables:
252 # tab-width: 4
253 # End: