rel_3_0 moved to HEAD
[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::Circ2;
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 %env;
38 my $query    = new CGI;
39 my $branches = GetBranches();
40 my $printers = GetPrinters( \%env );
41 my $branch   = $query->param('branch');
42 my $printer  = $query->param('printer');
43
44 my %cookie = $query->cookie('userenv');
45 ($branch)  || ( $branch  = $cookie{'branch'} );
46 ($printer) || ( $printer = $cookie{'printer'} );
47
48 ( $branches->{$branch} )  || ( $branch  = ( keys %$branches )[0] );
49 ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
50
51 # is you force a selection....
52 my $oldbranch  = $branch;
53 my $oldprinter = $printer;
54
55 $env{'branchcode'} = $branch;
56 $env{'printer'}    = $printer;
57 $env{'queue'}      = $printer;
58
59 # set up select options....
60 my $branchcount  = 0;
61 my $printercount = 0;
62 my @branchloop;
63 foreach my $br ( keys %$branches ) {
64     next unless $br =~ /\S/; # next unless $br is not blank.
65
66     $branchcount++;
67     my %branch;
68     $branch{selected} = ( $br eq $oldbranch );
69     $branch{name}     = $branches->{$br}->{'branchname'};
70     $branch{value}    = $br;
71     push( @branchloop, \%branch );
72 }
73 my @printerloop;
74 foreach ( keys %$printers ) {
75     (next) unless ($_); # next unless if this printer is blank.
76     $printercount++;
77     my %printer;
78     $printer{selected} = ( $_ eq $oldprinter );
79     $printer{name}     = $printers->{$_}->{'printername'};
80     $printer{value}    = $_;
81     push( @printerloop, \%printer );
82 }
83
84 # if there is only one....
85 my $printername;
86 my $branchname;
87
88 my $oneprinter = ( $printercount == 1 );
89 my $onebranch  = ( $branchcount == 1 );
90 if ( $printercount == 1 ) {
91     my ($tmpprinter) = keys %$printers;
92     $printername = $printers->{$tmpprinter}->{printername};
93 }
94 if ( $branchcount == 1 ) {
95     my ($tmpbranch) = keys %$branches;
96     $branchname = $branches->{$tmpbranch}->{branchname};
97 }
98
99 ################################################################################
100 # Start writing page....
101 # set header with cookie....
102
103 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
104     {
105         template_name   => "circ/selectbranchprinter.tmpl",
106         query           => $query,
107         type            => "intranet",
108         authnotrequired => 0,
109         flagsrequired   => { circulate => 1 },
110     }
111 );
112 $template->param(
113     oneprinter              => $oneprinter,
114     onebranch               => $onebranch,
115     printername             => $printername,
116     branchname              => $branchname,
117     printerloop             => \@printerloop,
118     branchloop              => \@branchloop,
119     intranetcolorstylesheet =>
120       C4::Context->preference("intranetcolorstylesheet"),
121     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
122     IntranetNav        => C4::Context->preference("IntranetNav"),
123 );
124
125 output_html_with_http_headers $query, $cookie, $template->output;