View | Details | Raw Unified | Return to bug 12460
Collapse All | Expand All

(-)a/C4/Search/History.pm (+32 lines)
Lines 228-233 sub set_to_session { Link Here
228
        uri_escape( encode_json($search_history) ) );
228
        uri_escape( encode_json($search_history) ) );
229
}
229
}
230
230
231
sub get_query {
232
    my ($id, $borrowernumber, $lang, $default) = @_;
233
234
    my $searches = C4::Search::History::get({
235
        type => 'biblio',
236
        userid => $borrowernumber,
237
        id => $id,
238
    });
239
240
    if (ref $searches eq 'ARRAY' && scalar @$searches > 0) {
241
        my $search = $searches->[0];
242
        my $scgi = new CGI($search->{query_cgi});
243
        my @operators = map uri_unescape($_), $scgi->multi_param('op');
244
        my @indexes = map uri_unescape($_), $scgi->multi_param('idx');
245
        my @operands = map uri_unescape($_), $scgi->multi_param('q');
246
        my @limits = map uri_unescape($_), $scgi->multi_param('limit');
247
        my @sort_by = $scgi->multi_param('sort_by');
248
        my $scan = $scgi->param('scan');
249
250
        require C4::Search;
251
        my ( undef, $query ) =
252
          C4::Search::buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by,
253
            $scan, $lang );
254
255
        return "($query)";
256
    }
257
258
    # Default if not found
259
    return "allrecords,alwaysmatches=''";
260
}
261
262
231
1;
263
1;
232
264
233
__END__
265
__END__
(-)a/catalogue/search-history.pl (-28 / +4 lines)
Lines 44-77 my $action = $cgi->param('action') || q{list}; Link Here
44
if ( $action eq 'search' ) {
44
if ( $action eq 'search' ) {
45
    # Start a new search
45
    # Start a new search
46
46
47
    my @ids = $cgi->multi_param('id');
47
    my $lang = C4::Languages::getlanguage($cgi);
48
    my @nots = $cgi->multi_param('not');
48
    my $search = $cgi->param('search');
49
    my $searches = C4::Search::History::get({
49
    $search =~ s|#(\d+)|C4::Search::History::get_query($1, $loggedinuser, $lang)|eg;
50
        userid => $loggedinuser,
50
    my $query = "ccl=$search";
51
        id => \@ids,
52
    });
53
    my @ccl_queries;
54
    foreach my $search (@$searches) {
55
        my $scgi = new CGI($search->{query_cgi});
56
        my @operators = map uri_unescape($_), $scgi->multi_param('op');
57
        my @indexes = map uri_unescape($_), $scgi->multi_param('idx');
58
        my @operands = map uri_unescape($_), $scgi->multi_param('q');
59
        my @limits = map uri_unescape($_), $scgi->multi_param('limit');
60
        my @sort_by = $scgi->param('sort_by');
61
        my $scan = $scgi->param('scan');
62
        my $lang = C4::Languages::getlanguage($cgi);
63
        my ( $error, $query ) =
64
          buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by,
65
            $scan, $lang );
66
67
        if (grep {$_ == $search->{id}} @nots) {
68
            $query = "allrecords,alwaysmatches='' not ($query)";
69
        }
70
71
        push @ccl_queries, $query;
72
    }
73
    my $join = ($cgi->param('join') eq 'or') ? 'or' : 'and';
74
    my $query = 'ccl=(' . join(") $join (", @ccl_queries) . ')';
75
    print $cgi->redirect("/cgi-bin/koha/catalogue/search.pl?q=$query");
51
    print $cgi->redirect("/cgi-bin/koha/catalogue/search.pl?q=$query");
76
    exit;
52
    exit;
77
} elsif ( $action eq 'delete' ) {
53
} elsif ( $action eq 'delete' ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt (-57 / +13 lines)
Lines 4-25 Link Here
4
[% USE date %]
4
[% USE date %]
5
5
6
[% BLOCK search_history_table %]
6
[% BLOCK search_history_table %]
7
  <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
7
  <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get" class="datatable">
8
    [%# Search from multiple lines is only enabled for biblios %]
8
    [%# Search from multiple lines is only enabled for biblios %]
9
    [% IF type == 'biblio' %]
10
    <div>
11
      <a href="#" class="action_search">Start a new search</a>
12
      <span class='search_options'>
13
        <span>New search:</span>
14
        <select name='join'>
15
          <option value="or" selected="selected">match any of selected searches</option>
16
          <option value="and">match all of selected searches</option>
17
        </select>
18
        <button type="submit">Go</button>
19
        <a href="#" class="action_search_cancel">Cancel</a>
20
      </span>
21
    </div>
22
    [% END %]
23
    <div class="selections-toolbar">
9
    <div class="selections-toolbar">
24
      <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
10
      <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
25
      <span class="sep">|</span>
11
      <span class="sep">|</span>
Lines 35-41 Link Here
35
      <thead>
21
      <thead>
36
        <tr>
22
        <tr>
37
          <th></th>
23
          <th></th>
38
          <th class="not">Not</th>
24
          <th>Id</th>
39
          <th>Session date</th>
25
          <th>Session date</th>
40
          <th>Date</th>
26
          <th>Date</th>
41
          <th>Search</th>
27
          <th>Search</th>
Lines 46-57 Link Here
46
      [% FOREACH s IN searches %]
32
      [% FOREACH s IN searches %]
47
        <tr>
33
        <tr>
48
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
34
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
49
          <td class="not">
35
          <td>#[% s.id %]</td>
50
            <select name="not">
51
              <option value=""></option>
52
              <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option>
53
            </select>
54
          </td>
55
          <td>
36
          <td>
56
            [% IF s.session %]
37
            [% IF s.session %]
57
              [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %]
38
              [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %]
Lines 81-86 Link Here
81
      </tbody>
62
      </tbody>
82
    </table>
63
    </table>
83
  </form>
64
  </form>
65
66
  [% IF type == 'biblio' %]
67
    <form method="post">
68
      <input type="hidden" name="action" value="search"/>
69
      <input type="text" name="search" placeholder="(#1 or #3) and #6"/>
70
      <button type="submit">Combine queries</button>
71
    </form>
72
  [% END %]
84
[% END %]
73
[% END %]
85
74
86
[% INCLUDE 'doc-head-open.inc' %]
75
[% INCLUDE 'doc-head-open.inc' %]
Lines 145-152 Link Here
145
            "aaSorting": [[ 3, "desc" ]],
134
            "aaSorting": [[ 3, "desc" ]],
146
            "aoColumnDefs": [
135
            "aoColumnDefs": [
147
                { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false },
136
                { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false },
148
                { "aTargets": [ 2, 3 ], "sType": "title-string" },
137
                { "aTargets": [ 2, 3 ], "sType": "title-string" }
149
                { "aTargets": [ 1 ], "bVisible": false }
150
            ],
138
            ],
151
            "sPaginationType": "full_numbers"
139
            "sPaginationType": "full_numbers"
152
        }));
140
        }));
Lines 156-162 Link Here
156
        // DataTables removes hidden rows from the DOM, so we can't expect a
144
        // DataTables removes hidden rows from the DOM, so we can't expect a
157
        // "regular" submit to work and we need to build another form containing
145
        // "regular" submit to work and we need to build another form containing
158
        // all form elements, and then submit this form.
146
        // all form elements, and then submit this form.
159
        $('#tabs form').submit(function(e) {
147
        $('#tabs form.datatable').submit(function(e) {
160
            e.preventDefault();
148
            e.preventDefault();
161
149
162
            var form = $(this);
150
            var form = $(this);
Lines 218-255 Link Here
218
            return false;
206
            return false;
219
        });
207
        });
220
208
221
        $(".action_search").click(function() {
222
          var $form = $(this).parents('form');
223
          var table = $form.find('table').dataTable();
224
          var $checked = table.$('input:checkbox:checked');
225
          $(this).hide();
226
          $('.search_options').show();
227
          table.fnSetColumnVis(1, true);
228
          return false;
229
        });
230
231
        $('.search_options button[type="submit"]').click(function() {
232
          var $form = $(this).parents('form');
233
          var table = $form.find('table').dataTable();
234
          var $checked = table.$('input:checkbox:checked');
235
          if ($checked.length) {
236
            $form.find('input[name="action"]').val('search');
237
            $form.submit();
238
          } else {
239
            alert(_("You have to select searches first"));
240
          }
241
          return false;
242
        });
243
244
        $('.action_search_cancel').click(function() {
245
          var form = $(this).parents('form').first();
246
          var table = form.find('table').dataTable();
247
          $('.action_search').show();
248
          $('.search_options').hide();
249
          table.fnSetColumnVis(1, false);
250
          return false;
251
        }).click();
252
253
        $('#tabs form').each(function() {
209
        $('#tabs form').each(function() {
254
            enableCheckboxActions($(this));
210
            enableCheckboxActions($(this));
255
        });
211
        });
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt (-47 / +11 lines)
Lines 3-23 Link Here
3
[% USE date %]
3
[% USE date %]
4
4
5
[% BLOCK search_history_table %]
5
[% BLOCK search_history_table %]
6
  <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
6
  <form action="/cgi-bin/koha/opac-search-history.pl" method="get" class="datatable">
7
    <div>
7
    <div>
8
      [% IF type == 'biblio' %]
9
        <a href="#" class="action_search">Start a new search</a>
10
        <span class='search_options form-inline'>
11
          <span>New search:</span>
12
          <select name='join'>
13
            <option value="or" selected="selected">match any of selected searches</option>
14
            <option value="and">match all of selected searches</option>
15
          </select>
16
          <button type="submit">Go</button>
17
          <a href="#" class="action_search_cancel">Cancel</a>
18
        </span>
19
        &nbsp;
20
      [% END %]
21
    </div>
8
    </div>
22
    <div class="selections-toolbar toolbar">
9
    <div class="selections-toolbar toolbar">
23
      <a class="CheckAll" href="#">Select all</a>
10
      <a class="CheckAll" href="#">Select all</a>
Lines 33-39 Link Here
33
      <thead>
20
      <thead>
34
        <tr>
21
        <tr>
35
          <th></th>
22
          <th></th>
36
          <th class="not">Not</th>
23
          <th>Id</th>
37
          [% IF hide_session_column %]
24
          [% IF hide_session_column %]
38
            <th class="hide">Session date</th>
25
            <th class="hide">Session date</th>
39
          [% ELSE %]
26
          [% ELSE %]
Lines 48-59 Link Here
48
      [% FOREACH s IN searches %]
35
      [% FOREACH s IN searches %]
49
        <tr>
36
        <tr>
50
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
37
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
51
          <td class="not">
38
          <td>#[% s.id %]</td>
52
            <select name="not">
53
              <option value=""></option>
54
              <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option>
55
            </select>
56
          </td>
57
          [% IF hide_session_column %]
39
          [% IF hide_session_column %]
58
            <td class="hide">
40
            <td class="hide">
59
          [% ELSE %]
41
          [% ELSE %]
Lines 94-99 Link Here
94
    </table>
76
    </table>
95
    <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
77
    <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
96
  </form>
78
  </form>
79
80
  [% IF type == 'biblio' %]
81
    <form method="post" class="form-inline">
82
      <input type="hidden" name="action" value="search"/>
83
      <input type="text" name="search" placeholder="(#1 or #3) and #6"/>
84
      <button type="submit" class="btn btn-default">Combine queries</button>
85
    </form>
86
  [% END %]
97
[% END %]
87
[% END %]
98
88
99
[% INCLUDE 'doc-head-open.inc' %]
89
[% INCLUDE 'doc-head-open.inc' %]
Lines 211-242 Link Here
211
            }
201
            }
212
            return false;
202
            return false;
213
        });
203
        });
214
        $(".action_search").click(function() {
215
          var $form = $(this).parents('form');
216
          $(this).hide();
217
          $('.search_options').show();
218
          $('.not').show();
219
          return false;
220
        });
221
222
        $('.search_options button[type="submit"]').click(function() {
223
          var $form = $(this).parents('form');
224
          var $checked = $form.find('input:checkbox:checked');
225
          if ($checked.length ) {
226
            $form.find('input[name="action"]').val('search');
227
            $form.submit();
228
          } else {
229
            alert(_("You have to select searches first"));
230
          }
231
          return false;
232
        });
233
234
        $('.action_search_cancel').click(function() {
235
          $('.action_search').show();
236
          $('.search_options').hide();
237
          $('.not').hide();
238
          return false;
239
        }).click();
240
204
241
        $('form').each(function() {
205
        $('form').each(function() {
242
          enableCheckboxActions(this);
206
          enableCheckboxActions(this);
(-)a/opac/opac-search-history.pl (-40 / +4 lines)
Lines 57-101 my $action = $cgi->param('action') || q{}; Link Here
57
if ( $action eq 'search' ) {
57
if ( $action eq 'search' ) {
58
    # Start a new search
58
    # Start a new search
59
59
60
    my @ids = $cgi->multi_param('id');
60
    my $lang = C4::Languages::getlanguage($cgi);
61
    my @nots = $cgi->multi_param('not');
61
    my $search = $cgi->param('search');
62
    my @searches;
62
    $search =~ s|#(\d+)|C4::Search::History::get_query($1, $loggedinuser, $lang)|eg;
63
    if ($loggedinuser) {
63
    my $query = "ccl=$search";
64
        @searches = @{ C4::Search::History::get({
65
            userid => $loggedinuser,
66
            id => \@ids,
67
        }) };
68
    } else {
69
        @searches = C4::Search::History::get_from_session({ cgi => $cgi });
70
        if ( @ids ) {
71
            @searches = map {
72
                my $search = $_;
73
                ( grep {/^$search->{id}$/} @ids ) ? $_ : ()
74
            } @searches;
75
        }
76
    }
77
    my @ccl_queries;
78
    foreach my $search (@searches) {
79
        my $scgi = new CGI($search->{query_cgi});
80
        my @operators = map uri_unescape($_), $scgi->multi_param('op');
81
        my @indexes = map uri_unescape($_), $scgi->multi_param('idx');
82
        my @operands = map uri_unescape($_), $scgi->multi_param('q');
83
        my @limits = map uri_unescape($_), $scgi->multi_param('limit');
84
        my @sort_by = $scgi->multi_param('sort_by');
85
        my $scan = $scgi->param('scan');
86
        my $lang = C4::Languages::getlanguage($cgi);
87
        my ( $error, $query ) =
88
          buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by,
89
            $scan, $lang );
90
91
        if (grep {$_ == $search->{id}} @nots) {
92
            $query = "allrecords,alwaysmatches='' not ($query)";
93
        }
94
95
        push @ccl_queries, $query;
96
    }
97
    my $join = ($cgi->param('join') eq 'or') ? 'or' : 'and';
98
    my $query = 'ccl=(' . join(") $join (", @ccl_queries) . ')';
99
    print $cgi->redirect("/cgi-bin/koha/opac-search.pl?q=$query");
64
    print $cgi->redirect("/cgi-bin/koha/opac-search.pl?q=$query");
100
    exit;
65
    exit;
101
} elsif ( $action eq 'delete' ) {
66
} elsif ( $action eq 'delete' ) {
102
- 

Return to bug 12460