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