Bug 24201: Attach desk to intranet session
authorNicolas Legrand <nicolas.legrand@bulac.fr>
Tue, 10 Dec 2019 14:02:31 +0000 (15:02 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Aug 2020 14:54:40 +0000 (16:54 +0200)
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 <martin.renvoize@ptfs-europe.com>
Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Auth.pm
C4/Context.pm
Koha/Template/Plugin/Desks.pm [new file with mode: 0644]
circ/selectdesk.pl [new file with mode: 0755]
koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc
koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectdesk.tt [new file with mode: 0644]

index 259b6d6..4585893 100644 (file)
@@ -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');
index 8c621e8..e30b210 100644 (file)
@@ -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 (file)
index 0000000..99fe232
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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 (executable)
index 0000000..7589bac
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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;
index 979871a..7360e1f 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Branches %]
+[% USE Desks %]
 <div id="navmenu">
     <div id="navmenulist">
 
@@ -17,6 +18,9 @@
             [% IF ( AutoLocation ) %][% ELSE %][% IF ( IndependentBranches ) %][% ELSE %]
                 <li><a href="/cgi-bin/koha/circ/set-library.pl">Set library</a></li>
             [% END %][% END %]
+            [% IF ( Desks.defined ) %]
+                <li><a href="/cgi-bin/koha/circ/selectdesk.pl">Set desk</a></li>
+            [% END %]
             [% IF ( fast_cataloging ) %][% IF ( CAN_user_editcatalogue_fast_cataloging ) %]
                 <li><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode=FA">Fast cataloging</a></li>
             [% END %][% END %]
index ef6cf61..366209e 100644 (file)
@@ -1,5 +1,6 @@
 [% USE raw %]
 [% USE Branches %]
+[% USE Desks %]
 [% USE Koha %]
 <nav class="navbar">
     <div class="navbar-header">
                                 <span class="logged-in-branch-code content_hidden">[% Branches.GetLoggedInBranchcode | html %]</span>
                             </strong>
                         [% END %]
+                        [% IF (Desks.defined) %]
+                            <span class="separator">|</span>
+                            <strong>
+                                [% IF ( LoginDeskname == '') %]
+                                   <span class="logged-in-desk-name">NO DESK SET</span>
+                                [% ELSE %]
+                                    <span class="logged-in-desk-name">[% LoginDeskname | html %]</span>
+                                    <span class="logged-in-desk-id content_hidden">[% Desks.GetLoggedInDeskId | html %]</span>
+                                [% END %]
+                            </strong>
+                         [% END %]
                     </span>
                     <b class="caret"></b>
                 </a>
                         <a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set library</a>
                     </li>
                     [% END %]
+                    [% IF Desks.defined %]
+                    <li>
+                        <a class="toplinks" href="/cgi-bin/koha/circ/selectdesk.pl">Set desk</a>
+                    </li>
+                    [% END %]
                     [% IF EnableSearchHistory %]
                     <li>
                         <a class="toplinks" href="/cgi-bin/koha/catalogue/search-history.pl">Search history</a>
index fbabec6..5c17f28 100644 (file)
@@ -1,6 +1,7 @@
 [% USE raw %]
 [% USE Koha %]
 [% USE Branches %]
+[% USE Desks %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Circulation</title>
 [% INCLUDE 'doc-head-close.inc' %]
                             <a class="circ-button" href="/cgi-bin/koha/circ/set-library.pl"><i class="fa fa-home"></i> Set library</a>
                         </li>
                     [% END %]
+                    [% IF Desks.defined %]
+                        <li>
+                            <a class="circ-button" href="/cgi-bin/koha/circ/selectdesk.pl"><i class="fa fa-location-arrow"></i> Set desk</a>
+                        </li>
+                    [% END %]
                     [% IF ( fast_cataloging ) %]
                         [% IF ( CAN_user_editcatalogue_fast_cataloging ) %]
                             <li>
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 (file)
index 0000000..f8315ac
--- /dev/null
@@ -0,0 +1,62 @@
+[% USE Koha %]
+
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Circulation &rsaquo; Set Desk</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+<body id="circ_selectdesk" class="circ">
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'circ-search.inc' %]
+
+<div id="breadcrumbs">
+         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
+&rsaquo; <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a>
+&rsaquo; <a href="/cgi-bin/koha/circ/selectdesk.pl">Set Desk</a>
+</div>
+
+<div class="main container-fluid">
+    <div class="row">
+        <div class="col-sm-12">
+            <main>
+                <div class="row">
+
+                [% IF Koha.Preference('CircSidebar') %]
+                    <div class="col-sm-10 col-sm-push-2">
+                [% ELSE %]
+                    <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
+                [% END %]
+
+<form method="post" action="selectdesk.pl">
+  <fieldset class="rows">
+    <legend>Set desk</legend>
+    <ol>
+      <li><label for="desk">Choose desk:</label>
+        <select name="desk_id" id="desk_id">
+        [% FOREACH desk IN desks_list %]
+        <option value="[% desk.desk_id|html %]">[% desk.desk_name|html %]</option>
+        [% END %]
+        </select>
+      </li>
+    </ol>
+    </fieldset>
+    <fieldset class="action">
+      <input type="submit" value="Submit" />
+      <a class="cancel" id="cancel_set_desk" href="[% referer or '/cgi-bin/koha/circ/circulation.pl'|html %]">Cancel</a>
+     </fieldset>
+       <input type="hidden" name="oldreferer" value="[% referer or "/cgi-bin/koha/mainpage.pl" |html %]" />
+ </form>
+
+                </div> <!-- /.col-sm-10.col-sm-push-2 -->
+                    [% IF Koha.Preference('CircSidebar') %]
+                            <div class="col-sm-2 col-sm-pull-10">
+                                <aside>
+                                    [% INCLUDE 'circ-nav.inc' %]
+                                </aside>
+                            </div> <!-- /.col-sm-2.col-sm-pull-10 -->
+                    [% END %]
+                </div> <!-- /.row -->
+            </main>
+        </div> <!-- /.col-sm-12 -->
+    </div> <!-- /.row -->
+
+[% INCLUDE 'intranet-bottom.inc' %]