55d312d4f960ac1b5813c77e679dfbd8509a04d3
[koha.git] / admin / columns_settings.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use CGI;
5 use C4::Auth qw( get_template_and_user );
6 use C4::Context;
7 use C4::Output qw( output_html_with_http_headers );
8 use C4::Utils::DataTables::TablesSettings qw( get_modules );
9 my $input = CGI->new;
10
11 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
12     {
13         template_name   => "admin/columns_settings.tt",
14         query           => $input,
15         type            => "intranet",
16         flagsrequired   => { parameters => 'manage_column_config' },
17     }
18 );
19
20 my $action = $input->param('action') // 'list';
21
22 if ( $action eq 'save' ) {
23     my $module = $input->param('module');
24     my @columnids = $input->multi_param("columnid");
25     my @columns;
26     for my $columnid (@columnids) {
27         next unless $columnid =~ m|^([^#]*)#([^#]*)#(.*)$|;
28         my $is_hidden = $input->param( $columnid . '_hidden' ) // 0;
29         my $cannot_be_toggled =
30           $input->param( $columnid . '_cannot_be_toggled' ) // 0;
31         push @columns,
32           {
33             module            => $module,
34             page              => $1,
35             tablename         => $2,
36             columnname        => $3,
37             is_hidden         => $is_hidden,
38             cannot_be_toggled => $cannot_be_toggled,
39           };
40     }
41
42     C4::Utils::DataTables::TablesSettings::update_columns(
43         {
44             columns => \@columns,
45         }
46     );
47
48     my @table_ids = $input->multi_param('table_id');
49     for my $table_id (@table_ids) {
50         next unless $table_id =~ m|^([^#]*)#(.*)$|;
51         my $default_display_length = $input->param( $table_id . '_default_display_length' );
52         my $default_sort_order     = $input->param( $table_id . '_default_sort_order' );
53         if (   defined $default_display_length && $default_display_length ne ""
54             && defined $default_sort_order     && $default_sort_order     ne "" ) {
55             C4::Utils::DataTables::TablesSettings::update_table_settings(
56                 {
57                     module                 => $module,
58                     page                   => $1,
59                     tablename              => $2,
60                     default_display_length => $default_display_length,
61                     default_sort_order     => $default_sort_order,
62                 }
63             );
64         }
65     }
66
67     $action = 'list';
68 }
69
70 if ( $action eq 'list' ) {
71     my $modules = C4::Utils::DataTables::TablesSettings::get_modules;
72     $template->param(
73         panel   => ( $input->param('panel') || 0 ),
74         modules => $modules,
75     );
76 }
77
78 output_html_with_http_headers $input, $cookie, $template->output;