3 #written 11/3/2002 by Finlay
4 #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
26 use C4::Circulation::Circ2;
31 ###############################################
35 my $headerbackgroundcolor='#99cc33';
36 my $circbackgroundcolor='#ffffcc';
37 my $circbackgroundcolor='white';
38 my $linecolor1='#ffffcc';
39 my $linecolor2='white';
40 my $backgroundimage="/images/background-mem.gif";
42 my $branches = getbranches();
43 my $printers = getprinters(\%env);
46 ###############################################
50 my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($query);
53 my $branch = $query->param("branch");
54 my $printer = $query->param("printer");
57 ($branch) || ($branch=$query->cookie('branch')) ;
58 ($printer) || ($printer=$query->cookie('printer')) ;
60 ($branches->{$branch}) || ($branch=(keys %$branches)[0]);
61 ($printers->{$printer}) || ($printer=(keys %$printers)[0]);
63 my $request=$query->param('request');
66 my $tobranchcd=$query->param('tobranchcd');
69 # set up the branchselect options....
71 foreach my $br (keys %$branches) {
72 (next) unless $branches->{$br}->{'CU'};
74 ($selected='selected') if ($br eq $tobranchcd);
75 $tobranchoptions.="<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
78 # collect the stack of books already transfered so they can printed...
83 foreach ($query->param){
84 (next) unless (/bc-(\d*)/);
86 my $barcode=$query->param("bc-$counter");
87 my $frbcd=$query->param("fb-$counter");
88 my $tobcd=$query->param("tb-$counter");
90 $transfereditems{$counter}=$barcode;
91 $frbranchcds{$counter}=$frbcd;
92 $tobranchcds{$counter}=$tobcd;
93 $ritext.="<input type=hidden name=bc-$counter value=$barcode>\n";
94 $ritext.="<input type=hidden name=fb-$counter value=$frbcd>\n";
95 $ritext.="<input type=hidden name=tb-$counter value=$tobcd>\n";
99 # Collect a few messages here...
103 # Deal with the requests....
104 if ($request eq "KillWaiting") {
105 my $item = $query->param('itemnumber');
106 my $borrnum = $query->param('borrowernumber');
107 CancelReserve(0, $item, $borrnum);
108 $messagetext .= "Reserve Cancelled<br>";
111 if ($request eq "SetWaiting") {
112 my $item = $query->param('itemnumber');
113 my $borrnum = $query->param('borrowernumber');
114 $tobranchcd = ReserveWaiting($item, $borrnum);
116 $messagetext .= "Item should now be waiting at branch: $branches->{$tobranchcd}->{'branchname'}<br>";
118 if ($request eq 'KillReserved'){
119 my $biblio = $query->param('biblionumber');
120 my $borrnum = $query->param('borrowernumber');
121 CancelReserve($biblio, 0, $borrnum);
122 $messagetext .= "Reserve Cancelled<br>";
128 # Warnings etc that get displayed at top of next page....
130 # if the barcode has been entered action that and write a message
131 # and put onto the top of the stack...
133 my $barcode = $query->param('barcode');
137 ($transfered, $messages, $iteminformation)
138 = transferbook($tobranchcd, $barcode, $ignoreRs);
140 my $frbranchcd = $iteminformation->{'holdingbranch'};
141 $ritext.="<input type=hidden name=bc-0 value=$barcode>\n";
142 $ritext.="<input type=hidden name=fb-0 value=$frbranchcd>\n";
143 $ritext.="<input type=hidden name=tb-0 value=$tobranchcd>\n";
144 $transfereditems{0}=$barcode;
145 $frbranchcds{0}=$frbranchcd;
146 $tobranchcds{0}=$tobranchcd;
151 #################################################################################
153 # collect together the various elements...
155 my $entrytext= << "EOF";
156 <form method=post action=/cgi-bin/koha/circ/branchtransfers.pl>
157 <table border=1 cellpadding=5 cellspacing=0 align=left>
158 <tr><td colspan=2 align=center background=$backgroundimage>
159 <font color=black><b>Select Branch</b></font></td></tr>
160 <tr><td>Destination Branch:</td>
161 <td><select name=tobranchcd> $tobranchoptions </select></td></tr></table>
163 <img src="/images/holder.gif" width=24 height=50 align=left>
165 <table border=1 cellpadding=5 cellspacing=0 ><tr>
166 <td colspan=2 align=center background=$backgroundimage>
167 <font color=black><b>Enter Book Barcode</b></font></td></tr>
168 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
170 <input type=hidden name=tobranchcd value=$tobranchcd>
177 #####################
179 my $reservefoundtext;
180 if ($messages->{'ResFound'}) {
181 my $res = $messages->{'ResFound'};
183 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
184 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
185 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
186 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
187 if ($res->{'ResFound'} eq "Waiting") {
188 $reservetext = <<"EOF";
189 <font color='red' size='+2'>Item marked Waiting:</font><br>
190 Item is marked waiting at $branchname for $name ($number).<br>
191 <table border=1 cellpadding=5 cellspacing=0>
192 <tr><td>Cancel reservation and then attempt transfer: </td>
194 <form method=post action='branchtransfers.pl'>
196 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
197 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
198 <input type=hidden name=tobranchcd value=$tobranchcd>
199 <input type=hidden name=barcode value=$barcode>
200 <input type=hidden name=request value='KillWaiting'>
201 <input type=submit value="Cancel">
204 <tr><td>Ignore and return to transfers: </td>
206 <form method=post action='branchtransfers.pl'>
208 <input type=hidden name=tobranchcd value=$tobranchcd>
209 <input type=hidden name=barcode value=0>
210 <input type=submit value="Ignore">
215 if ($res->{'ResFound'} eq "Reserved") {
216 $reservetext = <<"EOF";
217 <font color='red' size='+2'>Reserved:</font> reserve found for $name ($number).
218 <table border=1 cellpadding=5 cellspacing=0>
219 <tr><td>Set reserve to waiting and transfer book to <b>$branchname </b>: </td>
221 <form method=post action='branchtransfers.pl'>
223 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
224 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
225 <input type=hidden name=barcode value=$barcode>
226 <input type=hidden name=request value='SetWaiting'>
227 <input type=submit value="Waiting">
230 <tr><td>Cancel reservation and then attempt transfer: </td>
232 <form method=post action='branchtransfers.pl'>
234 <input type=hidden name=biblionumber value=$res->{'biblionumber'}>
235 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
236 <input type=hidden name=tobranchcd value=$tobranchcd>
237 <input type=hidden name=barcode value=$barcode>
238 <input type=hidden name=request value='KillReserved'>
239 <input type=submit value="Cancel">
241 </td></tr><tr><td>Ignore and return to transfers: </td>
243 <form method=post action='branchtransfers.pl'>
244 <input type=hidden name=tobranchcd value=$tobranchcd>
245 <input type=hidden name=barcode value=0>
247 <input type=submit value="Ignore">
252 $reservefoundtext = <<"EOF";
253 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
254 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
255 <tr><td> $reservetext </td></tr></table>
259 #####################
261 foreach my $code (keys %$messages) {
262 if ($code eq 'BadBarcode'){
263 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
265 if ($code eq 'IsPermanent'){
266 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
267 $messagetext .= "<font color='red' size='+2'> Please return item to home branch: $braname </font> <br>";
269 if ($code eq 'DestinationEqualsHolding'){
270 $messagetext .= "<font color='red' size='+2'> Item is already at destination branch. </font> <br>";
272 if ($code eq 'WasReturned') {
273 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
276 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrowerinfo->{'borrowernumber'}
277 onClick="openWindow(this,'Member', 480, 640)">$borrowerinfo->{'cardnumber'}</a>
278 $borrowerinfo->{'surname'}, $borrowerinfo->{'title'} $borrowerinfo->{'firstname'}
280 $messagetext .= "Item was on loan to $binfo and has been returned. <br>";
282 if ($code eq 'WasTransfered'){
283 # Put code here if you want to notify the user that item was transfered...
286 $messagetext = substr($messagetext, 0, -4);
290 $messagetable = << "EOF";
291 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
292 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
293 <tr><td> $messagetext </td></tr></table>
294 <img src="/images/holder.gif" width=24 height=24>
298 #######################################################################################
299 # Make the page .....
301 print $query->header(-cookie=>$sessioncookie);
303 #print startmenu('circulation');
304 my @inp=startmenu('circulation');
306 for (my $i=0;$i<$count;$i++){
307 $inp[$i]=~ s/document.forms\[0\].elements\[0\]/document\.forms\[0\]\.elements\[1\]/;
311 #foreach my $key (%$messages) {
312 # print $key." : ".$messages->{$key}."<br>";
316 <table align=right><tr><td>
317 <a href=circulation.pl>
318 <img src="/images/button-issues.gif" width="99" height="42" border="0" alt="Next Borrower"></a>  
320 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
323 <FONT SIZE=6><em>Circulation: Transfers</em></FONT><br>
324 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
325 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
326 <a href=selectbranchprinter.pl>Change Settings</a>
327 <input type=hidden name=branch value=$branch>
328 <input type=hidden name=printer value=$printer>
332 if ($reservefoundtext) {
333 print $reservefoundtext;
338 if (%transfereditems) {
341 <table border=1 cellpadding=5 cellspacing=0 bgcolor=#dddddd>
342 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Transfered Items</font></th></tr>
343 <tr><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>From</th><th>To</th></tr>
346 foreach (sort keys %transfereditems) {
347 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
348 my $barcode=$transfereditems{$_};
349 my $frbcd=$frbranchcds{$_};
350 my $tobcd=$tobranchcds{$_};
351 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
353 <tr><td bgcolor=$color align=center>
354 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
355 &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
356 <td bgcolor=$color>$iteminformation->{'title'}</td>
357 <td bgcolor=$color>$iteminformation->{'author'}</td>
358 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
359 <td bgcolor=$color align=center>$branches->{$frbcd}->{'branchname'}</td>
360 <td bgcolor=$color align=center>$branches->{$tobcd}->{'branchname'}</td>
368 print endmenu('circulation');