From 77f3a83b4e51a7419e108e876075655618f45358 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=UTF-8 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 --- C4/Auth.pm | 21 ++++-- C4/Context.pm | 7 +- Koha/Template/Plugin/Desks.pm | 79 ++++++++++++++++++++ circ/selectdesk.pl | 87 ++++++++++++++++++++++ .../intranet-tmpl/prog/en/includes/header.inc | 15 ++++ .../prog/en/modules/circ/circulation-home.tt | 6 ++ .../prog/en/modules/circ/selectdesk.tt | 66 ++++++++++++++++ 7 files changed, 274 insertions(+), 7 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 a882880..6c534e2 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/; @@ -461,6 +462,7 @@ sub get_template_and_user { OpenLibraryCovers => C4::Context->preference("OpenLibraryCovers"), KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"), LoginBranchcode => ( C4::Context->userenv ? C4::Context->userenv->{"branch"} : undef ), + 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 { IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"), LibraryName => C4::Context->preference("LibraryName"), LoginBranchname => ( C4::Context->userenv ? C4::Context->userenv->{"branchname"} : undef ), + 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"), @@ -558,6 +561,7 @@ sub get_template_and_user { LibraryName => "" . C4::Context->preference("LibraryName"), LibraryNameTitle => "" . $LibraryNameTitle, LoginBranchname => C4::Context->userenv ? C4::Context->userenv->{"branchname"} : "", + LoginDeskname => C4::Context->userenv ? C4::Context->userenv->{"desk_name"} : "", OPACAmazonCoverImages => C4::Context->preference("OPACAmazonCoverImages"), OPACFRBRizeEditions => C4::Context->preference("OPACFRBRizeEditions"), OpacHighlightedWords => C4::Context->preference("OpacHighlightedWords"), @@ -850,7 +854,8 @@ sub checkauth { $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('branchprinter'), - $session->param('shibboleth') + $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') ); @@ -1167,7 +1172,8 @@ sub checkauth { $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('branchprinter'), - $session->param('shibboleth') + $session->param('shibboleth'), $session->param('desk_id'), + $session->param('desk_name'), ); } @@ -1434,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('branchprinter') + $session->param('emailaddress'), $session->param('branchprinter'), + $session->param('desk_id'), $session->param('desk_name'), ); my $ip = $session->param('ip'); @@ -1595,7 +1602,9 @@ 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('branchprinter') + $session->param('emailaddress'), $session->param('branchprinter'), + $session->param('shibboleth'), $session->param('desk_id'), + $session->param('desk_name'), ); return ( "ok", $cookie, $sessionID ); } else { @@ -1683,7 +1692,9 @@ 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('branchprinter') + $session->param('emailaddress'), $session->param('branchprinter'), + $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 0fe571d..0f18156 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -856,7 +856,8 @@ sub userenv { C4::Context->set_userenv($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, - $emailaddress, $branchprinter, $shibboleth); + $emailaddress, $branchprinter, $shibboleth + $desk_id, $desk_name); Establish a hash of user environment variables. @@ -867,7 +868,7 @@ set_userenv is called in Auth.pm #' sub set_userenv { shift @_; - my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $shibboleth)= + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $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"} || ''; @@ -880,6 +881,8 @@ sub set_userenv { #possibly a law problem "branch" => $userbranch, "branchname" => $branchname, + "desk_id" => $desk_id, + "desk_name" => $desk_name, "flags" => $userflags, "emailaddress" => $emailaddress, "branchprinter" => $branchprinter, diff --git a/Koha/Template/Plugin/Desks.pm b/Koha/Template/Plugin/Desks.pm new file mode 100644 index 0000000..75c1d4f --- /dev/null +++ b/Koha/Template/Plugin/Desks.pm @@ -0,0 +1,79 @@ +package Koha::Template::Plugin::Desks; + +# Copyright BULAC 2019 + +# 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; + +sub GetName { + my ( $self, $desk_id ) = @_; + my $d = Koha::Desks->search( { desk_id => $desk_id} )->unblessed; + return @$d ? $d->{'desk_name'} : q{}; +} + +sub GetLoggedInDeskId { + my ($self) = @_; + + return C4::Context->userenv ? + C4::Context->userenv->{'desk_id'} : + ''; +} + +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; +} + +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 0000000..4ac52f6 --- /dev/null +++ b/circ/selectdesk.pl @@ -0,0 +1,87 @@ +#!/usr/bin/perl + +# Copyright 2019 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 2 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +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 = $query->param('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/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc index 460fd83..107fcab 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -1,5 +1,6 @@ [% USE raw %] [% USE Branches %] +[% USE Desks %] [% USE Koha %]