fixed a little bug with cookies and setting the branch and printer settings.
[koha-equinox.git] / circ / selectbranchprinter.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI qw/:standard/;
5 use C4::Circulation::Circ2;
6 use C4::Output;
7 use C4::Print;
8 use DBI;
9
10
11 # this is a reorganisation of circulationold.pl 
12 # dividing it up into three scripts......
13 # this will be the first one that chooses branch and printer settings....
14
15 #general design stuff...
16 my $headerbackgroundcolor='#99cc33';
17 my $circbackgroundcolor='#ffffcc';
18 my $circbackgroundcolor='white';
19 my $linecolor1='#ffffcc';
20 my $linecolor2='white';
21 my $backgroundimage="/images/background-mem.gif";
22
23 # try to get the branch and printer settings from the http....
24 my %env;
25 my $query=new CGI;
26 my $branches=getbranches(\%env);
27 my $printers=getprinters(\%env);
28 my $branch=$query->param('branch');
29 my $printer=$query->param('printer');
30
31 ($branch) || ($branch=$query->cookie('branch'));
32 ($printer) || ($printer=$query->cookie('printer'));
33
34 # is you force a selection....
35 my $oldbranch = $branch;
36 my $oldprinter = $printer;
37
38 $branch='';
39 $printer='';
40
41
42 $env{'branchcode'}=$branch;
43 $env{'printer'}=$printer;
44 $env{'queue'}=$printer;
45
46 # set up select options....
47 my $branchcount=0;
48 my $printercount=0;
49 my $branchoptions;
50 my $printeroptions;
51 foreach (keys %$branches) {
52     (next) unless ($_);
53     (next) unless ($branches->{$_}->{'IS'});
54     $branchcount++;
55     my $selected='';
56     ($selected='selected') if ($_ eq $oldbranch);
57     $branchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
58 }
59 foreach (keys %$printers) {
60     (next) unless ($_);
61     $printercount++;
62     my $selected='';
63     ($selected='selected') if ($_ eq $oldprinter);
64     $printeroptions.="<option value=$_ $selected>$printers->{$_}->{'printername'}\n";
65 }
66
67 # if there is only one....
68
69 if ($printercount==1) {
70     ($printer)=keys %$printers;
71 }
72 if ($branchcount==1) {
73     ($branch)=keys %$branches;
74 }
75
76 # set up printer and branch selection forms....
77 my ($printerform, $branchform);
78 if ($printercount>1) {
79     $printerform=<<"EOF";
80 <select name=printer> $printeroptions </select>
81 EOF
82 } else {
83     my ($printer) = keys %$printers;
84
85
86 if ($branchcount>1) {
87     $branchform=<<"EOF";
88 <select name=branch> $branchoptions </select>
89 EOF
90 } else {
91     my ($branch) = keys %$branches;
92
93
94
95
96 #############################################################################################
97 # Start writing page....
98 # set header with cookie....
99
100 print $query->header();
101
102 print startpage();
103 print startmenu('circulation');
104
105 print << "EOF";
106 <FONT SIZE=6><em>Circulation: Select Printer and Branch Settings</em></FONT><br>
107
108 <center>
109 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
110 <table border=1 cellpadding=5 cellspacing=0>
111 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
112 <font color=black><b>Please Set Branch and Printer</b></font></td></tr>
113 <tr><td>
114 $branchform
115 </td>
116 <td>
117 $printerform
118 </td></tr>
119 </table>
120 <input type="hidden" name="setcookies" value=1>
121 <input type="submit" value="Submit" type="changesettings">
122 </form>
123 </center>
124
125 EOF
126
127
128 print endmenu('circulation');
129 print endpage();
130