--- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -848,8 +848,8 @@ sub checkauth { $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), - $session->param('emailaddress'), - $session->param('shibboleth') + $session->param('emailaddress'), $session->param('shibboleth'), + $session->param('register_id') ); C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') ); C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') ); @@ -1069,7 +1069,7 @@ sub checkauth { C4::Context->_unset_userenv($sessionID); } my ( $borrowernumber, $firstname, $surname, $userflags, - $branchcode, $branchname, $emailaddress ); + $branchcode, $branchname, $emailaddress, $register_id ); if ( $return == 1 ) { my $select = " @@ -1113,6 +1113,9 @@ sub checkauth { my $library = Koha::Libraries->find($branchcode); $branchname = $library? $library->branchname: ''; } + if ( $query->param('register_id') ) { + $register_id = $query->param('register_id'); + } my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search }; if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) { @@ -1154,6 +1157,7 @@ sub checkauth { $session->param( 'lasttime', time() ); $session->param( 'interface', $type); $session->param( 'shibboleth', $shibSuccess ); + $session->param( 'register_id', $register_id ); $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); } $session->param('cas_ticket', $cas_ticket) if $cas_ticket; @@ -1162,7 +1166,8 @@ sub checkauth { $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), - $session->param('emailaddress'), $session->param('shibboleth') + $session->param('emailaddress'), $session->param('shibboleth'), + $session->param('register_id') ); } @@ -1440,7 +1445,8 @@ sub check_api_auth { $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), - $session->param('emailaddress') + $session->param('emailaddress'), $session->param('shibboleth'), + $session->param('register_id') ); my $ip = $session->param('ip'); @@ -1600,7 +1606,8 @@ sub check_api_auth { $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), - $session->param('emailaddress') + $session->param('emailaddress'), $session->param('shibboleth'), + $session->param('register_id') ); return ( "ok", $cookie, $sessionID ); } else { @@ -1688,7 +1695,8 @@ sub check_cookie_auth { $session->param('cardnumber'), $session->param('firstname'), $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), - $session->param('emailaddress') + $session->param('emailaddress'), $session->param('shibboleth'), + $session->param('register_id') ); my $ip = $session->param('ip'); --- a/C4/Context.pm +++ a/C4/Context.pm @@ -807,7 +807,8 @@ sub userenv { C4::Context->set_userenv($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, - $emailaddress, $shibboleth); + $emailaddress, $shibboleth, + $register_id); Establish a hash of user environment variables. @@ -818,8 +819,13 @@ set_userenv is called in Auth.pm #' sub set_userenv { shift @_; - my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth)= - map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here + my ( + $usernum, $userid, $usercnum, $userfirstname, + $usersurname, $userbranch, $branchname, $userflags, + $emailaddress, $shibboleth, $register_id + ) + = + map { Encode::is_utf8($_) ? $_ : Encode::decode( 'UTF-8', $_ ) } # CGI::Session doesn't handle utf-8, so we decode it here @_; my $var=$context->{"activeuser"} || ''; my $cell = { @@ -828,12 +834,14 @@ sub set_userenv { "cardnumber" => $usercnum, "firstname" => $userfirstname, "surname" => $usersurname, + #possibly a law problem - "branch" => $userbranch, - "branchname" => $branchname, - "flags" => $userflags, - "emailaddress" => $emailaddress, - "shibboleth" => $shibboleth, + "branch" => $userbranch, + "branchname" => $branchname, + "flags" => $userflags, + "emailaddress" => $emailaddress, + "shibboleth" => $shibboleth, + "register_id" => $register_id, }; $context->{userenv}->{$var} = $cell; return $cell; --- a/Koha/Template/Plugin/Registers.pm +++ a/Koha/Template/Plugin/Registers.pm @@ -0,0 +1,65 @@ +package Koha::Template::Plugin::Registers; + +# Copyright PTFS Europe 2020 + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Template::Plugin; +use base qw( Template::Plugin ); + +use C4::Koha; +use C4::Context; +use Koha::Cash::Registers; + +sub session_register { + my ($self) = @_; + + return C4::Context->userenv ? + C4::Context->userenv->{'register_id'} : + ''; +} + +sub session_register_name { + my ($self) = @_; + + my $register = Koha::Cash::Registers->find($self->session_register); + return $register ? $register->name : ''; +} + +=head2 + + [% SET registers = Registers.all() %] + [% SET registers = Registers.all( { branch => branchcode } ); + +Returns a list of all cash registers available that adhere to the passed filters. + +=cut + +sub all { + my ( $self, $params ) = @_; + + my $registers = Koha::Cash::Registers->search()->unblessed(); + for my $register ( @{$registers} ) { + $register->{selected} = ( defined( $self->session_register ) + && $register->{id} == $self->session_register ) ? 1 : 0; + } + + return $registers; +} + +1; --- a/circ/set-library.pl +++ a/circ/set-library.pl @@ -25,6 +25,7 @@ use C4::Output; use C4::Auth qw/:DEFAULT get_session/; use C4::Koha; use Koha::BiblioFrameworks; +use Koha::Cash::Registers; use Koha::Libraries; my $query = CGI->new(); @@ -41,11 +42,13 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user({ my $sessionID = $query->cookie("CGISESSID"); my $session = get_session($sessionID); -my $branch = $query->param('branch' ); -my $userenv_branch = C4::Context->userenv->{'branch'} || ''; +my $branch = $query->param('branch'); +my $register_id = $query->param('register_id'); +my $userenv_branch = C4::Context->userenv->{'branch'} || ''; +my $userenv_register_id = C4::Context->userenv->{'register_id'} || ''; my @updated; -# $session lddines here are doing the updating +# $session lines here are doing the updating if ( $branch and my $library = Koha::Libraries->find($branch) ) { if (! $userenv_branch or $userenv_branch ne $branch ) { my $branchname = $library->branchname; @@ -53,12 +56,25 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) { $template->param(LoginBranchcode => $branch); # update template for new branch $session->param('branchname', $branchname); # update sesssion in DB $session->param('branch', $branch); # update sesssion in DB - $session->flush(); push @updated, { updated_branch => 1, old_branch => $userenv_branch, }; } # else branch the same, no update + if ( defined($userenv_register_id) + && ( $userenv_register_id ne $register_id ) ) + { + my $register = Koha::Cash::Registers->find($register_id); + $template->param(LoginRegisterID => $register_id); # update template for new register + $template->param(LoginRegisterName => $register ? $register->name : ''); # update template for new register + $session->param( 'register_id', $register_id ); + push @updated, + { + updated_register => 1, + new_register => $register ? $register->name : '' + }; + } + $session->flush(); } else { $branch = $userenv_branch; # fallback value } @@ -66,14 +82,16 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) { $template->param(updated => \@updated) if (scalar @updated); my @recycle_loop; -foreach ($query->param()) { - $_ or next; # disclude blanks - $_ eq "branch" and next; # disclude branch - $_ eq "oldreferer" and next; # disclude oldreferer - push @recycle_loop, { +foreach ( $query->param() ) { + $_ or next; # disclude blanks + $_ eq "branch" and next; # disclude branch + $_ eq "register_id" and next; # disclude register + $_ eq "oldreferer" and next; # disclude oldreferer + push @recycle_loop, + { param => $_, value => scalar $query->param($_), - }; + }; } my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER}; --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -1,5 +1,6 @@ [% USE raw %] [% USE Branches %] +[% USE Registers %] [% USE Koha %]