@@ -, +, @@
history lines
---
C4/Search/History.pm | 45 +--
catalogue/search-history.pl | 98 +++---
.../prog/en/modules/catalogue/search-history.tt | 282 ++++++++---------
.../bootstrap/en/modules/opac-search-history.tt | 350 ++++++++++-----------
opac/opac-search-history.pl | 171 +++++-----
5 files changed, 466 insertions(+), 480 deletions(-)
--- a/C4/Search/History.pm
+++ a/C4/Search/History.pm
@@ -155,37 +155,44 @@ sub get {
}
my $query = q{
- SELECT *
- FROM search_history
+ SELECT sh.* , s.a_session
+ FROM search_history sh
+ LEFT JOIN sessions s ON (sh.sessionid = s.id)
WHERE 1
};
- $query .= q{ AND id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )}
- if @$id;
+ my @bind_params;
- $query .= q{
- AND userid = ?
- } if $userid;
+ if (@$id) {
+ $query .= q{ AND sh.id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )};
+ push @bind_params, @$id;
+ }
+
+ if ($userid) {
+ $query .= q{ AND sh.userid = ? };
+ push @bind_params, $userid;
+ }
if ($sessionid) {
- $query .=
- $previous
- ? q{ AND sessionid != ?}
- : q{ AND sessionid = ?};
+ if (defined $previous) {
+ $query .=
+ $previous
+ ? q{ AND sh.sessionid != ?}
+ : q{ AND sh.sessionid = ?};
+ push @bind_params, $sessionid;
+ }
}
- $query .= q{ AND type = ?}
- if $type;
+ if ($type) {
+ $query .= q{ AND sh.type = ?};
+ push @bind_params, $type;
+ }
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare($query);
- $sth->execute(
- ( @$id ? ( @$id ) : () ),
- ( $userid ? $userid : () ),
- ( $sessionid ? $sessionid : () ),
- ( $type ? $type : () )
- );
+ $sth->execute(@bind_params);
return $sth->fetchall_arrayref( {} );
+
}
sub get_from_session {
--- a/catalogue/search-history.pl
+++ a/catalogue/search-history.pl
@@ -20,8 +20,11 @@
use Modern::Perl;
use CGI qw ( -utf8 );
+use URI::Escape;
use C4::Auth;
+use C4::Languages;
+use C4::Search;
use C4::Search::History;
use C4::Output;
@@ -37,61 +40,74 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
my $type = $cgi->param('type');
my $action = $cgi->param('action') || q{list};
-my $previous = $cgi->param('previous');
-# Deleting search history
-if ( $action eq 'delete' ) {
- my $sessionid = defined $previous
- ? $cgi->cookie("CGISESSID")
- : q{};
- C4::Search::History::delete(
- {
- id => [ $cgi->param('id') ],
+if ( $action eq 'search' ) {
+ # Start a new search
+
+ my @ids = $cgi->param('id');
+ my @nots = $cgi->param('not');
+ my $searches = C4::Search::History::get({
+ userid => $loggedinuser,
+ id => \@ids,
+ });
+ 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)";
}
- );
- # Redirecting to this same url so the user won't see the search history link in the header
+
+ 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/catalogue/search.pl?q=$query");
+ exit;
+} elsif ( $action eq 'delete' ) {
+ # Deleting search history
+ C4::Search::History::delete({ id => [ $cgi->param('id') ] });
+ # 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
+ exit;
} else {
- my $current_searches = C4::Search::History::get({
+ # Showing search history
+ my $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 {
+ 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};
+ }
+ }
+ my @biblio_searches = map {
$_->{type} eq 'biblio' ? $_ : ()
- } @$previous_searches;
+ } @$searches;
- my @previous_authority_searches = map {
+ my @authority_searches = map {
$_->{type} eq 'authority' ? $_ : ()
- } @$previous_searches;
+ } @$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,
-
+ biblio_searches => \@biblio_searches,
+ authority_searches => \@authority_searches,
+ sessionid => $cgi->cookie("CGISESSID"),
);
}
-
-$template->param(
-);
-
output_html_with_http_headers $cgi, $cookie, $template->output;
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt
@@ -1,6 +1,87 @@
-[% INCLUDE 'doc-head-open.inc' %]
[% USE Koha %]
[% USE KohaDates %]
+[% USE date %]
+
+[% BLOCK search_history_table %]
+
+[% END %]
+
+[% INCLUDE 'doc-head-open.inc' %]
Koha › Catalog › Search history
[% INCLUDE 'doc-head-close.inc' %]
@@ -13,10 +94,10 @@ $(document).ready(function() {
// 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" },
],
"sPaginationType": "full_numbers"
}));
@@ -35,7 +116,7 @@ $(document).ready(function() {
var new_form = $('
+
+ [% IF type == 'biblio' %]
+
Start a new search
+
+ New search:
+
+ match any of selected searches
+ match all of selected searches
+
+ Go
+ Cancel
+
+
+ [% END %]
+
+
+
+
+
+[% END %]
+
[% INCLUDE 'doc-head-open.inc' %]
[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your search history
[% INCLUDE 'doc-head-close.inc' %]
@@ -31,186 +126,39 @@
[% END %]
-
Search history
- [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
-
-
+
Search history
+ [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
+
+
+ [% END %]
+
+ [% IF ( biblio_searches ) %]
+ [% INCLUDE search_history_table
+ searches = biblio_searches
+ type = 'biblio' %]
+ [% ELSE %]
+
Your catalog search history is empty.
[% END %]
-
-
- [% IF ( current_biblio_searches ) %]
-
Current session
-
-
-
-
-
-
- [% END # IF ( current_biblio_searches ) %]
-
-
-
- [% IF ( previous_biblio_searches ) %]
-
Previous sessions
-
-
-
-
-
-
-
- [% END # IF ( previous_biblio_searches ) %]
-
-
- [% IF !current_biblio_searches && !previous_biblio_searches %]
-
Your catalog search history is empty.
- [% END %]
-
+
- [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
-
- [% IF ( current_authority_searches ) %]
-
Current session
-
-
-
-
-
-
- [% END # / IF ( current_authority_searches ) %]
-
- [% IF ( previous_authority_searches ) %]
-
Previous sessions
-
-
-
-
-
-
- [% END # / IF ( previous_authority_searches )%]
-
- [% IF !current_authority_searches && !previous_authority_searches %]
-
Your authority search history is empty.
- [% END %]
-
- [% END # / IF Koha.Preference( 'OpacAuthorities' ) %]
-
-
-
-
-
-
+ [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
+
+ [% IF ( authority_searches ) %]
+ [% INCLUDE search_history_table
+ searches = authority_searches
+ type = 'authority' %]
+ [% ELSE %]
+
Your authority search history is empty.
+ [% END %]
+
+ [% END %]
+
+
+
+
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
@@ -220,14 +168,14 @@
//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);
--