Bug 8435: DBRev 3.13.00.038
[koha.git] / opac / opac-search.pl
index 880317a..2854da6 100755 (executable)
@@ -42,7 +42,7 @@ for ( $searchengine ) {
 }
 
 use C4::Output;
-use C4::Auth qw(:DEFAULT get_session);
+use C4::Auth qw(:DEFAULT get_session ParseSearchHistoryCookie);
 use C4::Languages qw(getAllLanguages);
 use C4::Search;
 use C4::Biblio;  # GetBiblioData
@@ -51,10 +51,11 @@ use C4::Tags qw(get_tags);
 use C4::Branch; # GetBranches
 use C4::SocialData;
 use C4::Ratings;
+use C4::External::OverDrive;
 
 use POSIX qw(ceil floor strftime);
 use URI::Escape;
-use Storable qw(thaw freeze);
+use JSON qw/decode_json encode_json/;
 use Business::ISBN;
 
 my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
@@ -246,10 +247,6 @@ foreach my $advanced_srch_type (@advanced_search_types) {
 }
 $template->param(advancedsearchesloop => \@advancedsearchesloop);
 
-# # load the itypes (Called item types in the template -- just authorized values for searching)
-# my ($itypecount,@itype_loop) = GetCcodes();
-# $template->param(itypeloop=>\@itype_loop,);
-
 # The following should only be loaded if we're bringing up the advanced search template
 if ( $template_type && $template_type eq 'advsearch' ) {
     # load the servers (used for searching -- to do federated searching, etc.)
@@ -619,16 +616,7 @@ for (my $i=0;$i<@servers;$i++) {
         # Opac search history
         my $newsearchcookie;
         if (C4::Context->preference('EnableOpacSearchHistory')) {
-            my @recentSearches;
-
-            # Getting the (maybe) already sent cookie
-            my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
-            if ($searchcookie){
-                $searchcookie = uri_unescape($searchcookie);
-                if (thaw($searchcookie)) {
-                    @recentSearches = @{thaw($searchcookie)};
-                }
-            }
+            my @recentSearches = ParseSearchHistoryCookie($cgi);
 
             # Adding the new search if needed
             my $path_info = $cgi->url(-path_info=>1);
@@ -641,8 +629,8 @@ for (my $i=0;$i<@servers;$i++) {
                 # To a cookie (the user is not logged in)
                 if (!$offset) {
                     push @recentSearches, {
-                                "query_desc" => $query_desc_history || "unknown",
-                                "query_cgi"  => $query_cgi_history  || "unknown",
+                                "query_desc" => Encode::decode_utf8($query_desc_history) || "unknown",
+                                "query_cgi"  => Encode::decode_utf8($query_cgi_history)  || "unknown",
                                 "time"       => time(),
                                 "total"      => $total
                               };
@@ -653,8 +641,8 @@ for (my $i=0;$i<@servers;$i++) {
                 # Pushing the cookie back
                 $newsearchcookie = $cgi->cookie(
                             -name => 'KohaOpacRecentSearches',
-                            # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
-                            -value =>freeze(\@recentSearches),
+                            # We uri_escape the whole serialized structure so we're sure we won't have any encoding problems
+                            -value => uri_escape( encode_json(\@recentSearches) ),
                             -expires => ''
                 );
                 $cookie = [$cookie, $newsearchcookie];
@@ -899,5 +887,10 @@ $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksRe
 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
 
+if ($offset == 0 && IsOverDriveEnabled()) {
+    $template->param(OverDriveEnabled => 1);
+    $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
+}
+
     $template->param( borrowernumber    => $borrowernumber);
 output_with_http_headers $cgi, $cookie, $template->output, $content_type;