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