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>.
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Auth qw( get_template_and_user get_session haspermission );
26 use Koha::BiblioFrameworks;
27 use Koha::Cash::Registers;
31 my $query = CGI->new();
33 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user({
34 template_name => "circ/set-library.tt",
37 flagsrequired => { catalogue => 1, },
40 my $sessionID = $query->cookie("CGISESSID");
41 my $session = get_session($sessionID);
43 my $op = $query->param('op') || q{};
44 my $branch = $query->param('branch');
45 my $desk_id = $query->param('desk_id');
46 my $register_id = $query->param('register_id');
47 my $userenv_branch = C4::Context->userenv->{'branch'} || '';
48 my $userenv_desk = C4::Context->userenv->{'desk_id'} || '';
49 my $userenv_register_id = C4::Context->userenv->{'register_id'} || '';
52 my $library = Koha::Libraries->find($branch);
53 # $session lines here are doing the updating
55 $op eq 'cud-set-library'
57 && ( C4::Auth::haspermission( C4::Context->userenv->{'id'}, { 'loggedinlibrary' => 1 } )
58 or C4::Context::IsSuperLibrarian() )
61 if ( !$userenv_branch or $userenv_branch ne $branch ) {
62 my $branchname = $library->branchname;
63 $session->param( 'branchname', $branchname ); # update sesssion in DB
64 $session->param( 'branch', $branch ); # update sesssion in DB
68 $branch = $userenv_branch; # fallback value
71 if ( $desk_id && ( !$userenv_desk or $userenv_desk ne $desk_id ) ) {
72 my $desk = Koha::Desks->find( { desk_id => $desk_id } );
73 my $old_desk_name = '';
75 $old_desk_name = Koha::Desks->find( { desk_id => $userenv_desk } )->desk_name;
77 $session->param( desk_name => $desk->desk_name );
78 $session->param( desk_id => $desk->desk_id );
81 $desk_id = $userenv_desk;
84 if ( defined($register_id)
85 && ( $userenv_register_id ne $register_id ) )
87 my $old_register_name = C4::Context->userenv->{'register_name'} || '';
88 my $register = Koha::Cash::Registers->find($register_id);
89 $session->param( 'register_id', $register_id );
90 $session->param( 'register_name', $register ? $register->name : '' );
93 $register_id = $userenv_register_id;
99 my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER} || '';
101 print $query->redirect($referer || '/cgi-bin/koha/mainpage.pl');
110 # Checking if there is a Fast Cataloging Framework
111 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
113 output_html_with_http_headers $query, $cookie, $template->output;