-
- [% END %]
-
- [% IF ( previous_biblio_searches ) %]
-
Previous sessions
-
- [% END %]
-
- [% IF !current_biblio_searches && !previous_biblio_searches %]
+ [% IF ( biblio_searches ) %]
+ [% INCLUDE search_history_table
+ searches = biblio_searches
+ type = 'biblio' %]
+ [% ELSE %]
Your catalog search history is empty.
[% END %]
- [% IF ( current_authority_searches ) %]
-
Current session
-
- [% END %]
-
- [% IF ( previous_authority_searches ) %]
-
Previous sessions
-
- [% END %]
-
- [% IF !current_authority_searches && !previous_authority_searches %]
+ [% IF ( authority_searches ) %]
+ [% INCLUDE search_history_table
+ searches = authority_searches
+ type = 'authority' %]
+ [% ELSE %]
Your authority search history is empty.
[% END %]
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt
@@ -1,5 +1,91 @@
[% USE Koha %]
[% USE KohaDates %]
+[% USE date %]
+
+[% BLOCK search_history_table %]
+
+[% END %]
+
[% INCLUDE 'doc-head-open.inc' %]
[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your search history
[% INCLUDE 'doc-head-close.inc' %]
@@ -40,173 +126,30 @@
[% END %]
-
- [% IF ( current_biblio_searches ) %]
-
Current session
-
- [% END %]
-
-
-
- [% IF ( previous_biblio_searches ) %]
-
Previous sessions
-
- [% END %]
-
-
- [% IF !current_biblio_searches && !previous_biblio_searches %]
+ [% IF ( biblio_searches ) %]
+ [% INCLUDE search_history_table
+ searches = biblio_searches
+ type = 'biblio' %]
+ [% ELSE %]
Your catalog search history is empty.
[% END %]
[% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
- [% IF ( current_authority_searches ) %]
-
Current session
-
- [% END %]
-
- [% IF ( previous_authority_searches ) %]
-
Previous sessions
-
- [% END %]
-
- [% IF !current_authority_searches && !previous_authority_searches %]
+ [% IF ( authority_searches ) %]
+ [% INCLUDE search_history_table
+ searches = authority_searches
+ type = 'authority' %]
+ [% ELSE %]
Your authority search history is empty.
[% END %]
-
-
- [% END %]
+ [% END %]
+
-
-
+
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
@@ -219,10 +162,10 @@
// We show table ordered by descending dates by default
// (so that the more recent query is shown first)
$(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
- "aaSorting": [[ 1, "desc" ]],
+ "aaSorting": [[ 3, "desc" ]],
"aoColumnDefs": [
- { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
- { "aTargets": [ 1 ], "sType": "title-string" },
+ { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false },
+ { "aTargets": [ 2, 3 ], "sType": "title-string" },
]
}));
@@ -258,6 +201,39 @@
}
return false;
});
+ $(".action_search").click(function() {
+ var $form = $(this).parents('form');
+ var $checked = $form.find('input:checkbox:checked');
+ if ($checked.length) {
+ $(this).hide();
+ $('.action_search_cancel').show();
+ $('.search_options').show();
+ $('.not').show();
+ }
+ return false;
+ });
+
+ $('.search_options button[type="submit"]').click(function() {
+ var $form = $(this).parents('form');
+ var $checked = $form.find('input:checkbox:checked');
+ if ($checked.length ) {
+ $form.find('input[name="action"]').val('search');
+ $form.submit();
+ }
+ return false;
+ });
+
+ $('.action_search_cancel').click(function() {
+ $(this).hide();
+ $('.action_search').show();
+ $('.search_options').hide();
+ $('.not').hide();
+ return false;
+ }).click();
+
+ $('form').each(function() {
+ enableCheckboxActions(this);
+ });
});
function enableCheckboxActions(form){
--- a/opac/opac-search-history.pl
+++ a/opac/opac-search-history.pl
@@ -22,11 +22,13 @@ use Modern::Perl;
use C4::Auth qw(:DEFAULT get_session);
use CGI;
use C4::Context;
+use C4::Languages;
use C4::Output;
use C4::Log;
use C4::Items;
use C4::Debug;
use C4::Dates;
+use C4::Search;
use C4::Search::History;
use URI::Escape;
use POSIX qw(strftime);
@@ -46,21 +48,66 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user(
}
);
-my $type = $cgi->param('type');
my $action = $cgi->param('action') || q{};
-my $previous = $cgi->param('previous');
-# If the user is not logged in, we deal with the session
-unless ( $loggedinuser ) {
+if ( $action eq 'search' ) {
+ # Start a new search
+
+ my @ids = $cgi->param('id');
+ my @nots = $cgi->param('not');
+ my @searches;
+ if ($loggedinuser) {
+ @searches = @{ C4::Search::History::get({
+ userid => $loggedinuser,
+ id => \@ids,
+ }) };
+ } else {
+ @searches = C4::Search::History::get_from_session({ cgi => $cgi });
+ if ( @ids ) {
+ @searches = map {
+ my $search = $_;
+ ( grep {/^$search->{id}$/} @ids ) ? $_ : ()
+ } @searches;
+ }
+ }
+ my @ccl_queries;
+ foreach my $search (@searches) {
+ my $scgi = new CGI($search->{query_cgi});
+ my @operators = map uri_unescape($_), $scgi->param('op');
+ my @indexes = map uri_unescape($_), $scgi->param('idx');
+ my @operands = map uri_unescape($_), $scgi->param('q');
+ my @limits = map uri_unescape($_), $scgi->param('limit');
+ my @sort_by = $scgi->param('sort_by');
+ my $scan = $scgi->param('scan');
+ my $lang = C4::Languages::getlanguage($cgi);
+ my ( $error, $query ) =
+ buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by,
+ $scan, $lang );
+
+ if (grep {$_ == $search->{id}} @nots) {
+ $query = "allrecords,alwaysmatches='' not ($query)";
+ }
+
+ push @ccl_queries, $query;
+ }
+ my $join = ($cgi->param('join') eq 'or') ? 'or' : 'and';
+ my $query = 'ccl=(' . join(") $join (", @ccl_queries) . ')';
+ print $cgi->redirect("/cgi-bin/koha/opac-search.pl?q=$query");
+ exit;
+} elsif ( $action eq 'delete' ) {
# Deleting search history
- if ( $action eq 'delete') {
+ my @id = $cgi->param('id');
+ if ($loggedinuser) {
+ if ( @id ) {
+ C4::Search::History::delete({ id => \@id });
+ } else {
+ C4::Search::History::delete({ userid => $loggedinuser });
+ }
+ } else {
# Deleting session's search history
- my @id = $cgi->param('id');
- my $all = not scalar( @id );
-
my $type = $cgi->param('type');
my @searches = ();
- unless ( $all ) {
+ if ( scalar @id ) {
@searches = C4::Search::History::get_from_session({ cgi => $cgi });
if ( $type ) {
@searches = map { $_->{type} ne $type ? $_ : () } @searches;
@@ -70,90 +117,48 @@ unless ( $loggedinuser ) {
}
}
C4::Search::History::set_to_session({ cgi => $cgi, search_history => \@searches });
-
- # Redirecting to this same url so the user won't see the search history link in the header
- my $uri = $cgi->url();
- print $cgi->redirect(-uri => $uri);
- # Showing search history
- } else {
- # Getting the searches from session
- my @current_searches = C4::Search::History::get_from_session({
- cgi => $cgi,
- });
-
- my @current_biblio_searches = map {
- $_->{type} eq 'biblio' ? $_ : ()
- } @current_searches;
-
- my @current_authority_searches = map {
- $_->{type} eq 'authority' ? $_ : ()
- } @current_searches;
-
- $template->param(
- current_biblio_searches => \@current_biblio_searches,
- current_authority_searches => \@current_authority_searches,
- );
}
+ # Redirecting to this same url so the user won't see the search history link in the header
+ my $uri = $cgi->url();
+ print $cgi->redirect($uri);
+ exit;
} else {
- # And if the user is logged in, we deal with the database
- my $dbh = C4::Context->dbh;
-
- # Deleting search history
- if ( $action eq 'delete' ) {
- my @id = $cgi->param('id');
- if ( @id ) {
- C4::Search::History::delete(
- {
- id => [ $cgi->param('id') ],
- }
- );
- } else {
- C4::Search::History::delete(
- {
- userid => $loggedinuser,
- }
- );
- }
- # Redirecting to this same url so the user won't see the search history link in the header
- my $uri = $cgi->url();
- print $cgi->redirect($uri);
-
# Showing search history
- } else {
- my $current_searches = C4::Search::History::get({
+ my @searches;
+ if ($loggedinuser) {
+ @searches = @{ C4::Search::History::get({
userid => $loggedinuser,
sessionid => $cgi->cookie("CGISESSID")
+ }) };
+ foreach my $row (@searches) {
+ if ($row->{a_session}) {
+ $row->{session} = YAML::Load($row->{a_session});
+ $row->{session}->{session_ctime} = $row->{session}->{_SESSION_CTIME};
+ $row->{session}->{session_id} = $row->{session}->{_SESSION_ID};
+ }
+ }
+ } else {
+ # Getting the searches from session
+ @searches = C4::Search::History::get_from_session({
+ cgi => $cgi,
});
- 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
- });
+ $template->param(hide_session_column => 1);
+ }
- my @previous_biblio_searches = map {
- $_->{type} eq 'biblio' ? $_ : ()
- } @$previous_searches;
- my @previous_authority_searches = map {
- $_->{type} eq 'authority' ? $_ : ()
- } @$previous_searches;
+ my @biblio_searches = map {
+ $_->{type} eq 'biblio' ? $_ : ()
+ } @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,
+ my @authority_searches = map {
+ $_->{type} eq 'authority' ? $_ : ()
+ } @searches;
- );
- }
+ $template->param(
+ biblio_searches => \@biblio_searches,
+ authority_searches => \@authority_searches,
+ sessionid => $cgi->cookie('CGISESSID'),
+ );
}
$template->param(searchhistoryview => 1);
--