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

(-)a/C4/Auth.pm (-7 / +15 lines)
Lines 844-851 sub checkauth { Link Here
844
                $session->param('cardnumber'),   $session->param('firstname'),
844
                $session->param('cardnumber'),   $session->param('firstname'),
845
                $session->param('surname'),      $session->param('branch'),
845
                $session->param('surname'),      $session->param('branch'),
846
                $session->param('branchname'),   $session->param('flags'),
846
                $session->param('branchname'),   $session->param('flags'),
847
                $session->param('emailaddress'),
847
                $session->param('emailaddress'), $session->param('shibboleth'),
848
                $session->param('shibboleth')
848
                $session->param('register_id')
849
            );
849
            );
850
            C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
850
            C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
851
            C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
851
            C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
Lines 1065-1071 sub checkauth { Link Here
1065
                    C4::Context->_unset_userenv($sessionID);
1065
                    C4::Context->_unset_userenv($sessionID);
1066
                }
1066
                }
1067
                my ( $borrowernumber, $firstname, $surname, $userflags,
1067
                my ( $borrowernumber, $firstname, $surname, $userflags,
1068
                    $branchcode, $branchname, $emailaddress );
1068
                    $branchcode, $branchname, $emailaddress, $register_id );
1069
1069
1070
                if ( $return == 1 ) {
1070
                if ( $return == 1 ) {
1071
                    my $select = "
1071
                    my $select = "
Lines 1109-1114 sub checkauth { Link Here
1109
                        my $library = Koha::Libraries->find($branchcode);
1109
                        my $library = Koha::Libraries->find($branchcode);
1110
                        $branchname = $library? $library->branchname: '';
1110
                        $branchname = $library? $library->branchname: '';
1111
                    }
1111
                    }
1112
                    if ( $query->param('register_id') ) {
1113
                        $register_id = $query->param('register_id');
1114
                    }
1112
                    my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
1115
                    my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
1113
                    if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) {
1116
                    if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) {
1114
1117
Lines 1150-1155 sub checkauth { Link Here
1150
                    $session->param( 'lasttime',     time() );
1153
                    $session->param( 'lasttime',     time() );
1151
                    $session->param( 'interface',    $type);
1154
                    $session->param( 'interface',    $type);
1152
                    $session->param( 'shibboleth',   $shibSuccess );
1155
                    $session->param( 'shibboleth',   $shibSuccess );
1156
                    $session->param( 'register_id',  $register_id );
1153
                    $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
1157
                    $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch);
1154
                }
1158
                }
1155
                $session->param('cas_ticket', $cas_ticket) if $cas_ticket;
1159
                $session->param('cas_ticket', $cas_ticket) if $cas_ticket;
Lines 1158-1164 sub checkauth { Link Here
1158
                    $session->param('cardnumber'),   $session->param('firstname'),
1162
                    $session->param('cardnumber'),   $session->param('firstname'),
1159
                    $session->param('surname'),      $session->param('branch'),
1163
                    $session->param('surname'),      $session->param('branch'),
1160
                    $session->param('branchname'),   $session->param('flags'),
1164
                    $session->param('branchname'),   $session->param('flags'),
1161
                    $session->param('emailaddress'), $session->param('shibboleth')
1165
                    $session->param('emailaddress'), $session->param('shibboleth'),
1166
                    $session->param('register_id')
1162
                );
1167
                );
1163
1168
1164
            }
1169
            }
Lines 1435-1441 sub check_api_auth { Link Here
1435
                $session->param('cardnumber'),   $session->param('firstname'),
1440
                $session->param('cardnumber'),   $session->param('firstname'),
1436
                $session->param('surname'),      $session->param('branch'),
1441
                $session->param('surname'),      $session->param('branch'),
1437
                $session->param('branchname'),   $session->param('flags'),
1442
                $session->param('branchname'),   $session->param('flags'),
1438
                $session->param('emailaddress')
1443
                $session->param('emailaddress'), $session->param('shibboleth'),
1444
                $session->param('register_id')
1439
            );
1445
            );
1440
1446
1441
            my $ip       = $session->param('ip');
1447
            my $ip       = $session->param('ip');
Lines 1595-1601 sub check_api_auth { Link Here
1595
                $session->param('cardnumber'),   $session->param('firstname'),
1601
                $session->param('cardnumber'),   $session->param('firstname'),
1596
                $session->param('surname'),      $session->param('branch'),
1602
                $session->param('surname'),      $session->param('branch'),
1597
                $session->param('branchname'),   $session->param('flags'),
1603
                $session->param('branchname'),   $session->param('flags'),
1598
                $session->param('emailaddress')
1604
                $session->param('emailaddress'), $session->param('shibboleth'),
1605
                $session->param('register_id')
1599
            );
1606
            );
1600
            return ( "ok", $cookie, $sessionID );
1607
            return ( "ok", $cookie, $sessionID );
1601
        } else {
1608
        } else {
Lines 1683-1689 sub check_cookie_auth { Link Here
1683
            $session->param('cardnumber'),   $session->param('firstname'),
1690
            $session->param('cardnumber'),   $session->param('firstname'),
1684
            $session->param('surname'),      $session->param('branch'),
1691
            $session->param('surname'),      $session->param('branch'),
1685
            $session->param('branchname'),   $session->param('flags'),
1692
            $session->param('branchname'),   $session->param('flags'),
1686
            $session->param('emailaddress')
1693
            $session->param('emailaddress'), $session->param('shibboleth'),
1694
            $session->param('register_id')
1687
        );
1695
        );
1688
1696
1689
        my $ip       = $session->param('ip');
1697
        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-63 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;
52
        $session->param('branchname', $branchname);         # update sesssion in DB
55
        $session->param('branchname', $branchname);         # update sesssion in DB
53
        $session->param('branch', $branch);                 # update sesssion in DB
56
        $session->param('branch', $branch);                 # update sesssion in DB
54
        $session->flush();
55
        push @updated, {
57
        push @updated, {
56
            updated_branch => 1,
58
            updated_branch => 1,
57
                old_branch => $userenv_branch,
59
                old_branch => $userenv_branch,
58
                new_branch => $branch,
60
                new_branch => $branch,
59
        };
61
        };
60
    } # else branch the same, no update
62
    } # else branch the same, no update
63
    if ( defined($userenv_register_id)
64
        && ( $userenv_register_id ne $register_id ) )
65
    {
66
        my $register = Koha::Cash::Registers->find($register_id);
67
        $template->param(LoginRegisterID   => $register_id);   # update template for new register
68
        $template->param(LoginRegisterName   => $register ? $register->name : '');   # update template for new register
69
        $session->param( 'register_id', $register_id );
70
        push @updated,
71
          {
72
            updated_register => 1,
73
            new_register     => $register ? $register->name : ''
74
          };
75
    }
76
    $session->flush();
61
} else {
77
} else {
62
    $branch = $userenv_branch;  # fallback value
78
    $branch = $userenv_branch;  # fallback value
63
}
79
}
Lines 65-78 if ( $branch and my $library = Koha::Libraries->find($branch) ) { Link Here
65
$template->param(updated => \@updated) if (scalar @updated);
81
$template->param(updated => \@updated) if (scalar @updated);
66
82
67
my @recycle_loop;
83
my @recycle_loop;
68
foreach ($query->param()) {
84
foreach ( $query->param() ) {
69
    $_ or next;                   # disclude blanks
85
    $_ or next;    # disclude blanks
70
    $_ eq "branch"     and next;  # disclude branch
86
    $_ eq "branch"      and next;    # disclude branch
71
    $_ eq "oldreferer" and next;  # disclude oldreferer
87
    $_ eq "register_id" and next;    # disclude register
72
    push @recycle_loop, {
88
    $_ eq "oldreferer"  and next;    # disclude oldreferer
89
    push @recycle_loop,
90
      {
73
        param => $_,
91
        param => $_,
74
        value => scalar $query->param($_),
92
        value => scalar $query->param($_),
75
    };
93
      };
76
}
94
}
77
95
78
my $referer =  $query->param('oldreferer') || $ENV{HTTP_REFERER};
96
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.new_branch or "?" | html %]</li>
42
        <li>Library: [% update.old_branch or "?" | html %] &rArr; [% update.new_branch 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