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