From 0b72b02bb949282512af594c3b94a7b8438026a3 Mon Sep 17 00:00:00 2001
From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Date: Fri, 15 Mar 2013 17:05:26 -0300
Subject: [PATCH] Bug 9457 - Followup - Ordering branches should be case
 independent (2)

This follow up reinstates or add check for undef returned
by C4::Context->userenv, only where previous patch touch
code.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
---
 members/memberentry.pl   |    6 +++++-
 opac/opac-suggestions.pl |    6 +++++-
 reports/itemtypes.plugin |   11 +++++++----
 reserve/request.pl       |    6 +++++-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/members/memberentry.pl b/members/memberentry.pl
index 79f1f93..6b0e846 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -572,7 +572,11 @@ foreach (keys(%flags)) {
 # in modify mod: userbranch value for GetBranchesLoop() comes from borrowers table
 # in add    mod: userbranch value come from branches table (ip correspondence)
 
-my $userbranch = C4::Context->userenv->{'branch'};
+my $userbranch = '';
+if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
+    $userbranch = C4::Context->userenv->{'branch'};
+}
+
 if (defined ($data{'branchcode'}) and ( $op eq 'modify' || ( $op eq 'add' && $category_type eq 'C' ) )) {
     $userbranch = $data{'branchcode'};
 }
diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl
index 1b353fd..32b5c3d 100755
--- a/opac/opac-suggestions.pl
+++ b/opac/opac-suggestions.pl
@@ -128,7 +128,11 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
     my ( $borr ) = GetMemberDetails( $borrowernumber );
 
 # pass the pickup branch along....
-    my $branch = $input->param('branch') || $borr->{'branchcode'} || C4::Context->userenv->{branch} || '' ;
+    my $userbranch = '';
+    if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
+        $userbranch = C4::Context->userenv->{'branch'};
+    }
+    my $branch = $input->param('branch') || $borr->{'branchcode'} || $userbranch || '' ;
 
 # make branch selection options...
     my $branchloop = GetBranchesLoop($branch);
diff --git a/reports/itemtypes.plugin b/reports/itemtypes.plugin
index 388649f..e4164a5 100755
--- a/reports/itemtypes.plugin
+++ b/reports/itemtypes.plugin
@@ -31,10 +31,13 @@ use C4::Branch; # GetBranches
 =cut
 
 sub set_parameters {
-	my ($template) = @_;
-    my $userbranch = C4::Context->userenv->{'branch'};
-     $template->param( branchloop => GetBranchesLoop($userbranch) );
-	return $template;
+    my ($template) = @_;
+    my $userbranch = '';
+    if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
+        $userbranch = C4::Context->userenv->{'branch'};
+    }
+    $template->param( branchloop => GetBranchesLoop($userbranch) );
+    return $template;
 }
 
 sub calculate {
diff --git a/reserve/request.pl b/reserve/request.pl
index f8e26a2..5bcaca2 100755
--- a/reserve/request.pl
+++ b/reserve/request.pl
@@ -65,7 +65,11 @@ my $showallitems = $input->param('showallitems');
 my $branches = GetBranches();
 my $itemtypes = GetItemTypes();
 
-my $userbranch = C4::Context->userenv->{branch};
+my $userbranch = '';
+if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
+    $userbranch = C4::Context->userenv->{'branch'};
+}
+
 
 # Select borrowers infos
 my $findborrower = $input->param('findborrower');
-- 
1.7.10.4