Bug 26922: Regression tests
[koha.git] / circ / set-library.pl
blobb460b15466ca9f3a38b5e42d445568ce4eaa940e
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 Modern::Perl;
21 use CGI qw ( -utf8 );
23 use C4::Context;
24 use C4::Output;
25 use C4::Auth qw/:DEFAULT get_session/;
26 use C4::Koha;
27 use Koha::BiblioFrameworks;
28 use Koha::Cash::Registers;
29 use Koha::Libraries;
30 use Koha::Desks;
32 my $query = CGI->new();
34 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user({
35 template_name => "circ/set-library.tt",
36 query => $query,
37 type => "intranet",
38 debug => 1,
39 flagsrequired => { catalogue => 1, },
40 });
42 my $sessionID = $query->cookie("CGISESSID");
43 my $session = get_session($sessionID);
45 my $branch = $query->param('branch');
46 my $desk_id = $query->param('desk_id');
47 my $register_id = $query->param('register_id');
48 my $userenv_branch = C4::Context->userenv->{'branch'} || '';
49 my $userenv_desk = C4::Context->userenv->{'desk_id'} || '';
50 my $userenv_register_id = C4::Context->userenv->{'register_id'} || '';
51 my @updated;
53 # $session lines here are doing the updating
54 if ( $branch and my $library = Koha::Libraries->find($branch) ) {
55 if (! $userenv_branch or $userenv_branch ne $branch ) {
56 my $branchname = $library->branchname;
57 $session->param('branchname', $branchname); # update sesssion in DB
58 $session->param('branch', $branch); # update sesssion in DB
59 push @updated, {
60 updated_branch => 1,
61 old_branch => $userenv_branch,
62 new_branch => $branch,
64 } # else branch the same, no update
65 if ( $desk_id && (!$userenv_desk or $userenv_desk ne $desk_id) ) {
66 my $desk = Koha::Desks->find( { desk_id => $desk_id } );
67 my $old_desk_name = '';
68 if ($userenv_desk) {
69 $old_desk_name = Koha::Desks->find( { desk_id => $userenv_desk })->desk_name;
71 $template->param( LoginDeskname => $desk->desk_name );
72 $template->param( LoginDeskid => $desk->desk_id );
73 $session->param( desk_name => $desk->desk_name );
74 $session->param( desk_id => $desk->desk_id );
75 $session->flush();
76 push @updated, {
77 updated_desk => 1,
78 old_desk => $old_desk_name,
81 if ( defined($userenv_register_id)
82 && ( $userenv_register_id ne $register_id ) )
84 my $old_register_name = C4::Context->userenv->{'register_name'} || '';
85 my $register = Koha::Cash::Registers->find($register_id);
86 $session->param( 'register_id', $register_id );
87 $session->param( 'register_name', $register ? $register->name : '' );
88 push @updated,
90 updated_register => 1,
91 old_register => $old_register_name
94 $session->flush();
95 } else {
96 $branch = $userenv_branch; # fallback value
97 $desk_id = $userenv_desk;
100 $template->param(updated => \@updated) if (scalar @updated);
102 my @recycle_loop;
103 foreach ($query->param()) {
104 $_ or next; # disclude blanks
105 $_ eq "branch" and next; # disclude branch
106 $_ eq "desk_id" and next; # disclude desk_id
107 $_ eq "register_id" and next; # disclude register
108 $_ eq "oldreferer" and next; # disclude oldreferer
109 push @recycle_loop, {
110 param => $_,
111 value => scalar $query->param($_),
115 my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER};
116 $referer =~ /set-library\.pl/ and undef $referer; # avoid sending them back to this same page.
118 if (scalar @updated and not scalar @recycle_loop) {
119 # we updated something, and there were no extra params to POST: quick redirect
120 print $query->redirect($referer || '/cgi-bin/koha/circ/circulation.pl');
123 $template->param(
124 referer => $referer,
125 branch => $branch,
126 desk_id => $desk_id,
127 recycle_loop=> \@recycle_loop,
130 # Checking if there is a Fast Cataloging Framework
131 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
133 output_html_with_http_headers $query, $cookie, $template->output;