some minor bugfixes, templates improvements & zebra default config file changes
[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::Koha;
27 use C4::Branch; # GetBranches
28
29 # this is a reorganisation of circulationold.pl
30 # dividing it up into three scripts......
31 # this will be the first one that chooses branch and printer settings....
32
33 #general design stuff...
34
35 # try to get the branch and printer settings from the http....
36 my $query    = new CGI;
37 my $branches = GetBranches();
38 my $printers = GetPrinters();
39 my $branch   = $query->param('branch');
40 my $printer  = $query->param('printer');
41
42 my %cookie = $query->cookie('userenv');
43 ($branch)  || ( $branch  = $cookie{'branch'} );
44 ($printer) || ( $printer = $cookie{'printer'} );
45
46 ( $branches->{$branch} )  || ( $branch  = ( keys %$branches )[0] );
47 ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
48
49 # is you force a selection....
50 my $oldbranch  = $branch;
51 my $oldprinter = $printer;
52
53 # set up select options....
54 my $branchcount  = 0;
55 my $printercount = 0;
56 my @branchloop;
57 foreach my $br ( keys %$branches ) {
58     next unless $br =~ /\S/; # next unless $br is not blank.
59
60     $branchcount++;
61     my %branch;
62     $branch{selected} = ( $br eq $oldbranch );
63     $branch{name}     = $branches->{$br}->{'branchname'};
64     $branch{value}    = $br;
65     push( @branchloop, \%branch );
66 }
67 my @printerloop;
68 foreach ( keys %$printers ) {
69     (next) unless ($_); # next unless if this printer is blank.
70     $printercount++;
71     my %printer;
72     $printer{selected} = ( $_ eq $oldprinter );
73     $printer{name}     = $printers->{$_}->{'printername'};
74     $printer{value}    = $_;
75     push( @printerloop, \%printer );
76 }
77
78 # if there is only one....
79 my $printername;
80 my $branchname;
81
82 my $oneprinter = ( $printercount == 1 );
83 my $onebranch  = ( $branchcount == 1 );
84 if ( $printercount == 1 ) {
85     my ($tmpprinter) = keys %$printers;
86     $printername = $printers->{$tmpprinter}->{printername};
87 }
88 if ( $branchcount == 1 ) {
89     my ($tmpbranch) = keys %$branches;
90     $branchname = $branches->{$tmpbranch}->{branchname};
91 }
92
93 ################################################################################
94 # Start writing page....
95 # set header with cookie....
96
97 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
98     {
99         template_name   => "circ/selectbranchprinter.tmpl",
100         query           => $query,
101         type            => "intranet",
102         authnotrequired => 0,
103         flagsrequired   => { circulate => 1 },
104     }
105 );
106 $template->param(
107     oneprinter              => $oneprinter,
108     onebranch               => $onebranch,
109     printername             => $printername,
110     branchname              => $branchname,
111     printerloop             => \@printerloop,
112     branchloop              => \@branchloop,
113     intranetcolorstylesheet =>
114       C4::Context->preference("intranetcolorstylesheet"),
115     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
116     IntranetNav        => C4::Context->preference("IntranetNav"),
117 );
118
119 output_html_with_http_headers $query, $cookie, $template->output;