Bug 24753: Change Koha/Middlware to Koha/Middleware in test name
[koha.git] / svc / mana / search
blob836e6b2adb91cb06bce0757c88b06a14878d8c1f
1 #!/usr/bin/perl
3 # Copyright 2016 BibLibre Morgane Alonso
5 # This file is part of Koha.
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.
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 Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Modern::Perl;
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 );
28 use CGI;
30 my $input = new CGI;
32 my ( $auth_status, $sessionID ) =
33 check_cookie_auth( $input->cookie('CGISESSID'),
34 { serials => 'create_subscription' } );
36 if ( $auth_status ne "ok" ) {
37 exit 0;
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";
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
49 template_name => $templatename,
50 query => $input,
51 type => "intranet",
52 authnotrequired => 0,
54 # flagsrequired => { serials => $permission },
55 flagsrequired => { serials => 'create_subscription' },
56 debug => 1,
60 my ($identifier, $sub_mana_info);
61 $identifier = $input->param('id');
62 $template->param( lowWarned => 5, warned => 10, highWarned => 20);
63 my $package = "Koha::".ucfirst($input->param( 'resource' ));
64 $sub_mana_info = $package->get_search_info($identifier);
66 $sub_mana_info->{ usecomments } = $input->param('usecomments');
67 my $resourcename = $input->param('resource');
68 my $result = Koha::SharedContent::search_entities( $resourcename, $sub_mana_info);
69 my $nbofcomment;
70 foreach my $resource (@{ $result->{data} }){
71 $nbofcomment = 0;
72 foreach my $comment (@{ $resource->{comments} }){
73 $nbofcomment += $comment->{nb};
75 $resource->{nbofcomment} = $nbofcomment;
78 $template->param( $input->param('resource')."s" => $result->{data} );
79 $template->param( statuscode => $result->{code} );
80 $template->param( msg => $result->{msg} );
82 output_html_with_http_headers $input, $cookie, $template->output;