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

(-)a/C4/Search/History.pm (-19 / +26 lines)
Lines 155-191 sub get { Link Here
155
    }
155
    }
156
156
157
    my $query = q{
157
    my $query = q{
158
        SELECT *
158
        SELECT sh.* , s.a_session
159
        FROM search_history
159
        FROM search_history sh
160
        LEFT JOIN sessions s ON (sh.sessionid = s.id)
160
        WHERE 1
161
        WHERE 1
161
    };
162
    };
162
163
163
    $query .= q{ AND id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )}
164
    my @bind_params;
164
        if @$id;
165
165
166
    $query .= q{
166
    if (@$id) {
167
        AND userid = ?
167
        $query .= q{ AND sh.id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )};
168
    } if $userid;
168
        push @bind_params, @$id;
169
    }
170
171
    if ($userid) {
172
        $query .= q{ AND sh.userid = ? };
173
        push @bind_params, $userid;
174
    }
169
175
170
    if ($sessionid) {
176
    if ($sessionid) {
171
        $query .=
177
        if (defined $previous) {
172
          $previous
178
            $query .=
173
          ? q{ AND sessionid != ?}
179
              $previous
174
          : q{ AND sessionid = ?};
180
              ? q{ AND sh.sessionid != ?}
181
              : q{ AND sh.sessionid = ?};
182
            push @bind_params, $sessionid;
183
        }
175
    }
184
    }
176
185
177
    $query .= q{ AND type = ?}
186
    if ($type) {
178
      if $type;
187
        $query .= q{ AND sh.type = ?};
188
        push @bind_params, $type;
189
    }
179
190
180
    my $dbh = C4::Context->dbh;
191
    my $dbh = C4::Context->dbh;
181
    my $sth = $dbh->prepare($query);
192
    my $sth = $dbh->prepare($query);
182
    $sth->execute(
193
    $sth->execute(@bind_params);
183
        ( @$id ? ( @$id ) : () ),
184
        ( $userid ? $userid : () ),
185
        ( $sessionid ? $sessionid : () ),
186
        ( $type      ? $type      : () )
187
    );
188
    return $sth->fetchall_arrayref( {} );
194
    return $sth->fetchall_arrayref( {} );
195
189
}
196
}
190
197
191
sub get_from_session {
198
sub get_from_session {
(-)a/catalogue/search-history.pl (-41 / +57 lines)
Lines 20-27 Link Here
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use URI::Escape;
23
24
24
use C4::Auth;
25
use C4::Auth;
26
use C4::Languages;
27
use C4::Search;
25
use C4::Search::History;
28
use C4::Search::History;
26
use C4::Output;
29
use C4::Output;
27
30
Lines 37-97 my ($template, $loggedinuser, $cookie) = get_template_and_user({ Link Here
37
40
38
my $type = $cgi->param('type');
41
my $type = $cgi->param('type');
39
my $action = $cgi->param('action') || q{list};
42
my $action = $cgi->param('action') || q{list};
40
my $previous = $cgi->param('previous');
41
43
42
# Deleting search history
44
if ( $action eq 'search' ) {
43
if ( $action eq 'delete' ) {
45
    # Start a new search
44
    my $sessionid = defined $previous
46
45
        ? $cgi->cookie("CGISESSID")
47
    my @ids = $cgi->param('id');
46
        : q{};
48
    my @nots = $cgi->param('not');
47
    C4::Search::History::delete(
49
    my $searches = C4::Search::History::get({
48
        {
50
        userid => $loggedinuser,
49
            id => [ $cgi->param('id') ],
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->param('op');
57
        my @indexes = map uri_unescape($_), $scgi->param('idx');
58
        my @operands = map uri_unescape($_), $scgi->param('q');
59
        my @limits = map uri_unescape($_), $scgi->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)";
50
        }
69
        }
51
    );
70
52
    # Redirecting to this same url so the user won't see the search history link in the header
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");
76
    exit;
77
} elsif ( $action eq 'delete' ) {
78
    # Deleting search history
79
    C4::Search::History::delete({ id => [ $cgi->param('id') ] });
80
    # Redirecting to this same url so the user won't see the search history link
81
    # in the header
53
    my $uri = $cgi->url();
82
    my $uri = $cgi->url();
54
    print $cgi->redirect($uri);
83
    print $cgi->redirect($uri);
55
84
    exit;
56
# Showing search history
57
} else {
85
} else {
58
    my $current_searches = C4::Search::History::get({
86
    # Showing search history
87
    my $searches = C4::Search::History::get({
59
        userid => $loggedinuser,
88
        userid => $loggedinuser,
60
        sessionid => $cgi->cookie("CGISESSID")
89
        sessionid => $cgi->cookie("CGISESSID")
61
    });
90
    });
62
    my @current_biblio_searches = map {
91
    foreach my $row (@$searches) {
63
        $_->{type} eq 'biblio' ? $_ : ()
92
        if ($row->{a_session}) {
64
    } @$current_searches;
93
            $row->{session} = YAML::Load($row->{a_session});
65
94
            $row->{session}->{session_ctime} = $row->{session}->{_SESSION_CTIME};
66
    my @current_authority_searches = map {
95
            $row->{session}->{session_id} = $row->{session}->{_SESSION_ID};
67
        $_->{type} eq 'authority' ? $_ : ()
96
        }
68
    } @$current_searches;
97
    }
69
98
    my @biblio_searches = map {
70
    my $previous_searches = C4::Search::History::get({
71
        userid => $loggedinuser,
72
        sessionid => $cgi->cookie("CGISESSID"),
73
        previous => 1
74
    });
75
76
    my @previous_biblio_searches = map {
77
        $_->{type} eq 'biblio' ? $_ : ()
99
        $_->{type} eq 'biblio' ? $_ : ()
78
    } @$previous_searches;
100
    } @$searches;
79
101
80
    my @previous_authority_searches = map {
102
    my @authority_searches = map {
81
        $_->{type} eq 'authority' ? $_ : ()
103
        $_->{type} eq 'authority' ? $_ : ()
82
    } @$previous_searches;
104
    } @$searches;
83
105
84
    $template->param(
106
    $template->param(
85
        current_biblio_searches => \@current_biblio_searches,
107
        biblio_searches => \@biblio_searches,
86
        current_authority_searches => \@current_authority_searches,
108
        authority_searches => \@authority_searches,
87
        previous_biblio_searches => \@previous_biblio_searches,
109
        sessionid => $cgi->cookie("CGISESSID"),
88
        previous_authority_searches => \@previous_authority_searches,
89
90
    );
110
    );
91
}
111
}
92
112
93
94
$template->param(
95
);
96
97
output_html_with_http_headers $cgi, $cookie, $template->output;
113
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt (-150 / +126 lines)
Lines 1-6 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% USE Koha %]
1
[% USE Koha %]
3
[% USE KohaDates %]
2
[% USE KohaDates %]
3
[% USE date %]
4
5
[% BLOCK search_history_table %]
6
  <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
7
    <div class="selections-toolbar">
8
      <a class="CheckAll" href="#">Select all</a>
9
      <a class="CheckNone" href="#">Clear all</a>
10
      <span class="sep">|</span>
11
      <span class="links">
12
        <span class="selections">Select searches to: </span>
13
        [%# Search from multiple lines is only enabled for biblios %]
14
        [% IF type == 'biblio' %]
15
          <a href="#" class="action_search disabled">Start a new search</a>
16
          <a href="#" class="action_search_cancel">Cancel new search</a>
17
          <span class='search_options'>
18
            <select name='join'>
19
              <option value="or" selected="selected">match any of selected searches</option>
20
              <option value="and">match all of selected searches</option>
21
            </select>
22
            <button type="submit">Go</button>
23
          </span>
24
          &nbsp;
25
        [% END %]
26
        <a href="#" class="action_delete disabled">Delete</a>
27
      </span>
28
    </div>
29
    <input type="hidden" name="action" value="delete" />
30
    <table class="historyt">
31
      <thead>
32
        <tr>
33
          <th></th>
34
          <th class="not">Not</th>
35
          <th>Session date</th>
36
          <th>Date</th>
37
          <th>Search</th>
38
          <th>Results</th>
39
        </tr>
40
      </thead>
41
      <tbody>
42
      [% FOREACH s IN searches %]
43
        <tr>
44
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
45
          <td class="not">
46
            <select name="not">
47
              <option value=""></option>
48
              <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option>
49
            </select>
50
          </td>
51
          <td>
52
            [% IF s.session %]
53
              [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %]
54
              <span title="[% session_ctime %]">
55
                [% IF s.session.session_id == sessionid %]
56
                  <strong title="Current session">
57
                [% END %]
58
                [% session_ctime | $KohaDates %]
59
                [% IF s.session.session_id == sessionid %]
60
                  </strong>
61
                [% END %]
62
              </span>
63
            [% ELSE %]
64
              <span title="">Unknown</span>
65
            [% END %]
66
          </td>
67
          <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
68
          [% IF type == 'biblio' %]
69
            [% search_url = '/cgi-bin/koha/catalogue/search.pl' %]
70
          [% ELSE %]
71
            [% search_url = '/cgi-bin/koha/authorities/authorities-home.pl' %]
72
          [% END %]
73
          <td><a href="[% search_url %]?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
74
          <td>[% s.total %]</td>
75
        </tr>
76
      [% END %]
77
      </tbody>
78
    </table>
79
  </form>
80
[% END %]
81
82
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Catalog &rsaquo; Search history</title>
83
<title>Koha &rsaquo; Catalog &rsaquo; Search history</title>
5
[% INCLUDE 'doc-head-close.inc' %]
84
[% INCLUDE 'doc-head-close.inc' %]
6
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
85
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
Lines 13-22 $(document).ready(function() { Link Here
13
    // We show table ordered by descending dates by default
92
    // We show table ordered by descending dates by default
14
    // (so that the more recent query is shown first)
93
    // (so that the more recent query is shown first)
15
    $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
94
    $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
16
        "aaSorting": [[ 1, "desc" ]],
95
        "aaSorting": [[ 3, "desc" ]],
17
        "aoColumnDefs": [
96
        "aoColumnDefs": [
18
            { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
97
            { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false },
19
            { "aTargets": [ 1 ], "sType": "title-string" },
98
            { "aTargets": [ 2, 3 ], "sType": "title-string" },
20
        ],
99
        ],
21
    }));
100
    }));
22
101
Lines 48-58 $(document).ready(function() { Link Here
48
            return false;
127
            return false;
49
        }
128
        }
50
        if ( confirm(MSG_CONFIRM_DELETE_HISTORY) ) {
129
        if ( confirm(MSG_CONFIRM_DELETE_HISTORY) ) {
130
            $(form).find('input[name="action"]').val('delete');
51
            $(form).submit();
131
            $(form).submit();
52
        }
132
        }
53
        return false;
133
        return false;
54
    });
134
    });
135
    $(".action_search").click(function() {
136
      var $form = $(this).parents('form');
137
      var $checked = $form.find('input:checkbox:checked');
138
      if ($checked.length) {
139
        $(this).hide();
140
        $('.action_search_cancel').show();
141
        $('.search_options').show();
142
        $('.not').show();
143
      }
144
      return false;
145
    });
146
147
    $('.search_options button[type="submit"]').click(function() {
148
      var $form = $(this).parents('form');
149
      var $checked = $form.find('input:checkbox:checked');
150
      if ($checked.length ) {
151
        $form.find('input[name="action"]').val('search');
152
        $form.submit();
153
      }
154
      return false;
155
    });
156
157
    $('.action_search_cancel').click(function() {
158
      $(this).hide();
159
      $('.action_search').show();
160
      $('.search_options').hide();
161
      $('.not').hide();
162
      return false;
163
    }).click();
55
164
165
    $('form').each(function() {
166
      enableCheckboxActions(this);
167
    });
56
});
168
});
57
169
58
function enableCheckboxActions(form){
170
function enableCheckboxActions(form){
Lines 92-248 function enableCheckboxActions(form){ Link Here
92
          <li><a href="#authority_tab">Authority</a></li>
204
          <li><a href="#authority_tab">Authority</a></li>
93
        </ul>
205
        </ul>
94
        <div id="biblio_tab">
206
        <div id="biblio_tab">
95
          [% IF ( current_biblio_searches ) %]
207
          [% IF ( biblio_searches ) %]
96
            <h2>Current session</h2>
208
            [% INCLUDE search_history_table
97
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
209
              searches = biblio_searches
98
              <div class="selections-toolbar">
210
              type = 'biblio' %]
99
                <a class="CheckAll" href="#">Select all</a>
211
          [% ELSE %]
100
                <a class="CheckNone" href="#">Clear all</a>
101
                <span class="sep">|</span>
102
                <span class="links">
103
                  <span class="selections">Select searches to: </span>
104
                  <a href="#" class="action_delete disabled">Delete</a>
105
                </span>
106
              </div>
107
              <input type="hidden" name="action" value="delete" />
108
              <table class="historyt">
109
                <thead>
110
                  <tr>
111
                    <th></th>
112
                    <th>Date</th>
113
                    <th>Search</th>
114
                    <th>Results</th>
115
                  </tr>
116
                </thead>
117
                <tbody>
118
                [% FOREACH s IN current_biblio_searches %]
119
                  <tr>
120
                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
121
                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
122
                    <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
123
                    <td>[% s.total %]</td>
124
                  </tr>
125
                [% END %]
126
                </tbody>
127
              </table>
128
            </form>
129
          [% END %]
130
131
          [% IF ( previous_biblio_searches ) %]
132
            <h2>Previous sessions</h2>
133
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
134
              <div class="selections-toolbar">
135
                <a class="CheckAll" href="#">Select all</a>
136
                <a class="CheckNone" href="#">Clear all</a>
137
                <span class="sep">|</span>
138
                <span class="links">
139
                  <span class="selections">Select searches to: </span>
140
                  <a href="#" class="action_delete disabled">Delete</a>
141
                </span>
142
              </div>
143
              <input type="hidden" name="action" value="delete" />
144
              <table class="historyt">
145
                <thead>
146
                  <tr>
147
                    <th></th>
148
                    <th>Date</th>
149
                    <th>Search</th>
150
                    <th>Results</th>
151
                  </tr>
152
                </thead>
153
                <tbody>
154
                [% FOREACH s IN previous_biblio_searches %]
155
                  <tr>
156
                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
157
                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
158
                    <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
159
                    <td>[% s.total %]</td>
160
                  </tr>
161
                [% END %]
162
                </tbody>
163
              </table>
164
            </form>
165
          [% END %]
166
167
          [% IF !current_biblio_searches && !previous_biblio_searches %]
168
            <p>Your catalog search history is empty.</p>
212
            <p>Your catalog search history is empty.</p>
169
          [% END %]
213
          [% END %]
170
        </div>
214
        </div>
171
215
172
        <div id="authority_tab">
216
        <div id="authority_tab">
173
          [% IF ( current_authority_searches ) %]
217
          [% IF ( authority_searches ) %]
174
            <h2>Current session</h2>
218
            [% INCLUDE search_history_table
175
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
219
              searches = authority_searches
176
              <div class="selections-toolbar">
220
              type = 'authority' %]
177
                <a class="CheckAll" href="#">Select all</a>
221
          [% ELSE %]
178
                <a class="CheckNone" href="#">Clear all</a>
179
                <span class="sep">|</span>
180
                <span class="links">
181
                  <span class="selections">Select searches to: </span>
182
                  <a href="#" class="action_delete disabled">Delete</a>
183
                </span>
184
              </div>
185
              <input type="hidden" name="action" value="delete" />
186
              <table class="historyt">
187
                <thead>
188
                  <tr>
189
                    <th></th>
190
                    <th>Date</th>
191
                    <th>Search</th>
192
                    <th>Results</th>
193
                  </tr>
194
                </thead>
195
                <tbody>
196
                [% FOREACH s IN current_authority_searches %]
197
                  <tr>
198
                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
199
                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
200
                    <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
201
                    <td>[% s.total %]</td>
202
                  </tr>
203
                [% END %]
204
                </tbody>
205
              </table>
206
            </form>
207
          [% END %]
208
209
          [% IF ( previous_authority_searches ) %]
210
            <h2>Previous sessions</h2>
211
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
212
              <div class="selections-toolbar">
213
                <a class="CheckAll" href="#">Select all</a>
214
                <a class="CheckNone" href="#">Clear all</a>
215
                <span class="sep">|</span>
216
                <span class="links">
217
                  <span class="selections">Select searches to: </span>
218
                  <a href="#" class="action_delete disabled">Delete</a>
219
                </span>
220
              </div>
221
              <input type="hidden" name="action" value="delete" />
222
              <table class="historyt">
223
                <thead>
224
                  <tr>
225
                    <th></th>
226
                    <th>Date</th>
227
                    <th>Search</th>
228
                    <th>Results</th>
229
                  </tr>
230
                </thead>
231
                <tbody>
232
                [% FOREACH s IN previous_authority_searches %]
233
                  <tr>
234
                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
235
                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
236
                    <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
237
                    <td>[% s.total %]</td>
238
                  </tr>
239
                [% END %]
240
                </tbody>
241
              </table>
242
            </form>
243
          [% END %]
244
245
          [% IF !current_authority_searches && !previous_authority_searches %]
246
            <p>Your authority search history is empty.</p>
222
            <p>Your authority search history is empty.</p>
247
          [% END %]
223
          [% END %]
248
        </div>
224
        </div>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt (-186 / +164 lines)
Lines 1-5 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE KohaDates %]
2
[% USE KohaDates %]
3
[% USE date %]
4
5
[% BLOCK search_history_table %]
6
  <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
7
    <div class="selections-toolbar toolbar">
8
      <a class="CheckAll" href="#">Select all</a>
9
      <a class="CheckNone" href="#">Clear all</a>
10
      <span class="sep">|</span>
11
      <span class="links">
12
        <span class="selections">Select searches to: </span>
13
        [% IF type == 'biblio' %]
14
          <a href="#" class="action_search disabled">Start a new search</a>
15
          <a href="#" class="action_search_cancel">Cancel new search</a>
16
          <span class='search_options'>
17
            <select name='join'>
18
              <option value="or" selected="selected">match any of selected searches</option>
19
              <option value="and">match all of selected searches</option>
20
            </select>
21
            <button type="submit">Go</button>
22
          </span>
23
          &nbsp;
24
        [% END %]
25
        <a href="#" class="action_delete disabled">Delete</a>
26
      </span>
27
    </div>
28
    <input type="hidden" name="action" value="delete" />
29
    <table class="historyt table table-bordered table-striped">
30
      <thead>
31
        <tr>
32
          <th></th>
33
          <th class="not">Not</th>
34
          [% IF hide_session_column %]
35
            <th class="hide">Session date</th>
36
          [% ELSE %]
37
            <th>Session date</th>
38
          [% END %]
39
          <th>Date</th>
40
          <th>Search</th>
41
          <th>Results</th>
42
        </tr>
43
      </thead>
44
      <tbody>
45
      [% FOREACH s IN searches %]
46
        <tr>
47
          <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
48
          <td class="not">
49
            <select name="not">
50
              <option value=""></option>
51
              <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option>
52
            </select>
53
          </td>
54
          [% IF hide_session_column %]
55
            <td class="hide">
56
          [% ELSE %]
57
            <td>
58
          [% END %]
59
            [% IF s.session %]
60
              [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %]
61
              <span title="[% session_ctime %]">
62
                [% IF s.session.session_id == sessionid %]
63
                  <strong title="Current session">
64
                [% END %]
65
                [% session_ctime | $KohaDates %]
66
                [% IF s.session.session_id == sessionid %]
67
                  </strong>
68
                [% END %]
69
              </span>
70
            [% ELSE %]
71
              <span title="">Unknown</span>
72
            [% END %]
73
          </td>
74
          <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
75
          [% IF type == 'biblio' %]
76
            [% search_url = '/cgi-bin/koha/opac-search.pl' %]
77
          [% ELSIF type == 'authority' %]
78
            [% search_url = '/cgi-bin/koha/opac-authorities-home.pl' %]
79
          [% END %]
80
          <td>
81
            [% IF type == 'biblio' %]
82
              <a href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html |url %][% limit_cgi |html | url %]&amp;[% s.query_cgi |html %]&amp;count=[% countrss |html %]&amp;sort_by=acqdate_dsc&amp;format=rss2" class="rsssearchlink">
83
                <img src="[% interface %]/[% theme %]/images/feed-icon-16x16.png" alt="Subscribe to this search" title="Subscribe to this search" class="rsssearchicon"/>
84
              </a>
85
            [% END %]
86
            <a href="[% search_url %]?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
87
          <td>[% s.total %]</td>
88
        </tr>
89
      [% END %]
90
      </tbody>
91
    </table>
92
  </form>
93
[% END %]
94
3
[% INCLUDE 'doc-head-open.inc' %]
95
[% INCLUDE 'doc-head-open.inc' %]
4
[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Your search history
96
[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Your search history
5
[% INCLUDE 'doc-head-close.inc' %]
97
[% INCLUDE 'doc-head-close.inc' %]
Lines 31-216 Link Here
31
                <div class="span12">
123
                <div class="span12">
32
            [% END %]
124
            [% END %]
33
                <div id="searchhistory" class="maincontent">
125
                <div id="searchhistory" class="maincontent">
34
                    <h1>Search history</h1>
126
                  <h1>Search history</h1>
35
                    [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
127
                  [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
36
                        <div id="tabs" class="toptabs">
128
                    <div id="tabs" class="toptabs">
37
                            <ul>
129
                      <ul>
38
                                <li><a href="#biblio_tab">Catalog</a></li>
130
                        <li><a href="#biblio_tab">Catalog</a></li>
39
                                <li><a href="#authority_tab">Authority</a></li>
131
                        <li><a href="#authority_tab">Authority</a></li>
40
                            </ul>
132
                      </ul>
133
                  [% END %]
134
                  <div id="biblio_tab">
135
                    [% IF ( biblio_searches ) %]
136
                      [% INCLUDE search_history_table
137
                        searches = biblio_searches
138
                        type = 'biblio' %]
139
                    [% ELSE %]
140
                      <p>Your catalog search history is empty.</p>
41
                    [% END %]
141
                    [% END %]
42
                        <div id="biblio_tab">
142
                  </div>
43
                            <div id="current_biblio">
44
                                [% IF ( current_biblio_searches ) %]
45
                                    <h2>Current session</h2>
46
                                    <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
47
                                        <div class="selections-toolbar toolbar">
48
                                            <a class="CheckAll" href="#">Select all</a>
49
                                            <a class="CheckNone" href="#">Clear all</a>
50
                                            <span class="sep">|</span>
51
                                            <span class="links">
52
                                                <span class="selections">Select searches to: </span>
53
                                                <a href="#" class="removeitems disabled">Delete</a>
54
                                            </span>
55
                                        </div>
56
                                        <input type="hidden" name="action" value="delete" />
57
                                        <table class="historyt table table-bordered table-striped">
58
                                            <thead>
59
                                                <tr>
60
                                                    <th></th>
61
                                                    <th>Date</th>
62
                                                    <th>Search</th>
63
                                                    <th>Results</th>
64
                                                </tr>
65
                                            </thead>
66
                                            <tbody>
67
                                                [% FOREACH s IN current_biblio_searches %]
68
                                                    <tr>
69
                                                        <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
70
                                                        <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
71
                                                        <td><a href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html |url %][% limit_cgi |html | url %]&amp;[% s.query_cgi |html %]&amp;count=[% countrss |html %]&amp;sort_by=acqdate_dsc&amp;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>
72
                                                        <td>[% s.total %]</td>
73
                                                    </tr>
74
                                                [% END %]
75
                                            </tbody>
76
                                        </table>
77
                                        <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
78
                                    </form>
79
                                [% END # IF ( current_biblio_searches ) %]
80
                            </div> <!-- / #current_biblio -->
81
82
                            <div id="previous_biblio">
83
                                [% IF ( previous_biblio_searches ) %]
84
                                    <h2>Previous sessions</h2>
85
                                    <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
86
                                        <div class="selections-toolbar toolbar">
87
                                            <a class="CheckAll" href="#">Select all</a>
88
                                            <a class="CheckNone" href="#">Clear all</a>
89
                                            <span class="sep">|</span>
90
                                            <span class="links">
91
                                                <span class="selections">Select searches to: </span>
92
                                                <a href="#" class="removeitems disabled">Delete</a>
93
                                            </span>
94
                                        </div>
95
96
                                        <input type="hidden" name="action" value="delete" />
97
                                        <table class="historyt table table-bordered table-striped">
98
                                            <thead>
99
                                                <tr>
100
                                                    <th></th>
101
                                                    <th>Date</th>
102
                                                    <th>Search</th>
103
                                                    <th>Results</th>
104
                                                </tr>
105
                                            </thead>
106
                                            <tbody>
107
                                            [% FOREACH s IN previous_biblio_searches %]
108
                                                <tr>
109
                                                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
110
                                                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
111
                                                    <td><a href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html |url %][% limit_cgi |html | url %]&amp;[% s.query_cgi |html %]&amp;count=[% countrss |html %]&amp;sort_by=acqdate_dsc&amp;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>
112
                                                    <td>[% s.total %]</td>
113
                                                </tr>
114
                                            [% END %]
115
                                            </tbody>
116
                                        </table>
117
                                        <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
118
                                    </form>
119
                                [% END # IF ( previous_biblio_searches ) %]
120
                            </div> <!-- / #previous_biblio -->
121
122
                            [% IF !current_biblio_searches && !previous_biblio_searches %]
123
                                <p>Your catalog search history is empty.</p>
124
                            [% END %]
125
                        </div> <!-- / #biblio_tab -->
126
143
127
                        [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
144
                  [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
128
                            <div id="authority_tab">
145
                    <div id="authority_tab">
129
                                [% IF ( current_authority_searches ) %]
146
                      [% IF ( authority_searches ) %]
130
                                    <h2>Current session</h2>
147
                        [% INCLUDE search_history_table
131
                                    <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
148
                          searches = authority_searches
132
                                        <div class="selections-toolbar toolbar">
149
                          type = 'authority' %]
133
                                            <a class="CheckAll" href="#">Select all</a>
150
                      [% ELSE %]
134
                                            <a class="CheckNone" href="#">Clear all</a>
151
                        <p>Your authority search history is empty.</p>
135
                                            <span class="sep">|</span>
152
                      [% END %]
136
                                            <span class="links">
153
                    </div>
137
                                                <span class="selections">Select searches to: </span>
154
                  [% END %]
138
                                                <a href="#" class="removeitems disabled">Delete</a>
155
                </div> <!-- / #search_history -->
139
                                            </span>
156
        </div> <!-- / .span10/12 -->
140
                                        </div>
157
    </div> <!-- / .row-fluid -->
141
                                        <input type="hidden" name="action" value="delete" />
158
</div> <!-- / .container-fluid -->
142
                                        <table class="historyt table table-bordered table-striped">
143
                                            <thead>
144
                                                <tr>
145
                                                    <th></th>
146
                                                    <th>Date</th>
147
                                                    <th>Search</th>
148
                                                    <th>Results</th>
149
                                                </tr>
150
                                            </thead>
151
                                            <tbody>
152
                                                [% FOREACH s IN current_authority_searches %]
153
                                                    <tr>
154
                                                        <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
155
                                                        <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
156
                                                        <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
157
                                                        <td>[% s.total %]</td>
158
                                                    </tr>
159
                                                [% END %]
160
                                            </tbody>
161
                                        </table>
162
                                        <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
163
                                    </form>
164
                                [% END # / IF ( current_authority_searches ) %]
165
166
                                [% IF ( previous_authority_searches ) %]
167
                                    <h2>Previous sessions</h2>
168
                                    <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
169
                                        <div class="selections-toolbar toolbar">
170
                                            <a class="CheckAll" href="#">Select all</a>
171
                                            <a class="CheckNone" href="#">Clear all</a>
172
                                            <span class="sep">|</span>
173
                                            <span class="links">
174
                                                <span class="selections">Select searches to: </span>
175
                                                <a href="#" class="removeitems disabled">Delete</a>
176
                                            </span>
177
                                        </div>
178
                                        <input type="hidden" name="action" value="delete" />
179
                                        <table class="historyt table table-bordered table-striped">
180
                                            <thead>
181
                                                <tr>
182
                                                    <th></th>
183
                                                    <th>Date</th>
184
                                                    <th>Search</th>
185
                                                    <th>Results</th>
186
                                                </tr>
187
                                            </thead>
188
                                            <tbody>
189
                                                [% FOREACH s IN previous_authority_searches %]
190
                                                    <tr>
191
                                                        <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
192
                                                        <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
193
                                                        <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
194
                                                        <td>[% s.total %]</td>
195
                                                    </tr>
196
                                                [% END %]
197
                                            </tbody>
198
                                        </table>
199
                                        <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches">
200
                                    </form>
201
                                [% END # / IF ( previous_authority_searches )%]
202
203
                                [% IF !current_authority_searches && !previous_authority_searches %]
204
                                    <p>Your authority search history is empty.</p>
205
                                [% END %]
206
                            </div> <!-- / #authority_tab -->
207
                        [% END # / IF Koha.Preference( 'OpacAuthorities' ) %]
208
                    </div> <!-- / #tabs -->
209
                </div> <!-- / #searchhistory -->
210
            </div> <!-- / .span10/12 -->
211
        </div> <!-- / .row-fluid -->
212
    </div> <!-- / .container-fluid -->
213
</div> <!-- / #main -->
214
159
215
[% INCLUDE 'opac-bottom.inc' %]
160
[% INCLUDE 'opac-bottom.inc' %]
216
[% BLOCK jsinclude %]
161
[% BLOCK jsinclude %]
Lines 220-233 Link Here
220
//<![CDATA[
165
//<![CDATA[
221
    var MSG_CONFIRM_DELETE_HISTORY = _("Are you sure you want to delete selected search history entries?");
166
    var MSG_CONFIRM_DELETE_HISTORY = _("Are you sure you want to delete selected search history entries?");
222
    $(document).ready(function() {
167
    $(document).ready(function() {
223
        // We show table ordered by descending dates by default
168
       // We show table ordered by descending dates by default
224
        // (so that the more recent query is shown first)
169
       // (so that the more recent query is shown first)
225
        $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
170
       $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
226
            "aaSorting": [[ 1, "desc" ]],
171
           "aaSorting": [[ 3, "desc" ]],
227
            "aoColumnDefs": [
172
           "aoColumnDefs": [
228
                { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
173
               { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false },
229
                { "aTargets": [ 1 ], "sType": "title-string" },
174
               { "aTargets": [ 2, 3 ], "sType": "title-string" },
230
            ]
175
           ]
231
        }));
176
        }));
232
177
233
        [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]$('#tabs').tabs();[% END %]
178
        [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]$('#tabs').tabs();[% END %]
Lines 262-267 Link Here
262
            }
207
            }
263
            return false;
208
            return false;
264
        });
209
        });
210
        $(".action_search").click(function() {
211
          var $form = $(this).parents('form');
212
          var $checked = $form.find('input:checkbox:checked');
213
          if ($checked.length) {
214
            $(this).hide();
215
            $('.action_search_cancel').show();
216
            $('.search_options').show();
217
            $('.not').show();
218
          }
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
          }
229
          return false;
230
        });
231
232
        $('.action_search_cancel').click(function() {
233
          $(this).hide();
234
          $('.action_search').show();
235
          $('.search_options').hide();
236
          $('.not').hide();
237
          return false;
238
        }).click();
239
240
        $('form').each(function() {
241
          enableCheckboxActions(this);
242
        });
265
    });
243
    });
266
244
267
    function enableCheckboxActions(form){
245
    function enableCheckboxActions(form){
(-)a/opac/opac-search-history.pl (-84 / +88 lines)
Lines 22-32 use Modern::Perl; Link Here
22
use C4::Auth qw(:DEFAULT get_session);
22
use C4::Auth qw(:DEFAULT get_session);
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use C4::Context;
24
use C4::Context;
25
use C4::Languages;
25
use C4::Output;
26
use C4::Output;
26
use C4::Log;
27
use C4::Log;
27
use C4::Items;
28
use C4::Items;
28
use C4::Debug;
29
use C4::Debug;
29
use C4::Dates;
30
use C4::Dates;
31
use C4::Search;
30
use C4::Search::History;
32
use C4::Search::History;
31
use URI::Escape;
33
use URI::Escape;
32
use POSIX qw(strftime);
34
use POSIX qw(strftime);
Lines 46-66 my ($template, $loggedinuser, $cookie) = get_template_and_user( Link Here
46
    }
48
    }
47
);
49
);
48
50
49
my $type = $cgi->param('type');
50
my $action = $cgi->param('action') || q{};
51
my $action = $cgi->param('action') || q{};
51
my $previous = $cgi->param('previous');
52
52
53
# If the user is not logged in, we deal with the session
53
if ( $action eq 'search' ) {
54
unless ( $loggedinuser ) {
54
    # Start a new search
55
56
    my @ids = $cgi->param('id');
57
    my @nots = $cgi->param('not');
58
    my @searches;
59
    if ($loggedinuser) {
60
        @searches = @{ C4::Search::History::get({
61
            userid => $loggedinuser,
62
            id => \@ids,
63
        }) };
64
    } else {
65
        @searches = C4::Search::History::get_from_session({ cgi => $cgi });
66
        if ( @ids ) {
67
            @searches = map {
68
                my $search = $_;
69
                ( grep {/^$search->{id}$/} @ids ) ? $_ : ()
70
            } @searches;
71
        }
72
    }
73
    my @ccl_queries;
74
    foreach my $search (@searches) {
75
        my $scgi = new CGI($search->{query_cgi});
76
        my @operators = map uri_unescape($_), $scgi->param('op');
77
        my @indexes = map uri_unescape($_), $scgi->param('idx');
78
        my @operands = map uri_unescape($_), $scgi->param('q');
79
        my @limits = map uri_unescape($_), $scgi->param('limit');
80
        my @sort_by = $scgi->param('sort_by');
81
        my $scan = $scgi->param('scan');
82
        my $lang = C4::Languages::getlanguage($cgi);
83
        my ( $error, $query ) =
84
          buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by,
85
            $scan, $lang );
86
87
        if (grep {$_ == $search->{id}} @nots) {
88
            $query = "allrecords,alwaysmatches='' not ($query)";
89
        }
90
91
        push @ccl_queries, $query;
92
    }
93
    my $join = ($cgi->param('join') eq 'or') ? 'or' : 'and';
94
    my $query = 'ccl=(' . join(") $join (", @ccl_queries) . ')';
95
    print $cgi->redirect("/cgi-bin/koha/opac-search.pl?q=$query");
96
    exit;
97
} elsif ( $action eq 'delete' ) {
55
    # Deleting search history
98
    # Deleting search history
56
    if ( $action eq 'delete') {
99
    my @id = $cgi->param('id');
100
    if ($loggedinuser) {
101
        if ( @id ) {
102
            C4::Search::History::delete({ id => \@id });
103
        } else {
104
            C4::Search::History::delete({ userid => $loggedinuser });
105
        }
106
    } else {
57
        # Deleting session's search history
107
        # Deleting session's search history
58
        my @id = $cgi->param('id');
59
        my $all = not scalar( @id );
60
61
        my $type = $cgi->param('type');
108
        my $type = $cgi->param('type');
62
        my @searches = ();
109
        my @searches = ();
63
        unless ( $all ) {
110
        if ( scalar @id ) {
64
            @searches = C4::Search::History::get_from_session({ cgi => $cgi });
111
            @searches = C4::Search::History::get_from_session({ cgi => $cgi });
65
            if ( $type ) {
112
            if ( $type ) {
66
                @searches = map { $_->{type} ne $type ? $_ : () } @searches;
113
                @searches = map { $_->{type} ne $type ? $_ : () } @searches;
Lines 70-159 unless ( $loggedinuser ) { Link Here
70
            }
117
            }
71
        }
118
        }
72
        C4::Search::History::set_to_session({ cgi => $cgi, search_history => \@searches });
119
        C4::Search::History::set_to_session({ cgi => $cgi, search_history => \@searches });
73
74
        # Redirecting to this same url so the user won't see the search history link in the header
75
        my $uri = $cgi->url();
76
        print $cgi->redirect(-uri => $uri);
77
    # Showing search history
78
    } else {
79
        # Getting the searches from session
80
        my @current_searches = C4::Search::History::get_from_session({
81
            cgi => $cgi,
82
        });
83
84
        my @current_biblio_searches = map {
85
            $_->{type} eq 'biblio' ? $_ : ()
86
        } @current_searches;
87
88
        my @current_authority_searches = map {
89
            $_->{type} eq 'authority' ? $_ : ()
90
        } @current_searches;
91
92
        $template->param(
93
            current_biblio_searches => \@current_biblio_searches,
94
            current_authority_searches => \@current_authority_searches,
95
        );
96
    }
120
    }
121
    # Redirecting to this same url so the user won't see the search history link in the header
122
    my $uri = $cgi->url();
123
    print $cgi->redirect($uri);
124
    exit;
97
} else {
125
} else {
98
    # And if the user is logged in, we deal with the database
99
    my $dbh = C4::Context->dbh;
100
101
    # Deleting search history
102
    if ( $action eq 'delete' ) {
103
        my @id = $cgi->param('id');
104
        if ( @id ) {
105
            C4::Search::History::delete(
106
                {
107
                    id => [ $cgi->param('id') ],
108
                }
109
            );
110
        } else {
111
            C4::Search::History::delete(
112
                {
113
                   userid => $loggedinuser,
114
                }
115
            );
116
        }
117
        # Redirecting to this same url so the user won't see the search history link in the header
118
        my $uri = $cgi->url();
119
        print $cgi->redirect($uri);
120
121
    # Showing search history
126
    # Showing search history
122
    } else {
127
    my @searches;
123
        my $current_searches = C4::Search::History::get({
128
    if ($loggedinuser) {
129
        @searches = @{ C4::Search::History::get({
124
            userid => $loggedinuser,
130
            userid => $loggedinuser,
125
            sessionid => $cgi->cookie("CGISESSID")
131
            sessionid => $cgi->cookie("CGISESSID")
132
        }) };
133
        foreach my $row (@searches) {
134
            if ($row->{a_session}) {
135
                $row->{session} = YAML::Load($row->{a_session});
136
                $row->{session}->{session_ctime} = $row->{session}->{_SESSION_CTIME};
137
                $row->{session}->{session_id} = $row->{session}->{_SESSION_ID};
138
            }
139
        }
140
    } else {
141
        # Getting the searches from session
142
        @searches = C4::Search::History::get_from_session({
143
            cgi => $cgi,
126
        });
144
        });
127
        my @current_biblio_searches = map {
145
        $template->param(hide_session_column => 1);
128
            $_->{type} eq 'biblio' ? $_ : ()
146
    }
129
        } @$current_searches;
130
131
        my @current_authority_searches = map {
132
            $_->{type} eq 'authority' ? $_ : ()
133
        } @$current_searches;
134
135
        my $previous_searches = C4::Search::History::get({
136
            userid => $loggedinuser,
137
            sessionid => $cgi->cookie("CGISESSID"),
138
            previous => 1
139
        });
140
147
141
        my @previous_biblio_searches = map {
142
            $_->{type} eq 'biblio' ? $_ : ()
143
        } @$previous_searches;
144
148
145
        my @previous_authority_searches = map {
149
    my @biblio_searches = map {
146
            $_->{type} eq 'authority' ? $_ : ()
150
        $_->{type} eq 'biblio' ? $_ : ()
147
        } @$previous_searches;
151
    } @searches;
148
152
149
        $template->param(
153
    my @authority_searches = map {
150
            current_biblio_searches => \@current_biblio_searches,
154
        $_->{type} eq 'authority' ? $_ : ()
151
            current_authority_searches => \@current_authority_searches,
155
    } @searches;
152
            previous_biblio_searches => \@previous_biblio_searches,
153
            previous_authority_searches => \@previous_authority_searches,
154
156
155
        );
157
    $template->param(
156
    }
158
        biblio_searches => \@biblio_searches,
159
        authority_searches => \@authority_searches,
160
        sessionid => $cgi->cookie('CGISESSID'),
161
    );
157
}
162
}
158
163
159
$template->param(searchhistoryview => 1);
164
$template->param(searchhistoryview => 1);
160
- 

Return to bug 12460