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

(-)a/C4/Auth.pm (+2 lines)
Lines 279-284 sub get_template_and_user { Link Here
279
                                         );
279
                                         );
280
                $cookie = [$cookie, $newsearchcookie];
280
                $cookie = [$cookie, $newsearchcookie];
281
            }
281
            }
282
        } elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
283
            $template->param( EnableSearchHistory => 1 );
282
        }
284
        }
283
    }
285
    }
284
    else {    # if this is an anonymous session, setup to display public lists...
286
    else {    # if this is an anonymous session, setup to display public lists...
(-)a/authorities/authorities-home.pl (+21 lines)
Lines 31-36 use C4::AuthoritiesMarc; Link Here
31
use C4::Acquisition;
31
use C4::Acquisition;
32
use C4::Koha;    # XXX subfield_is_koha_internal_p
32
use C4::Koha;    # XXX subfield_is_koha_internal_p
33
use C4::Biblio;
33
use C4::Biblio;
34
use C4::Search::History;
34
35
35
my $query = new CGI;
36
my $query = new CGI;
36
my $dbh   = C4::Context->dbh;
37
my $dbh   = C4::Context->dbh;
Lines 97-102 if ( $op eq "do_search" ) { Link Here
97
        $orderby
98
        $orderby
98
    );
99
    );
99
100
101
100
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
102
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
101
        {
103
        {
102
            template_name   => "authorities/searchresultlist.tmpl",
104
            template_name   => "authorities/searchresultlist.tmpl",
Lines 108-113 if ( $op eq "do_search" ) { Link Here
108
        }
110
        }
109
    );
111
    );
110
112
113
    # search history
114
    if (C4::Context->preference('EnableSearchHistory')) {
115
        if ( $startfrom == 1) {
116
            my $path_info = $query->url(-path_info=>1);
117
            my $query_cgi_history = $query->url(-query=>1);
118
            $query_cgi_history =~ s/^$path_info\?//;
119
            $query_cgi_history =~ s/;/&/g;
120
121
            C4::Search::History::add({
122
                userid => $loggedinuser,
123
                sessionid => $query->cookie("CGISESSID"),
124
                query_desc => $value,
125
                query_cgi => $query_cgi_history,
126
                total => $total,
127
                type => "authority",
128
            });
129
        }
130
    }
131
111
    $template->param(
132
    $template->param(
112
        marclist       => $marclist,
133
        marclist       => $marclist,
113
        and_or         => $and_or,
134
        and_or         => $and_or,
(-)a/catalogue/search-history.pl (+101 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2013 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 3
10
# of the License, or (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General
18
# Public License along with Koha; if not, see
19
# <http://www.gnu.org/licenses>
20
21
use Modern::Perl;
22
use CGI;
23
24
use C4::Auth;
25
use C4::Search::History;
26
use C4::Output;
27
28
my $cgi = new CGI;
29
30
my ($template, $loggedinuser, $cookie) = get_template_and_user({
31
    template_name   => 'catalogue/search-history.tt',
32
    query           => $cgi,
33
    type            => "intranet",
34
    authnotrequired => 0,
35
    flagsrequired   => {catalogue => 1},
36
});
37
38
my $type = $cgi->param('type');
39
my $action = $cgi->param('action') || q{list};
40
my $previous = $cgi->param('previous');
41
42
# Deleting search history
43
if ( $action eq 'delete' ) {
44
    my $sessionid = defined $previous
45
        ? $cgi->cookie("CGISESSID")
46
        : q{};
47
    C4::Search::History::delete(
48
        {
49
            userid => $loggedinuser,
50
            sessionid => $sessionid,
51
            type => $type,
52
            previous => $previous
53
        }
54
    );
55
    # Redirecting to this same url so the user won't see the search history link in the header
56
    my $uri = $cgi->url();
57
    print $cgi->redirect($uri);
58
59
# Showing search history
60
} else {
61
    my $current_searches = C4::Search::History::get({
62
        userid => $loggedinuser,
63
        sessionid => $cgi->cookie("CGISESSID")
64
    });
65
    my @current_biblio_searches = map {
66
        $_->{type} eq 'biblio' ? $_ : ()
67
    } @$current_searches;
68
69
    my @current_authority_searches = map {
70
        $_->{type} eq 'authority' ? $_ : ()
71
    } @$current_searches;
72
73
    my $previous_searches = C4::Search::History::get({
74
        userid => $loggedinuser,
75
        sessionid => $cgi->cookie("CGISESSID"),
76
        previous => 1
77
    });
78
79
    my @previous_biblio_searches = map {
80
        $_->{type} eq 'biblio' ? $_ : ()
81
    } @$previous_searches;
82
83
    my @previous_authority_searches = map {
84
        $_->{type} eq 'authority' ? $_ : ()
85
    } @$previous_searches;
86
87
    $template->param(
88
        current_biblio_searches => \@current_biblio_searches,
89
        current_authority_searches => \@current_authority_searches,
90
        previous_biblio_searches => \@previous_biblio_searches,
91
        previous_authority_searches => \@previous_authority_searches,
92
93
    );
94
}
95
96
97
$template->param(
98
);
99
100
output_html_with_http_headers $cgi, $cookie, $template->output;
101
(-)a/catalogue/search.pl (-2 / +25 lines)
Lines 152-157 use URI::Escape; Link Here
152
use POSIX qw(ceil floor);
152
use POSIX qw(ceil floor);
153
use String::Random;
153
use String::Random;
154
use C4::Branch; # GetBranches
154
use C4::Branch; # GetBranches
155
use C4::Search::History;
155
156
156
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
157
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
157
# create a new CGI object
158
# create a new CGI object
Lines 159-165 my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); Link Here
159
use CGI qw('-no_undef_params');
160
use CGI qw('-no_undef_params');
160
my $cgi = new CGI;
161
my $cgi = new CGI;
161
162
162
my ($template,$borrowernumber,$cookie);
163
my $lang = C4::Templates::getlanguage($cgi, 'intranet');
163
my $lang = C4::Templates::getlanguage($cgi, 'intranet');
164
# decide which template to use
164
# decide which template to use
165
my $template_name;
165
my $template_name;
Lines 173-179 else { Link Here
173
    $template_type = 'advsearch';
173
    $template_type = 'advsearch';
174
}
174
}
175
# load the template
175
# load the template
176
($template, $borrowernumber, $cookie) = get_template_and_user({
176
my ($template, $borrowernumber, $cookie) = get_template_and_user({
177
    template_name => $template_name,
177
    template_name => $template_name,
178
    query => $cgi,
178
    query => $cgi,
179
    type => "intranet",
179
    type => "intranet",
Lines 653-658 for (my $i=0;$i<@servers;$i++) { Link Here
653
            $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_desc));
653
            $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_desc));
654
        }
654
        }
655
655
656
        # Search history
657
        if (C4::Context->preference('EnableSearchHistory')) {
658
            unless ( $offset ) {
659
                my $path_info = $cgi->url(-path_info=>1);
660
                my $query_cgi_history = $cgi->url(-query=>1);
661
                $query_cgi_history =~ s/^$path_info\?//;
662
                $query_cgi_history =~ s/;/&/g;
663
                my $query_desc_history = $query_desc;
664
                $query_desc_history .= ", $limit_desc"
665
                    if $limit_desc;
666
667
                C4::Search::History::add({
668
                    userid => $borrowernumber,
669
                    sessionid => $cgi->cookie("CGISESSID"),
670
                    query_desc => $query_desc_history,
671
                    query_cgi => $query_cgi_history,
672
                    total => $total,
673
                    type => "biblio",
674
                });
675
            }
676
            $template->param( EnableSearchHistory => 1 );
677
        }
678
656
    } # end of the if local
679
    } # end of the if local
657
680
658
    # asynchronously search the authority server
681
    # asynchronously search the authority server
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 98-103 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
98
('EasyAnalyticalRecords','0','','If on, display in the catalogue screens tools to easily setup analytical record relationships','YesNo'),
98
('EasyAnalyticalRecords','0','','If on, display in the catalogue screens tools to easily setup analytical record relationships','YesNo'),
99
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
99
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
100
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
100
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
101
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
101
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
102
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
102
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
103
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
103
('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'),
104
('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+20 lines)
Lines 7117-7122 if ( CheckVersion($DBversion) ) { Link Here
7117
    SetVersion($DBversion);
7117
    SetVersion($DBversion);
7118
}
7118
}
7119
7119
7120
7121
7122
7123
7124
7125
7126
$DBversion = "3.13.00.XXX";
7127
if ( CheckVersion($DBversion) ) {
7128
    $dbh->do(q|
7129
        INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('EnableSearchHistory','1','','Enable or disable search history','YesNo')
7130
    |);
7131
    print "Upgrade to $DBversion done (MT12541: Add EnableSearchHistory syspref)\n";
7132
    SetVersion($DBversion);
7133
}
7134
7135
7136
7137
7138
7139
7120
=head1 FUNCTIONS
7140
=head1 FUNCTIONS
7121
7141
7122
=head2 TableExists($table)
7142
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc (+5 lines)
Lines 75-80 Link Here
75
                     <a class="toplinks" href="/cgi-bin/koha/circ/selectbranchprinter.pl">Set library</a>
75
                     <a class="toplinks" href="/cgi-bin/koha/circ/selectbranchprinter.pl">Set library</a>
76
                  </li>
76
                  </li>
77
           [% END %]
77
           [% END %]
78
           [% IF EnableSearchHistory %]
79
              <li>
80
                 <a class="toplinks" href="/cgi-bin/koha/catalogue/search-history.pl">Search history</a>
81
              </li>
82
           [% END %]
78
              <li>
83
              <li>
79
                  <a id="logout" class="toplinks" href="/cgi-bin/koha/mainpage.pl?logout.x=1">Log out</a>
84
                  <a id="logout" class="toplinks" href="/cgi-bin/koha/mainpage.pl?logout.x=1">Log out</a>
80
              </li>
85
              </li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+7 lines)
Lines 71-76 Searching: Link Here
71
                  yes: Include
71
                  yes: Include
72
                  no: "Don't include"
72
                  no: "Don't include"
73
            - "<i>see from</i> (non-preferred form) headings in bibliographic searches. Please note: you will need to reindex your bibliographic database when changing this preference."
73
            - "<i>see from</i> (non-preferred form) headings in bibliographic searches. Please note: you will need to reindex your bibliographic database when changing this preference."
74
        -
75
            - pref: EnableSearchHistory
76
              default: 0
77
              choices:
78
                  yes: Keep
79
                  no: "Don't keep"
80
            - patron search history in the OPAC.
74
    Search Form:
81
    Search Form:
75
        -
82
        -
76
            - Show tabs in OPAC and staff-side advanced search for limiting searches on the
83
            - Show tabs in OPAC and staff-side advanced search for limiting searches on the
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt (-1 / +178 lines)
Line 0 Link Here
0
- 
1
[% USE Koha %]
2
[% USE KohaDates %]
3
<title>Koha &rsaquo; Catalog &rsaquo; History search</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
6
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
7
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.columnFilter.js"></script>
8
[% INCLUDE 'datatables-strings.inc' %]
9
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
10
<script type="text/javascript">
11
//<![CDATA[
12
var MSG_CONFIRM_DELETE_HISTORY = _("Are you sure you want to delete your search history?");
13
$(document).ready(function() {
14
    // We show table ordered by descending dates by default
15
    // (so that the more recent query is shown first)
16
    $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
17
        "aaSorting": [[ 0, "desc" ]],
18
        "aoColumns": [
19
            { "sType": "title-string" },
20
            null,
21
            null
22
        ]
23
    }));
24
25
    $('#tabs').tabs();
26
});
27
//]]>
28
29
</script>
30
</head>
31
<body id="catalogue_search-history" class="catalogue">
32
33
[% INCLUDE 'header.inc' %]
34
[% INCLUDE 'cat-search.inc' %]
35
36
<div id="breadcrumbs">
37
  <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>  &rsaquo; History search
38
</div>
39
40
<div id="doc3" class="yui-t2">
41
42
<div id="bd">
43
  <div id="yui-main">
44
    <div class="yui-b">
45
      <h1>Search history</h1>
46
      <div id="tabs" class="toptabs">
47
        <ul>
48
          <li><a href="#biblio_tab">Biblio</a></li>
49
          <li><a href="#authority_tab">Authority</a></li>
50
        </ul>
51
        <div id="biblio_tab">
52
          [% IF ( current_biblio_searches ) %]
53
            <h2>Current session</h2>
54
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
55
              <input type="hidden" name="action" value="delete" />
56
              <input type="hidden" name="previous" value="0" />
57
              <input type="hidden" name="type" value="biblio" />
58
              <input type="submit" class="deleteshelf" value="Delete your current biblio history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
59
            </form>
60
            <table class="historyt">
61
              <thead>
62
                <tr>
63
                  <th>Date</th>
64
                  <th>Search</th>
65
                  <th>Results</th>
66
                </tr>
67
              </thead>
68
              <tbody>
69
              [% FOREACH s IN current_biblio_searches %]
70
                <tr>
71
                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
72
                  <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
73
                  <td>[% s.total %]</td>
74
                </tr>
75
              [% END %]
76
              </tbody>
77
            </table>
78
          [% END %]
79
80
          [% IF ( previous_biblio_searches ) %]
81
            <h2>Previous sessions</h2>
82
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
83
              <input type="hidden" name="action" value="delete" />
84
              <input type="hidden" name="previous" value="1" />
85
              <input type="hidden" name="type" value="biblio" />
86
              <input type="submit" class="deleteshelf" value="Delete your previous biblio search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
87
            </form>
88
            <table class="historyt">
89
              <thead>
90
                <tr>
91
                  <th>Date</th>
92
                  <th>Search</th>
93
                  <th>Results</th>
94
                </tr>
95
              </thead>
96
              <tbody>
97
              [% FOREACH s IN previous_biblio_searches %]
98
                <tr>
99
                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
100
                  <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
101
                  <td>[% s.total %]</td>
102
                </tr>
103
              [% END %]
104
              </tbody>
105
            </table>
106
          [% END %]
107
108
          [% IF !current_biblio_searches && !previous_biblio_searches %]
109
            <p>Your biblio search history is empty.</p>
110
          [% END %]
111
        </div>
112
113
        <div id="authority_tab">
114
          [% IF ( current_authority_searches ) %]
115
            <h2>Current session</h2>
116
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
117
              <input type="hidden" name="action" value="delete" />
118
              <input type="hidden" name="previous" value="0" />
119
              <input type="hidden" name="type" value="authority" />
120
              <input type="submit" class="deleteshelf" value="Delete your current authority search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
121
            </form>
122
            <table class="historyt">
123
              <thead>
124
                <tr>
125
                  <th>Date</th>
126
                  <th>Search</th>
127
                  <th>Results</th>
128
                </tr>
129
              </thead>
130
              <tbody>
131
              [% FOREACH s IN current_authority_searches %]
132
                <tr>
133
                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
134
                  <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
135
                  <td>[% s.total %]</td>
136
                </tr>
137
              [% END %]
138
              </tbody>
139
            </table>
140
          [% END %]
141
142
          [% IF ( previous_authority_searches ) %]
143
            <h2>Previous sessions</h2>
144
            <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
145
              <input type="hidden" name="action" value="delete" />
146
              <input type="hidden" name="previous" value="1" />
147
              <input type="hidden" name="type" value="authority" />
148
              <input type="submit" class="deleteshelf" value="Delete your previous authority search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
149
            </form>
150
            <table class="historyt">
151
              <thead>
152
                <tr>
153
                  <th>Date</th>
154
                  <th>Search</th>
155
                  <th>Results</th>
156
                </tr>
157
              </thead>
158
              <tbody>
159
              [% FOREACH s IN previous_authority_searches %]
160
                <tr>
161
                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
162
                  <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
163
                  <td>[% s.total %]</td>
164
                </tr>
165
              [% END %]
166
              </tbody>
167
            </table>
168
          [% END %]
169
170
          [% IF !current_authority_searches && !previous_authority_searches %]
171
            <p>Your authority search history is empty.</p>
172
          [% END %]
173
        </div>
174
      </div>
175
    </div>
176
  </div>
177
</div>
178
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 10862