From fe0135295cf73580bdf7da1fd948e33f4573fb00 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Thu, 4 Jun 2015 11:41:15 +0200 Subject: [PATCH] Bug 13881: Select desk in an intranet session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the selected Desk appears in the header. The desk can be selecting in the menu beside username, branchname. Test plan : 1/ Go to the intranet administration, remove all desks if you have any. The desks should not appear in the header. 2/ add some desks in administration, without selecting some. The message « NO DESK SET » should appear at the left of the branchname. 3/ set a desk for your session. The desk deskcode should appear beside the branchname. 4/ change desk, the new name should appear also. --- C4/Auth.pm | 50 +++++++++-- C4/Context.pm | 7 +- circ/selectdesk.pl | 92 ++++++++++++++++++++ .../intranet-tmpl/prog/en/includes/header.inc | 14 +++ .../prog/en/modules/circ/selectdesk.tt | 50 +++++++++++ 5 files changed, 204 insertions(+), 9 deletions(-) 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 544bf7e..75caa08 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -29,6 +29,7 @@ use C4::Context; use C4::Templates; # to get the template use C4::Languages; use C4::Branch; # GetBranches +use C4::Desks; use C4::Search::History; use Koha; use Koha::AuthUtils qw(hash_password); @@ -390,6 +391,21 @@ sub get_template_and_user { marcflavour => C4::Context->preference("marcflavour"), persona => C4::Context->preference("persona"), ); + if (C4::Context->userenv->{"branch"}) { + my $desksaref = GetDesks(C4::Context->userenv->{"branch"}); + if ($#$desksaref > -1) { + $template->param( + LoginDeskcode => ( C4::Context->userenv ? C4::Context->userenv->{"deskcode"} : undef ), + LoginDeskname => ( C4::Context->userenv ? C4::Context->userenv->{"deskname"} : undef ), + HasDesk => (1), + ); + } + else { + $template->param( + HasDesk => (undef), + ); + } + } if ( $in->{'type'} eq "intranet" ) { $template->param( AmazonCoverImages => C4::Context->preference("AmazonCoverImages"), @@ -403,6 +419,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->{"deskname"} : undef ), advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), @@ -475,6 +492,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->{"deskname"} : "", OPACAmazonCoverImages => C4::Context->preference("OPACAmazonCoverImages"), OPACFRBRizeEditions => C4::Context->preference("OPACFRBRizeEditions"), OpacHighlightedWords => C4::Context->preference("OpacHighlightedWords"), @@ -765,7 +783,8 @@ sub checkauth { $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('branchprinter'), - $session->param('persona'), $session->param('shibboleth') + $session->param('persona'), $session->param('shibboleth'), + $session->param('deskcode'), $session->param('deskname') ); C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') ); C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') ); @@ -989,7 +1008,8 @@ sub checkauth { C4::Context->_unset_userenv($sessionID); } my ( $borrowernumber, $firstname, $surname, $userflags, - $branchcode, $branchname, $branchprinter, $emailaddress ); + $branchcode, $branchname, $branchprinter, $emailaddress, + $deskcode, $deskname); if ( $return == 1 ) { my $select = " @@ -1065,6 +1085,8 @@ sub checkauth { $session->param( 'surname', $surname ); $session->param( 'branch', $branchcode ); $session->param( 'branchname', $branchname ); + $session->param( 'deskcode', $deskcode ); + $session->param( 'deskname', $deskname ); $session->param( 'flags', $userflags ); $session->param( 'emailaddress', $emailaddress ); $session->param( 'ip', $session->remote_addr() ); @@ -1083,6 +1105,8 @@ sub checkauth { $session->param( 'surname', C4::Context->config('user') ); $session->param( 'branch', 'NO_LIBRARY_SET' ); $session->param( 'branchname', 'NO_LIBRARY_SET' ); + $session->param( 'deskcode', 'NO_DESK_SET' ); + $session->param( 'deskname', 'NO_DESK_SET' ); $session->param( 'flags', 1 ); $session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); $session->param( 'ip', $session->remote_addr() ); @@ -1097,7 +1121,8 @@ sub checkauth { $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('branchprinter'), - $session->param('persona'), $session->param('shibboleth') + $session->param('persona'), $session->param('shibboleth'), + $session->param('deskcode'), $session->param('deskname') ); } @@ -1346,7 +1371,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('persona'), $session->param('shibboleth'), + $session->param('deskcode'), $session->param('deskname') ); my $ip = $session->param('ip'); @@ -1433,7 +1460,8 @@ sub check_api_auth { my ( $borrowernumber, $firstname, $surname, $userflags, $branchcode, $branchname, - $branchprinter, $emailaddress + $branchprinter, $emailaddress, $deskcode, + $deskname ); my $sth = $dbh->prepare( @@ -1494,6 +1522,8 @@ sub check_api_auth { $session->param( 'surname', $surname ); $session->param( 'branch', $branchcode ); $session->param( 'branchname', $branchname ); + $session->param( 'deskcode', $deskcode ); + $session->param( 'deskname', $deskname ); $session->param( 'flags', $userflags ); $session->param( 'emailaddress', $emailaddress ); $session->param( 'ip', $session->remote_addr() ); @@ -1508,6 +1538,8 @@ sub check_api_auth { $session->param( 'surname', C4::Context->config('user') ); $session->param( 'branch', 'NO_LIBRARY_SET' ); $session->param( 'branchname', 'NO_LIBRARY_SET' ); + $session->param( 'deskcode', 'NO_DESK_SET' ); + $session->param( 'deskname', 'NO_DESK_SET' ); $session->param( 'flags', 1 ); $session->param( 'emailaddress', C4::Context->preference('KohaAdminEmailAddress') ); $session->param( 'ip', $session->remote_addr() ); @@ -1518,7 +1550,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('persona'), $session->param('shibboleth'), + $session->param('deskcode'), $session->param('deskname'), ); return ( "ok", $cookie, $sessionID ); } else { @@ -1599,7 +1633,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('persona'), $session->param('shibboleth'), + $session->param('deskcode'), $session->param('deskname'), ); my $ip = $session->param('ip'); diff --git a/C4/Context.pm b/C4/Context.pm index a51f5c7..a81a3b9 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -1065,7 +1065,8 @@ sub userenv { C4::Context->set_userenv($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, - $emailaddress, $branchprinter, $persona); + $emailaddress, $branchprinter, $persona, + $desk, $deskcode); Establish a hash of user environment variables. @@ -1076,7 +1077,7 @@ set_userenv is called in Auth.pm #' sub set_userenv { shift @_; - my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona, $shibboleth)= + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona, $shibboleth, $deskcode, $deskname)= map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here @_; my $var=$context->{"activeuser"} || ''; @@ -1093,6 +1094,8 @@ sub set_userenv { "emailaddress" => $emailaddress, "branchprinter" => $branchprinter, "persona" => $persona, + "deskcode" => $deskcode, + "deskname" => $deskname, "shibboleth" => $shibboleth, }; $context->{userenv}->{$var} = $cell; diff --git a/circ/selectdesk.pl b/circ/selectdesk.pl new file mode 100755 index 0000000..5b797e3 --- /dev/null +++ b/circ/selectdesk.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl + +# 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 C4::Branch; +use C4::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 $desks; +if ($branch) { + $desks = GetDesks($branch); +} +else { + $desks = GetDesks(); +} +my $deskloop = []; +for my $desk (@$desks) { + push @$deskloop, GetDesk($desk); +} + +my $deskcode = $query->param('deskcode'); + +my $userenv_desk = C4::Context->userenv->{'desk'} || ''; +my $updated = ''; + +if ($deskcode) { + if ( !$userenv_desk or $userenv_desk ne $deskcode ) { + my $desk = GetDesk($deskcode); + $template->param( LoginDeskname => $desk->{'deskname'} ); + $template->param( LoginDeskcode => $desk->{'deskcode'} ); + $session->param( deskname => $desk->{'deskname'} ); + $session->param( deskcode => $desk->{'deskcode'} ); + $updated = 1; + } +} +else { + $deskcode = $userenv_desk; +} + +$template->param( updated => \$updated ); + +unless ( $deskcode ~~ $desks ) { + $deskcode = @$desks[0]; +} + +my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER}; +if ($updated) { + print $query->redirect( $referer || '/cgi-bin/koha/mainpage.pl' ); +} + +$template->param( + referer => $referer, + deskloop => $deskloop, +); + +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 e4caee8..fd77762 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -44,6 +44,17 @@ [% IF ( loggedinusername ) %] [% loggedinusername %] + [% IF ( LoginDeskcode ) %] + | + + [% LoginDeskcode %] + + [% ELSIF (HasDesk) %] + | + + NO DESK SET + + [% END %] | [% IF ( AutoLocation ) %] @@ -73,6 +84,9 @@ Set library [% END %] +
  • + Set desk +
  • [% IF EnableSearchHistory %]
  • Search history diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectdesk.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectdesk.tt new file mode 100644 index 0000000..f49c68c --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectdesk.tt @@ -0,0 +1,50 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Circulation › Set library +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'circ-search.inc' %] + + + +
    +
    +
    +
    +
    +
    + Set desk +
      +
    1. + +
    2. +
    +
    +
    + + Cancel +
    +
    + +
    +
    +
    +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] -- 1.7.10.4