@@ -, +, @@ (#1 or #3) and #6 --- C4/Search/History.pm | 32 +++++++++ catalogue/search-history.pl | 32 ++------- .../en/modules/catalogue/search-history.tt | 70 ++++--------------- .../en/modules/opac-search-history.tt | 58 +++------------ opac/opac-search-history.pl | 43 ++---------- 5 files changed, 64 insertions(+), 171 deletions(-) --- a/C4/Search/History.pm +++ a/C4/Search/History.pm @@ -228,6 +228,38 @@ sub set_to_session { uri_escape( encode_json($search_history) ) ); } +sub get_query { + my ($id, $borrowernumber, $lang, $default) = @_; + + my $searches = C4::Search::History::get({ + type => 'biblio', + userid => $borrowernumber, + id => $id, + }); + + if (ref $searches eq 'ARRAY' && scalar @$searches > 0) { + my $search = $searches->[0]; + 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'); + + require C4::Search; + my ( undef, $query ) = + C4::Search::buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by, + $scan, $lang ); + + return "($query)"; + } + + # Default if not found + return "allrecords,alwaysmatches=''"; +} + + 1; __END__ --- a/catalogue/search-history.pl +++ a/catalogue/search-history.pl @@ -44,34 +44,10 @@ my $action = $cgi->param('action') || q{list}; 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) . ')'; + my $lang = C4::Languages::getlanguage($cgi); + my $search = $cgi->param('search'); + $search =~ s|#(\d+)|C4::Search::History::get_query($1, $loggedinuser, $lang)|eg; + my $query = "ccl=$search"; print $cgi->redirect("/cgi-bin/koha/catalogue/search.pl?q=$query"); exit; } elsif ( $action eq 'delete' ) { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt @@ -6,22 +6,8 @@ [% USE date %] [% BLOCK search_history_table %] -
+ [%# Search from multiple lines is only enabled for biblios %] - [% IF type == 'biblio' %] -
- Start a new search - - New search: - - - Cancel - -
- [% END %]
Select all visible rows | @@ -37,7 +23,7 @@ - Not + Id Session date Date Search @@ -48,12 +34,7 @@ [% FOREACH s IN searches %] - - - + #[% s.id %] [% IF s.session %] [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %] @@ -83,6 +64,14 @@ + + [% IF type == 'biblio' %] +
+ + + +
+ [% END %] [% END %] [% INCLUDE 'doc-head-open.inc' %] @@ -145,8 +134,7 @@ "aaSorting": [[ 3, "desc" ]], "aoColumnDefs": [ { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false }, - { "aTargets": [ 2, 3 ], "sType": "title-string" }, - { "aTargets": [ 1 ], "bVisible": false } + { "aTargets": [ 2, 3 ], "sType": "title-string" } ], "sPaginationType": "full_numbers" })); @@ -156,7 +144,7 @@ // DataTables removes hidden rows from the DOM, so we can't expect a // "regular" submit to work and we need to build another form containing // all form elements, and then submit this form. - $('#tabs form').submit(function(e) { + $('#tabs form.datatable').submit(function(e) { e.preventDefault(); var form = $(this); @@ -218,38 +206,6 @@ 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)); }); --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt @@ -5,21 +5,8 @@ [% USE date %] [% BLOCK search_history_table %] -
+
- [% IF type == 'biblio' %] - Start a new search - - New search: - - - Cancel - -   - [% END %]
Select all @@ -35,7 +22,7 @@ - Not + Id [% IF hide_session_column %] Session date [% ELSE %] @@ -50,12 +37,7 @@ [% FOREACH s IN searches %] - - - + #[% s.id %] [% IF hide_session_column %] [% ELSE %] @@ -96,6 +78,14 @@ + + [% IF type == 'biblio' %] +
+ + + +
+ [% END %] [% END %] [% INCLUDE 'doc-head-open.inc' %] @@ -214,32 +204,6 @@ } 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); --- a/opac/opac-search-history.pl +++ a/opac/opac-search-history.pl @@ -57,45 +57,10 @@ my $action = $cgi->param('action') || q{}; if ( $action eq 'search' ) { # Start a new search - 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 { - @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->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) . ')'; + my $lang = C4::Languages::getlanguage($cgi); + my $search = $cgi->param('search'); + $search =~ s|#(\d+)|C4::Search::History::get_query($1, $loggedinuser, $lang)|eg; + my $query = "ccl=$search"; print $cgi->redirect("/cgi-bin/koha/opac-search.pl?q=$query"); exit; } elsif ( $action eq 'delete' ) { --