Bug 13041: Fix add of basket's manager when name contains a single quote
[koha.git] / circ / branchtransfers.pl
blob5aa6cac433d5243b279e50fe34920cdeb35d3a21
1 #!/usr/bin/perl
3 #script to execute branch transfers of books
5 # Copyright 2000-2002 Katipo Communications
6 # copyright 2010 BibLibre
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use strict;
24 use warnings;
25 use CGI qw ( -utf8 );
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;
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");
48 exit;
52 #######################################################################################
53 # Make the page .....
54 my ($template, $user, $cookie) = get_template_and_user(
56 template_name => "circ/branchtransfers.tt",
57 query => $query,
58 type => "intranet",
59 authnotrequired => 0,
60 flagsrequired => { circulate => "circulate_remaining_permissions" },
64 my $branches = GetBranches;
66 my $messages;
67 my $found;
68 my $reserved;
69 my $waiting;
70 my $reqmessage;
71 my $cancelled;
72 my $setwaiting;
74 my $request = $query->param('request') || '';
75 my $borrowernumber = $query->param('borrowernumber') || 0;
76 my $tobranchcd = $query->param('tobranchcd') || '';
78 my $ignoreRs = 0;
79 ############
80 # Deal with the requests....
81 if ( $request eq "KillWaiting" ) {
82 my $item = $query->param('itemnumber');
83 CancelReserve({
84 itemnumber => $item,
85 borrowernumber => $borrowernumber
86 });
87 $cancelled = 1;
88 $reqmessage = 1;
90 elsif ( $request eq "SetWaiting" ) {
91 my $item = $query->param('itemnumber');
92 ModReserveAffect( $item, $borrowernumber );
93 $ignoreRs = 1;
94 $setwaiting = 1;
95 $reqmessage = 1;
97 elsif ( $request eq 'KillReserved' ) {
98 my $biblio = $query->param('biblionumber');
99 CancelReserve({
100 biblionumber => $biblio,
101 borrowernumber => $borrowernumber
103 $cancelled = 1;
104 $reqmessage = 1;
107 # collect the stack of books already transfered so they can printed...
108 my @trsfitemloop;
109 my $transfered;
110 my $barcode = $query->param('barcode');
111 # remove leading/trailing whitespace
112 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
113 # warn "barcode : $barcode";
114 if ($barcode) {
116 my $iteminformation;
117 ( $transfered, $messages, $iteminformation ) =
118 transferbook( $tobranchcd, $barcode, $ignoreRs );
119 # use Data::Dumper;
120 # warn "Transfered : $transfered / ".Dumper($messages);
121 $found = $messages->{'ResFound'};
122 if ($transfered) {
123 my %item;
124 my $frbranchcd = C4::Context->userenv->{'branch'};
125 # if ( not($found) ) {
126 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
127 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
128 $item{'title'} = $iteminformation->{'title'};
129 $item{'author'} = $iteminformation->{'author'};
130 $item{'itemtype'} = $iteminformation->{'itemtype'};
131 $item{'ccode'} = $iteminformation->{'ccode'};
132 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
133 $item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
134 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
135 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
137 $item{counter} = 0;
138 $item{barcode} = $barcode;
139 $item{frombrcd} = $frbranchcd;
140 $item{tobrcd} = $tobranchcd;
141 push( @trsfitemloop, \%item );
142 # warn Dumper(@trsfitemloop);
146 foreach ( $query->param ) {
147 (next) unless (/bc-(\d*)/);
148 my $counter = $1;
149 my %item;
150 my $bc = $query->param("bc-$counter");
151 my $frbcd = $query->param("fb-$counter");
152 my $tobcd = $query->param("tb-$counter");
153 $counter++;
154 $item{counter} = $counter;
155 $item{barcode} = $bc;
156 $item{frombrcd} = $frbcd;
157 $item{tobrcd} = $tobcd;
158 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
159 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
160 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
161 $item{'title'} = $iteminformation->{'title'};
162 $item{'author'} = $iteminformation->{'author'};
163 $item{'itemtype'} = $iteminformation->{'itemtype'};
164 $item{'ccode'} = $iteminformation->{'ccode'};
165 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
166 $item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
167 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
168 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
169 push( @trsfitemloop, \%item );
172 my $itemnumber;
173 my $biblionumber;
175 #####################
177 if ($found) {
178 my $res = $messages->{'ResFound'};
179 $itemnumber = $res->{'itemnumber'};
181 if ( $res->{'ResFound'} eq "Waiting" ) {
182 $waiting = 1;
184 elsif ( $res->{'ResFound'} eq "Reserved" ) {
185 $reserved = 1;
186 $biblionumber = $res->{'biblionumber'};
190 #####################
192 # Used for branch transfer limits error messages.
193 my $codeTypeDescription = 'Collection Code';
194 my $codeType = C4::Context->preference("BranchTransferLimitsType");
195 if ( $codeType eq 'itemtype' ) {
196 $codeTypeDescription = 'Item Type';
199 my @errmsgloop;
200 foreach my $code ( keys %$messages ) {
201 if ( $code ne 'WasTransfered' ) {
202 my %err;
203 if ( $code eq 'BadBarcode' ) {
204 $err{msg} = $messages->{'BadBarcode'};
205 $err{errbadcode} = 1;
207 elsif ( $code eq "NotAllowed" ) {
208 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
209 # Do we really want a error log message here? --atz
210 $err{errnotallowed} = 1;
211 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
212 $err{tbr} = $branches->{ $tbr }->{'branchname'};
213 $err{code} = $typecode;
214 $err{codeType} = $codeTypeDescription;
216 elsif ( $code eq 'IsPermanent' ) {
217 $err{errispermanent} = 1;
218 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
220 elsif ( $code eq 'WasReturned' ) {
221 $err{errwasreturned} = 1;
222 $err{borrowernumber} = $messages->{'WasReturned'};
223 my $borrower = GetMember('borrowernumber'=>$messages->{'WasReturned'});
224 $err{title} = $borrower->{'title'};
225 $err{firstname} = $borrower->{'firstname'};
226 $err{surname} = $borrower->{'surname'};
227 $err{cardnumber} = $borrower->{'cardnumber'};
229 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
230 push( @errmsgloop, \%err );
234 # use Data::Dumper;
235 # warn "FINAL ============= ".Dumper(@trsfitemloop);
236 $template->param(
237 found => $found,
238 reserved => $reserved,
239 waiting => $waiting,
240 borrowernumber => $borrowernumber,
241 itemnumber => $itemnumber,
242 barcode => $barcode,
243 biblionumber => $biblionumber,
244 tobranchcd => $tobranchcd,
245 reqmessage => $reqmessage,
246 cancelled => $cancelled,
247 setwaiting => $setwaiting,
248 trsfitemloop => \@trsfitemloop,
249 branchoptionloop => GetBranchesLoop($tobranchcd),
250 errmsgloop => \@errmsgloop,
251 CircAutocompl => C4::Context->preference("CircAutocompl")
253 output_html_with_http_headers $query, $cookie, $template->output;