Bugzilla – Attachment 59384 Details for
Bug 12460
Search history: Combine to start a new search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12460: Allow to start a new search from multiple search history lines
Bug-12460-Allow-to-start-a-new-search-from-multipl.patch (text/plain), 50.84 KB, created by
Julian Maurice
on 2017-01-20 17:12:18 UTC
(
hide
)
Description:
Bug 12460: Allow to start a new search from multiple search history lines
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2017-01-20 17:12:18 UTC
Size:
50.84 KB
patch
obsolete
>From 2b2d101c2da130acc7ccbed905b1c480cfc589f1 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 19 Jun 2014 09:46:23 +0200 >Subject: [PATCH] Bug 12460: Allow to start a new search from multiple search > history lines > >This patch regroups searches of current and previous sessions to allow >selecting lines from both groups. >It adds a new column (session date) to allow to differentiate searches >of current session from other sessions. >Patch is for Intranet and OPAC (bootstrap only) > >Test plan: >1/ Login to intranet interface >2/ Do some biblio searches >3/ Go to the search history page >4/ See you have a new action available "Start a new search", grayed >beacause you haven't selected any line >5/ Select two or more searches >6/ "Start a new search" is now enabled, click it. >7/ A dropdown list appears, asking you to chose between a "Match any" >search and a "Match all" search. There is also a new column in the table >("Not") allowing you to apply a NOT to the corresponding line. >8/ Make your choice, and then click on Go button, next to the dropdown >list. You will be redirected to the catalogue search results. >9/ Confirm that the results are correct. >10/ Set syspref opacthemes to 'bootstrap' >11/ Go to OPAC interface anonymously and repeat steps 2-9 >12/ Login to OPAC interface and repeat steps 2-9 >13/ Check that authority search history still works as before the patch >(except that there is only one table instead of two) >--- > C4/Search/History.pm | 45 +-- > catalogue/search-history.pl | 92 +++--- > .../prog/en/modules/catalogue/search-history.tt | 285 ++++++++--------- > .../bootstrap/en/modules/opac-search-history.tt | 351 ++++++++++----------- > opac/opac-search-history.pl | 172 +++++----- > 5 files changed, 469 insertions(+), 476 deletions(-) > >diff --git a/C4/Search/History.pm b/C4/Search/History.pm >index 8406f3086b..7463a65684 100644 >--- a/C4/Search/History.pm >+++ b/C4/Search/History.pm >@@ -162,37 +162,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 { >diff --git a/catalogue/search-history.pl b/catalogue/search-history.pl >index f6714e11c6..411ebe169c 100755 >--- a/catalogue/search-history.pl >+++ b/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,76 @@ 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{}; >+if ( $action eq 'search' ) { >+ # Start a new search >+ >+ my @ids = $cgi->multi_param('id'); >+ my @nots = $cgi->multi_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->multi_param('op'); >+ my @indexes = map uri_unescape($_), $scgi->multi_param('idx'); >+ my @operands = map uri_unescape($_), $scgi->multi_param('q'); >+ my @limits = map uri_unescape($_), $scgi->multi_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/catalogue/search.pl?q=$query"); >+ exit; >+} elsif ( $action eq 'delete' ) { > C4::Search::History::delete( > { > userid => $loggedinuser, >- id => [ $cgi->param('id') ], >+ id => [ $cgi->multi_param('id') ], > } > ); > # Redirecting to this same url so the user won't see the search history link in the header > print $cgi->redirect('/cgi-bin/koha/catalogue/search-history.pl'); >- >-# 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; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt >index f55d4fc276..444521a4e1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt >@@ -1,6 +1,88 @@ >-[% INCLUDE 'doc-head-open.inc' %] > [% USE Koha %] > [% USE KohaDates %] >+[% USE date %] >+ >+[% BLOCK search_history_table %] >+ <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get"> >+ [%# Search from multiple lines is only enabled for biblios %] >+ [% IF type == 'biblio' %] >+ <div> >+ <a href="#" class="action_search">Start a new search</a> >+ <span class='search_options'> >+ <span>New search:</span> >+ <select name='join'> >+ <option value="or" selected="selected">match any of selected searches</option> >+ <option value="and">match all of selected searches</option> >+ </select> >+ <button type="submit">Go</button> >+ <a href="#" class="action_search_cancel">Cancel</a> >+ </span> >+ </div> >+ [% END %] >+ <div class="selections-toolbar"> >+ <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a> >+ <span class="sep">|</span> >+ <a class="CheckNone" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a> >+ <span class="sep">|</span> >+ <span class="links"> >+ <span class="selections">Select searches to: </span> >+ <a href="#" class="action_delete disabled">Delete</a> >+ </span> >+ </div> >+ <input type="hidden" name="action" value="delete" /> >+ <table class="historyt"> >+ <thead> >+ <tr> >+ <th></th> >+ <th class="not">Not</th> >+ <th>Session date</th> >+ <th>Date</th> >+ <th>Search</th> >+ <th>Results</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH s IN searches %] >+ <tr> >+ <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >+ <td class="not"> >+ <select name="not"> >+ <option value=""></option> >+ <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option> >+ </select> >+ </td> >+ <td> >+ [% IF s.session %] >+ [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %] >+ <span title="[% session_ctime %]"> >+ [% IF s.session.session_id == sessionid %] >+ <strong title="Current session"> >+ [% END %] >+ [% session_ctime | $KohaDates %] >+ [% IF s.session.session_id == sessionid %] >+ </strong> >+ [% END %] >+ </span> >+ [% ELSE %] >+ <span title="">Unknown</span> >+ [% END %] >+ </td> >+ <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >+ [% IF type == 'biblio' %] >+ [% search_url = '/cgi-bin/koha/catalogue/search.pl' %] >+ [% ELSE %] >+ [% search_url = '/cgi-bin/koha/authorities/authorities-home.pl' %] >+ [% END %] >+ <td><a href="[% search_url %]?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >+ <td>[% s.total %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+ </form> >+[% END %] >+ >+[% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Catalog › Search history</title> > [% INCLUDE 'doc-head-close.inc' %] > <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" /> >@@ -12,10 +94,11 @@ $(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" }, >+ { "aTargets": [ 1 ], "bVisible": false } > ], > "sPaginationType": "full_numbers" > })); >@@ -34,7 +117,7 @@ $(document).ready(function() { > var new_form = $('<form>') > .attr('action', form.attr('action')) > .attr('method', form.attr('method')); >- form.find('input[type="hidden"]') >+ form.find('input[type="hidden"],select') > .add(table.$('input:checkbox:checked')) > .each(function() { > var input = $('<input type="hidden">') >@@ -81,10 +164,42 @@ $(document).ready(function() { > } > > if ( confirm(msg) ) { >+ form.find('input[name="action"]').val('delete'); > form.submit(); > } > return false; > }); >+ $(".action_search").click(function() { >+ var $form = $(this).parents('form'); >+ var table = $form.find('table').dataTable(); >+ var $checked = table.$('input:checkbox:checked'); >+ $(this).hide(); >+ $('.search_options').show(); >+ table.fnSetColumnVis(1, true); >+ return false; >+ }); >+ >+ $('.search_options button[type="submit"]').click(function() { >+ var $form = $(this).parents('form'); >+ var table = $form.find('table').dataTable(); >+ var $checked = table.$('input:checkbox:checked'); >+ if ($checked.length) { >+ $form.find('input[name="action"]').val('search'); >+ $form.submit(); >+ } else { >+ alert(_("You have to select searches first")); >+ } >+ return false; >+ }); >+ >+ $('.action_search_cancel').click(function() { >+ var form = $(this).parents('form').first(); >+ var table = form.find('table').dataTable(); >+ $('.action_search').show(); >+ $('.search_options').hide(); >+ table.fnSetColumnVis(1, false); >+ return false; >+ }).click(); > > $('#tabs form').each(function() { > enableCheckboxActions($(this)); >@@ -133,161 +248,21 @@ function enableCheckboxActions(form){ > <li><a href="#authority_tab">Authority</a></li> > </ul> > <div id="biblio_tab"> >- [% IF ( current_biblio_searches ) %] >- <h2>Current session</h2> >- <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get"> >- <div class="selections-toolbar"> >- <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a> >- <span class="sep">|</span> >- <a class="CheckNone" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="action_delete disabled">Delete</a> >- </span> >- </div> >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN current_biblio_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- </form> >- [% END %] >- >- [% IF ( previous_biblio_searches ) %] >- <h2>Previous sessions</h2> >- <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get"> >- <div class="selections-toolbar"> >- <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a> >- <span class="sep">|</span> >- <a class="CheckNone" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="action_delete disabled">Delete</a> >- </span> >- </div> >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN previous_biblio_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- </form> >- [% END %] >- >- [% IF !current_biblio_searches && !previous_biblio_searches %] >+ [% IF ( biblio_searches ) %] >+ [% INCLUDE search_history_table >+ searches = biblio_searches >+ type = 'biblio' %] >+ [% ELSE %] > <p>Your catalog search history is empty.</p> > [% END %] > </div> > > <div id="authority_tab"> >- [% IF ( current_authority_searches ) %] >- <h2>Current session</h2> >- <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get"> >- <div class="selections-toolbar"> >- <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a> >- <span class="sep">|</span> >- <a class="CheckNone" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="action_delete disabled">Delete</a> >- </span> >- </div> >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN current_authority_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- </form> >- [% END %] >- >- [% IF ( previous_authority_searches ) %] >- <h2>Previous sessions</h2> >- <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get"> >- <div class="selections-toolbar"> >- <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a> >- <span class="sep">|</span> >- <a class="CheckNone" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="action_delete disabled">Delete</a> >- </span> >- </div> >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN previous_authority_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- </form> >- [% END %] >- >- [% IF !current_authority_searches && !previous_authority_searches %] >+ [% IF ( authority_searches ) %] >+ [% INCLUDE search_history_table >+ searches = authority_searches >+ type = 'authority' %] >+ [% ELSE %] > <p>Your authority search history is empty.</p> > [% END %] > </div> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt >index d8d6c579b3..19bd4f602c 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt >@@ -1,5 +1,101 @@ > [% USE Koha %] > [% USE KohaDates %] >+[% USE date %] >+ >+[% BLOCK search_history_table %] >+ <form action="/cgi-bin/koha/opac-search-history.pl" method="get"> >+ <div> >+ [% IF type == 'biblio' %] >+ <a href="#" class="action_search">Start a new search</a> >+ <span class='search_options form-inline'> >+ <span>New search:</span> >+ <select name='join'> >+ <option value="or" selected="selected">match any of selected searches</option> >+ <option value="and">match all of selected searches</option> >+ </select> >+ <button type="submit">Go</button> >+ <a href="#" class="action_search_cancel">Cancel</a> >+ </span> >+ >+ [% END %] >+ </div> >+ <div class="selections-toolbar toolbar"> >+ <a class="CheckAll" href="#">Select all</a> >+ <a class="CheckNone" href="#">Clear all</a> >+ <span class="sep">|</span> >+ <span class="links"> >+ <span class="selections">Select searches to: </span> >+ <a href="#" class="removeitems disabled">Delete</a> >+ </span> >+ </div> >+ <input type="hidden" name="action" value="delete" /> >+ <table class="historyt table table-bordered table-striped"> >+ <thead> >+ <tr> >+ <th></th> >+ <th class="not">Not</th> >+ [% IF hide_session_column %] >+ <th class="hide">Session date</th> >+ [% ELSE %] >+ <th>Session date</th> >+ [% END %] >+ <th>Date</th> >+ <th>Search</th> >+ <th>Results</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH s IN searches %] >+ <tr> >+ <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >+ <td class="not"> >+ <select name="not"> >+ <option value=""></option> >+ <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option> >+ </select> >+ </td> >+ [% IF hide_session_column %] >+ <td class="hide"> >+ [% ELSE %] >+ <td> >+ [% END %] >+ [% IF s.session %] >+ [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %] >+ <span title="[% session_ctime %]"> >+ [% IF s.session.session_id == sessionid %] >+ <strong title="Current session"> >+ [% END %] >+ [% session_ctime | $KohaDates %] >+ [% IF s.session.session_id == sessionid %] >+ </strong> >+ [% END %] >+ </span> >+ [% ELSE %] >+ <span title="">Unknown</span> >+ [% END %] >+ </td> >+ <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >+ [% IF type == 'biblio' %] >+ [% search_url = '/cgi-bin/koha/opac-search.pl' %] >+ [% ELSIF type == 'authority' %] >+ [% search_url = '/cgi-bin/koha/opac-authorities-home.pl' %] >+ [% END %] >+ <td> >+ [% IF type == 'biblio' %] >+ <a href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html |url %][% limit_cgi |html | url %]&[% s.query_cgi |html %]&count=[% countrss |html %]&sort_by=acqdate_dsc&format=rss2" class="rsssearchlink"> >+ <img src="[% interface %]/[% theme %]/images/feed-icon-16x16.png" alt="Subscribe to this search" title="Subscribe to this search" class="rsssearchicon"/> >+ </a> >+ [% END %] >+ <a href="[% search_url %]?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >+ <td>[% s.total %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+ <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches"> >+ </form> >+[% END %] >+ > [% INCLUDE 'doc-head-open.inc' %] > <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your search history</title> > [% INCLUDE 'doc-head-close.inc' %] >@@ -31,186 +127,39 @@ > <div class="span12"> > [% END %] > <div id="searchhistory" class="maincontent"> >- <h1>Search history</h1> >- [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %] >- <div id="tabs" class="toptabs"> >- <ul> >- <li><a href="#biblio_tab">Catalog</a></li> >- <li><a href="#authority_tab">Authority</a></li> >- </ul> >+ <h1>Search history</h1> >+ [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %] >+ <div id="tabs" class="toptabs"> >+ <ul> >+ <li><a href="#biblio_tab">Catalog</a></li> >+ <li><a href="#authority_tab">Authority</a></li> >+ </ul> >+ [% END %] >+ <div id="biblio_tab"> >+ [% IF ( biblio_searches ) %] >+ [% INCLUDE search_history_table >+ searches = biblio_searches >+ type = 'biblio' %] >+ [% ELSE %] >+ <p>Your catalog search history is empty.</p> > [% END %] >- <div id="biblio_tab"> >- <div id="current_biblio"> >- [% IF ( current_biblio_searches ) %] >- <h2>Current session</h2> >- <form action="/cgi-bin/koha/opac-search-history.pl" method="get"> >- <div class="selections-toolbar toolbar"> >- <a class="CheckAll" href="#">Select all</a> >- <a class="CheckNone" href="#">Clear all</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="removeitems disabled">Delete</a> >- </span> >- </div> >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt table table-bordered table-striped"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN current_biblio_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html |url %][% limit_cgi |html | url %]&[% s.query_cgi |html %]&count=[% countrss |html %]&sort_by=acqdate_dsc&format=rss2" class="rsssearchlink"><img src="[% interface %]/[% theme %]/images/feed-icon-16x16.png" alt="Subscribe to this search" title="Subscribe to this search" class="rsssearchicon"/></a> <a href="/cgi-bin/koha/opac-search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches"> >- </form> >- [% END # IF ( current_biblio_searches ) %] >- </div> <!-- / #current_biblio --> >- >- <div id="previous_biblio"> >- [% IF ( previous_biblio_searches ) %] >- <h2>Previous sessions</h2> >- <form action="/cgi-bin/koha/opac-search-history.pl" method="get"> >- <div class="selections-toolbar toolbar"> >- <a class="CheckAll" href="#">Select all</a> >- <a class="CheckNone" href="#">Clear all</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="removeitems disabled">Delete</a> >- </span> >- </div> >- >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt table table-bordered table-striped"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN previous_biblio_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html |url %][% limit_cgi |html | url %]&[% s.query_cgi |html %]&count=[% countrss |html %]&sort_by=acqdate_dsc&format=rss2" class="rsssearchlink"><img src="[% interface %]/[% theme %]/images/feed-icon-16x16.png" alt="Subscribe to this search" title="Subscribe to this search" class="rsssearchicon"/></a> <a href="/cgi-bin/koha/opac-search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches"> >- </form> >- [% END # IF ( previous_biblio_searches ) %] >- </div> <!-- / #previous_biblio --> >- >- [% IF !current_biblio_searches && !previous_biblio_searches %] >- <p>Your catalog search history is empty.</p> >- [% END %] >- </div> <!-- / #biblio_tab --> >+ </div> > >- [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %] >- <div id="authority_tab"> >- [% IF ( current_authority_searches ) %] >- <h2>Current session</h2> >- <form action="/cgi-bin/koha/opac-search-history.pl" method="get"> >- <div class="selections-toolbar toolbar"> >- <a class="CheckAll" href="#">Select all</a> >- <a class="CheckNone" href="#">Clear all</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="removeitems disabled">Delete</a> >- </span> >- </div> >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt table table-bordered table-striped"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN current_authority_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches"> >- </form> >- [% END # / IF ( current_authority_searches ) %] >- >- [% IF ( previous_authority_searches ) %] >- <h2>Previous sessions</h2> >- <form action="/cgi-bin/koha/opac-search-history.pl" method="get"> >- <div class="selections-toolbar toolbar"> >- <a class="CheckAll" href="#">Select all</a> >- <a class="CheckNone" href="#">Clear all</a> >- <span class="sep">|</span> >- <span class="links"> >- <span class="selections">Select searches to: </span> >- <a href="#" class="removeitems disabled">Delete</a> >- </span> >- </div> >- <input type="hidden" name="action" value="delete" /> >- <table class="historyt table table-bordered table-striped"> >- <thead> >- <tr> >- <th></th> >- <th>Date</th> >- <th>Search</th> >- <th>Results</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH s IN previous_authority_searches %] >- <tr> >- <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td> >- <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td> >- <td>[% s.total %]</td> >- </tr> >- [% END %] >- </tbody> >- </table> >- <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches"> >- </form> >- [% END # / IF ( previous_authority_searches )%] >- >- [% IF !current_authority_searches && !previous_authority_searches %] >- <p>Your authority search history is empty.</p> >- [% END %] >- </div> <!-- / #authority_tab --> >- [% END # / IF Koha.Preference( 'OpacAuthorities' ) %] >- </div> <!-- / #tabs --> >- </div> <!-- / #searchhistory --> >- </div> <!-- / .span10/12 --> >- </div> <!-- / .row-fluid --> >- </div> <!-- / .container-fluid --> >-</div> <!-- / #main --> >+ [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %] >+ <div id="authority_tab"> >+ [% IF ( authority_searches ) %] >+ [% INCLUDE search_history_table >+ searches = authority_searches >+ type = 'authority' %] >+ [% ELSE %] >+ <p>Your authority search history is empty.</p> >+ [% END %] >+ </div> >+ [% END %] >+ </div> <!-- / #search_history --> >+ </div> <!-- / .span10/12 --> >+ </div> <!-- / .row-fluid --> >+</div> <!-- / .container-fluid --> > > [% INCLUDE 'opac-bottom.inc' %] > [% BLOCK jsinclude %] >@@ -220,14 +169,14 @@ > //<![CDATA[ > var MSG_CONFIRM_DELETE_HISTORY = _("Are you sure you want to delete selected search history entries?"); > $(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" ]], >- "aoColumnDefs": [ >- { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false }, >- { "aTargets": [ 1 ], "sType": "title-string" }, >- ] >+ // We show table ordered by descending dates by default >+ // (so that the more recent query is shown first) >+ $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, { >+ "aaSorting": [[ 3, "desc" ]], >+ "aoColumnDefs": [ >+ { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false }, >+ { "aTargets": [ 2, 3 ], "sType": "title-string" }, >+ ] > })); > > [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]$('#tabs').tabs();[% END %] >@@ -262,6 +211,36 @@ > } > return false; > }); >+ $(".action_search").click(function() { >+ var $form = $(this).parents('form'); >+ $(this).hide(); >+ $('.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(); >+ } else { >+ alert(_("You have to select searches first")); >+ } >+ return false; >+ }); >+ >+ $('.action_search_cancel').click(function() { >+ $('.action_search').show(); >+ $('.search_options').hide(); >+ $('.not').hide(); >+ return false; >+ }).click(); >+ >+ $('form').each(function() { >+ enableCheckboxActions(this); >+ }); > }); > > function enableCheckboxActions(form){ >diff --git a/opac/opac-search-history.pl b/opac/opac-search-history.pl >index 34b0e84c63..fb7e11bf8f 100755 >--- a/opac/opac-search-history.pl >+++ b/opac/opac-search-history.pl >@@ -22,10 +22,12 @@ use Modern::Perl; > use C4::Auth qw(:DEFAULT get_session); > use CGI qw ( -utf8 ); > use C4::Context; >+use C4::Languages; > use C4::Output; > use C4::Log; > use C4::Items; > use C4::Debug; >+use C4::Search; > use C4::Search::History; > > use URI::Escape; >@@ -46,65 +48,61 @@ 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 ) { >- # Deleting search history >- if ( $action eq 'delete') { >- # Deleting session's search history >- my @id = $cgi->multi_param('id'); >- my $all = not scalar( @id ); >- >- my $type = $cgi->param('type'); >- my @searches = (); >- unless ( $all ) { >- @searches = C4::Search::History::get_from_session({ cgi => $cgi }); >- if ( $type ) { >- @searches = map { $_->{type} ne $type ? $_ : () } @searches; >- } >- if ( @id ) { >- @searches = map { my $search = $_; ( grep {/^$search->{id}$/} @id ) ? () : $_ } @searches; >- } >- } >- C4::Search::History::set_to_session({ cgi => $cgi, search_history => \@searches }); >+if ( $action eq 'search' ) { >+ # Start a new search > >- # Redirecting to this same url so the user won't see the search history link in the header >- print $cgi->redirect(-uri => '/cgi-bin/koha/opac-search-history.pl'); >- # Showing search history >+ my @ids = $cgi->multi_param('id'); >+ my @nots = $cgi->multi_param('not'); >+ my @searches; >+ if ($loggedinuser) { >+ @searches = @{ C4::Search::History::get({ >+ userid => $loggedinuser, >+ id => \@ids, >+ }) }; > } 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, >- ); >+ @searches = C4::Search::History::get_from_session({ cgi => $cgi }); >+ if ( @ids ) { >+ @searches = map { >+ my $search = $_; >+ ( grep {/^$search->{id}$/} @ids ) ? $_ : () >+ } @searches; >+ } > } >-} else { >- # And if the user is logged in, we deal with the database >- my $dbh = C4::Context->dbh; >+ my @ccl_queries; >+ foreach my $search (@searches) { >+ my $scgi = new CGI($search->{query_cgi}); >+ my @operators = map uri_unescape($_), $scgi->multi_param('op'); >+ my @indexes = map uri_unescape($_), $scgi->multi_param('idx'); >+ my @operands = map uri_unescape($_), $scgi->multi_param('q'); >+ my @limits = map uri_unescape($_), $scgi->multi_param('limit'); >+ my @sort_by = $scgi->multi_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->multi_param('id'); >+ my @id = $cgi->multi_param('id'); >+ if ($loggedinuser) { > if ( @id ) { > C4::Search::History::delete( > { > userid => $loggedinuser, >- id => [ $cgi->param('id') ], >+ id => \@id, > } > ); > } else { >@@ -114,45 +112,61 @@ unless ( $loggedinuser ) { > } > ); > } >- # Redirecting to this same url so the user won't see the search history link in the header >- print $cgi->redirect(-uri => '/cgi-bin/koha/opac-search-history.pl'); >- >- # Showing search history > } else { >- my $current_searches = C4::Search::History::get({ >+ # Deleting session's search history >+ my $type = $cgi->param('type'); >+ my @searches = (); >+ if ( scalar @id ) { >+ @searches = C4::Search::History::get_from_session({ cgi => $cgi }); >+ if ( $type ) { >+ @searches = map { $_->{type} ne $type ? $_ : () } @searches; >+ } >+ if ( @id ) { >+ @searches = map { my $search = $_; ( grep {/^$search->{id}$/} @id ) ? () : $_ } @searches; >+ } >+ } >+ 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 >+ print $cgi->redirect(-uri => '/cgi-bin/koha/opac-search-history.pl'); >+ exit; >+} else { >+ # Showing search history >+ 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); >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12460
:
29102
|
35699
|
41782
|
42450
|
59384
|
72091
|
72092
|
78648
|
78649
|
78650