c878742820690bf68048cf73a833a42a70cfd6b0
[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 warnings;
22 use CGI;
23
24 use C4::Context;
25 use C4::Output;
26 use C4::Auth;
27 use C4::Print;  # GetPrinters
28 use C4::Koha;
29 use C4::Branch; # GetBranches GetBranchesLoop
30
31 # this will be the script that chooses branch and printer settings....
32
33 my $query = CGI->new();
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user({
35     template_name   => "circ/selectbranchprinter.tmpl",
36     query           => $query,
37     type            => "intranet",
38     debug           => 1,
39     authnotrequired => 0,
40     flagsrequired   => { circulate => "circulate_remaining_permissions" },
41 });
42
43 # try to get the branch and printer settings from http, fallback to userenv
44 my $branches = GetBranches();
45 my $printers = GetPrinters();
46 my $branch   = $query->param('branch' ) || C4::Context->userenv->{'branch'}; 
47 my $printer  = $query->param('printer') || C4::Context->userenv->{'branchprinter'};
48
49 unless ($branches->{$branch}) {
50     $branch = (keys %$branches)[0];  # if branch didn't really exist, then replace it w/ one that does
51 }
52
53 my @printkeys = sort keys %$printers;
54 if (scalar(@printkeys) == 1 or not $printers->{$printer}) {
55     $printer = $printkeys[0];
56 }
57
58 my @printerloop;
59 foreach ( @printkeys ) {
60     next unless ($_); # skip printer if blank.
61     push @printerloop, {
62         selected => ( $_ eq $printer ),
63         name     => $printers->{$_}->{'printername'},
64         value    => $_,
65     };
66 }
67
68 my @recycle_loop;
69 foreach ($query->param()) {
70     /^branch(printer)?$/ and next;  # disclude branch and branchprinter
71     push @recycle_loop, {
72         param => $_,
73         value => $query->param($_),
74     };
75 }
76
77 $template->param(
78     referer     => $ENV{HTTP_REFERER},
79     printerloop => \@printerloop,
80     branchloop  => GetBranchesLoop($branch),
81     recycle_loop=> \@recycle_loop,
82 );
83
84 output_html_with_http_headers $query, $cookie, $template->output;