Completely new. This file handles the issues, and sets branch and printer
[koha.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     $branchcount++;
54     my $selected='';
55     ($selected='selected') if ($_ eq $oldbranch);
56     $branchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
57 }
58 foreach (keys %$printers) {
59     (next) unless ($_);
60     $printercount++;
61     my $selected='';
62     ($selected='selected') if ($_ eq $oldprinter);
63     $printeroptions.="<option value=$_ $selected>$printers->{$_}->{'printername'}\n";
64 }
65
66 # if there is only one....
67
68 if ($printercount==1) {
69     ($printer)=keys %$printers;
70 }
71 if ($branchcount==1) {
72     ($branch)=keys %$branches;
73 }
74
75 # set up printer and branch selection forms....
76 my ($printerform, $branchform);
77 if ($printercount>1) {
78     $printerform=<<"EOF";
79 <select name=printer> $printeroptions </select>
80 EOF
81 } else {
82     my ($printer) = keys %$printers;
83
84
85 if ($branchcount>1) {
86     $branchform=<<"EOF";
87 <select name=branch> $branchoptions </select>
88 EOF
89 } else {
90     my ($branch) = keys %$branches;
91
92
93
94
95 #############################################################################################
96 # Start writing page....
97 # set header with cookie....
98
99 print $query->header();
100
101 print startpage();
102 print startmenu('circulation');
103
104 print << "EOF";
105 <FONT SIZE=6><em>Circulation: Select Printer and Branch Settings</em></FONT><br>
106
107 <center>
108 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
109 <table border=1 cellpadding=5 cellspacing=0>
110 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
111 <font color=black><b>Please Set Branch and Printer</b></font></td></tr>
112 <tr><td>
113 $branchform
114 </td>
115 <td>
116 $printerform
117 </td></tr>
118 </table>
119 <input type="submit" value="Change Settings" type="changesettings">
120 </form>
121 </center>
122
123 EOF
124
125
126 print endmenu('circulation');
127 print endpage();
128