Missing "use" statement
[koha.git] / circ / branchtransfers.pl
1 #!/usr/bin/perl
2 # WARNING: This file uses 4-character tabs!
3
4 #written 11/3/2002 by Finlay
5 #script to execute branch transfers of books
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use CGI;
27 use C4::Circulation::Circ2;
28 use C4::Output;
29 use C4::Reserves2;
30 use C4::Auth;
31 use C4::Interface::CGI::Output;
32 use HTML::Template;
33
34 ###############################################
35 # constants
36
37 my %env;
38 my $headerbackgroundcolor='#99cc33';
39 my $circbackgroundcolor='#ffffcc';
40 my $circbackgroundcolor='white';
41 my $linecolor1='#ffffcc';
42 my $linecolor2='white';
43 my $backgroundimage="/images/background-mem.gif";
44
45 my $branches = getbranches();
46 my $printers = getprinters(\%env);
47
48
49 ###############################################
50 #  Getting state
51
52 my $query=new CGI;
53 my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($query);
54
55
56 my $branch = $query->param("branch");
57 my $printer = $query->param("printer");
58
59 ($branch) || ($branch=$query->cookie('branch')) ;
60 ($printer) || ($printer=$query->cookie('printer')) ;
61
62 ($branches->{$branch}) || ($branch=(keys %$branches)[0]);
63 ($printers->{$printer}) || ($printer=(keys %$printers)[0]);
64
65 my $genbrname = $branches->{$branch}->{'branchname'} ;
66 my $genprname = $printers->{$printer}->{'printername'};
67
68 my $messages;
69 my $found;
70 my $reserved;
71 my $waiting;
72 my $reqmessage;
73 my $cancelled;
74 my $setwaiting;
75 my $reqbrchname;
76
77 my $request=$query->param('request');
78 my $borrnum = $query->param('borrowernumber');
79
80 my $tobranchcd=$query->param('tobranchcd');
81 my $frbranchcd='';
82
83 ############
84 # Deal with the requests....
85 if ($request eq "KillWaiting") {
86     my $item = $query->param('itemnumber');
87     CancelReserve(0, $item, $borrnum);
88         $cancelled = 1;
89         $reqmessage =1;
90 }
91
92 my $ignoreRs = 0;
93 if ($request eq "SetWaiting") {
94     my $item = $query->param('itemnumber');
95     $tobranchcd = ReserveWaiting($item, $borrnum);
96         $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
97     $ignoreRs = 1;
98         $setwaiting = 1;
99         $reqmessage =1;
100 }
101 if ($request eq 'KillReserved'){
102     my $biblio = $query->param('biblionumber');
103     CancelReserve($biblio, 0, $borrnum);
104         $cancelled = 1;
105         $reqmessage =1;
106 }
107
108
109
110 # set up the branchselect options....
111 my @branchoptionloop;
112 foreach my $br (keys %$branches) {
113     (next) unless $branches->{$br}->{'CU'};
114     my %branch;
115     $branch{selected}=($br eq $tobranchcd);
116         $branch{code}=$br;
117         $branch{name}=$branches->{$br}->{'branchname'};
118         push (@branchoptionloop, \%branch);
119 }
120
121
122 # collect the stack of books already transfered so they can printed...
123 my @trsfitemloop;
124 my %transfereditems;
125 my %frbranchcds;
126 my %tobranchcds;
127 my $color=$linecolor2;
128
129 my $barcode = $query->param('barcode');
130 if ($barcode) {
131         my $transfered;
132         my $iteminformation;
133         ($transfered, $messages, $iteminformation)
134                         = transferbook($tobranchcd, $barcode, $ignoreRs);
135         $found = $messages->{'ResFound'};
136         if ($transfered) {
137                 my %item;
138                 my $frbranchcd = $iteminformation->{'holdingbranch'};
139                 if (not ($found)) {
140                         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
141                         $item{'color'}=$color;
142                         $item{'biblionumber'}=$iteminformation->{'biblionumber'};
143                         $item{'title'}=$iteminformation->{'title'};
144                         $item{'author'}=$iteminformation->{'author'};
145                         $item{'itemtype'}=$iteminformation->{'itemtype'};
146                         $item{'frbrname'}=$branches->{$frbranchcd}->{'branchname'};
147                         $item{'tobrname'}=$branches->{$tobranchcd}->{'branchname'};
148                 }
149                 $item{counter}=0;
150                 $item{barcode}=$barcode;
151                 $item{frombrcd}=$frbranchcd;
152                 $item{tobrcd}=$tobranchcd;
153 ##########
154 #Are these lines still useful ???
155                 $transfereditems{0}=$barcode;
156                 $frbranchcds{0}=$frbranchcd;
157                 $tobranchcds{0}=$tobranchcd;
158 ##########
159                 push (@trsfitemloop, \%item);
160         }
161 }
162
163 foreach ($query->param){
164         (next) unless (/bc-(\d*)/);
165         my $counter=$1;
166         my %item;
167         my $bc=$query->param("bc-$counter");
168         my $frbcd=$query->param("fb-$counter");
169         my $tobcd=$query->param("tb-$counter");
170         $counter++;
171         $item{counter}=$counter;
172         $item{barcode}=$bc;
173         $item{frombrcd}=$frbcd;
174         $item{tobrcd}=$tobcd;
175         my ($iteminformation) = getiteminformation(\%env, 0, $bc);
176         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
177         $item{'color'}=$color;
178         $item{'biblionumber'}=$iteminformation->{'biblionumber'};
179         $item{'title'}=$iteminformation->{'title'};
180         $item{'author'}=$iteminformation->{'author'};
181         $item{'itemtype'}=$iteminformation->{'itemtype'};
182         $item{'frbrname'}=$branches->{$frbcd}->{'branchname'};
183         $item{'tobrname'}=$branches->{$tobcd}->{'branchname'};
184 ##########
185 #Are these lines still useful ???
186         $transfereditems{$counter}=$bc;
187         $frbranchcds{$counter}=$frbcd;
188         $tobranchcds{$counter}=$tobcd;
189 #########
190         push (@trsfitemloop, \%item);
191 }
192
193
194 my $name;
195 my $bornum;
196 my $borcnum;
197 my $itemnumber;
198 my $biblionum;
199 my $branchname;
200
201
202 #####################
203
204 if ($found) {
205     my $res = $messages->{'ResFound'};
206         $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
207         my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
208         $name = name($borr);
209         $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
210         $borcnum = $borr->{'cardnumber'};
211         $itemnumber = $res->{'itemnumber'};
212
213         if ($res->{'ResFound'} eq "Waiting") {
214                 $waiting = 1;
215         }
216         if ($res->{'ResFound'} eq "Reserved") {
217                 $reserved = 1;
218                 $biblionum = $res->{'biblionumber'};
219         }
220 }
221
222 #####################
223
224 my @errmsgloop;
225 foreach my $code (keys %$messages) {
226         my %err;
227     $err{errbadcode} = ($code eq 'BadBarcode');
228         if ($code eq 'BadBarcode') {
229                 $err{msg}=$messages->{'BadBarcode'};
230         }
231
232     $err{errispermanent} = ($code eq 'IsPermanent');
233     if ($code eq 'IsPermanent'){
234                 $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
235                 # Here, msg contains the branchname
236                 # Not so satisfied with this... But should work
237     }
238     $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
239
240         $err{errwasreturned} = ($code eq 'WasReturned');
241         if ($code eq 'WasReturned') {
242                 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
243                 $name =name($borrowerinfo);
244                 $bornum =$borrowerinfo->{'borrowernumber'};
245                 $borcnum =$borrowerinfo->{'cardnumber'};
246     }
247     if ($code eq 'WasTransfered'){
248 # Put code here if you want to notify the user that item was transfered...
249     }
250         push (@errmsgloop, \%err);
251 }
252
253
254 #######################################################################################
255 # Make the page .....
256 my ($template, $borrowernumber, $cookie)
257     = get_template_and_user({template_name => "circ/branchtransfers.tmpl",
258                                                         query => $query,
259                             type => "intranet",
260                             authnotrequired => 0,
261                             flagsrequired => {parameters => 1},
262                          });
263 $template->param(       genbrname => $genbrname,
264                                                                 genprname => $genprname,
265                                                                 branch => $branch,
266                                                                 printer => $printer,
267                                                                 found => $found,
268                                                                 hdrbckgdcolor => $headerbackgroundcolor,
269                                                                 bckgdimg => $backgroundimage,
270                                                                 reserved => $reserved,
271                                                                 waiting => $waiting,
272                                                                 name => $name,
273                                                                 bornum => $bornum,
274                                                                 borcnum => $borcnum,
275                                                                 branchname => $branchname,
276                                                                 itemnumber => $itemnumber,
277                                                                 barcode => $barcode,
278                                                                 biblionumber => $biblionum,
279                                                                 tobranchcd => $tobranchcd,
280                                                                 reqmessage => $reqmessage,
281                                                                 cancelled => $cancelled,
282                                                                 setwaiting => $setwaiting,
283                                                                 trsfitemloop => \@trsfitemloop,
284                                                                 branchoptionloop => \@branchoptionloop,
285                                                                 errmsgloop => \@errmsgloop
286                                                         );
287 output_html_with_http_headers $query, $sessioncookie, $template->output;
288
289
290 sub name {
291         my ($borinfo) = @_;
292         return $borinfo->{'surname'}." ".$borinfo->{'title'}." ".$borinfo->{'firstname'};
293 }
294
295 # Local Variables:
296 # tab-width: 4
297 # End: