Bug 14395: Code changes
[koha.git] / C4 / Auth.pm
index 8c6d747..332b8c6 100644 (file)
@@ -20,6 +20,7 @@ package C4::Auth;
 use strict;
 use warnings;
 use Digest::MD5 qw(md5_base64);
+use File::Spec;
 use JSON qw/encode_json/;
 use URI::Escape;
 use CGI::Session;
@@ -32,6 +33,8 @@ use C4::Branch;       # GetBranches
 use C4::Search::History;
 use Koha;
 use Koha::AuthUtils qw(hash_password);
+use Koha::LibraryCategories;
+use Koha::Libraries;
 use POSIX qw/strftime/;
 use List::MoreUtils qw/ any /;
 use Encode qw( encode is_utf8);
@@ -208,9 +211,10 @@ sub get_template_and_user {
         # It's possible for $user to be the borrowernumber if they don't have a
         # userid defined (and are logging in through some other method, such
         # as SSL certs against an email address)
+        my $borrower;
         $borrowernumber = getborrowernumber($user) if defined($user);
         if ( !defined($borrowernumber) && defined($user) ) {
-            my $borrower = C4::Members::GetMember( borrowernumber => $user );
+            $borrower = C4::Members::GetMember( borrowernumber => $user );
             if ($borrower) {
                 $borrowernumber = $user;
 
@@ -218,6 +222,8 @@ sub get_template_and_user {
                 # to do it.
                 $user = $borrower->{firstname} . ' ' . $borrower->{surname};
             }
+        } else {
+            $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
         }
 
         # user info
@@ -244,10 +250,7 @@ sub get_template_and_user {
             );
         }
 
-        my ($borr) = C4::Members::GetMemberDetails($borrowernumber);
-        my @bordat;
-        $bordat[0] = $borr;
-        $template->param( "USER_INFO" => \@bordat );
+        $template->param( "USER_INFO" => $borrower );
 
         my $all_perms = get_all_subpermissions();
 
@@ -396,7 +399,7 @@ sub get_template_and_user {
         $template->param( dateformat => C4::Context->preference('dateformat') );
     }
 
-    $template->param(auth_forwarded_hash => $in->{'query'}->param('auth_forwarded_hash'));
+    $template->param(auth_forwarded_hash => scalar $in->{'query'}->param('auth_forwarded_hash'));
 
     # these template parameters are set the same regardless of $in->{'type'}
 
@@ -420,7 +423,7 @@ sub get_template_and_user {
         hide_marc       => C4::Context->preference("hide_marc"),
         item_level_itypes  => C4::Context->preference('item-level_itypes'),
         patronimages       => C4::Context->preference("patronimages"),
-        singleBranchMode   => C4::Context->preference("singleBranchMode"),
+        singleBranchMode   => ( Koha::Libraries->search->count == 1 ),
         XSLTDetailsDisplay => C4::Context->preference("XSLTDetailsDisplay"),
         XSLTResultsDisplay => C4::Context->preference("XSLTResultsDisplay"),
         using_https        => $using_https,
@@ -501,12 +504,14 @@ sub get_template_and_user {
             $opac_name = C4::Context->userenv->{'branch'};
         }
 
+        my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']});
         $template->param(
             OpacAdditionalStylesheet                   => C4::Context->preference("OpacAdditionalStylesheet"),
             AnonSuggestions                       => "" . C4::Context->preference("AnonSuggestions"),
             AuthorisedValueImages                 => C4::Context->preference("AuthorisedValueImages"),
             BranchesLoop                          => GetBranchesLoop($opac_name),
-            BranchCategoriesLoop                  => GetBranchCategories( 'searchdomain', 1, $opac_name ),
+            BranchCategoriesLoop                  => $library_categories,
+            opac_name                             => $opac_name,
             LibraryName                           => "" . C4::Context->preference("LibraryName"),
             LibraryNameTitle                      => "" . $LibraryNameTitle,
             LoginBranchname                       => C4::Context->userenv ? C4::Context->userenv->{"branchname"} : "",
@@ -545,6 +550,7 @@ sub get_template_and_user {
             opacreadinghistory                    => C4::Context->preference("opacreadinghistory"),
             OPACUserJS                            => C4::Context->preference("OPACUserJS"),
             opacuserlogin                         => "" . C4::Context->preference("opacuserlogin"),
+            OpenLibrarySearch                     => C4::Context->preference("OpenLibrarySearch"),
             ShowReviewer                          => C4::Context->preference("ShowReviewer"),
             ShowReviewerPhoto                     => C4::Context->preference("ShowReviewerPhoto"),
             suggestion                            => "" . C4::Context->preference("suggestion"),
@@ -810,7 +816,9 @@ sub checkauth {
             $sessiontype = $session->param('sessiontype') || '';
         }
         if ( ( $query->param('koha_login_context') && ( $q_userid ne $s_userid ) )
-            || ( $cas && $query->param('ticket') && !C4::Context->userenv->{'id'} ) || ( $shib && $shib_login && !$logout ) ) {
+            || ( $cas && $query->param('ticket') && !C4::Context->userenv->{'id'} )
+            || ( $shib && $shib_login && !$logout && !C4::Context->userenv->{'id'} )
+        ) {
 
             #if a user enters an id ne to the id in the current session, we need to log them in...
             #first we need to clear the anonymous session...
@@ -1229,6 +1237,7 @@ sub checkauth {
         intranetbookbag                       => C4::Context->preference("intranetbookbag"),
         IntranetNav                           => C4::Context->preference("IntranetNav"),
         IntranetFavicon                       => C4::Context->preference("IntranetFavicon"),
+        IntranetUserCSS                       => C4::Context->preference("IntranetUserCSS"),
         IntranetUserJS                        => C4::Context->preference("IntranetUserJS"),
         IndependentBranches                   => C4::Context->preference("IndependentBranches"),
         AutoLocation                          => C4::Context->preference("AutoLocation"),
@@ -1707,7 +1716,9 @@ sub get_session {
     }
     else {
         # catch all defaults to tmp should work on all systems
-        $session = new CGI::Session( "driver:File;serializer:yaml;id:md5", $sessionID, { Directory => '/tmp' } );
+        my $dir = File::Spec->tmpdir;
+        my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is
+        $session = new CGI::Session( "driver:File;serializer:yaml;id:md5", $sessionID, { Directory => "$dir/cgisess_$instance" } );
     }
     return $session;
 }