Bug 10862: Add search history to the intranet interface

Like OPAC, the search history is now available for intranet.  This
is controlled by the EnableSearchHistory system preference.

Test plan:
 1/ Switch on the 'EnableSearchHistory' syspref.
 3/ Launch some biblio and authority searches.
 4/ Go on your search history page (top right, under "Set library").
 5/ Check that all yours searches are displayed.
 6/ Click on some links and check that results are consistent.
 7/ Delete your biblio history searches.
 8/ Delete your authority searches history searches.
 9/ Launch some biblio and authority searches
10/ Play with the 4 delete links (current / previous and biblio /
authority).

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Jonathan Druart 2013-09-02 17:02:02 +02:00 committed by Galen Charlton
parent b16336caf8
commit a6a954efa8
9 changed files with 349 additions and 3 deletions

View File

@ -279,6 +279,8 @@ sub get_template_and_user {
# we've saved it to the database
C4::Search::History::set_to_session({ cgi => $in->{'query'}, search_history => [] });
}
} elsif ( $in->{type} eq 'intranet' and C4::Context->preference('EnableSearchHistory') ) {
$template->param( EnableSearchHistory => 1 );
}
}
else { # if this is an anonymous session, setup to display public lists...

View File

@ -31,6 +31,7 @@ use C4::AuthoritiesMarc;
use C4::Acquisition;
use C4::Koha; # XXX subfield_is_koha_internal_p
use C4::Biblio;
use C4::Search::History;
my $query = new CGI;
my $dbh = C4::Context->dbh;
@ -97,6 +98,7 @@ if ( $op eq "do_search" ) {
$orderby
);
( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "authorities/searchresultlist.tmpl",
@ -108,6 +110,25 @@ if ( $op eq "do_search" ) {
}
);
# search history
if (C4::Context->preference('EnableSearchHistory')) {
if ( $startfrom == 1) {
my $path_info = $query->url(-path_info=>1);
my $query_cgi_history = $query->url(-query=>1);
$query_cgi_history =~ s/^$path_info\?//;
$query_cgi_history =~ s/;/&/g;
C4::Search::History::add({
userid => $loggedinuser,
sessionid => $query->cookie("CGISESSID"),
query_desc => $value,
query_cgi => $query_cgi_history,
total => $total,
type => "authority",
});
}
}
$template->param(
marclist => $marclist,
and_or => $and_or,

100
catalogue/search-history.pl Executable file
View File

@ -0,0 +1,100 @@
#!/usr/bin/perl
# This file is part of Koha.
#
# Copyright 2013 BibLibre
#
# Koha is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General
# Public License along with Koha; if not, see
# <http://www.gnu.org/licenses>
use Modern::Perl;
use CGI;
use C4::Auth;
use C4::Search::History;
use C4::Output;
my $cgi = new CGI;
my ($template, $loggedinuser, $cookie) = get_template_and_user({
template_name => 'catalogue/search-history.tt',
query => $cgi,
type => "intranet",
authnotrequired => 0,
flagsrequired => {catalogue => 1},
});
my $type = $cgi->param('type');
my $action = $cgi->param('action') || q{list};
my $previous = $cgi->param('previous');
# Deleting search history
if ( $action eq 'delete' ) {
my $sessionid = defined $previous
? $cgi->cookie("CGISESSID")
: q{};
C4::Search::History::delete(
{
userid => $loggedinuser,
sessionid => $sessionid,
type => $type,
previous => $previous
}
);
# Redirecting to this same url so the user won't see the search history link in the header
my $uri = $cgi->url();
print $cgi->redirect($uri);
# Showing search history
} else {
my $current_searches = C4::Search::History::get({
userid => $loggedinuser,
sessionid => $cgi->cookie("CGISESSID")
});
my @current_biblio_searches = map {
$_->{type} eq 'biblio' ? $_ : ()
} @$current_searches;
my @current_authority_searches = map {
$_->{type} eq 'authority' ? $_ : ()
} @$current_searches;
my $previous_searches = C4::Search::History::get({
userid => $loggedinuser,
sessionid => $cgi->cookie("CGISESSID"),
previous => 1
});
my @previous_biblio_searches = map {
$_->{type} eq 'biblio' ? $_ : ()
} @$previous_searches;
my @previous_authority_searches = map {
$_->{type} eq 'authority' ? $_ : ()
} @$previous_searches;
$template->param(
current_biblio_searches => \@current_biblio_searches,
current_authority_searches => \@current_authority_searches,
previous_biblio_searches => \@previous_biblio_searches,
previous_authority_searches => \@previous_authority_searches,
);
}
$template->param(
);
output_html_with_http_headers $cgi, $cookie, $template->output;

View File

@ -152,6 +152,7 @@ use URI::Escape;
use POSIX qw(ceil floor);
use String::Random;
use C4::Branch; # GetBranches
use C4::Search::History;
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
# create a new CGI object
@ -159,7 +160,6 @@ my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
use CGI qw('-no_undef_params');
my $cgi = new CGI;
my ($template,$borrowernumber,$cookie);
my $lang = C4::Templates::getlanguage($cgi, 'intranet');
# decide which template to use
my $template_name;
@ -173,7 +173,7 @@ else {
$template_type = 'advsearch';
}
# load the template
($template, $borrowernumber, $cookie) = get_template_and_user({
my ($template, $borrowernumber, $cookie) = get_template_and_user({
template_name => $template_name,
query => $cgi,
type => "intranet",
@ -654,6 +654,29 @@ for (my $i=0;$i<@servers;$i++) {
$template->param(searchdesc => 1,query_desc => $query_desc,limit_desc => $limit_desc);
}
# Search history
if (C4::Context->preference('EnableSearchHistory')) {
unless ( $offset ) {
my $path_info = $cgi->url(-path_info=>1);
my $query_cgi_history = $cgi->url(-query=>1);
$query_cgi_history =~ s/^$path_info\?//;
$query_cgi_history =~ s/;/&/g;
my $query_desc_history = $query_desc;
$query_desc_history .= ", $limit_desc"
if $limit_desc;
C4::Search::History::add({
userid => $borrowernumber,
sessionid => $cgi->cookie("CGISESSID"),
query_desc => $query_desc_history,
query_cgi => $query_cgi_history,
total => $total,
type => "biblio",
});
}
$template->param( EnableSearchHistory => 1 );
}
} # end of the if local
# asynchronously search the authority server

View File

@ -107,6 +107,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('EasyAnalyticalRecords','0','','If on, display in the catalogue screens tools to easily setup analytical record relationships','YesNo'),
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'),
@ -436,4 +437,4 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('yuipath','local','local|http://yui.yahooapis.com/2.5.1/build','Insert the path to YUI libraries, choose local if you use koha offline','Choice'),
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
;
;

View File

@ -8394,6 +8394,15 @@ if ( CheckVersion($DBversion) ) {
SetVersion($DBversion);
}
$DBversion = "3.13.00.XXX";
if ( CheckVersion($DBversion) ) {
$dbh->do(q|
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('EnableSearchHistory','1','','Enable or disable search history','YesNo')
|);
print "Upgrade to $DBversion done (MT12541: Add EnableSearchHistory syspref)\n";
SetVersion($DBversion);
}
=head1 FUNCTIONS
=head2 TableExists($table)

View File

@ -73,6 +73,11 @@
<a class="toplinks" href="/cgi-bin/koha/circ/selectbranchprinter.pl">Set library</a>
</li>
[% END %]
[% IF EnableSearchHistory %]
<li>
<a class="toplinks" href="/cgi-bin/koha/catalogue/search-history.pl">Search history</a>
</li>
[% END %]
<li>
<a id="logout" class="toplinks" href="/cgi-bin/koha/mainpage.pl?logout.x=1">Log out</a>
</li>

View File

@ -71,6 +71,13 @@ Searching:
yes: Include
no: "Don't include"
- "<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."
-
- pref: EnableSearchHistory
default: 0
choices:
yes: Keep
no: "Don't keep"
- patron search history in the OPAC.
Search Form:
-
- Show tabs in OPAC and staff-side advanced search for limiting searches on the

View File

@ -0,0 +1,178 @@
[% USE Koha %]
[% USE KohaDates %]
<title>Koha &rsaquo; Catalog &rsaquo; History search</title>
[% INCLUDE 'doc-head-close.inc' %]
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.columnFilter.js"></script>
[% INCLUDE 'datatables-strings.inc' %]
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
<script type="text/javascript">
//<![CDATA[
var MSG_CONFIRM_DELETE_HISTORY = _("Are you sure you want to delete your search history?");
$(document).ready(function() {
// We show table ordered by descending dates by default
// (so that the more recent query is shown first)
$(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
"aaSorting": [[ 0, "desc" ]],
"aoColumns": [
{ "sType": "title-string" },
null,
null
]
}));
$('#tabs').tabs();
});
//]]>
</script>
</head>
<body id="catalogue_search-history" class="catalogue">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> &rsaquo; History search
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<h1>Search history</h1>
<div id="tabs" class="toptabs">
<ul>
<li><a href="#biblio_tab">Biblio</a></li>
<li><a href="#authority_tab">Authority</a></li>
</ul>
<div id="biblio_tab">
[% IF ( current_biblio_searches ) %]
<h2>Current session</h2>
<form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="previous" value="0" />
<input type="hidden" name="type" value="biblio" />
<input type="submit" class="deleteshelf" value="Delete your current biblio history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
</form>
<table class="historyt">
<thead>
<tr>
<th>Date</th>
<th>Search</th>
<th>Results</th>
</tr>
</thead>
<tbody>
[% FOREACH s IN current_biblio_searches %]
<tr>
<td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
<td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
<td>[% s.total %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
[% IF ( previous_biblio_searches ) %]
<h2>Previous sessions</h2>
<form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="previous" value="1" />
<input type="hidden" name="type" value="biblio" />
<input type="submit" class="deleteshelf" value="Delete your previous biblio search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
</form>
<table class="historyt">
<thead>
<tr>
<th>Date</th>
<th>Search</th>
<th>Results</th>
</tr>
</thead>
<tbody>
[% FOREACH s IN previous_biblio_searches %]
<tr>
<td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
<td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
<td>[% s.total %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
[% IF !current_biblio_searches && !previous_biblio_searches %]
<p>Your biblio search history is empty.</p>
[% END %]
</div>
<div id="authority_tab">
[% IF ( current_authority_searches ) %]
<h2>Current session</h2>
<form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="previous" value="0" />
<input type="hidden" name="type" value="authority" />
<input type="submit" class="deleteshelf" value="Delete your current authority search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
</form>
<table class="historyt">
<thead>
<tr>
<th>Date</th>
<th>Search</th>
<th>Results</th>
</tr>
</thead>
<tbody>
[% FOREACH s IN current_authority_searches %]
<tr>
<td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
<td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
<td>[% s.total %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
[% IF ( previous_authority_searches ) %]
<h2>Previous sessions</h2>
<form action="/cgi-bin/koha/catalogue/search-history.pl" method="get">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="previous" value="1" />
<input type="hidden" name="type" value="authority" />
<input type="submit" class="deleteshelf" value="Delete your previous authority search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
</form>
<table class="historyt">
<thead>
<tr>
<th>Date</th>
<th>Search</th>
<th>Results</th>
</tr>
</thead>
<tbody>
[% FOREACH s IN previous_authority_searches %]
<tr>
<td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
<td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
<td>[% s.total %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
[% IF !current_authority_searches && !previous_authority_searches %]
<p>Your authority search history is empty.</p>
[% END %]
</div>
</div>
</div>
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]