X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=opac%2Fopac-search-history.pl;h=8ef23062e7fd8dbaef0ef095de118a23de4c15fd;hb=ccb4180339544d6700de80b2d9879fdf175b51b9;hp=5b5a66d754a231a03c8dfac512b9844a590e10b4;hpb=afd2418d7387dc2a50835128e24840686600ef4b;p=koha-ffzg.git diff --git a/opac/opac-search-history.pl b/opac/opac-search-history.pl index 5b5a66d754..8ef23062e7 100755 --- a/opac/opac-search-history.pl +++ b/opac/opac-search-history.pl @@ -4,35 +4,30 @@ # # This file is part of Koha. # -# 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 2 of the License, or (at your option) any later -# version. +# 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. +# 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, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use Modern::Perl; -use C4::Auth qw(:DEFAULT get_session); -use CGI; +use C4::Auth qw( get_template_and_user ); +use CGI qw ( -utf8 ); use C4::Context; -use C4::Output; -use C4::Log; -use C4::Items; -use C4::Debug; -use C4::Dates; +use C4::Output qw( output_html_with_http_headers ); use C4::Search::History; -use URI::Escape; -use POSIX qw(strftime); -my $cgi = new CGI; + +my $cgi = CGI->new; # Getting the template and auth my ($template, $loggedinuser, $cookie) = get_template_and_user( @@ -40,12 +35,15 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user( template_name => "opac-search-history.tt", query => $cgi, type => "opac", - authnotrequired => 1, - flagsrequired => {borrowers => 1}, - debug => 1, + authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), } ); +unless ( C4::Context->preference("EnableOpacSearchHistory") ) { + print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); # escape early + exit; +} + my $type = $cgi->param('type'); my $action = $cgi->param('action') || q{}; my $previous = $cgi->param('previous'); @@ -53,19 +51,26 @@ my $previous = $cgi->param('previous'); # If the user is not logged in, we deal with the session unless ( $loggedinuser ) { # Deleting search history - if ($cgi->param('action') && $cgi->param('action') eq 'delete') { + if ( $action eq 'delete') { # Deleting session's search history + my @id = $cgi->multi_param('id'); + my $all = not scalar( @id ); + my $type = $cgi->param('type'); my @searches = (); - if ( $type ) { + unless ( $all ) { @searches = C4::Search::History::get_from_session({ cgi => $cgi }); - @searches = map { $_->{type} ne $type ? $_ : () } @searches; + if ( $type ) { + @searches = map { $_->{type} ne $type ? $_ : () } @searches; + } + if ( @id ) { + @searches = map { my $search = $_; ( grep { $_ eq $search->{id} } @id ) ? () : $_ } @searches; + } } C4::Search::History::set_to_session({ cgi => $cgi, search_history => \@searches }); # 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 => $uri); + print $cgi->redirect(-uri => '/cgi-bin/koha/opac-search-history.pl'); # Showing search history } else { # Getting the searches from session @@ -92,20 +97,23 @@ unless ( $loggedinuser ) { # 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 - } - ); + my @id = $cgi->multi_param('id'); + if ( @id ) { + C4::Search::History::delete( + { + userid => $loggedinuser, + id => [ @id ], + } + ); + } else { + C4::Search::History::delete( + { + userid => $loggedinuser, + } + ); + } # 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); + print $cgi->redirect(-uri => '/cgi-bin/koha/opac-search-history.pl'); # Showing search history } else { @@ -147,4 +155,4 @@ unless ( $loggedinuser ) { $template->param(searchhistoryview => 1); -output_html_with_http_headers $cgi, $cookie, $template->output; +output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };