From 4163f24014addb4cc5fddbb854f84617ffffb988 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Tue, 28 Apr 2020 12:02:15 +0200 Subject: [PATCH] Bug 24201: (follow-up) add desk choice with library choice You should be able to add desk choice when you are logging in or changing library. Test plan: 1. apply patch 2. have at least three libraries, one without desk, one with one and one with a few. 3. At login, when choosing a library, it should enable all desks it has. Pick one. 4. the desk id and name should be set in your session and appear in the top right, next to the library name. 5. change library and desks from intranet (at the set-library.pl page) 6. you should have the same behaviours 7. if you have a library without a desk, it should prompt you a '---' option and no desks will be attached to the session. Signed-off-by: Martin Renvoize Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- C4/Auth.pm | 11 ++- Koha/Template/Plugin/Desks.pm | 17 +++- circ/selectdesk.pl | 87 ------------------- circ/set-library.pl | 22 +++++ .../prog/en/includes/circ-nav.inc | 4 - .../intranet-tmpl/prog/en/includes/header.inc | 5 -- .../prog/en/includes/html_helpers.inc | 11 +++ .../prog/en/includes/intranet-bottom.inc | 1 + .../prog/en/includes/js_includes.inc | 3 + .../intranet-tmpl/prog/en/modules/auth.tt | 16 ++++ .../prog/en/modules/circ/circulation-home.tt | 6 -- .../prog/en/modules/circ/set-library.tt | 18 +++- .../intranet-tmpl/prog/js/desk_selection.js | 42 +++++++++ 13 files changed, 137 insertions(+), 106 deletions(-) delete mode 100755 circ/selectdesk.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/js/desk_selection.js diff --git a/C4/Auth.pm b/C4/Auth.pm index 17df921ad2..c5396781e7 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1066,7 +1066,7 @@ sub checkauth { C4::Context->_unset_userenv($sessionID); } my ( $borrowernumber, $firstname, $surname, $userflags, - $branchcode, $branchname, $emailaddress ); + $branchcode, $branchname, $emailaddress, $desk_id, $desk_name ); if ( $return == 1 ) { my $select = " @@ -1110,6 +1110,11 @@ sub checkauth { my $library = Koha::Libraries->find($branchcode); $branchname = $library? $library->branchname: ''; } + if ( $query->param('desk_id') ) { + $desk_id = $query->param('desk_id'); + my $desk = Koha::Desks->find($desk_id); + $desk_name = $desk ? $desk->desk_name : ''; + } my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search }; if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) { @@ -1145,6 +1150,8 @@ sub checkauth { $session->param( 'surname', $surname ); $session->param( 'branch', $branchcode ); $session->param( 'branchname', $branchname ); + $session->param( 'desk_id', $desk_id); + $session->param( 'desk_name', $desk_name); $session->param( 'flags', $userflags ); $session->param( 'emailaddress', $emailaddress ); $session->param( 'ip', $session->remote_addr() ); @@ -1160,7 +1167,7 @@ sub checkauth { $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('shibboleth'), - $session->param('desk_id'), $session->param('desk_name') + $session->param('desk_id'), $session->param('desk_name') ); } diff --git a/Koha/Template/Plugin/Desks.pm b/Koha/Template/Plugin/Desks.pm index 27d0297081..42164976e7 100644 --- a/Koha/Template/Plugin/Desks.pm +++ b/Koha/Template/Plugin/Desks.pm @@ -73,7 +73,7 @@ sub GetLoggedInDeskName { [% Desks.ListForLibrary %] -returns all desks existing at the library +returns all desks existing at the current library =cut @@ -87,4 +87,19 @@ sub ListForLibrary { ); } +=head3 all + +[% Desks.all %] + +returns all desks existing at all libraries + +=cut + + +sub all { + + my ( $self ) = @_; + return Koha::Desks->search( )->unblessed; +} + 1; diff --git a/circ/selectdesk.pl b/circ/selectdesk.pl deleted file mode 100755 index 7589bac5c3..0000000000 --- a/circ/selectdesk.pl +++ /dev/null @@ -1,87 +0,0 @@ -#!/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/circ/set-library.pl b/circ/set-library.pl index 35b013ca33..3fdc0a7700 100755 --- a/circ/set-library.pl +++ b/circ/set-library.pl @@ -26,6 +26,7 @@ use C4::Auth qw/:DEFAULT get_session/; use C4::Koha; use Koha::BiblioFrameworks; use Koha::Libraries; +use Koha::Desks; my $query = CGI->new(); @@ -42,7 +43,9 @@ my $sessionID = $query->cookie("CGISESSID"); my $session = get_session($sessionID); my $branch = $query->param('branch' ); +my $desk_id = $query->param('desk_id'); my $userenv_branch = C4::Context->userenv->{'branch'} || ''; +my $userenv_desk = C4::Context->userenv->{'desk_id'} || ''; my @updated; # $session lddines here are doing the updating @@ -58,8 +61,25 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) { new_branch => $branch, }; } # else branch the same, no update + if ( $desk_id && (!$userenv_desk or $userenv_desk ne $desk_id) ) { + my $desk = Koha::Desks->find( { desk_id => $desk_id } ); + my $old_desk_name = ''; + if ($userenv_desk) { + $old_desk_name = Koha::Desks->find( { desk_id => $userenv_desk })->desk_name; + } + $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 ); + $session->flush(); + push @updated, { + updated_desk => 1, + old_desk => $old_desk_name, + }; + } } else { $branch = $userenv_branch; # fallback value + $desk_id = $userenv_desk; } $template->param(updated => \@updated) if (scalar @updated); @@ -68,6 +88,7 @@ my @recycle_loop; foreach ($query->param()) { $_ or next; # disclude blanks $_ eq "branch" and next; # disclude branch + $_ eq "desk_id" and next; # disclude desk_id $_ eq "oldreferer" and next; # disclude oldreferer push @recycle_loop, { param => $_, @@ -86,6 +107,7 @@ if (scalar @updated and not scalar @recycle_loop) { $template->param( referer => $referer, branch => $branch, + desk_id => $desk_id, recycle_loop=> \@recycle_loop, ); 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 574224cdd6..979871a0b9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc @@ -1,5 +1,4 @@ [% USE Branches %] -[% USE Desks %]