From f606f2c741a24a4f0277bfe6206a5f264c392a79 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 1 Aug 2018 09:57:29 -0300
Subject: [PATCH] Bug 21137: Replace USER_INFO with logged_in_user

This patch set does several things:
- it removes USER_INFO and BORROWER_INFO
These 2 variables contained logged-in patron's info. They must be
accessed from logged_in_user
- Use patron-title.inc for the breadcrumb at the OPAC, for consistencies

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
---
 C4/Auth.pm                                                   |  4 +---
 C4/InstallAuth.pm                                            |  2 +-
 admin/aqbudgets.pl                                           |  5 +----
 admin/aqplan.pl                                              | 12 ++++++++----
 koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc    | 10 +++++-----
 .../intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt   |  2 +-
 .../intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt    |  2 +-
 koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc       |  2 +-
 .../opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt     |  4 ++--
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt |  4 ++--
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt        |  2 +-
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt     |  2 +-
 .../opac-tmpl/bootstrap/en/modules/opac-search-history.tt    |  2 +-
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shareshelf.tt  |  2 +-
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt     |  2 +-
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt |  2 +-
 16 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/C4/Auth.pm b/C4/Auth.pm
index e27b1b3..f0f3eb8 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -145,7 +145,7 @@ See C<&checkauth> for an explanation of these parameters.
 
 The C<template_name> is then used to find the correct template for
 the page. The authenticated users details are loaded onto the
-template in the HTML::Template LOOP variable C<USER_INFO>. Also the
+template in the logged_in_user variable (which is a Koha::Patron object). Also the
 C<sessionID> is passed to the template. This can be used in templates
 if cookies are disabled. It needs to be put as and input to every
 authenticated page.
@@ -285,8 +285,6 @@ sub get_template_and_user {
             );
         }
 
-        $template->param( "USER_INFO" => $patron->unblessed ) if $borrowernumber != 0;
-
         my $all_perms = get_all_subpermissions();
 
         my @flagroots = qw(circulate catalogue parameters borrowers permissions reserveforothers borrow
diff --git a/C4/InstallAuth.pm b/C4/InstallAuth.pm
index 5f5f213..67319b3 100644
--- a/C4/InstallAuth.pm
+++ b/C4/InstallAuth.pm
@@ -96,7 +96,7 @@ InstallAuth - Authenticates Koha users for Install process
 
     The C<template_name> is then used to find the correct template for
     the page. The authenticated users details are loaded onto the
-    template in the HTML::Template LOOP variable C<USER_INFO>. Also the
+    template in the logged_in_user variable (which is a Koha::Patron object). Also the
     C<sessionID> is passed to the template. This can be used in templates
     if cookies are disabled. It needs to be put as and input to every
     authenticated page.
diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl
index 5aeb8b9..44f0d7f 100755
--- a/admin/aqbudgets.pl
+++ b/admin/aqbudgets.pl
@@ -89,9 +89,6 @@ if ( $budget_period_id ) {
 
 # ------- get periods stuff ------------------
 
-# USED FOR PERMISSION COMPARISON LATER
-my $borrower_id         = $template->{VARS}->{'USER_INFO'}->{'borrowernumber'};
-
 $template->param(
     show_mine   => $show_mine,
     op  => $op,
@@ -235,7 +232,7 @@ if ( $op eq 'list' ) {
     );
 
     my @budgets = @{
-        GetBudgetHierarchy( $$period{budget_period_id}, undef, ( $show_mine ? $borrower_id : 0 ))
+        GetBudgetHierarchy( $$period{budget_period_id}, undef, ( $show_mine ? $borrowernumber : 0 ))
     };
 
     my $period_total = 0;
diff --git a/admin/aqplan.pl b/admin/aqplan.pl
index f01e5e8..0ba3d25 100755
--- a/admin/aqplan.pl
+++ b/admin/aqplan.pl
@@ -84,8 +84,8 @@ $template->param(
 
 # ------- get periods stuff ------------------
 
-my $borrower_id         = $template->{VARS}->{'USER_INFO'}->{'borrowernumber'};
-my $borrower_branchcode = $template->{VARS}->{'USER_INFO'}->{'branchcode'};
+
+my $borrower_branchcode = my $branch_code = C4::Context->userenv->{'branch'};
 
 my $authcat      = $input->param('authcat');
 my $show_active  = $input->param('show_active') // 0;
@@ -108,7 +108,11 @@ $authcat = 'Asort1' if  not defined $authcat; # defaults to Asort if no authcat
 my $budget_id = $input->param('budget_id');
 my $op        = $input->param("op") // q{};
 
-my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}->{'borrowernumber'}:'' );
+my $budgets_ref = GetBudgetHierarchy(
+    $budget_period_id,
+    $show_mine ? $borrower_branchcode : '',
+    $show_mine ? $borrowernumber      : ''
+);
 
 # build categories list
 my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
@@ -315,7 +319,7 @@ foreach my $budget (@budgets) {
     if ( $period->{budget_period_locked} == 1 ) {
         $budget_lock = 1;
     } elsif ( $budget->{budget_permission} == 1 ) {
-        $budget_lock = 1 if $borrower_id != $budget->{'budget_owner_id'};
+        $budget_lock = 1 if $borrowernumber != $budget->{'budget_owner_id'};
     } elsif ( $budget->{budget_permission} == 2 ) {
         $budget_lock = 1 if $borrower_branchcode ne $budget->{budget_branchcode};
     }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc
index d052fd9..25902af 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc
@@ -620,7 +620,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
             $( sel ).on( event, function (e) {
                 e.preventDefault();
                 handler( e, Preferences.user[pref] );
-                Preferences.Save( [% USER_INFO.borrowernumber %] );
+                Preferences.Save( [% logged_in_user.borrowernumber %] );
                 showPreference(pref);
             } );
         }
@@ -645,7 +645,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
                 $( document ).on( 'change', 'input.search-toggle-server', function() {
                     var server_id = $( this ).closest('li').data('server-id');
                     Preferences.user.selected_search_targets[server_id] = this.checked;
-                    Preferences.Save( [% USER_INFO.borrowernumber %] );
+                    Preferences.Save( [% logged_in_user.borrowernumber %] );
                 } );
                 break;
         }
@@ -683,7 +683,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
             delete Preferences.user.macros[name];
         }
 
-        Preferences.Save( [% USER_INFO.borrowernumber %] );
+        Preferences.Save( [% logged_in_user.borrowernumber %] );
     }
 
     function showSavedMacros( macros ) {
@@ -980,7 +980,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
         $( '#switch-editor' ).click( function() {
             if ( !confirm( _("Any changes will not be saved. Continue?") ) ) return;
 
-            $.cookie( 'catalogue_editor_[% USER_INFO.borrowernumber %]', 'basic', { expires: 365, path: '/' } );
+            $.cookie( 'catalogue_editor_[% logged_in_user.borrowernumber %]', 'basic', { expires: 365, path: '/' } );
 
             if ( state.backend == 'catalog' ) {
                 window.location = '/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=' + state.recordID;
@@ -1093,7 +1093,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
         };
 
         // Start editor
-        Preferences.Load( [% USER_INFO.borrowernumber || 0 %] );
+        Preferences.Load( [% logged_in_user.borrowernumber || 0 %] );
         displayPreferences(editor);
         makeAuthorisedValueWidgets( '' );
         Search.Init( {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
index 2f31727..f8bf448 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
@@ -111,7 +111,7 @@
 
             if ( !confirm( breedingid ? _("This record cannot be transferred to the advanced editor. Continue?") : _("Any changes will not be saved. Continue?") ) ) return false;
 
-            $.cookie( 'catalogue_editor_[% USER_INFO.borrowernumber %]', 'advanced', { expires: 365, path: '/' } );
+            $.cookie( 'catalogue_editor_[% logged_in_user.borrowernumber %]', 'advanced', { expires: 365, path: '/' } );
 
             var biblionumber = [% biblionumber || "null" %];
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
index 7305bd5..fd2d8ba 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
@@ -236,7 +236,7 @@
             });
 
             $("#useadvanced").click(function(){
-                $.cookie( 'catalogue_editor_[% USER_INFO.borrowernumber %]', 'advanced', { expires: 365, path: '/' } );
+                $.cookie( 'catalogue_editor_[% logged_in_user.borrowernumber %]', 'advanced', { expires: 365, path: '/' } );
                 return true;
             });
 
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
index 15d185f..95b025f 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
@@ -103,7 +103,7 @@
                                         [% END %]
                                     [% END %]
                                     [% IF ( loggedinusername ) %]
-                                        <li><p class="members navbar-text">Welcome, <a class="login-link" href="/cgi-bin/koha/opac-user.pl"><span class="loggedinusername" data-borrowernumber="[% USER_INFO.borrowernumber %]" data-branchcode="[% USER_INFO.branchcode %]" >[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</span></a></p></li>
+                                        <li><p class="members navbar-text">Welcome, <a class="login-link" href="/cgi-bin/koha/opac-user.pl"><span class="loggedinusername" data-borrowernumber="[% logged_in_user.borrowernumber %]" data-branchcode="[% logged_in_user.branchcode %]" >[% INCLUDE 'patron-title.inc' patron = logged_in_user no_html = 1 %]</span></a></p></li>
                                         <li class="divider-vertical"></li>
                                     [% END %]
                                 [% END %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt
index 805b072..e47844e 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt
@@ -9,8 +9,8 @@
         <div class="main">
             <ul class="breadcrumb">
                 <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
-                [% IF ( loggedinusername ) %]
-                    <li><a href="/cgi-bin/koha/opac-user.pl">[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</a> <span class="divider">&rsaquo;</span></li>
+                [% IF ( logged_in_user ) %]
+                    <li><a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a> <span class="divider">&rsaquo;</span></li>
                 [% END %]
                 <li>
                     [% IF shelf.category == 1 %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt
index 073f8d3..fadd6fb 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt
@@ -16,8 +16,8 @@
 <div class="main">
     <ul class="breadcrumb noprint">
         <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
-        [% IF ( loggedinusername ) %]
-            <li><a href="/cgi-bin/koha/opac-user.pl">[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</a> <span class="divider">&rsaquo;</span></li>
+        [% IF ( logged_in_user ) %]
+            <li><a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE patron-title.inc patron = logged_in_user %]</a> <span class="divider">&rsaquo;</span></li>
         [% END %]
 
         [% IF method != 'list' %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
index 892840e..24c3d43 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
@@ -145,7 +145,7 @@
                     [% ELSE %]
                         [% IF Koha.Preference('OPACUserSummary') && dashboard_info %]
                             <div id="user_summary">
-                                <h3>Welcome, <a href="/cgi-bin/koha/opac-user.pl"><span class="loggedinusername">[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</span></a></h3>
+                                <h3>Welcome, <a href="/cgi-bin/koha/opac-user.pl"><span class="loggedinusername">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</span></a></h3>
                                 <ul id="user_summary_shortcuts">
                                     [% IF checkouts && checkouts > 0 %]
                                         <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-checkouts"><span class="user_checkouts_count count_label">[% checkouts %]</span> checkout(s)</a></li>
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt
index 4b13a3a..ae417ba 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt
@@ -123,7 +123,7 @@
 
                     [% UNLESS ( message ) %]
                         [% UNLESS ( none_available ) %]
-                            <h3>Confirm holds for:[% USER_INFO.firstname %] [% USER_INFO.surname %] ([% USER_INFO.cardnumber %])</h3>
+                            <h3>Confirm holds for:[% INCLUDE 'patron-title.inc' patron = logged_in_user %] ([% logged_in_user.cardnumber %])</h3>
                         [% END # / UNLESS none_available %]
 
                         [% IF (RESERVE_CHARGE) %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt
index 5a8e07a..8fac44a 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt
@@ -13,7 +13,7 @@
     <ul class="breadcrumb">
         <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
         [% IF ( loggedinusername ) %]
-            <li><a href="/cgi-bin/koha/opac-user.pl">[% USER_INFO.firstname %] [% USER_INFO.surname %]</a> <span class="divider">&rsaquo;</span></li>
+            <li><a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a> <span class="divider">&rsaquo;</span></li>
             <li><a href="#">Your search history</a></li>
         [% ELSE %]
             <li><a href="#">Search history</a></li>
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shareshelf.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shareshelf.tt
index 6b0fc07..cffc687 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shareshelf.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shareshelf.tt
@@ -11,7 +11,7 @@
     <ul class="breadcrumb">
         <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
         [% IF ( loggedinusername ) %]
-            <li><a href="/cgi-bin/koha/opac-user.pl">[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</a> <span class="divider">&rsaquo;</span></li>
+            <li><a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a> <span class="divider">&rsaquo;</span></li>
         [% END %]
         <li><a href="/cgi-bin/koha/opac-shelves.pl">Lists</a> <span class="divider">&rsaquo;</span></li>
         <li>Share a list</li>
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
index c122ae2..eb523c6 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
@@ -36,7 +36,7 @@
     <ul class="breadcrumb noprint">
         <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
         [% IF ( loggedinusername ) %]
-            <li><a href="/cgi-bin/koha/opac-user.pl">[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</a> <span class="divider">&rsaquo;</span></li>
+            <li><a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a> <span class="divider">&rsaquo;</span></li>
         [% END %]
 
         [% IF op != 'list' %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt
index 45b4047..06c851c 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt
@@ -16,7 +16,7 @@
     <div class="main">
         <ul class="breadcrumb">
             <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
-            <li><a href="/cgi-bin/koha/opac-user.pl">[% USER_INFO.title %] [% USER_INFO.firstname %] [% USER_INFO.surname %]</a> <span class="divider">&rsaquo;</span></li>
+            <li><a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a> <span class="divider">&rsaquo;</span></li>
             <li><a href="#">Your purchase suggestions</a></li>
         </ul>
 
-- 
2.1.4