Fixed a small problem in the <form>, not hidden inputs are getting passed
[koha.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::Search;
10 use C4::Output;
11
12
13 my %env;
14 my $headerbackgroundcolor='#99cc33';
15 my $circbackgroundcolor='#ffffcc';
16 my $circbackgroundcolor='white';
17 my $linecolor1='#ffffcc';
18 my $linecolor2='white';
19 my $backgroundimage="/images/background-mem.gif";
20
21 my $query=new CGI;
22 my $branches=getbranches(\%env);
23
24 my $tobranchcd=$query->param('tobranchcd');
25 my $frbranchcd='';
26
27 $env{'tobranchcd'}=$tobranchcd;
28
29
30 my $tobranchoptions;
31 foreach (keys %$branches) {
32         (next) unless ($_);
33         (next) if (/^TR$/);
34         my $selected='';
35         ($selected='selected') if ($_ eq $tobranchcd);
36         $tobranchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
37 }
38
39 # collect the stack of books already transfered so they can printed...
40 my @messages;
41 my %transfereditems;
42 my $ritext = '';
43 my %frbranchcds;
44 my %tobranchcds;
45 foreach ($query->param){
46     (next) unless (/bc-(\d*)/);
47     my $counter=$1;
48     my $barcode=$query->param("bc-$counter");
49     my $frbcd=$query->param("fb-$counter");
50     my $tobcd=$query->param("tb-$counter");
51     $counter++;
52     $transfereditems{$counter}=$barcode;
53     $frbranchcds{$counter}=$frbcd;
54     $tobranchcds{$counter}=$tobcd;
55     $ritext.="<input type=hidden name=bc-$counter value=$barcode>\n";
56     $ritext.="<input type=hidden name=fb-$counter value=$frbcd>\n";
57     $ritext.="<input type=hidden name=tb-$counter value=$tobcd>\n";
58     }
59
60 #if the barcode has been entered action that and write a message and onto the top of the stack...
61 my $iteminformation;
62
63 my $todaysdate;
64 if (my $barcode=$query->param('barcode')) {
65     my $iteminformation = getiteminformation(\%env,0, $barcode);
66     my $fail=0;
67     if (not $iteminformation) {
68         $fail=1;
69         @messages = ("There is no book with barcode: $barcode ", @messages);
70     }
71     $frbranchcd = $iteminformation->{'holdingbranch'};
72     %env->{'frbranchcd'} = $frbranchcd;
73     if ($frbranchcd eq $tobranchcd) {
74         $fail=1;
75         @messages = ("You can't transfer the book to the branch it is already at!", @messages);
76     }
77 # should add some more tests ... like is the book already out, maybe it cant be moved....
78     if (not $fail) {
79         my ($transfered, $message) = transferbook(\%env, $iteminformation, $barcode);
80         if (not $transfered) {@messages = ($message, @messages);}
81         else {
82             $ritext.="<input type=hidden name=bc-0 value=$barcode>\n";
83             $ritext.="<input type=hidden name=fb-0 value=$frbranchcd>\n";
84             $ritext.="<input type=hidden name=tb-0 value=$tobranchcd>\n";
85             $transfereditems{0}=$barcode;
86             $frbranchcds{0}=$frbranchcd;
87             $tobranchcds{0}=$tobranchcd;
88             @messages = ("Book: $barcode has been transfered", @messages);
89         }
90     }
91 }
92
93 my $entrytext= << "EOF";
94 <form method=post action=/cgi-bin/koha/circ/branchtransfers.pl>
95 <table border=0 cellpadding=5 cellspacing=0 bgcolor='#dddddd' >
96 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
97 <font color=black><b>Select Branch</b></font></td></tr>
98 <tr><td>Destination Branch:</td>
99     <td><select name=tobranchcd> $tobranchoptions </select></td></tr></table>    
100 <table border=0 cellpadding=5 cellspacing=0 bgcolor='#dddddd' ><tr>
101 <td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
102 <font color=black><b>Enter Book Barcode</b></font></td></tr>
103 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
104 </table>
105 <input type=hidden name=tobranchcd value=$tobranchcd>
106 $ritext
107 </form>
108 EOF
109
110 my $messagetable;
111 if (@messages) {
112     my $messagetext='';
113     foreach (@messages) {
114         $messagetext.="$_<p>\n";
115     }
116     $messagetable = << "EOF";
117 <table border=0 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
118 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Messages</font></th></tr>
119 <tr><td> $messagetext </td></tr></table>
120 EOF
121 }
122
123
124
125 print $query->header;
126 print startpage;
127 print startmenu('circulation');
128 print "<h3>Branch Transfers</h3>";
129
130
131 print $messagetable if (@messages);
132
133
134 print $entrytext;
135
136 if (%transfereditems) {
137     print << "EOF"; 
138 <p>
139 <table border=0 cellpadding=5 cellspacing=0 bgcolor=#dddddd>                                                                
140 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Transfered Items</font></th></tr>
141 <tr><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>From</th><th>To</th></tr>
142 EOF
143     my $color='';
144     foreach (keys %transfereditems) {
145         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
146         my $barcode=$transfereditems{$_};
147         my $frbcd=$frbranchcds{$_};
148         my $tobcd=$tobranchcds{$_};
149         my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
150         print << "EOF";
151 <tr><td bgcolor=$color align=center>
152 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
153 &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
154 <td bgcolor=$color>$iteminformation->{'title'}</td>
155 <td bgcolor=$color>$iteminformation->{'author'}</td>
156 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
157 <td bgcolor=$color align=center>$branches->{$frbcd}->{'branchname'}</td>
158 <td bgcolor=$color align=center>$branches->{$tobcd}->{'branchname'}</td>
159 </tr>\n
160 EOF
161 }
162     print "</table>\n";
163 }
164
165 print endmenu('circulation');
166 print endpage;
167