Revert "Bug 6554: Followup for preferences.pl"
[koha.git] / admin / didyoumean.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use CGI;
6 use C4::Context;
7 use C4::Auth;
8 use C4::Output;
9 use Koha::SuggestionEngine;
10 use Module::Load::Conditional qw(can_load);
11 use JSON;
12
13 my $input = new CGI;
14
15 my ($template, $loggedinuser, $cookie)
16     = get_template_and_user({template_name => "admin/didyoumean.tt",
17             query => $input,
18             type => "intranet",
19             authnotrequired => 0,
20             flagsrequired => {parameters => 'parameters_remaining_permissions'},
21             debug => 1,
22             });
23
24 my $opacplugins = from_json(C4::Context->preference('OPACdidyoumean') || '[]');
25
26 my $intraplugins = from_json(C4::Context->preference('INTRAdidyoumean') || '[]');
27
28 my @pluginlist = Koha::SuggestionEngine::AvailablePlugins();
29 foreach my $plugin (@pluginlist) {
30     next if $plugin eq 'Koha::SuggestionEngine::Plugin::Null';
31     next unless (can_load( modules => { "$plugin" => undef } ));
32     push @$opacplugins, { name => $plugin->NAME } unless grep { $_->{name} eq $plugin->NAME } @$opacplugins;
33     push @$intraplugins, { name => $plugin->NAME } unless grep { $_->{name} eq $plugin->NAME } @$intraplugins;
34 }
35 $template->{VARS}->{OPACpluginlist} = $opacplugins;
36 $template->{VARS}->{INTRApluginlist} = $intraplugins;
37 output_html_with_http_headers $input, $cookie, $template->output;