Bug 17600: Standardize our EXPORT_OK
[koha.git] / catalogue / search-history.pl
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 qw ( -utf8 );
23
24 use C4::Auth qw( get_template_and_user );
25 use C4::Search::History;
26 use C4::Output qw( output_html_with_http_headers );
27
28 my $cgi = CGI->new;
29
30 my ($template, $loggedinuser, $cookie) = get_template_and_user({
31     template_name   => 'catalogue/search-history.tt',
32     query           => $cgi,
33     type            => "intranet",
34     flagsrequired   => {catalogue => 1},
35 });
36
37 my $type = $cgi->param('type');
38 my $action = $cgi->param('action') || q{list};
39 my $previous = $cgi->param('previous');
40
41 # Deleting search history
42 if ( $action eq 'delete' ) {
43     my $sessionid = defined $previous
44         ? $cgi->cookie("CGISESSID")
45         : q{};
46     C4::Search::History::delete(
47         {
48             userid => $loggedinuser,
49             id     => [ $cgi->param('id') ],
50         }
51     );
52     # Redirecting to this same url so the user won't see the search history link in the header
53     print $cgi->redirect('/cgi-bin/koha/catalogue/search-history.pl');
54
55 # Showing search history
56 } else {
57     my $current_searches = C4::Search::History::get({
58         userid => $loggedinuser,
59         sessionid => $cgi->cookie("CGISESSID")
60     });
61     my @current_biblio_searches = map {
62         $_->{type} eq 'biblio' ? $_ : ()
63     } @$current_searches;
64
65     my @current_authority_searches = map {
66         $_->{type} eq 'authority' ? $_ : ()
67     } @$current_searches;
68
69     my $previous_searches = C4::Search::History::get({
70         userid => $loggedinuser,
71         sessionid => $cgi->cookie("CGISESSID"),
72         previous => 1
73     });
74
75     my @previous_biblio_searches = map {
76         $_->{type} eq 'biblio' ? $_ : ()
77     } @$previous_searches;
78
79     my @previous_authority_searches = map {
80         $_->{type} eq 'authority' ? $_ : ()
81     } @$previous_searches;
82
83     $template->param(
84         current_biblio_searches => \@current_biblio_searches,
85         current_authority_searches => \@current_authority_searches,
86         previous_biblio_searches => \@previous_biblio_searches,
87         previous_authority_searches => \@previous_authority_searches,
88
89     );
90 }
91
92
93 $template->param(
94 );
95
96 output_html_with_http_headers $cgi, $cookie, $template->output;