Bug 6254: make it possible to set default privacy setting for new patrons
[koha_fer] / C4 / Auth.pm
index 24e0bf1..95b2717 100644 (file)
@@ -27,6 +27,7 @@ use CGI::Session;
 require Exporter;
 use C4::Context;
 use C4::Templates;    # to get the template
+use C4::Languages;
 use C4::Branch; # GetBranches
 use C4::Search::History;
 use C4::VirtualShelves;
@@ -134,6 +135,8 @@ sub get_template_and_user {
     my $in       = shift;
     my ( $user, $cookie, $sessionID, $flags );
 
+    C4::Context->interface($in->{type});
+
     my $template = C4::Templates::gettemplate(
         $in->{'template_name'},
         $in->{'type'},
@@ -279,6 +282,8 @@ sub get_template_and_user {
                 # we've saved it to the database
                 C4::Search::History::set_to_session({ cgi => $in->{'query'}, search_history => [] });
             }
+        } elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
+            $template->param( EnableSearchHistory => 1 );
         }
     }
     else {    # if this is an anonymous session, setup to display public lists...
@@ -305,6 +310,12 @@ sub get_template_and_user {
     }
 
     # these template parameters are set the same regardless of $in->{'type'}
+
+    # Set the using_https variable for templates
+    # FIXME Under Plack the CGI->https method always returns 'OFF'
+    my $https = $in->{query}->https();
+    my $using_https = (defined $https and $https ne 'OFF') ? 1 : 0;
+
     $template->param(
             "BiblioDefaultView".C4::Context->preference("BiblioDefaultView")         => 1,
             EnhancedMessagingPreferences => C4::Context->preference('EnhancedMessagingPreferences'),
@@ -323,7 +334,7 @@ sub get_template_and_user {
             singleBranchMode             => C4::Context->preference("singleBranchMode"),
             XSLTDetailsDisplay           => C4::Context->preference("XSLTDetailsDisplay"),
             XSLTResultsDisplay           => C4::Context->preference("XSLTResultsDisplay"),
-            using_https                  => $in->{'query'}->https() ? 1 : 0,
+            using_https                  => $using_https,
             noItemTypeImages             => C4::Context->preference("noItemTypeImages"),
             marcflavour                  => C4::Context->preference("marcflavour"),
             persona                      => C4::Context->preference("persona"),
@@ -382,7 +393,11 @@ sub get_template_and_user {
         my $opac_search_limit = $ENV{'OPAC_SEARCH_LIMIT'};
         my $opac_limit_override = $ENV{'OPAC_LIMIT_OVERRIDE'};
         my $opac_name = '';
-        if (($opac_search_limit && $opac_search_limit =~ /branch:(\w+)/ && $opac_limit_override) || ($in->{'query'}->param('limit') && $in->{'query'}->param('limit') =~ /branch:(\w+)/)){
+        if (
+            ($opac_limit_override && $opac_search_limit && $opac_search_limit =~ /branch:(\w+)/) ||
+            ($in->{'query'}->param('limit') && $in->{'query'}->param('limit') =~ /branch:(\w+)/) ||
+            ($in->{'query'}->param('multibranchlimit') && $in->{'query'}->param('multibranchlimit') =~ /multibranchlimit-(\w+)/)
+        ) {
             $opac_name = $1;   # opac_search_limit is a branch, so we use it.
         } elsif ( $in->{'query'}->param('multibranchlimit') ) {
             $opac_name = $in->{'query'}->param('multibranchlimit');
@@ -472,9 +487,9 @@ sub get_template_and_user {
 
     # Check if we were asked using parameters to force a specific language
     if ( defined $in->{'query'}->param('language') ) {
-        # Extract the language, let C4::Templates::getlanguage choose
+        # Extract the language, let C4::Languages::getlanguage choose
         # what to do
-        my $language = C4::Templates::getlanguage($in->{'query'},$in->{'type'});
+        my $language = C4::Languages::getlanguage($in->{'query'});
         my $languagecookie = C4::Templates::getlanguagecookie($in->{'query'},$language);
         if ( ref $cookie eq 'ARRAY' ) {
             push @{ $cookie }, $languagecookie;
@@ -1533,6 +1548,7 @@ sub checkpw {
         $debug and print STDERR "## checkpw - checking CAS\n";
     # In case of a CAS authentication, we use the ticket instead of the password
         my $ticket = $query->param('ticket');
+        $query->delete('ticket'); # remove ticket to come back to original URL
         my ($retval,$retcard,$retuserid) = checkpw_cas($dbh, $ticket, $query);    # EXTERNAL AUTH
         ($retval) and return ($retval,$retcard,$retuserid);
         return 0;