Make sure flagsrequired is *circulate* not parameters
[koha.git] / circ / selectbranchprinter.pl
1 #!/usr/bin/perl
2 # WARNING: This file uses 4-character tabs!
3
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use CGI qw/:standard/;
24 use C4::Circulation::Circ2;
25 use C4::Output;
26 use C4::Auth;
27 use C4::Print;
28 use C4::Interface::CGI::Output;
29 use HTML::Template;
30 use DBI;
31
32
33 # this is a reorganisation of circulationold.pl
34 # dividing it up into three scripts......
35 # this will be the first one that chooses branch and printer settings....
36
37 #general design stuff...
38 my $headerbackgroundcolor='#99cc33';
39 my $circbackgroundcolor='#ffffcc';
40 my $circbackgroundcolor='white';
41 my $linecolor1='#ffffcc';
42 my $linecolor2='white';
43 my $backgroundimage="/images/background-mem.gif";
44
45 # try to get the branch and printer settings from the http....
46 my %env;
47 my $query=new CGI;
48 my $branches=getbranches(\%env);
49 my $printers=getprinters(\%env);
50 my $branch=$query->param('branch');
51 my $printer=$query->param('printer');
52
53 ($branch) || ($branch=$query->cookie('branch'));
54 ($printer) || ($printer=$query->cookie('printer'));
55
56 ($branches->{$branch}) || ($branch=(keys %$branches)[0]);
57 ($printers->{$printer}) || ($printer=(keys %$printers)[0]);
58
59
60 # is you force a selection....
61 my $oldbranch = $branch;
62 my $oldprinter = $printer;
63
64 $branch='';
65 $printer='';
66
67
68 $env{'branchcode'}=$branch;
69 $env{'printer'}=$printer;
70 $env{'queue'}=$printer;
71
72 # set up select options....
73 my $branchcount=0;
74 my $printercount=0;
75 my @branchloop;
76 foreach my $br (keys %$branches) {
77     next unless $br =~ /\S/;
78     #(next) unless ($branches->{$_}->{'IS'}); # FIXME disabled to fix bug 202
79     $branchcount++;
80         my %branch;
81         $branch{selected}=($br eq $oldbranch);
82         $branch{name}=$branches->{$br}->{'branchname'};
83         $branch{value}=$br;
84     push(@branchloop,\%branch);
85 }
86 my @printerloop;
87 foreach (keys %$printers) {
88     (next) unless ($_);
89     $printercount++;
90         my %printer;
91         $printer{selected}=($_ eq $oldprinter);
92         $printer{name}=$printers->{$_}->{'printername'};
93         $printer{value}=$_;
94     push(@printerloop,\%printer);
95 }
96
97 # if there is only one....
98 my $printername;
99 my $branchname;
100
101 my $oneprinter=($printercount==1) ;
102 my $onebranch=($branchcount==1) ;
103 if ($printercount==1) {
104     ($printer)=keys %$printers;
105         $printername=$printers->{$printer}->{printername};
106 }
107 if ($branchcount==1) {
108     ($branch)=keys %$branches;
109         $branchname=$branches->{$branch}->{branchname};
110 }
111
112
113 #############################################################################################
114 # Start writing page....
115 # set header with cookie....
116
117 my ($template, $borrowernumber, $cookie)
118     = get_template_and_user({template_name => "circ/selectbranchprinter.tmpl",
119                                                         query => $query,
120                             type => "intranet",
121                             authnotrequired => 0,
122                             flagsrequired => {circulate => 1},
123                          });
124 $template->param(headerbackgroundcolor => $headerbackgroundcolor,
125                                                         backgroundimage => $backgroundimage,
126                                                         oneprinter => $oneprinter,
127                                                         onebranch => $onebranch,
128                                                         printername => $printername,
129                                                         branchname => $branchname,
130                                                         printerloop => \@printerloop,
131                                                         branchloop => \@branchloop
132                                                         );
133
134 output_html_with_http_headers $query, $cookie, $template->output;
135
136
137 # Local Variables:
138 # tab-width: 4
139 # End: