changed the destination branch dropdown to only show branches that have
[koha-equinox.git] / circ / branchtransfers.pl
1 #!/usr/bin/perl
2
3 #written 11/3/2002 by Finlay
4 #script to execute branch transfers of books
5
6 use strict;
7 use CGI;
8 use C4::Circulation::Circ2;
9 use C4::Output;
10
11 ###############################################
12 # constants
13
14 my %env;
15 my $headerbackgroundcolor='#99cc33';
16 my $circbackgroundcolor='#ffffcc';
17 my $circbackgroundcolor='white';
18 my $linecolor1='#ffffcc';
19 my $linecolor2='white';
20 my $backgroundimage="/images/background-mem.gif";
21
22 my $branches=getbranches();
23
24 ###############################################
25 #  Getting state
26
27 my $query=new CGI;
28
29 my $tobranchcd=$query->param('tobranchcd');
30 my $frbranchcd='';
31
32
33 # set up the branchselect options....
34 my $tobranchoptions;
35 foreach my $br (keys %$branches) {
36     (next) unless $branches->{$br}->{'CU'};
37     my $selected='';
38     ($selected='selected') if ($br eq $tobranchcd);
39     $tobranchoptions.="<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
40 }
41
42 # collect the stack of books already transfered so they can printed...
43 my %transfereditems;
44 my $ritext = '';
45 my %frbranchcds;
46 my %tobranchcds;
47 foreach ($query->param){
48     (next) unless (/bc-(\d*)/);
49     my $counter=$1;
50     my $barcode=$query->param("bc-$counter");
51     my $frbcd=$query->param("fb-$counter");
52     my $tobcd=$query->param("tb-$counter");
53     $counter++;
54     $transfereditems{$counter}=$barcode;
55     $frbranchcds{$counter}=$frbcd;
56     $tobranchcds{$counter}=$tobcd;
57     $ritext.="<input type=hidden name=bc-$counter value=$barcode>\n";
58     $ritext.="<input type=hidden name=fb-$counter value=$frbcd>\n";
59     $ritext.="<input type=hidden name=tb-$counter value=$tobcd>\n";
60     }
61
62 # Warnings etc that get displayed at top of next page....
63 my @messages;
64
65 #if the barcode has been entered action that and write a message and onto the top of the stack...
66 my $iteminformation;
67 if (my $barcode=$query->param('barcode')) {
68     my $iteminformation = getiteminformation(\%env,0 ,$barcode);
69     my ($transfered, $message, $iteminformation) = transferbook($tobranchcd, $barcode);
70     if (not $transfered) {
71         push(@messages, $message);
72     }
73     else {
74         my $frbranchcd = $iteminformation->{'holdingbranch'};
75         $ritext.="<input type=hidden name=bc-0 value=$barcode>\n";
76         $ritext.="<input type=hidden name=fb-0 value=$frbranchcd>\n";
77         $ritext.="<input type=hidden name=tb-0 value=$tobranchcd>\n";
78         $transfereditems{0}=$barcode;
79         $frbranchcds{0}=$frbranchcd;
80         $tobranchcds{0}=$tobranchcd;
81         push(@messages, "Book: $barcode has been transfered");
82     }
83 }
84
85 #################################################################################
86 # Html code....
87
88 my $entrytext= << "EOF";
89 <form method=post action=/cgi-bin/koha/circ/branchtransfers.pl>
90 <table border=1 cellpadding=5 cellspacing=0 align=left>
91 <tr><td colspan=2 align=center background=$backgroundimage>
92 <font color=black><b>Select Branch</b></font></td></tr>
93 <tr><td>Destination Branch:</td>
94     <td><select name=tobranchcd> $tobranchoptions </select></td></tr></table>    
95
96 <img src="/images/holder.gif" width=24 height=50 align=left>
97
98 <table border=1 cellpadding=5 cellspacing=0 ><tr>
99 <td colspan=2 align=center background=$backgroundimage>
100 <font color=black><b>Enter Book Barcode</b></font></td></tr>
101 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
102 </table>
103 <input type=hidden name=tobranchcd value=$tobranchcd>
104 $ritext
105 </form>
106 EOF
107
108 my $messagetable;
109 if (@messages) {
110     my $messagetext='';
111     foreach (@messages) {
112         $messagetext.="$_<br>";
113     }
114     $messagetext = substr($messagetext, 0, -4);
115     $messagetable = << "EOF";
116 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
117 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
118 <tr><td> $messagetext </td></tr></table>
119 EOF
120 }
121
122 #######################################################################################
123 # Make the page .....
124
125 print $query->header;
126 print startpage;
127 print startmenu('circulation');
128 print <<"EOF";
129 <p align=right>
130 <FONT SIZE=2  face="arial, helvetica">
131 <a href=circulationold.pl?module=issues>Next Borrower</a> ||
132 <a href=returns.pl>Returns</a> ||
133 <a href=branchtransfers.pl>Transfers</a></font></p><FONT SIZE=6><em>Circulation: Transfers</em></FONT><br>
134 EOF
135
136 print $messagetable;
137
138 print $entrytext;
139
140 if (%transfereditems) {
141     print << "EOF"; 
142 <p>
143 <table border=1 cellpadding=5 cellspacing=0 bgcolor=#dddddd>                                                                
144 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Transfered Items</font></th></tr>
145 <tr><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>From</th><th>To</th></tr>
146 EOF
147     my $color='';
148     foreach (keys %transfereditems) {
149         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
150         my $barcode=$transfereditems{$_};
151         my $frbcd=$frbranchcds{$_};
152         my $tobcd=$tobranchcds{$_};
153         my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
154         print << "EOF";
155 <tr><td bgcolor=$color align=center>
156 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
157 &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
158 <td bgcolor=$color>$iteminformation->{'title'}</td>
159 <td bgcolor=$color>$iteminformation->{'author'}</td>
160 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
161 <td bgcolor=$color align=center>$branches->{$frbcd}->{'branchname'}</td>
162 <td bgcolor=$color align=center>$branches->{$tobcd}->{'branchname'}</td>
163 </tr>\n
164 EOF
165 }
166     print "</table>\n";
167 }
168
169 print endmenu('circulation');
170 print endpage;
171