fix number two for bug 1204: Lists of issues and overdues on opac-user.pl
[koha.git] / circ / selectbranchprinter.pl
blobf7173a114819fb05454cf160b420e262725c0bd5
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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.
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.
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
20 use strict;
21 use CGI qw/:standard/;
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
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....
35 #general design stuff...
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');
44 # set header with cookie....
46 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
48 template_name => "circ/selectbranchprinter.tmpl",
49 query => $query,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => { circulate => 1 },
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] );
62 # if you force a selection....
63 my $oldbranch = $branch;
64 my $oldprinter = $printer;
66 # set up select options....
67 my $branchcount = 0;
68 my $printercount = 0;
69 my @branchloop;
70 for my $br (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
71 next unless $br =~ /\S/; # next unless $br is not blank.
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 );
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 );
91 # if there is only one....
92 my $printername;
93 my $branchname;
95 my $oneprinter = ( $printercount == 1 );
96 my $onebranch = ( $branchcount == 1 );
97 if ( $printercount == 1 ) {
98 my ($tmpprinter) = keys %$printers;
99 $printername = $printers->{$tmpprinter}->{printername};
101 if ( $branchcount == 1 ) {
102 my ($tmpbranch) = keys %$branches;
103 $branchname = $branches->{$tmpbranch}->{branchname};
106 ################################################################################
107 # Start writing page....
109 $template->param(
110 oneprinter => $oneprinter,
111 onebranch => $onebranch,
112 printername => $printername,
113 branchname => $branchname,
114 printerloop => \@printerloop,
115 branchloop => \@branchloop,
118 output_html_with_http_headers $query, $cookie, $template->output;