From 3fc961b7c263a74da4759c70a3acff00eee71ec1 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Tue, 10 Dec 2019 15:02:31 +0100 Subject: [PATCH] Bug 24201: Attach desk to intranet session MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When Desks are defined, a librarian can attach a desk to its session. Test plan: 1. apply 13881 and create some desks 2. you should see “NO DESK SET” in the intranet header 3. go to circulation > Set desk 4. you should see your desk name in the header, whatever the page 5. you can also set desk with the header menu Signed-off-by: Martin Renvoize Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Martin Renvoize Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- C4/Auth.pm | 21 ++- C4/Context.pm | 7 +- Koha/Template/Plugin/Desks.pm | 122 ++++++++++++++++++ circ/selectdesk.pl | 87 +++++++++++++ .../prog/en/includes/circ-nav.inc | 4 + .../intranet-tmpl/prog/en/includes/header.inc | 17 +++ .../prog/en/modules/circ/circulation-home.tt | 6 + .../prog/en/modules/circ/selectdesk.tt | 62 +++++++++ 8 files changed, 317 insertions(+), 9 deletions(-) create mode 100644 Koha/Template/Plugin/Desks.pm create mode 100755 circ/selectdesk.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectdesk.tt diff --git a/C4/Auth.pm b/C4/Auth.pm index 259b6d6063..4585893968 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -38,6 +38,7 @@ use Koha::Checkouts; use Koha::DateUtils qw(dt_from_string); use Koha::Library::Groups; use Koha::Libraries; +use Koha::Desks; use Koha::Patrons; use Koha::Patron::Consents; use POSIX qw/strftime/; @@ -462,6 +463,7 @@ sub get_template_and_user { GoogleJackets => C4::Context->preference("GoogleJackets"), OpenLibraryCovers => C4::Context->preference("OpenLibraryCovers"), KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"), + LoginDeskname => ( C4::Context->userenv ? C4::Context->userenv->{"desk_name"} : undef ), LoginFirstname => ( C4::Context->userenv ? C4::Context->userenv->{"firstname"} : "Bel" ), LoginSurname => C4::Context->userenv ? C4::Context->userenv->{"surname"} : "Inconnu", emailaddress => C4::Context->userenv ? C4::Context->userenv->{"emailaddress"} : undef, @@ -489,6 +491,7 @@ sub get_template_and_user { IntranetNav => C4::Context->preference("IntranetNav"), IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"), LibraryName => C4::Context->preference("LibraryName"), + LoginDeskname => ( C4::Context->userenv ? C4::Context->userenv->{"desk_name"} : undef ), advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), @@ -556,6 +559,7 @@ sub get_template_and_user { opac_name => $opac_name, LibraryName => "" . C4::Context->preference("LibraryName"), LibraryNameTitle => "" . $LibraryNameTitle, + LoginDeskname => C4::Context->userenv ? C4::Context->userenv->{"desk_name"} : "", OPACAmazonCoverImages => C4::Context->preference("OPACAmazonCoverImages"), OPACFRBRizeEditions => C4::Context->preference("OPACFRBRizeEditions"), OpacHighlightedWords => C4::Context->preference("OpacHighlightedWords"), @@ -844,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('desk_id'), $session->param('desk_name') ); C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') ); C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') ); @@ -1158,7 +1162,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('desk_id'), $session->param('desk_name') ); } @@ -1435,7 +1440,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('desk_id'), + $session->param('desk_name') ); my $ip = $session->param('ip'); @@ -1594,8 +1600,8 @@ sub check_api_auth { $session->param('number'), $session->param('id'), $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('desk_id'), $session->param('desk_name') ); return ( "ok", $cookie, $sessionID ); } else { @@ -1683,7 +1689,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('desk_id'), $session->param('desk_name') ); my $ip = $session->param('ip'); diff --git a/C4/Context.pm b/C4/Context.pm index 8c621e8576..e30b2104e4 100644 --- a/C4/Context.pm +++ b/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 + $desk_id, $desk_name); Establish a hash of user environment variables. @@ -818,7 +819,7 @@ set_userenv is called in Auth.pm #' sub set_userenv { shift @_; - my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth)= + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth, $desk_id, $desk_name)= map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here @_; my $var=$context->{"activeuser"} || ''; @@ -831,6 +832,8 @@ sub set_userenv { #possibly a law problem "branch" => $userbranch, "branchname" => $branchname, + "desk_id" => $desk_id, + "desk_name" => $desk_name, "flags" => $userflags, "emailaddress" => $emailaddress, "shibboleth" => $shibboleth, diff --git a/Koha/Template/Plugin/Desks.pm b/Koha/Template/Plugin/Desks.pm new file mode 100644 index 0000000000..99fe2329e3 --- /dev/null +++ b/Koha/Template/Plugin/Desks.pm @@ -0,0 +1,122 @@ +package Koha::Template::Plugin::Desks; + +# Copyright (C) BULAC 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::Desks; + +=head1 NAME + +Koha::Template::Plugin::Desks - A module for dealing with desks in templates + +=head1 DESCRIPTION + +This plugin contains getters functions, to fetch all desks a library +got or the current one. + +=head2 Methods + +=head3 GetName + +[% Desk.GetName(desk_id) %] + +return desk name or empty string + +=cut + +sub GetName { + my ( $self, $desk_id ) = @_; + my $d = Koha::Desks->search( { desk_id => $desk_id} )->unblessed; + return @$d ? $d->{'desk_name'} : q{}; +} + +=head3 GetLoggedInDeskId + +[% Desks.GetLoggedInDeskId %] + +return the desk name that is attached to the session or empty string + +=cut + +sub GetLoggedInDeskId { + my ($self) = @_; + + return C4::Context->userenv ? + C4::Context->userenv->{'desk_id'} : + ''; +} + +=head3 all + +[% Desks.all %] + +returns all desks existing at the library + +=cut + +sub all { + my ( $self, $params ) = @_; + my $selected = $params->{selected}; + my $unfiltered = $params->{unfiltered} || 0; + my $search_params = $params->{search_params} || {}; + + if ( !$unfiltered ) { + $search_params->{only_from_group} = $params->{only_from_group} || 0; + } + + my $desks = $unfiltered + ? Koha::Desks->search( $search_params, { order_by => ['desk_name'] } )->unblessed + : Koha::Desks->search_filtered( $search_params, { order_by => ['desk_name'] } )->unblessed; + + for my $d ( @$desks ) { + if ( defined $selected and $d->{desk_id} eq $selected + or not defined $selected and C4::Context->userenv and $d->{branchcode} eq ( C4::Context->userenv->{desk_id} // q{} ) + ) { + $d->{selected} = 1; + } + } + + return $desks; +} + +=head3 defined + +[% Desks.defined %] + +return 1 if there is at least a desk defined for the library. + +=cut + +sub defined { + my ( $self ) = @_; + my $desks = Koha::Desks->search()->unblessed; + if (@$desks) { + return 1 ; + } + else { + return 0; + } +} + +1; diff --git a/circ/selectdesk.pl b/circ/selectdesk.pl new file mode 100755 index 0000000000..7589bac5c3 --- /dev/null +++ b/circ/selectdesk.pl @@ -0,0 +1,87 @@ +#!/usr/bin/perl + +# Copyright (C) 2020 BULAC +# +# 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 CGI qw ( -utf8 ); + +use C4::Context; +use C4::Output; +use C4::Auth qw/:DEFAULT get_session/; +use C4::Koha; +use Koha::Desks; + +my $query = CGI->new(); + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "circ/selectdesk.tt", + query => $query, + type => "intranet", + debug => 1, + authnotrequired => 0, + flagsrequired => { catalogue => 1, }, + } +); + +my $sessionID = $query->cookie("CGISESSID"); +my $session = get_session($sessionID); + +my $branch = C4::Context->userenv->{'branch'}; +my $searchfield = $query->param('searchfield'); +my $desks_lists; +if ($branch) { + $desks_lists = Koha::Desks->search( { branchcode => $branch } )->unblessed; +} +else { + $desks_lists = Koha::Desks->search( )->unblessed; +} + +my $desk_id = $query->param('desk_id'); + +my $userenv_desk = C4::Context->userenv->{'desk_id'} || ''; +my $updated = ''; + +if ($desk_id) { + if ( !$userenv_desk or $userenv_desk ne $desk_id ) { + my $desk = Koha::Desks->find( { desk_id => $desk_id } ); + $template->param( LoginDeskname => $desk->desk_name ); + $template->param( LoginDeskid => $desk->desk_id ); + $session->param( desk_name => $desk->desk_name ); + $session->param( desk_id => $desk->desk_id ); + $updated = 1; + } +} +else { + $desk_id = $userenv_desk; +} + +$template->param( updated => \$updated ); + +my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER}; +if ($updated) { + print $query->redirect( $referer || '/cgi-bin/koha/mainpage.pl' ); +} + +$template->param( + referer => $referer, + desks_list => $desks_lists, + desk_id => $desk_id, +); + +output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc index 979871a0b9..7360e1f288 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE Desks %]