Bug 18050: (QA follow-up) Adjust conditions and make use of message text
[koha.git] / admin / columns_settings.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use CGI;
5 use YAML qw( LoadFile );
6 use C4::Auth;
7 use C4::Context;
8 use C4::Output;
9 use C4::Utils::DataTables::ColumnsSettings qw( get_modules );
10 my $input = new CGI;
11
12 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
13     {
14         template_name   => "admin/columns_settings.tt",
15         query           => $input,
16         type            => "intranet",
17         flagsrequired   => { parameters => 'manage_column_config' },
18         debug           => 1,
19     }
20 );
21
22 my $action = $input->param('action') // 'list';
23
24 if ( $action eq 'save' ) {
25     my $module = $input->param('module');
26     my @columnids = $input->multi_param("columnid");
27     my @columns;
28     for my $columnid (@columnids) {
29         next unless $columnid =~ m|^([^#]*)#([^#]*)#(.*)$|;
30         my $is_hidden = $input->param( $columnid . '_hidden' ) // 0;
31         my $cannot_be_toggled =
32           $input->param( $columnid . '_cannot_be_toggled' ) // 0;
33         push @columns,
34           {
35             module            => $module,
36             page              => $1,
37             tablename         => $2,
38             columnname        => $3,
39             is_hidden         => $is_hidden,
40             cannot_be_toggled => $cannot_be_toggled,
41           };
42     }
43
44     C4::Utils::DataTables::ColumnsSettings::update_columns(
45         {
46             columns => \@columns,
47         }
48     );
49
50     $action = 'list';
51 }
52
53 if ( $action eq 'list' ) {
54     my $modules = C4::Utils::DataTables::ColumnsSettings::get_modules;
55     $template->param(
56         panel   => ( $input->param('panel') || 0 ),
57         modules => $modules,
58     );
59 }
60
61 output_html_with_http_headers $input, $cookie, $template->output;