-
- my $date = C4::Dates->new();
- my $dateformat = $date->DHTMLcalendar() . " %H:%i:%S"; # Current syspref date format + standard time format
-
- # Getting the data with date format work done by mysql
- my $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($loggedinuser, $cgi->cookie("CGISESSID"));
- my $searches = $sth->fetchall_arrayref({});
- $template->param(recentSearches => $searches);
-
- # Getting searches from previous sessions
- $query = "SELECT COUNT(*) FROM search_history WHERE userid = ? AND sessionid != ?";
- $sth = $dbh->prepare($query);
- $sth->execute($loggedinuser, $cgi->cookie("CGISESSID"));
-
- # If at least one search from previous sessions has been performed
- if ($sth->fetchrow_array > 0) {
- $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid != ?";
- $sth = $dbh->prepare($query);
- $sth->execute($loggedinuser, $cgi->cookie("CGISESSID"));
- my $previoussearches = $sth->fetchall_arrayref({});
- $template->param(previousSearches => $previoussearches);
-
- }
-
- $sth->finish;
-
-
+ my $current_searches = C4::Search::History::get({
+ userid => $loggedinuser,
+ sessionid => $cgi->cookie("CGISESSID")
+ });
+ my @current_biblio_searches = map {
+ $_->{type} eq 'biblio' ? $_ : ()
+ } @$current_searches;
+
+ my @current_authority_searches = map {
+ $_->{type} eq 'authority' ? $_ : ()
+ } @$current_searches;
+
+ my $previous_searches = C4::Search::History::get({
+ userid => $loggedinuser,
+ sessionid => $cgi->cookie("CGISESSID"),
+ previous => 1
+ });
+
+ my @previous_biblio_searches = map {
+ $_->{type} eq 'biblio' ? $_ : ()
+ } @$previous_searches;
+
+ my @previous_authority_searches = map {
+ $_->{type} eq 'authority' ? $_ : ()
+ } @$previous_searches;
+
+ $template->param(
+ current_biblio_searches => \@current_biblio_searches,
+ current_authority_searches => \@current_authority_searches,
+ previous_biblio_searches => \@previous_biblio_searches,
+ previous_authority_searches => \@previous_authority_searches,
+
+ );