From a6a954efa83a4d87eee8a8b1a0864b60f01eaa7f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 2 Sep 2013 17:02:02 +0200 Subject: [PATCH] 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 Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton --- C4/Auth.pm | 2 + authorities/authorities-home.pl | 21 +++ catalogue/search-history.pl | 100 ++++++++++ catalogue/search.pl | 27 ++- installer/data/mysql/sysprefs.sql | 3 +- installer/data/mysql/updatedatabase.pl | 9 + .../intranet-tmpl/prog/en/includes/header.inc | 5 + .../modules/admin/preferences/searching.pref | 7 + .../en/modules/catalogue/search-history.tt | 178 ++++++++++++++++++ 9 files changed, 349 insertions(+), 3 deletions(-) create mode 100755 catalogue/search-history.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt diff --git a/C4/Auth.pm b/C4/Auth.pm index 24e0bf1d1a..9496b97c67 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -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... diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index f67f5c9c40..8128e0cb79 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -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, diff --git a/catalogue/search-history.pl b/catalogue/search-history.pl new file mode 100755 index 0000000000..20e3b82110 --- /dev/null +++ b/catalogue/search-history.pl @@ -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 +# + +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; diff --git a/catalogue/search.pl b/catalogue/search.pl index 168ca935a6..c449299838 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -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 diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index e714ed1290..7a0ad47a2b 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -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') -; \ No newline at end of file +; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 0f3fe1eff7..8264c0e616 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -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) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc index 5a7188b6b2..b8bd714e0e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -73,6 +73,11 @@ Set library [% END %] + [% IF EnableSearchHistory %] +
  • + Search history +
  • + [% END %]
  • Log out
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref index 5a4bdf17e0..3f24edba56 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -71,6 +71,13 @@ Searching: yes: Include no: "Don't include" - "see from (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 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt new file mode 100644 index 0000000000..23bda8074f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt @@ -0,0 +1,178 @@ +[% USE Koha %] +[% USE KohaDates %] +Koha › Catalog › History search +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'datatables-strings.inc' %] + + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + + +
    + +
    +
    +
    +

    Search history

    +
    + +
    + [% IF ( current_biblio_searches ) %] +

    Current session

    +
    + + + + +
    + + + + + + + + + + [% FOREACH s IN current_biblio_searches %] + + + + + + [% END %] + +
    DateSearchResults
    [% s.time |$KohaDates with_hours => 1 %][% s.query_desc |html %][% s.total %]
    + [% END %] + + [% IF ( previous_biblio_searches ) %] +

    Previous sessions

    +
    + + + + +
    + + + + + + + + + + [% FOREACH s IN previous_biblio_searches %] + + + + + + [% END %] + +
    DateSearchResults
    [% s.time |$KohaDates with_hours => 1 %][% s.query_desc |html %][% s.total %]
    + [% END %] + + [% IF !current_biblio_searches && !previous_biblio_searches %] +

    Your biblio search history is empty.

    + [% END %] +
    + +
    + [% IF ( current_authority_searches ) %] +

    Current session

    +
    + + + + +
    + + + + + + + + + + [% FOREACH s IN current_authority_searches %] + + + + + + [% END %] + +
    DateSearchResults
    [% s.time |$KohaDates with_hours => 1 %][% s.query_desc |html %][% s.total %]
    + [% END %] + + [% IF ( previous_authority_searches ) %] +

    Previous sessions

    +
    + + + + +
    + + + + + + + + + + [% FOREACH s IN previous_authority_searches %] + + + + + + [% END %] + +
    DateSearchResults
    [% s.time |$KohaDates with_hours => 1 %][% s.query_desc |html %][% s.total %]
    + [% END %] + + [% IF !current_authority_searches && !previous_authority_searches %] +

    Your authority search history is empty.

    + [% END %] +
    +
    +
    +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] -- 2.39.5