- my @recentSearches = ParseSearchHistoryCookie($cgi);
-
- # Adding the new search if needed
- my $path_info = $cgi->url(-path_info=>1);
- my $query_cgi_history = $cgi->url(-query=>1);
- $query_cgi_history =~ s/^$path_info\?//;
- $query_cgi_history =~ s/;/&/g;
- my $query_desc_history = join ", ", grep { defined $_ } $query_desc, $limit_desc;
-
- if (!$borrowernumber || $borrowernumber eq '') {
- # To a cookie (the user is not logged in)
- if (!$offset) {
- push @recentSearches, {
- "query_desc" => Encode::decode_utf8($query_desc_history) || "unknown",
- "query_cgi" => Encode::decode_utf8($query_cgi_history) || "unknown",
- "time" => time(),
- "total" => $total
- };
- $template->param(ShowOpacRecentSearchLink => 1);
- }
-
- shift @recentSearches if (@recentSearches > 15);
- # Pushing the cookie back
- $newsearchcookie = $cgi->cookie(
- -name => 'KohaOpacRecentSearches',
- # 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];
- }
- else {
- # To the session (the user is logged in)
- if (!$offset) {
- AddSearchHistory($borrowernumber, $cgi->cookie("CGISESSID"), $query_desc_history, $query_cgi_history, $total);
- $template->param(ShowOpacRecentSearchLink => 1);
+ unless ( $offset ) {
+ my $path_info = $cgi->url(-path_info=>1);
+ my $query_cgi_history = $cgi->url(-query=>1);
+ $query_cgi_history =~ s/^$path_info\?//;
+ $query_cgi_history =~ s/;/&/g;
+ my $query_desc_history = join ", ", grep { defined $_ } $query_desc, $limit_desc;
+
+ unless ( $borrowernumber ) {
+ my $new_searches = C4::Search::History::add_to_session({
+ cgi => $cgi,
+ query_desc => $query_desc_history,
+ query_cgi => $query_cgi_history,
+ total => $total,
+ type => "biblio",
+ });
+ } else {
+ # To the session (the user is logged in)
+ C4::Search::History::add({
+ userid => $borrowernumber,
+ sessionid => $cgi->cookie("CGISESSID"),
+ query_desc => $query_desc_history,
+ query_cgi => $query_cgi_history,
+ total => $total,
+ type => "biblio",
+ });