Bug 18782: Remove unused C4::Serials::getsupplierbyserialid
[koha.git] / circ / selectbranchprinter.pl
blob8099a38466893cd1dbb00fca823100c1f33bfdb3
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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use strict;
21 use warnings;
22 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Output;
26 use C4::Auth qw/:DEFAULT get_session/;
27 use C4::Print; # GetPrinters
28 use C4::Koha;
29 use Koha::BiblioFrameworks;
30 use Koha::Libraries;
32 # this will be the script that chooses branch and printer settings....
34 my $query = CGI->new();
36 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user({
37 template_name => "circ/selectbranchprinter.tt",
38 query => $query,
39 type => "intranet",
40 debug => 1,
41 authnotrequired => 0,
42 flagsrequired => { catalogue => 1, },
43 });
45 my $sessionID = $query->cookie("CGISESSID");
46 my $session = get_session($sessionID);
48 # try to get the branch and printer settings from http, fallback to userenv
49 my $printers = GetPrinters();
50 my $branch = $query->param('branch' );
51 my $printer = $query->param('printer');
52 # fallbacks for $branch and $printer after possible session updates
54 my $userenv_branch = C4::Context->userenv->{'branch'} || '';
55 my $userenv_printer = C4::Context->userenv->{'branchprinter'} || '';
56 my @updated;
58 # $session lddines here are doing the updating
59 if ( $branch and my $library = Koha::Libraries->find($branch) ) {
60 if (! $userenv_branch or $userenv_branch ne $branch ) {
61 my $branchname = $library->branchname;
62 $template->param(LoginBranchname => $branchname); # update template for new branch
63 $template->param(LoginBranchcode => $branch); # update template for new branch
64 $session->param('branchname', $branchname); # update sesssion in DB
65 $session->param('branch', $branch); # update sesssion in DB
66 push @updated, {
67 updated_branch => 1,
68 old_branch => $userenv_branch,
70 } # else branch the same, no update
71 } else {
72 $branch = $userenv_branch; # fallback value
75 # FIXME: branchprinter is not retained by session. This feature was not adequately
76 # ported from Koha 2.2.3 where it had been a separate cookie.
77 # So this needs to be fixed for Koha 3 or removed outright.
78 # --atz (w/ info from chris cormack)
80 if ($printer) {
81 if (! $userenv_printer or $userenv_printer ne $printer ) {
82 $session->param('branchprinter', $printer); # update sesssion in DB
83 $template->param('new_printer', $printer); # update template
84 push @updated, {
85 updated_printer => 1,
86 old_printer => $userenv_printer,
88 } # else printer is the same, no update
89 } else {
90 $printer = $userenv_printer; # fallback value
93 $template->param(updated => \@updated) if (scalar @updated);
95 my @printkeys = sort keys %$printers;
96 if (scalar(@printkeys) == 1 or not $printers->{$printer}) {
97 $printer = $printkeys[0]; # if printer didn't really exist, or there is only 1 anyway, then replace it w/ one that does
100 my @printerloop;
101 foreach ( @printkeys ) {
102 next unless ($_); # skip printer if blank.
103 push @printerloop, {
104 selected => ( $_ eq $printer ),
105 name => $printers->{$_}->{'printername'},
106 value => $_,
110 my @recycle_loop;
111 foreach ($query->param()) {
112 $_ or next; # disclude blanks
113 $_ eq "branch" and next; # disclude branch
114 $_ eq "printer" and next; # disclude printer
115 $_ eq "oldreferer" and next; # disclude oldreferer
116 push @recycle_loop, {
117 param => $_,
118 value => scalar $query->param($_),
122 my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER};
123 $referer =~ /selectbranchprinter\.pl/ and undef $referer; # avoid sending them back to this same page.
125 if (scalar @updated and not scalar @recycle_loop) {
126 # we updated something, and there were no extra params to POST: quick redirect
127 print $query->redirect($referer || '/cgi-bin/koha/circ/circulation.pl');
130 $template->param(
131 referer => $referer,
132 printerloop => \@printerloop,
133 branch => $branch,
134 recycle_loop=> \@recycle_loop,
137 # Checking if there is a Fast Cataloging Framework
138 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
140 output_html_with_http_headers $query, $cookie, $template->output;