Bug 8130 - attach PDF files to a patron record
[koha.git] / C4 / Auth.pm
index f74fc84..f796d11 100644 (file)
@@ -41,8 +41,8 @@ BEGIN {
        if ( psgi_env ) { die 'psgi:exit' }
        else { exit }
     }
+    $VERSION     = 3.07.00.049;   # set version for version checking
 
-    $VERSION     = 3.02;                                                                                                            # set version for version checking
     $debug       = $ENV{DEBUG};
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
@@ -164,19 +164,13 @@ sub get_template_and_user {
         $template->param( loggedinusername => $user );
         $template->param( sessionID        => $sessionID );
 
-        my ($total, $pubshelves, $barshelves) = C4::Context->get_shelves_userenv();
-        if (defined($pubshelves)) {
-            $template->param( pubshelves     => scalar @{$pubshelves},
-                              pubshelvesloop => $pubshelves,
-            );
-            $template->param( pubtotal   => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
-        }
-        if (defined($barshelves)) {
-            $template->param( barshelves      => scalar @{$barshelves},
-                              barshelvesloop  => $barshelves,
-            );
-            $template->param( bartotal  => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar @{$barshelves});
-        }
+        my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($borrowernumber, 'MASTHEAD');
+        $template->param(
+            pubshelves     => $total->{pubtotal},
+            pubshelvesloop => $pubshelves,
+            barshelves      => $total->{bartotal},
+            barshelvesloop  => $barshelves,
+        );
 
         require C4::Members;
         my ( $borr ) = C4::Members::GetMemberDetails( $borrowernumber );
@@ -284,14 +278,11 @@ sub get_template_and_user {
 
         $template->param( sessionID        => $sessionID );
         
-        my ($total, $pubshelves) = C4::Context->get_shelves_userenv();  # an anonymous user has no 'barshelves'...
-        if (defined $pubshelves) {
-            $template->param(   pubshelves      => scalar @{$pubshelves},
-                                pubshelvesloop  => $pubshelves,
-                            );
-            $template->param(   pubtotal        => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
-        }
-
+        my ($total, $pubshelves) = C4::VirtualShelves::GetSomeShelfNames(undef, 'MASTHEAD');
+       $template->param(
+           pubshelves     => $total->{pubtotal},
+           pubshelvesloop => $pubshelves,
+       );
     }
        # Anonymous opac search history
        # If opac search history is enabled and at least one search has already been performed
@@ -324,7 +315,7 @@ sub get_template_and_user {
             "BiblioDefaultView".C4::Context->preference("BiblioDefaultView")         => 1,
             EnhancedMessagingPreferences => C4::Context->preference('EnhancedMessagingPreferences'),
             GoogleJackets                => C4::Context->preference("GoogleJackets"),
-           OpenLibraryCovers            => C4::Context->preference("OpenLibraryCovers"),
+            OpenLibraryCovers            => C4::Context->preference("OpenLibraryCovers"),
             KohaAdminEmailAddress        => "" . C4::Context->preference("KohaAdminEmailAddress"),
             LoginBranchcode              => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"),
             LoginFirstname               => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
@@ -337,7 +328,8 @@ sub get_template_and_user {
             XSLTDetailsDisplay           => C4::Context->preference("XSLTDetailsDisplay"),
             XSLTResultsDisplay           => C4::Context->preference("XSLTResultsDisplay"),
             using_https                  => $in->{'query'}->https() ? 1 : 0,
-            noItemTypeImages            => C4::Context->preference("noItemTypeImages"),
+            noItemTypeImages             => C4::Context->preference("noItemTypeImages"),
+            marcflavour                  => C4::Context->preference("marcflavour"),
     );
 
     if ( $in->{'type'} eq "intranet" ) {
@@ -373,6 +365,7 @@ sub get_template_and_user {
             LocalCoverImages            => C4::Context->preference('LocalCoverImages'),
             OPACLocalCoverImages        => C4::Context->preference('OPACLocalCoverImages'),
             AllowMultipleCovers         => C4::Context->preference('AllowMultipleCovers'),
+            EnableBorrowerFiles         => C4::Context->preference('EnableBorrowerFiles'),
         );
     }
     else {
@@ -382,7 +375,7 @@ sub get_template_and_user {
         $LibraryNameTitle =~ s/<(?:\/?)(?:br|p)\s*(?:\/?)>/ /sgi;
         $LibraryNameTitle =~ s/<(?:[^<>'"]|'(?:[^']*)'|"(?:[^"]*)")*>//sg;
         # clean up the busc param in the session if the page is not opac-detail
-        if ($in->{'template_name'} =~ /opac-(.+)\.(?:tt|tmpl)$/ && $1 !~ /^(?:MARC|ISBD)?detail$/) {
+        if (C4::Context->preference("OpacBrowseResults") && $in->{'template_name'} =~ /opac-(.+)\.(?:tt|tmpl)$/ && $1 !~ /^(?:MARC|ISBD)?detail$/) {
             my $sessionSearch = get_session($sessionID || $in->{'query'}->cookie("CGISESSID"));
             $sessionSearch->clear(["busc"]) if ($sessionSearch->param("busc"));
         }
@@ -436,6 +429,7 @@ sub get_template_and_user {
             OpacKohaUrl               => C4::Context->preference("OpacKohaUrl"),
             OpacMainUserBlock         => "" . C4::Context->preference("OpacMainUserBlock"),
             OpacNav                   => "" . C4::Context->preference("OpacNav"),
+            OpacNavRight              => "" . C4::Context->preference("OpacNavRight"),
             OpacNavBottom             => "" . C4::Context->preference("OpacNavBottom"),
             OpacPasswordChange        => C4::Context->preference("OpacPasswordChange"),
             OPACPatronDetails        => C4::Context->preference("OPACPatronDetails"),
@@ -699,7 +693,7 @@ sub checkauth {
         elsif ( $lasttime < time() - $timeout ) {
             # timed logout
             $info{'timed_out'} = 1;
-            $session->delete();
+            $session->delete() if $session;
             C4::Context->_unset_userenv($sessionID);
             #_session_log(sprintf "%20s from %16s logged out at %30s (inactivity).\n", $userid,$ip,(strftime "%c",localtime));
             $userid    = undef;
@@ -900,22 +894,6 @@ sub checkauth {
                     $session->param('emailaddress'), $session->param('branchprinter')
                 );
 
-                # Grab borrower's shelves and public shelves and add them to the session
-                # $row_count determines how many records are returned from the db query
-                # and the number of lists to be displayed of each type in the 'Lists' button drop down
-                my $row_count = 10; # FIXME:This probably should be a syspref
-                my ($total, $totshelves, $barshelves, $pubshelves);
-                ($barshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(1, $row_count, $borrowernumber);
-                $total->{'bartotal'} = $totshelves;
-                ($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
-                $total->{'pubtotal'} = $totshelves;
-                $session->param('barshelves', $barshelves);
-                $session->param('pubshelves', $pubshelves);
-                $session->param('totshelves', $total);
-
-                C4::Context::set_shelves_userenv('bar',$barshelves);
-                C4::Context::set_shelves_userenv('pub',$pubshelves);
-                C4::Context::set_shelves_userenv('tot',$total);
             }
                else {
                if ($userid) {
@@ -929,16 +907,6 @@ sub checkauth {
             # anonymous sessions are created only for the OPAC
                        $debug and warn "Initiating an anonymous session...";
 
-                       # Grab the public shelves and add to the session...
-                       my $row_count = 20; # FIXME:This probably should be a syspref
-                       my ($total, $totshelves, $pubshelves);
-                       ($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
-                       $total->{'pubtotal'} = $totshelves;
-                       $session->param('pubshelves', $pubshelves);
-                       $session->param('totshelves', $total);
-                       C4::Context::set_shelves_userenv('pub',$pubshelves);
-                       C4::Context::set_shelves_userenv('tot',$total);
-
                        # setting a couple of other session vars...
                        $session->param('ip',$session->remote_addr());
                        $session->param('lasttime',time());
@@ -998,6 +966,7 @@ sub checkauth {
         LibraryName          => C4::Context->preference("LibraryName"),
         opacuserlogin        => C4::Context->preference("opacuserlogin"),
         OpacNav              => C4::Context->preference("OpacNav"),
+        OpacNavRight         => C4::Context->preference("OpacNavRight"),
         OpacNavBottom        => C4::Context->preference("OpacNavBottom"),
         opaccredits          => C4::Context->preference("opaccredits"),
         OpacFavicon          => C4::Context->preference("OpacFavicon"),
@@ -1459,7 +1428,7 @@ sub checkpw {
 
     my ( $dbh, $userid, $password, $query ) = @_;
     if ($ldap) {
-        $debug and print "## checkpw - checking LDAP\n";
+        $debug and print STDERR "## checkpw - checking LDAP\n";
         my ($retval,$retcard,$retuserid) = checkpw_ldap(@_);    # EXTERNAL AUTH
         ($retval) and return ($retval,$retcard,$retuserid);
     }
@@ -1700,6 +1669,7 @@ sub getborrowernumber {
     return 0;
 }
 
+
 END { }    # module clean-up code here (global destructor)
 1;
 __END__