View | Details | Raw Unified | Return to bug 24786
Collapse All | Expand All

(-)a/C4/Auth.pm (-7 / +15 lines)
Lines 848-855 sub checkauth { Link Here
848
                $session->param('cardnumber'),   $session->param('firstname'),
848
                $session->param('cardnumber'),   $session->param('firstname'),
849
                $session->param('surname'),      $session->param('branch'),
849
                $session->param('surname'),      $session->param('branch'),
850
                $session->param('branchname'),   $session->param('flags'),
850
                $session->param('branchname'),   $session->param('flags'),
851
                $session->param('emailaddress'),
851
                $session->param('emailaddress'), $session->param('shibboleth'),
852
                $session->param('shibboleth')
852
                $session->param('register_id')
853
            );
853
            );
854
            C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
854
            C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
855
            C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
855
            C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
Lines 1069-1075 sub checkauth { Link Here
1069
                    C4::Context->_unset_userenv($sessionID);
1069
                    C4::Context->_unset_userenv($sessionID);
1070
                }
1070
                }
1071
                my ( $borrowernumber, $firstname, $surname, $userflags,
1071
                my ( $borrowernumber, $firstname, $surname, $userflags,
1072
                    $branchcode, $branchname, $emailaddress );
1072
                    $branchcode, $branchname, $emailaddress, $register_id );
1073
1073
1074
                if ( $return == 1 ) {
1074
                if ( $return == 1 ) {
1075
                    my $select = "
1075
                    my $select = "
Lines 1113-1118 sub checkauth { Link Here
1113
                        my $library = Koha::Libraries->find($branchcode);
1113
                        my $library = Koha::Libraries->find($branchcode);
1114
                        $branchname = $library? $library->branchname: '';
1114
                        $branchname = $library? $library->branchname: '';
1115
                    }
1115
                    }
1116
                    if ( $query->param('register_id') ) {
1117
                        $register_id = $query->param('register_id');
1118
                    }
1116
                    my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
1119
                    my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
1117
                    if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) {
1120
                    if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) {
1118
1121
Lines 1154-1159 sub checkauth { Link Here
1154
                    $session->param( 'lasttime',     time() );
1157
                    $session->param( 'lasttime',     time() );
1155
                    $session->param( 'interface',    $type);
1158
                    $session->param( 'interface',    $type);
1156
                    $session->param( 'shibboleth',   $shibSuccess );
1159
                    $session->param( 'shibboleth',   $shibSuccess );
1160
                    $session->param( 'register_id',  $register_id );
1157
                    $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
1161
                    $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
1158
                }
1162
                }
1159
                $session->param('cas_ticket', $cas_ticket) if $cas_ticket;
1163
                $session->param('cas_ticket', $cas_ticket) if $cas_ticket;
Lines 1162-1168 sub checkauth { Link Here
1162
                    $session->param('cardnumber'),   $session->param('firstname'),
1166
                    $session->param('cardnumber'),   $session->param('firstname'),
1163
                    $session->param('surname'),      $session->param('branch'),
1167
                    $session->param('surname'),      $session->param('branch'),
1164
                    $session->param('branchname'),   $session->param('flags'),
1168
                    $session->param('branchname'),   $session->param('flags'),
1165
                    $session->param('emailaddress'), $session->param('shibboleth')
1169
                    $session->param('emailaddress'), $session->param('shibboleth'),
1170
                    $session->param('register_id')
1166
                );
1171
                );
1167
1172
1168
            }
1173
            }
Lines 1440-1446 sub check_api_auth { Link Here
1440
                $session->param('cardnumber'),   $session->param('firstname'),
1445
                $session->param('cardnumber'),   $session->param('firstname'),
1441
                $session->param('surname'),      $session->param('branch'),
1446
                $session->param('surname'),      $session->param('branch'),
1442
                $session->param('branchname'),   $session->param('flags'),
1447
                $session->param('branchname'),   $session->param('flags'),
1443
                $session->param('emailaddress')
1448
                $session->param('emailaddress'), $session->param('shibboleth'),
1449
                $session->param('register_id')
1444
            );
1450
            );
1445
1451
1446
            my $ip       = $session->param('ip');
1452
            my $ip       = $session->param('ip');
Lines 1600-1606 sub check_api_auth { Link Here
1600
                $session->param('cardnumber'),   $session->param('firstname'),
1606
                $session->param('cardnumber'),   $session->param('firstname'),
1601
                $session->param('surname'),      $session->param('branch'),
1607
                $session->param('surname'),      $session->param('branch'),
1602
                $session->param('branchname'),   $session->param('flags'),
1608
                $session->param('branchname'),   $session->param('flags'),
1603
                $session->param('emailaddress')
1609
                $session->param('emailaddress'), $session->param('shibboleth'),
1610
                $session->param('register_id')
1604
            );
1611
            );
1605
            return ( "ok", $cookie, $sessionID );
1612
            return ( "ok", $cookie, $sessionID );
1606
        } else {
1613
        } else {
Lines 1688-1694 sub check_cookie_auth { Link Here
1688
            $session->param('cardnumber'),   $session->param('firstname'),
1695
            $session->param('cardnumber'),   $session->param('firstname'),
1689
            $session->param('surname'),      $session->param('branch'),
1696
            $session->param('surname'),      $session->param('branch'),
1690
            $session->param('branchname'),   $session->param('flags'),
1697
            $session->param('branchname'),   $session->param('flags'),
1691
            $session->param('emailaddress')
1698
            $session->param('emailaddress'), $session->param('shibboleth'),
1699
            $session->param('register_id')
1692
        );
1700
        );
1693
1701
1694
        my $ip       = $session->param('ip');
1702
        my $ip       = $session->param('ip');
(-)a/C4/Context.pm (-8 / +16 lines)
Lines 807-813 sub userenv { Link Here
807
  C4::Context->set_userenv($usernum, $userid, $usercnum,
807
  C4::Context->set_userenv($usernum, $userid, $usercnum,
808
                           $userfirstname, $usersurname,
808
                           $userfirstname, $usersurname,
809
                           $userbranch, $branchname, $userflags,
809
                           $userbranch, $branchname, $userflags,
810
                           $emailaddress, $shibboleth);
810
                           $emailaddress, $shibboleth,
811
                           $register_id);
811
812
812
Establish a hash of user environment variables.
813
Establish a hash of user environment variables.
813
814
Lines 818-825 set_userenv is called in Auth.pm Link Here
818
#'
819
#'
819
sub set_userenv {
820
sub set_userenv {
820
    shift @_;
821
    shift @_;
821
    my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth)=
822
    my (
822
    map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here
823
        $usernum,      $userid,     $usercnum,   $userfirstname,
824
        $usersurname,  $userbranch, $branchname, $userflags,
825
        $emailaddress, $shibboleth, $register_id
826
      )
827
      =
828
      map { Encode::is_utf8($_) ? $_ : Encode::decode( 'UTF-8', $_ ) } # CGI::Session doesn't handle utf-8, so we decode it here
823
    @_;
829
    @_;
824
    my $var=$context->{"activeuser"} || '';
830
    my $var=$context->{"activeuser"} || '';
825
    my $cell = {
831
    my $cell = {
Lines 828-839 sub set_userenv { Link Here
828
        "cardnumber" => $usercnum,
834
        "cardnumber" => $usercnum,
829
        "firstname"  => $userfirstname,
835
        "firstname"  => $userfirstname,
830
        "surname"    => $usersurname,
836
        "surname"    => $usersurname,
837
831
        #possibly a law problem
838
        #possibly a law problem
832
        "branch"     => $userbranch,
839
        "branch"       => $userbranch,
833
        "branchname" => $branchname,
840
        "branchname"   => $branchname,
834
        "flags"      => $userflags,
841
        "flags"        => $userflags,
835
        "emailaddress"     => $emailaddress,
842
        "emailaddress" => $emailaddress,
836
        "shibboleth" => $shibboleth,
843
        "shibboleth"   => $shibboleth,
844
        "register_id"  => $register_id,
837
    };
845
    };
838
    $context->{userenv}->{$var} = $cell;
846
    $context->{userenv}->{$var} = $cell;
839
    return $cell;
847
    return $cell;
(-)a/Koha/Template/Plugin/Registers.pm (+65 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::Registers;
2
3
# Copyright PTFS Europe 2020
4
5
# This file is part of Koha.
6
#
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.
11
#
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.
16
#
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>.
19
20
use Modern::Perl;
21
22
use Template::Plugin;
23
use base qw( Template::Plugin );
24
25
use C4::Koha;
26
use C4::Context;
27
use Koha::Cash::Registers;
28
29
sub session_register {
30
    my ($self) = @_;
31
32
    return C4::Context->userenv ?
33
        C4::Context->userenv->{'register_id'} :
34
        '';
35
}
36
37
sub session_register_name {
38
    my ($self) = @_;
39
40
    my $register = Koha::Cash::Registers->find($self->session_register);
41
    return $register ? $register->name : '';
42
}
43
44
=head2
45
46
    [% SET registers = Registers.all() %]
47
    [% SET registers = Registers.all( { branch => branchcode } );
48
49
Returns a list of all cash registers available that adhere to the passed filters.
50
51
=cut
52
53
sub all {
54
    my ( $self, $params ) = @_;
55
56
    my $registers = Koha::Cash::Registers->search()->unblessed();
57
    for my $register ( @{$registers} ) {
58
        $register->{selected} = ( defined( $self->session_register )
59
              && $register->{id} == $self->session_register ) ? 1 : 0;
60
    }
61
62
    return $registers;
63
}
64
65
1;
(-)a/circ/set-library.pl (-10 / +28 lines)
Lines 25-30 use C4::Output; Link Here
25
use C4::Auth qw/:DEFAULT get_session/;
25
use C4::Auth qw/:DEFAULT get_session/;
26
use C4::Koha;
26
use C4::Koha;
27
use Koha::BiblioFrameworks;
27
use Koha::BiblioFrameworks;
28
use Koha::Cash::Registers;
28
use Koha::Libraries;
29
use Koha::Libraries;
29
30
30
my $query = CGI->new();
31
my $query = CGI->new();
Lines 41-51 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user({ Link Here
41
my $sessionID = $query->cookie("CGISESSID");
42
my $sessionID = $query->cookie("CGISESSID");
42
my $session = get_session($sessionID);
43
my $session = get_session($sessionID);
43
44
44
my $branch   = $query->param('branch' );
45
my $branch              = $query->param('branch');
45
my $userenv_branch  = C4::Context->userenv->{'branch'}        || '';
46
my $register_id         = $query->param('register_id');
47
my $userenv_branch      = C4::Context->userenv->{'branch'} || '';
48
my $userenv_register_id = C4::Context->userenv->{'register_id'} || '';
46
my @updated;
49
my @updated;
47
50
48
# $session lddines here are doing the updating
51
# $session lines here are doing the updating
49
if ( $branch and my $library = Koha::Libraries->find($branch) ) {
52
if ( $branch and my $library = Koha::Libraries->find($branch) ) {
50
    if (! $userenv_branch or $userenv_branch ne $branch ) {
53
    if (! $userenv_branch or $userenv_branch ne $branch ) {
51
        my $branchname = $library->branchname;
54
        my $branchname = $library->branchname;
Lines 53-64 if ( $branch and my $library = Koha::Libraries->find($branch) ) { Link Here
53
        $template->param(LoginBranchcode => $branch);       # update template for new branch
56
        $template->param(LoginBranchcode => $branch);       # update template for new branch
54
        $session->param('branchname', $branchname);         # update sesssion in DB
57
        $session->param('branchname', $branchname);         # update sesssion in DB
55
        $session->param('branch', $branch);                 # update sesssion in DB
58
        $session->param('branch', $branch);                 # update sesssion in DB
56
        $session->flush();
57
        push @updated, {
59
        push @updated, {
58
            updated_branch => 1,
60
            updated_branch => 1,
59
                old_branch => $userenv_branch,
61
                old_branch => $userenv_branch,
60
        };
62
        };
61
    } # else branch the same, no update
63
    } # else branch the same, no update
64
    if ( defined($userenv_register_id)
65
        && ( $userenv_register_id ne $register_id ) )
66
    {
67
        my $register = Koha::Cash::Registers->find($register_id);
68
        $template->param(LoginRegisterID   => $register_id);   # update template for new register
69
        $template->param(LoginRegisterName   => $register ? $register->name : '');   # update template for new register
70
        $session->param( 'register_id', $register_id );
71
        push @updated,
72
          {
73
            updated_register => 1,
74
            new_register     => $register ? $register->name : ''
75
          };
76
    }
77
    $session->flush();
62
} else {
78
} else {
63
    $branch = $userenv_branch;  # fallback value
79
    $branch = $userenv_branch;  # fallback value
64
}
80
}
Lines 66-79 if ( $branch and my $library = Koha::Libraries->find($branch) ) { Link Here
66
$template->param(updated => \@updated) if (scalar @updated);
82
$template->param(updated => \@updated) if (scalar @updated);
67
83
68
my @recycle_loop;
84
my @recycle_loop;
69
foreach ($query->param()) {
85
foreach ( $query->param() ) {
70
    $_ or next;                   # disclude blanks
86
    $_ or next;    # disclude blanks
71
    $_ eq "branch"     and next;  # disclude branch
87
    $_ eq "branch"      and next;    # disclude branch
72
    $_ eq "oldreferer" and next;  # disclude oldreferer
88
    $_ eq "register_id" and next;    # disclude register
73
    push @recycle_loop, {
89
    $_ eq "oldreferer"  and next;    # disclude oldreferer
90
    push @recycle_loop,
91
      {
74
        param => $_,
92
        param => $_,
75
        value => scalar $query->param($_),
93
        value => scalar $query->param($_),
76
    };
94
      };
77
}
95
}
78
96
79
my $referer =  $query->param('oldreferer') || $ENV{HTTP_REFERER};
97
my $referer =  $query->param('oldreferer') || $ENV{HTTP_REFERER};
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc (+12 lines)
Lines 1-5 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Branches %]
2
[% USE Branches %]
3
[% USE Registers %]
3
[% USE Koha %]
4
[% USE Koha %]
4
<nav class="navbar">
5
<nav class="navbar">
5
    <div class="navbar-header">
6
    <div class="navbar-header">
Lines 85-90 Link Here
85
                                <span class="logged-in-branch-code content_hidden">[% Branches.GetLoggedInBranchcode | html %]</span>
86
                                <span class="logged-in-branch-code content_hidden">[% Branches.GetLoggedInBranchcode | html %]</span>
86
                            </strong>
87
                            </strong>
87
                        [% END %]
88
                        [% END %]
89
                        [% IF Koha.Preference('UseCashRegisters') %]
90
                            <span class="separator">|</span>
91
                            <strong>
92
                                [% IF ( Registers.session_register_name == '' ) %]
93
                                    <span class="logged-in-desk-name">REGISTER NOT SET</span>
94
                                [% ELSE %]
95
                                    <span class="logged-in-desk-name">[% Registers.session_register_name | html %]</span>
96
                                    <span class="logged-in-desk-id content_hidden">[% Registers.session_register | html %]</span>
97
                                [% END %]
98
                            </strong>
99
                        [% END %]
88
                    </span>
100
                    </span>
89
                    <b class="caret"></b>
101
                    <b class="caret"></b>
90
                </a>
102
                </a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc (+16 lines)
Lines 8-13 Link Here
8
    [% END %]
8
    [% END %]
9
[% END %]
9
[% END %]
10
10
11
[% BLOCK options_for_registers %]
12
    <!-- <option hidden disabled selected value> -- select an option -- </option> -->
13
    <option id="noregister" value="">-- None --</option>
14
    [% FOREACH r IN registers %]
15
        [% IF r.branch == branch %]
16
            [% IF r.selected %]
17
                <option class="[% r.branch | html %] [% IF r.branch_default %]default[% END %]" value="[% r.id | html %]" selected="selected">[% r.name | html %]</option>
18
            [% ELSE %]
19
                <option class="[% r.branch | html %] [% IF r.branch_default %]default[% END %]" value="[% r.id | html %]">[% r.name | html %]</option>
20
            [% END%]
21
        [% ELSE %]
22
            <option class="[% r.branch | html %] [% IF r.branch_default %]default[% END %]" value="[% r.id | html %]" disabled hidden>[% r.name | html %]</option>
23
        [% END %]
24
    [% END %]
25
[% END %]
26
11
[% BLOCK options_for_authorised_value_categories %]
27
[% BLOCK options_for_authorised_value_categories %]
12
    [% FOREACH avc IN authorised_value_categories %]
28
    [% FOREACH avc IN authorised_value_categories %]
13
        [% IF avc.selected %]
29
        [% IF avc.selected %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt (-2 / +56 lines)
Lines 1-5 Link Here
1
[% USE Branches %]
1
[% USE Branches %]
2
[% USE Registers %]
2
[% USE Koha %]
3
[% USE Koha %]
4
[% SET footerjs = 1 %]
3
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Circulation &rsaquo; Set library</title>
6
<title>Koha &rsaquo; Circulation &rsaquo; Set library</title>
5
[% INCLUDE 'doc-head-close.inc' %]
7
[% INCLUDE 'doc-head-close.inc' %]
Lines 35-42 Link Here
35
<h2>Update succeeded</h2>
37
<h2>Update succeeded</h2>
36
Updated:<ul>
38
Updated:<ul>
37
    [% FOREACH update IN updated %]
39
    [% FOREACH update IN updated %]
38
    [% IF ( update.updated_branch ) %]
40
    [% IF ( update.updated_branch || update.updated_register ) %]
41
        [% IF ( updated.updated.branch ) %]
39
        <li>Library: [% update.old_branch or "?" | html %] &rArr; [% update.LoginBranchcode or "?" | html %]</li>
42
        <li>Library: [% update.old_branch or "?" | html %] &rArr; [% update.LoginBranchcode or "?" | html %]</li>
43
        [% END %]
44
        [% IF ( updated.updated_register ) %]
45
        <li>Register: [% updated.new_register | html %]</li>
46
        [% END %]
40
    [% ELSE %]
47
    [% ELSE %]
41
        <li>ERROR - unknown</li>
48
        <li>ERROR - unknown</li>
42
    [% END %]
49
    [% END %]
Lines 67-72 Updated:<ul> Link Here
67
    [% END %]
74
    [% END %]
68
    </ol>
75
    </ol>
69
</fieldset>
76
</fieldset>
77
78
[% IF Koha.Preference('UseCashRegisters') %]
79
<fieldset class="rows">
80
    <legend>Set cash register</legend>
81
    <ol>
82
        <li>
83
            <label for="register_id">Choose cash register:</label>
84
            <select name="register_id" id="register_id">
85
                [% PROCESS options_for_registers registers => Registers.all() %]
86
            </select>
87
        </li>
88
    </ol>
89
</fieldset>
90
[% END %]
91
70
<fieldset class="action">
92
<fieldset class="action">
71
    <input type="submit" value="Submit" />
93
    <input type="submit" value="Submit" />
72
    <a class="cancel" id="cancel_set_library" href="[% referer or '/cgi-bin/koha/circ/circulation.pl' %]">Cancel</a>
94
    <a class="cancel" id="cancel_set_library" href="[% referer or '/cgi-bin/koha/circ/circulation.pl' %]">Cancel</a>
Lines 95-98 Updated:<ul> Link Here
95
        </div> <!-- /.col-sm-12 -->
117
        </div> <!-- /.col-sm-12 -->
96
    </div> <!-- /.row -->
118
    </div> <!-- /.row -->
97
119
120
[% MACRO jsinclude BLOCK %]
121
<script>
122
    $(document).ready(function() {
123
        $("#branch").on("change", function() {
124
            var selectedBranch = $("#branch").children(
125
                    "option:selected").val();
126
127
            $("#register_id").children().each(function() {
128
                // default to no-register
129
                if ($(this).is("#noregister")) {
130
                    $(this).prop("selected", true)
131
                }
132
                // display branch registers
133
                else if ($(this).hasClass(selectedBranch)) {
134
                    $(this).prop("disabled", false);
135
                    $(this).show();
136
                    // default to branch default if there is one
137
                    if ($(this).hasClass("default")) {
138
                        $(this).prop("selected", true)
139
                    }
140
                }
141
                // hide non-branch registers
142
                else
143
                {
144
                    $(this).hide();
145
                    $(this).prop("disabled", true);
146
                }
147
            });
148
        });
149
    });
150
</script>
151
[% END %]
152
98
[% INCLUDE 'intranet-bottom.inc' %]
153
[% INCLUDE 'intranet-bottom.inc' %]
99
- 

Return to bug 24786