Bug 25898: Prohibit indirect object notation
[koha.git] / svc / mana / search
1 #!/usr/bin/perl
2
3 # Copyright 2016 BibLibre Morgane Alonso
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (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 Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 #
20
21 use Modern::Perl;
22
23 use Koha::SharedContent;
24 use Koha::Subscription;
25 use C4::Auth qw(check_cookie_auth), qw(get_template_and_user);
26 use C4::Output qw( output_html_with_http_headers );
27
28 use CGI;
29
30 my $input = CGI->new;
31
32 my ( $auth_status, $sessionID ) =
33   check_cookie_auth( $input->cookie('CGISESSID'),
34     { serials => 'create_subscription' } );
35
36 if ( $auth_status ne "ok" ) {
37     exit 0;
38 }
39
40 my $templatename;
41 if ($input->param( "resource" ) eq 'report') {
42     $templatename = "mana/mana-report-search-result.tt";
43 } else {
44     $templatename = "mana/mana-subscription-search-result.tt";
45 }
46
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48     {
49         template_name   => $templatename,
50         query           => $input,
51         type            => "intranet",
52
53         # flagsrequired   => { serials => $permission },
54         flagsrequired => { serials => 'create_subscription' },
55         debug         => 1,
56     }
57 );
58
59 my ($identifier, $sub_mana_info);
60 $identifier = $input->param('id');
61 $template->param( lowWarned => 5, warned => 10, highWarned => 20);
62 my $package = "Koha::".ucfirst($input->param( 'resource' ));
63 $sub_mana_info = $package->get_search_info($identifier);
64
65 $sub_mana_info->{ usecomments } = $input->param('usecomments');
66 my $resourcename = $input->param('resource');
67 my $result = Koha::SharedContent::search_entities( $resourcename, $sub_mana_info);
68 my $nbofcomment;
69 foreach my $resource (@{ $result->{data} }){
70     $nbofcomment = 0;
71     foreach my $comment (@{ $resource->{comments} }){
72         $nbofcomment += $comment->{nb};
73     }
74     $resource->{nbofcomment} = $nbofcomment;
75 }
76
77 $template->param( $input->param('resource')."s" => $result->{data} );
78 $template->param( statuscode => $result->{code} );
79 $template->param( msg => $result->{msg} );
80
81 output_html_with_http_headers $input, $cookie, $template->output;