some fixes, and links to themelang/images
[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 use C4::Koha;
34
35 ###############################################
36 # constants
37
38 my %env;
39 my $linecolor1='#ffffcc';
40 my $linecolor2='white';
41
42 my $branches = getbranches();
43 my $printers = getprinters(\%env);
44
45
46 ###############################################
47 #  Getting state
48
49 my $query=new CGI;
50
51
52 my $branch = getbranch($query, $branches);
53 my $printer = getprinter($query, $printers);
54
55 my $genbrname = $branches->{$branch}->{'branchname'} ;
56 my $genprname = $printers->{$printer}->{'printername'};
57
58 my $messages;
59 my $found;
60 my $reserved;
61 my $waiting;
62 my $reqmessage;
63 my $cancelled;
64 my $setwaiting;
65 my $reqbrchname;
66
67 my $request=$query->param('request');
68 my $borrnum = $query->param('borrowernumber');
69
70 my $tobranchcd=$query->param('tobranchcd');
71 my $frbranchcd='';
72
73 ############
74 # Deal with the requests....
75 if ($request eq "KillWaiting") {
76     my $item = $query->param('itemnumber');
77     CancelReserve(0, $item, $borrnum);
78         $cancelled = 1;
79         $reqmessage =1;
80 }
81
82 my $ignoreRs = 0;
83 if ($request eq "SetWaiting") {
84     my $item = $query->param('itemnumber');
85     $tobranchcd = ReserveWaiting($item, $borrnum);
86         $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
87     $ignoreRs = 1;
88         $setwaiting = 1;
89         $reqmessage =1;
90 }
91 if ($request eq 'KillReserved'){
92     my $biblio = $query->param('biblionumber');
93     CancelReserve($biblio, 0, $borrnum);
94         $cancelled = 1;
95         $reqmessage =1;
96 }
97
98
99
100 # set up the branchselect options....
101 my @branchoptionloop;
102 foreach my $br (keys %$branches) {
103     #(next) unless $branches->{$br}->{'CU'}; #FIXME disabled to fix bug 202
104     my %branch;
105     $branch{selected}=($br eq $tobranchcd);
106         $branch{code}=$br;
107         $branch{name}=$branches->{$br}->{'branchname'};
108         push (@branchoptionloop, \%branch);
109 }
110
111
112 # collect the stack of books already transfered so they can printed...
113 my @trsfitemloop;
114 my %transfereditems;
115 my %frbranchcds;
116 my %tobranchcds;
117 my $color=$linecolor2;
118
119 my $barcode = $query->param('barcode');
120 if ($barcode) {
121         my $transfered;
122         my $iteminformation;
123         ($transfered, $messages, $iteminformation)
124                         = transferbook($tobranchcd, $barcode, $ignoreRs);
125         $found = $messages->{'ResFound'};
126         if ($transfered) {
127                 my %item;
128                 my $frbranchcd = $iteminformation->{'holdingbranch'};
129                 if (not ($found)) {
130                         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
131                         $item{'color'}=$color;
132                         $item{'biblionumber'}=$iteminformation->{'biblionumber'};
133                         $item{'title'}=$iteminformation->{'title'};
134                         $item{'author'}=$iteminformation->{'author'};
135                         $item{'itemtype'}=$iteminformation->{'itemtype'};
136                         $item{'frbrname'}=$branches->{$frbranchcd}->{'branchname'};
137                         $item{'tobrname'}=$branches->{$tobranchcd}->{'branchname'};
138                 }
139                 $item{counter}=0;
140                 $item{barcode}=$barcode;
141                 $item{frombrcd}=$frbranchcd;
142                 $item{tobrcd}=$tobranchcd;
143 ##########
144 #Are these lines still useful ???
145                 $transfereditems{0}=$barcode;
146                 $frbranchcds{0}=$frbranchcd;
147                 $tobranchcds{0}=$tobranchcd;
148 ##########
149                 push (@trsfitemloop, \%item);
150         }
151 }
152
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) = getiteminformation(\%env, 0, $bc);
166         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
167         $item{'color'}=$color;
168         $item{'biblionumber'}=$iteminformation->{'biblionumber'};
169         $item{'title'}=$iteminformation->{'title'};
170         $item{'author'}=$iteminformation->{'author'};
171         $item{'itemtype'}=$iteminformation->{'itemtype'};
172         $item{'frbrname'}=$branches->{$frbcd}->{'branchname'};
173         $item{'tobrname'}=$branches->{$tobcd}->{'branchname'};
174 ##########
175 #Are these lines still useful ???
176         $transfereditems{$counter}=$bc;
177         $frbranchcds{$counter}=$frbcd;
178         $tobranchcds{$counter}=$tobcd;
179 #########
180         push (@trsfitemloop, \%item);
181 }
182
183
184 my $name;
185 my $bornum;
186 my $borcnum;
187 my $itemnumber;
188 my $biblionum;
189 my $branchname;
190
191
192 #####################
193
194 if ($found) {
195     my $res = $messages->{'ResFound'};
196         $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
197         my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
198         $name = name($borr);
199         $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
200         $borcnum = $borr->{'cardnumber'};
201         $itemnumber = $res->{'itemnumber'};
202
203         if ($res->{'ResFound'} eq "Waiting") {
204                 $waiting = 1;
205         }
206         if ($res->{'ResFound'} eq "Reserved") {
207                 $reserved = 1;
208                 $biblionum = $res->{'biblionumber'};
209         }
210 }
211
212 #####################
213
214 my @errmsgloop;
215 foreach my $code (keys %$messages) {
216         my %err;
217     $err{errbadcode} = ($code eq 'BadBarcode');
218         if ($code eq 'BadBarcode') {
219                 $err{msg}=$messages->{'BadBarcode'};
220         }
221
222     $err{errispermanent} = ($code eq 'IsPermanent');
223     if ($code eq 'IsPermanent'){
224                 $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
225                 # Here, msg contains the branchname
226                 # Not so satisfied with this... But should work
227     }
228     $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
229
230         $err{errwasreturned} = ($code eq 'WasReturned');
231         if ($code eq 'WasReturned') {
232                 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
233                 $name =name($borrowerinfo);
234                 $bornum =$borrowerinfo->{'borrowernumber'};
235                 $borcnum =$borrowerinfo->{'cardnumber'};
236     }
237     if ($code eq 'WasTransfered'){
238 # Put code here if you want to notify the user that item was transfered...
239     }
240         push (@errmsgloop, \%err);
241 }
242
243
244 #######################################################################################
245 # Make the page .....
246 my ($template, $borrowernumber, $cookie)
247     = get_template_and_user({template_name => "circ/branchtransfers.tmpl",
248                                                         query => $query,
249                             type => "intranet",
250                             authnotrequired => 0,
251                             flagsrequired => {circulate => 1},
252                          });
253 $template->param(       genbrname => $genbrname,
254                                                                 genprname => $genprname,
255                                                                 branch => $branch,
256                                                                 printer => $printer,
257                                                                 found => $found,
258                                                                 reserved => $reserved,
259                                                                 waiting => $waiting,
260                                                                 name => $name,
261                                                                 bornum => $bornum,
262                                                                 borcnum => $borcnum,
263                                                                 branchname => $branchname,
264                                                                 itemnumber => $itemnumber,
265                                                                 barcode => $barcode,
266                                                                 biblionumber => $biblionum,
267                                                                 tobranchcd => $tobranchcd,
268                                                                 reqmessage => $reqmessage,
269                                                                 cancelled => $cancelled,
270                                                                 setwaiting => $setwaiting,
271                                                                 trsfitemloop => \@trsfitemloop,
272                                                                 branchoptionloop => \@branchoptionloop,
273                                                                 errmsgloop => \@errmsgloop
274                                                         );
275 output_html_with_http_headers $query, $cookie, $template->output;
276
277
278 sub name {
279         my ($borinfo) = @_;
280         return $borinfo->{'surname'}." ".$borinfo->{'title'}." ".$borinfo->{'firstname'};
281 }
282
283 # Local Variables:
284 # tab-width: 4
285 # End: