Bug 12274: Invoice detail: don't crash on certain billing dates
[koha.git] / catalogue / search-history.pl
blob20e3b8211047464722a84ae4ea3341d1d8c57db1
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2013 BibLibre
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.
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.
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>
21 use Modern::Perl;
22 use CGI;
24 use C4::Auth;
25 use C4::Search::History;
26 use C4::Output;
28 my $cgi = new CGI;
30 my ($template, $loggedinuser, $cookie) = get_template_and_user({
31 template_name => 'catalogue/search-history.tt',
32 query => $cgi,
33 type => "intranet",
34 authnotrequired => 0,
35 flagsrequired => {catalogue => 1},
36 });
38 my $type = $cgi->param('type');
39 my $action = $cgi->param('action') || q{list};
40 my $previous = $cgi->param('previous');
42 # Deleting search history
43 if ( $action eq 'delete' ) {
44 my $sessionid = defined $previous
45 ? $cgi->cookie("CGISESSID")
46 : q{};
47 C4::Search::History::delete(
49 userid => $loggedinuser,
50 sessionid => $sessionid,
51 type => $type,
52 previous => $previous
55 # Redirecting to this same url so the user won't see the search history link in the header
56 my $uri = $cgi->url();
57 print $cgi->redirect($uri);
59 # Showing search history
60 } else {
61 my $current_searches = C4::Search::History::get({
62 userid => $loggedinuser,
63 sessionid => $cgi->cookie("CGISESSID")
64 });
65 my @current_biblio_searches = map {
66 $_->{type} eq 'biblio' ? $_ : ()
67 } @$current_searches;
69 my @current_authority_searches = map {
70 $_->{type} eq 'authority' ? $_ : ()
71 } @$current_searches;
73 my $previous_searches = C4::Search::History::get({
74 userid => $loggedinuser,
75 sessionid => $cgi->cookie("CGISESSID"),
76 previous => 1
77 });
79 my @previous_biblio_searches = map {
80 $_->{type} eq 'biblio' ? $_ : ()
81 } @$previous_searches;
83 my @previous_authority_searches = map {
84 $_->{type} eq 'authority' ? $_ : ()
85 } @$previous_searches;
87 $template->param(
88 current_biblio_searches => \@current_biblio_searches,
89 current_authority_searches => \@current_authority_searches,
90 previous_biblio_searches => \@previous_biblio_searches,
91 previous_authority_searches => \@previous_authority_searches,
97 $template->param(
100 output_html_with_http_headers $cgi, $cookie, $template->output;