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 6-27 Link Here
6
[% USE date %]
6
[% USE date %]
7
7
8
[% BLOCK search_history_table %]
8
[% BLOCK search_history_table %]
9
  <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
9
  <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get" class="datatable">
10
    [%# Search from multiple lines is only enabled for biblios %]
10
    [%# Search from multiple lines is only enabled for biblios %]
11
    [% IF type == 'biblio' %]
12
    <div>
13
      <a href="#" class="action_search">Start a new search</a>
14
      <span class='search_options'>
15
        <span>New search:</span>
16
        <select name='join'>
17
          <option value="or" selected="selected">match any of selected searches</option>
18
          <option value="and">match all of selected searches</option>
19
        </select>
20
        <button type="submit">Go</button>
21
        <a href="#" class="action_search_cancel">Cancel</a>
22
      </span>
23
    </div>
24
    [% END %]
25
    <div class="selections-toolbar">
11
    <div class="selections-toolbar">
26
      <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
12
      <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
27
      <span class="sep">|</span>
13
      <span class="sep">|</span>
Lines 37-43 Link Here
37
      <thead>
23
      <thead>
38
        <tr>
24
        <tr>
39
          <th></th>
25
          <th></th>
40
          <th class="not">Not</th>
26
          <th>Id</th>
41
          <th>Session date</th>
27
          <th>Session date</th>
42
          <th>Date</th>
28
          <th>Date</th>
43
          <th>Search</th>
29
          <th>Search</th>
Lines 48-59 Link Here
48
      [% FOREACH s IN searches %]
34
      [% FOREACH s IN searches %]
49
        <tr>
35
        <tr>
50
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
36
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
51
          <td class="not">
37
          <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
          <td>
38
          <td>
58
            [% IF s.session %]
39
            [% IF s.session %]
59
              [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %]
40
              [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %]
Lines 83-88 Link Here
83
      </tbody>
64
      </tbody>
84
    </table>
65
    </table>
85
  </form>
66
  </form>
67
68
  [% IF type == 'biblio' %]
69
    <form method="post">
70
      <input type="hidden" name="action" value="search"/>
71
      <input type="text" name="search" placeholder="(#1 or #3) and #6"/>
72
      <button type="submit">Combine queries</button>
73
    </form>
74
  [% END %]
86
[% END %]
75
[% END %]
87
76
88
[% INCLUDE 'doc-head-open.inc' %]
77
[% 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 5-25 Link Here
5
[% USE date %]
5
[% USE date %]
6
6
7
[% BLOCK search_history_table %]
7
[% BLOCK search_history_table %]
8
  <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
8
  <form action="/cgi-bin/koha/opac-search-history.pl" method="get" class="datatable">
9
    <div>
9
    <div>
10
      [% IF type == 'biblio' %]
11
        <a href="#" class="action_search">Start a new search</a>
12
        <span class='search_options form-inline'>
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
        &nbsp;
22
      [% END %]
23
    </div>
10
    </div>
24
    <div class="selections-toolbar toolbar">
11
    <div class="selections-toolbar toolbar">
25
      <a class="CheckAll" href="#">Select all</a>
12
      <a class="CheckAll" href="#">Select all</a>
Lines 35-41 Link Here
35
      <thead>
22
      <thead>
36
        <tr>
23
        <tr>
37
          <th></th>
24
          <th></th>
38
          <th class="not">Not</th>
25
          <th>Id</th>
39
          [% IF hide_session_column %]
26
          [% IF hide_session_column %]
40
            <th class="hide">Session date</th>
27
            <th class="hide">Session date</th>
41
          [% ELSE %]
28
          [% ELSE %]
Lines 50-61 Link Here
50
      [% FOREACH s IN searches %]
37
      [% FOREACH s IN searches %]
51
        <tr>
38
        <tr>
52
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
39
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
53
          <td class="not">
40
          <td>#[% s.id %]</td>
54
            <select name="not">
55
              <option value=""></option>
56
              <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option>
57
            </select>
58
          </td>
59
          [% IF hide_session_column %]
41
          [% IF hide_session_column %]
60
            <td class="hide">
42
            <td class="hide">
61
          [% ELSE %]
43
          [% ELSE %]
Lines 96-101 Link Here
96
    </table>
78
    </table>
97
    <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
79
    <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
98
  </form>
80
  </form>
81
82
  [% IF type == 'biblio' %]
83
    <form method="post" class="form-inline">
84
      <input type="hidden" name="action" value="search"/>
85
      <input type="text" name="search" placeholder="(#1 or #3) and #6"/>
86
      <button type="submit" class="btn btn-default">Combine queries</button>
87
    </form>
88
  [% END %]
99
[% END %]
89
[% END %]
100
90
101
[% INCLUDE 'doc-head-open.inc' %]
91
[% INCLUDE 'doc-head-open.inc' %]
Lines 214-245 Link Here
214
            }
204
            }
215
            return false;
205
            return false;
216
        });
206
        });
217
        $(".action_search").click(function() {
218
          var $form = $(this).parents('form');
219
          $(this).hide();
220
          $('.search_options').show();
221
          $('.not').show();
222
          return false;
223
        });
224
225
        $('.search_options button[type="submit"]').click(function() {
226
          var $form = $(this).parents('form');
227
          var $checked = $form.find('input:checkbox:checked');
228
          if ($checked.length ) {
229
            $form.find('input[name="action"]').val('search');
230
            $form.submit();
231
          } else {
232
            alert(_("You have to select searches first"));
233
          }
234
          return false;
235
        });
236
237
        $('.action_search_cancel').click(function() {
238
          $('.action_search').show();
239
          $('.search_options').hide();
240
          $('.not').hide();
241
          return false;
242
        }).click();
243
207
244
        $('form').each(function() {
208
        $('form').each(function() {
245
          enableCheckboxActions(this);
209
          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