From 58c9fed6eed41aebfe3298966650b01173308de8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 2 Sep 2013 17:02:02 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 10862: Add an search history for the intranet interface Content-Type: text/plain; charset="utf-8" Like OPAC, the search history is now available for intranet. 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 --- C4/Auth.pm | 2 + authorities/authorities-home.pl | 21 +++ catalogue/search-history.pl | 100 +++++++++++ catalogue/search.pl | 27 ++- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 20 +++ .../intranet-tmpl/prog/en/includes/header.inc | 5 + .../en/modules/admin/preferences/searching.pref | 7 + .../prog/en/modules/catalogue/search-history.tt | 178 ++++++++++++++++++++ 9 files changed, 359 insertions(+), 2 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 7b61da0..4c3f4bb 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -279,6 +279,8 @@ sub get_template_and_user { ); $cookie = [$cookie, $newsearchcookie]; } + } 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 f67f5c9..8128e0c 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 0000000..20e3b82 --- /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 9e81a81..4bb8d21 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", @@ -653,6 +653,29 @@ for (my $i=0;$i<@servers;$i++) { $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_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 e8ca401..88f2d62 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -98,6 +98,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'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index cef18e3..daded51 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7117,6 +7117,26 @@ 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 58f721f..666eaf5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -75,6 +75,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 29da64e..b430406 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 0000000..23bda80 --- /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' %] -- 1.7.9.5