View | Details | Raw Unified | Return to bug 38838
Collapse All | Expand All

(-)a/C4/Reports/Guided.pm (-31 / +26 lines)
Lines 191-232 This will return a list of all columns for a report area Link Here
191
=cut
191
=cut
192
192
193
sub get_columns {
193
sub get_columns {
194
194
    my ($area)      = @_;
195
    # this calls the internal function _get_columns
196
    my ( $area, $cgi ) = @_;
197
    my %table_areas = get_table_areas;
195
    my %table_areas = get_table_areas;
198
    my $tables = $table_areas{$area}
196
    my $tables      = $table_areas{$area}
199
      or die qq{Unsuported report area "$area"};
197
        or die qq{Unsupported report area "$area"};
200
198
201
    my @allcolumns;
199
    my $columns;
202
    my $first = 1;
200
    for my $table (@$tables) {
203
    foreach my $table (@$tables) {
201
        $columns->{$table} = _get_columns($table);
204
        my @columns = _get_columns($table,$cgi, $first);
205
        $first = 0;
206
        push @allcolumns, @columns;
207
    }
202
    }
208
    return ( \@allcolumns );
203
    return $columns;
209
}
204
}
210
205
211
sub _get_columns {
206
sub _get_columns {
212
    my ($tablename,$cgi, $first) = @_;
207
    my ($table_name) = @_;
213
    my $dbh         = C4::Context->dbh();
208
    my $dbh          = C4::Context->dbh();
214
    my $sth         = $dbh->prepare("show columns from $tablename");
209
    my $all_columns  = Koha::Database::Columns->columns;
215
    $sth->execute();
210
216
    my @columns;
211
    # Sanitize input, just in case
217
    my $columns = Koha::Database::Columns->columns;
212
    die sprintf( 'Invalid table name %s', $table_name ) unless exists $all_columns->{$table_name};
218
	my %tablehash;
213
219
	$tablehash{'table'}=$tablename;
214
    my $columns = $dbh->selectall_arrayref( sprintf( q{SHOW COLUMNS FROM %s}, $table_name ), { Slice => {} } );
220
    $tablehash{'__first__'} = $first;
215
    return [
221
	push @columns, \%tablehash;
216
        map {
222
    while ( my $data = $sth->fetchrow_arrayref() ) {
217
            my $column_name = $_->{Field};
223
        my %temphash;
218
            {
224
        $temphash{'name'}        = "$tablename.$data->[0]";
219
                name        => sprintf( "%s.%s", $table_name, $column_name ),
225
        $temphash{'description'} = $columns->{$tablename}->{$data->[0]};
220
                description => $all_columns->{$table_name}->{$column_name},
226
        push @columns, \%temphash;
221
            };
227
    }
222
228
    $sth->finish();
223
        } @$columns
229
    return (@columns);
224
    ];
230
}
225
}
231
226
232
=head2 build_query($columns,$criteria,$orderby,$area)
227
=head2 build_query($columns,$criteria,$orderby,$area)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tt (-19 / +14 lines)
Lines 191-215 Link Here
191
<input type="hidden" name="definition_name" value="[% definition_name | html %]" />
191
<input type="hidden" name="definition_name" value="[% definition_name | html %]" />
192
<input type="hidden" name="definition_description" value="[% definition_description | html %]" />
192
<input type="hidden" name="definition_description" value="[% definition_description | html %]" />
193
193
194
<select id="availableColumns" name="columns" size="25" style="width:200px;height:300px;margin:1em;">
194
<select id="availableColumns" name="columns" size="25" style="min-width:200px; height:300px; margin:1em;">
195
[% FOREACH column IN columns %]
195
    [% FOREACH table IN columns.keys.sort %]
196
[% IF ( column.table ) %]
196
        <optgroup label="[% table | html %]">
197
[% IF ( loop.first ) %]                              
197
            [% FOREACH column IN columns.item(table) %]
198
[% ELSE %]               
198
                <option value="[% column.name | html %]">
199
</optgroup>        
199
                    [% IF ( column.description ) %]
200
[% END %]                                                         
200
                        [% column.description | html %] &nbsp; / &nbsp; [% column.name | html %]
201
201
                    [% ELSE %]
202
<optgroup label="[% column.table | html %]">              
202
                        [% column.name | html %]
203
[% ELSE %]               
203
                    [% END %]
204
<option value="[% column.name | html %]">
204
                </option>
205
[% IF ( column.description ) %][% column.description | html %]    
205
            [% END %]
206
[% ELSE %]               
206
        </optgroup>
207
[% column.name | html %]                          
207
    [% END %]
208
[% END %]              
209
</option>      
210
[% END %]              
211
[% END %]                
212
</optgroup>
213
</select>
208
</select>
214
209
215
<input type="hidden" name="op" value="cud-add_form_4" />
210
<input type="hidden" name="op" value="cud-add_form_4" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-17 / +12 lines)
Lines 546-570 Link Here
546
                            <div class="row">
546
                            <div class="row">
547
                                <div class="col-sm-6">
547
                                <div class="col-sm-6">
548
                                    <div style="float: left;">
548
                                    <div style="float: left;">
549
                                        <select id="availableColumns" name="oldcolumns2" multiple="multiple" size="25" style="min-width: 200px;height:300px;">
549
                                        <select id="availableColumns" name="oldcolumns2" multiple="multiple" size="25" style="min-width:200px; height:300px;">
550
                                            [% FOREACH column IN columns %]
550
                                            [% FOREACH table IN columns.keys.sort %]
551
                                                [% IF ( column.table ) %]
551
                                                <optgroup label="[% table | html %]">
552
                                                    [% IF ( loop.first ) %]
552
                                                    [% FOREACH column IN columns.item(table) %]
553
                                                    [% ELSE %]
553
                                                        <option value="[% column.name | html %]">
554
                                                        </optgroup>
554
                                                            [% IF ( column.description ) %]
555
                                                                [% column.description | html %] &nbsp; / &nbsp; [% column.name | html %]
556
                                                            [% ELSE %]
557
                                                                [% column.name | html %]
558
                                                            [% END %]
559
                                                        </option>
555
                                                    [% END %]
560
                                                    [% END %]
556
                                                    <optgroup label="[% column.table | html %]">
561
                                                </optgroup>
557
                                                [% ELSE %]
558
                                                    <option value="[% column.name | html %]">
559
                                                        [% IF ( column.description ) %]
560
                                                            [% column.description | html %] &nbsp; / &nbsp; [% column.name | html %]
561
                                                        [% ELSE %]
562
                                                            [% column.name | html %]
563
                                                        [% END %]
564
                                                    </option>
565
                                                [% END %]
566
                                            [% END %]
562
                                            [% END %]
567
                                            </optgroup>
568
                                        </select>
563
                                        </select>
569
                                    </div>
564
                                    </div>
570
                                    <div style="width: 6.3em; float: right; margin-top: 100px">
565
                                    <div style="width: 6.3em; float: right; margin-top: 100px">
(-)a/reports/dictionary.pl (-2 / +1 lines)
Lines 67-77 elsif ( $op eq 'cud-add_form_2' ) { Link Here
67
elsif ( $op eq 'cud-add_form_3' ) {
67
elsif ( $op eq 'cud-add_form_3' ) {
68
68
69
    # Choosing the columns
69
    # Choosing the columns
70
    my $columns                = get_columns( $area, $input );
71
    $template->param(
70
    $template->param(
72
        'step_3'                 => 1,
71
        'step_3'                 => 1,
73
        'area'                   => $area,
72
        'area'                   => $area,
74
        'columns'                => $columns,
73
        'columns'                => get_columns($area),
75
        'definition_name'        => $definition_name,
74
        'definition_name'        => $definition_name,
76
        'definition_description' => $definition_description,
75
        'definition_description' => $definition_description,
77
    );
76
    );
(-)a/reports/guided_reports.pl (-1 / +1 lines)
Lines 313-319 elsif ( $op eq 'cud-choose_type' ) { Link Here
313
        'build3' => 1,
313
        'build3' => 1,
314
        'area'   => $area,
314
        'area'   => $area,
315
        'type'   => $type,
315
        'type'   => $type,
316
        columns  => get_columns($area,$input),
316
        columns  => get_columns($area),
317
        'cache_expiry' => scalar $input->param('cache_expiry'),
317
        'cache_expiry' => scalar $input->param('cache_expiry'),
318
        'public' => scalar $input->param('public'),
318
        'public' => scalar $input->param('public'),
319
    );
319
    );
(-)a/t/db_dependent/Reports/Guided.t (-2 / +19 lines)
Lines 20-26 Link Here
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use Test::More tests => 12;
23
use Test::More tests => 13;
24
use Test::Warn;
24
use Test::Warn;
25
25
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
Lines 535-540 subtest 'Returning passwords tests' => sub { Link Here
535
    $schema->storage->txn_rollback;
535
    $schema->storage->txn_rollback;
536
};
536
};
537
537
538
subtest 'get_columns' => sub {
539
    plan tests => 7;
540
    $schema->storage->txn_begin;
541
    my $area    = 'foo';
542
    my $success = eval { C4::Reports::Guided::get_columns($area) };
543
    ok !$success && $@ =~ m{^Unsupported report area "$area"}, 'Call with wrong report area explodes';
544
545
    my $columns = C4::Reports::Guided::get_columns('CAT');
546
    ok exists $columns->{biblio};
547
    ok exists $columns->{biblioitems};
548
    ok exists $columns->{items};
549
    ok scalar grep  { $_->{name} eq 'biblio.biblionumber' } @{ $columns->{biblio} };
550
    ok scalar grep  { $_->{description} =~ m{Biblio number} } @{ $columns->{biblio} };
551
    ok !scalar grep { $_->{name} eq 'not_a_column' } @{ $columns->{biblio} };
552
553
    $schema->storage->txn_rollback;
554
};
555
538
sub trim {
556
sub trim {
539
    my ($s) = @_;
557
    my ($s) = @_;
540
    $s =~ s/^\s*(.*?)\s*$/$1/s;
558
    $s =~ s/^\s*(.*?)\s*$/$1/s;
541
- 

Return to bug 38838