Merging changes from rel-1-2 into trunk (circulation module only)
[koha.git] / circ / selectbranchprinter.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use CGI qw/:standard/;
23 use C4::Circulation::Circ2;
24 use C4::Output;
25 use C4::Print;
26 use DBI;
27
28
29 # this is a reorganisation of circulationold.pl
30 # dividing it up into three scripts......
31 # this will be the first one that chooses branch and printer settings....
32
33 #general design stuff...
34 my $headerbackgroundcolor='#99cc33';
35 my $circbackgroundcolor='#ffffcc';
36 my $circbackgroundcolor='white';
37 my $linecolor1='#ffffcc';
38 my $linecolor2='white';
39 my $backgroundimage="/images/background-mem.gif";
40
41 # try to get the branch and printer settings from the http....
42 my %env;
43 my $query=new CGI;
44 my $branches=getbranches(\%env);
45 my $printers=getprinters(\%env);
46 my $branch=$query->param('branch');
47 my $printer=$query->param('printer');
48
49 ($branch) || ($branch=$query->cookie('branch'));
50 ($printer) || ($printer=$query->cookie('printer'));
51
52 ($branches->{$branch}) || ($branch=(keys %$branches)[0]);
53 ($printers->{$printer}) || ($printer=(keys %$printers)[0]);
54
55
56 # is you force a selection....
57 my $oldbranch = $branch;
58 my $oldprinter = $printer;
59
60 $branch='';
61 $printer='';
62
63
64 $env{'branchcode'}=$branch;
65 $env{'printer'}=$printer;
66 $env{'queue'}=$printer;
67
68 # set up select options....
69 my $branchcount=0;
70 my $printercount=0;
71 my $branchoptions;
72 my $printeroptions;
73 foreach (keys %$branches) {
74     (next) unless ($_);
75     (next) unless ($branches->{$_}->{'IS'});
76     $branchcount++;
77     my $selected='';
78     ($selected='selected') if ($_ eq $oldbranch);
79     $branchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
80 }
81 foreach (keys %$printers) {
82     (next) unless ($_);
83     $printercount++;
84     my $selected='';
85     ($selected='selected') if ($_ eq $oldprinter);
86     $printeroptions.="<option value=$_ $selected>$printers->{$_}->{'printername'}\n";
87 }
88
89 # if there is only one....
90
91 if ($printercount==1) {
92     ($printer)=keys %$printers;
93 }
94 if ($branchcount==1) {
95     ($branch)=keys %$branches;
96 }
97
98 # set up printer and branch selection forms....
99 my ($printerform, $branchform);
100 if ($printercount>1) {
101     $printerform=<<"EOF";
102 <select name=printer> $printeroptions </select>
103 EOF
104 } else {
105     my ($printer) = keys %$printers;
106     $printerform.="Printer: ".$printers->{$printer}->{printername};
107
108
109 if ($branchcount>1) {
110     $branchform=<<"EOF";
111 <select name=branch> $branchoptions </select>
112 EOF
113 } else {
114     my ($branch) = keys %$branches;
115     $branchform.= "Branch: ".$branches->{$branch}->{branchname};
116
117
118
119
120 #############################################################################################
121 # Start writing page....
122 # set header with cookie....
123
124 print $query->header();
125
126 print startpage();
127 print startmenu('circulation');
128
129 print << "EOF";
130 <FONT SIZE=6><em>Circulation: Select Printer and Branch Settings</em></FONT><br>
131
132 <center>
133 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
134 <table border=1 cellpadding=5 cellspacing=0>
135 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
136 <font color=black><b>Please Set Branch and Printer</b></font></td></tr>
137 <tr><td>
138 $branchform
139 </td>
140 <td>
141 $printerform
142 </td></tr>
143 </table>
144 <input type="hidden" name="setcookies" value=1>
145 <input type="submit" value="Submit" type="changesettings">
146 </form>
147 </center>
148
149 EOF
150
151
152 print endmenu('circulation');
153 print endpage();
154