Finalized XML version for intranet
[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 use C4::Koha;
32
33
34 # this is a reorganisation of circulationold.pl
35 # dividing it up into three scripts......
36 # this will be the first one that chooses branch and printer settings....
37
38 #general design stuff...
39 my $headerbackgroundcolor='#99cc33';
40 my $circbackgroundcolor='#ffffcc';
41 my $circbackgroundcolor='white';
42 my $linecolor1='#ffffcc';
43 my $linecolor2='white';
44 my $backgroundimage="/images/background-mem.gif";
45
46 # try to get the branch and printer settings from the http....
47 my %env;
48 my $query=new CGI;
49 my $branches=GetBranches('IS');
50 my $printers=getprinters(\%env);
51 my $branch=$query->param('branch');
52 my $printer=$query->param('printer');
53
54 ($branch) || ($branch=$query->cookie('branch'));
55 ($printer) || ($printer=$query->cookie('printer'));
56
57 ($branches->{$branch}) || ($branch=(keys %$branches)[0]);
58 ($printers->{$printer}) || ($printer=(keys %$printers)[0]);
59
60
61 # is you force a selection....
62 my $oldbranch = $branch;
63 my $oldprinter = $printer;
64
65 #$branch='';
66 #$printer='';
67
68
69 $env{'branchcode'}=$branch;
70 $env{'printer'}=$printer;
71 $env{'queue'}=$printer;
72
73 # set up select options....
74 my $branchcount=0;
75 my $printercount=0;
76 my @branchloop;
77 foreach my $br (keys %$branches) {
78     next unless $br =~ /\S/;
79     #(next) unless ($branches->{$_}->{'IS'}); # FIXME disabled to fix bug 202
80     $branchcount++;
81         my %branch;
82         $branch{selected}=($br eq $oldbranch);
83         $branch{name}=$branches->{$br}->{'branchname'};
84         $branch{value}=$br;
85     push(@branchloop,\%branch);
86 }
87 my @printerloop;
88 foreach (keys %$printers) {
89     (next) unless ($_);
90     $printercount++;
91         my %printer;
92         $printer{selected}=($_ eq $oldprinter);
93         $printer{name}=$printers->{$_}->{'printername'};
94         $printer{value}=$_;
95     push(@printerloop,\%printer);
96 }
97
98 # if there is only one....
99 my $printername;
100 my $branchname;
101
102 my $oneprinter=($printercount==1) ;
103 my $onebranch=($branchcount==1) ;
104 if ($printercount==1) {
105     my ($tmpprinter)=keys %$printers;
106         $printername=$printers->{$tmpprinter}->{printername};
107 }
108 if ($branchcount==1) {
109     my ($tmpbranch)=keys %$branches;
110         $branchname=$branches->{$tmpbranch}->{branchname};
111 }
112
113
114 #############################################################################################
115 # Start writing page....
116 # set header with cookie....
117
118 my ($template, $borrowernumber, $cookie)
119     = get_template_and_user({template_name => "circ/selectbranchprinter.tmpl",
120                                                         query => $query,
121                             type => "intranet",
122                             authnotrequired => 0,
123                             flagsrequired => {circulate => 1},
124                          });
125 $template->param(headerbackgroundcolor => $headerbackgroundcolor,
126                                                         backgroundimage => $backgroundimage,
127                                                         oneprinter => $oneprinter,
128                                                         onebranch => $onebranch,
129                                                         printername => $printername,
130                                                         branchname => $branchname,
131                                                         printerloop => \@printerloop,
132                                                         branchloop => \@branchloop,
133                                                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
134                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
135                 IntranetNav => C4::Context->preference("IntranetNav"),
136                                                         );
137
138 my $branchcookie=$query->cookie(-name => 'branch', -value => "$branch", -expires => '+1y');
139 my $printercookie=$query->cookie(-name => 'printer', -value => "$printer", -expires => '+1y');
140
141 my $cookies=[$cookie,$branchcookie, $printercookie]; 
142 output_html_with_http_headers $query, $cookies, $template->output;
143
144
145 # Local Variables:
146 # tab-width: 4
147 # End: