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

(-)a/C4/Reports/Guided.pm (-4 / +6 lines)
Lines 561-571 sub save_report { Link Here
561
    my $subgroup = $fields->{subgroup};
561
    my $subgroup = $fields->{subgroup};
562
    my $cache_expiry = $fields->{cache_expiry} || 300;
562
    my $cache_expiry = $fields->{cache_expiry} || 300;
563
    my $public = $fields->{public};
563
    my $public = $fields->{public};
564
    my $combine_params = $fields->{combine_params} || 0;
564
565
565
    my $dbh = C4::Context->dbh();
566
    my $dbh = C4::Context->dbh();
566
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
567
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
567
    my $query = "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public)  VALUES (?,now(),now(),?,?,?,?,?,?,?,?,?)";
568
    my $query = "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public,combine_params)  VALUES (?,now(),now(),?,?,?,?,?,?,?,?,?,?)";
568
    $dbh->do($query, undef, $borrowernumber, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public);
569
    $dbh->do($query, undef, $borrowernumber, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public,$combine_params);
569
570
570
    my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef,
571
    my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef,
571
                                   $borrowernumber, $name);
572
                                   $borrowernumber, $name);
Lines 582-587 sub update_sql { Link Here
582
    my $subgroup = $fields->{subgroup};
583
    my $subgroup = $fields->{subgroup};
583
    my $cache_expiry = $fields->{cache_expiry};
584
    my $cache_expiry = $fields->{cache_expiry};
584
    my $public = $fields->{public};
585
    my $public = $fields->{public};
586
    my $combine_params = $fields->{combine_params};
585
587
586
    if( $cache_expiry >= 2592000 ){
588
    if( $cache_expiry >= 2592000 ){
587
      die "Please specify a cache expiry less than 30 days\n";
589
      die "Please specify a cache expiry less than 30 days\n";
Lines 589-596 sub update_sql { Link Here
589
591
590
    my $dbh        = C4::Context->dbh();
592
    my $dbh        = C4::Context->dbh();
591
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
593
    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
592
    my $query = "UPDATE saved_sql SET savedsql = ?, last_modified = now(), report_name = ?, report_group = ?, report_subgroup = ?, notes = ?, cache_expiry = ?, public = ? WHERE id = ? ";
594
    my $query = "UPDATE saved_sql SET savedsql = ?, last_modified = now(), report_name = ?, report_group = ?, report_subgroup = ?, notes = ?, cache_expiry = ?, public = ?, combine_params = ? WHERE id = ? ";
593
    $dbh->do($query, undef, $sql, $name, $group, $subgroup, $notes, $cache_expiry, $public, $id );
595
    $dbh->do($query, undef, $sql, $name, $group, $subgroup, $notes, $cache_expiry, $public, $combine_params, $id );
594
}
596
}
595
597
596
sub store_results {
598
sub store_results {
(-)a/installer/data/mysql/atomicupdate/bug9634_add_combine_params_option_to_reports.perl (+7 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do( "ALTER TABLE saved_sql ADD COLUMN combine_params tinyint(1) NOT NULL DEFAULT 0" );
4
5
    SetVersion( $DBversion );
6
    print "Upgrade to $DBversion done (Bug XXXXX - add combine params option to reports)\n";
7
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (+27 lines)
Lines 165-170 canned reports and writing custom SQL reports.</p> Link Here
165
                    <th class="title-string">Last run</th>
165
                    <th class="title-string">Last run</th>
166
                    <th class="report_public">Public</th>
166
                    <th class="report_public">Public</th>
167
                    <th class="report_json_url">JSON URL</th>
167
                    <th class="report_json_url">JSON URL</th>
168
                    <th class="combine_params">Combine parameters</th>
168
                    [% IF (usecache) %] <th>Cache expiry (seconds)</th> [% END %]
169
                    [% IF (usecache) %] <th>Cache expiry (seconds)</th> [% END %]
169
                    <th>Saved results</th>
170
                    <th>Saved results</th>
170
                    [% IF has_obsolete_reports %]<th>Update</th>[% END %]
171
                    [% IF has_obsolete_reports %]<th>Update</th>[% END %]
Lines 209-214 canned reports and writing custom SQL reports.</p> Link Here
209
                            <a href="/cgi-bin/koha/svc/report?id=[% savedreport.id | uri %]">[% Koha.Preference('staffClientBaseURL') %]/cgi-bin/koha/svc/report?id=[% savedreport.id | html %]</a>
210
                            <a href="/cgi-bin/koha/svc/report?id=[% savedreport.id | uri %]">[% Koha.Preference('staffClientBaseURL') %]/cgi-bin/koha/svc/report?id=[% savedreport.id | html %]</a>
210
                        [% END %]
211
                        [% END %]
211
                        </td>
212
                        </td>
213
                        <td class="combine_params">
214
                        [% IF (savedreport.combine_params) %]
215
                            Yes
216
                        [% ELSE %]
217
                            No
218
                        [% END %]
219
                        </td>
212
                        [% IF (usecache) %] <td>[% savedreport.cache_expiry %]</td> [% END %]
220
                        [% IF (usecache) %] <td>[% savedreport.cache_expiry %]</td> [% END %]
213
                        <td>
221
                        <td>
214
                            [% FOR result IN savedreport.results %]
222
                            [% FOR result IN savedreport.results %]
Lines 316-321 canned reports and writing custom SQL reports.</p> Link Here
316
[% ELSE %]
324
[% ELSE %]
317
  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
325
  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
318
[% END %]
326
[% END %]
327
[% IF (combine_params) %]
328
  <li><label for="combine_params">Combine parameters:</label><select id="combine_params" name="combine_params"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
329
[% ELSE %]
330
  <li><label for="combine_params">Combine parameters:</label><select id="combine_params" name="combine_params"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
331
[% END %]
319
[% IF (usecache) %] <li>
332
[% IF (usecache) %] <li>
320
<label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
333
<label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
321
<select id="cache_expiry_units" name="cache_expiry_units">
334
<select id="cache_expiry_units" name="cache_expiry_units">
Lines 668-673 canned reports and writing custom SQL reports.</p> Link Here
668
                    </li>
681
                    </li>
669
                [% END %]
682
                [% END %]
670
            [% END %]
683
            [% END %]
684
            [% FOREACH key IN uniq_params.keys %]
685
                <input type="hidden" name="param_name" value="[% key %]">
686
                <input type="hidden" name="param_value" value="[% uniq_params.$key %]">
687
            [% END %]
671
            </ol>
688
            </ol>
672
        </fieldset>
689
        </fieldset>
673
        <fieldset class="action"><input type="submit" value="Run the report" /></fieldset>
690
        <fieldset class="action"><input type="submit" value="Run the report" /></fieldset>
Lines 737-742 $(document).ready(function() { Link Here
737
[% ELSE %]
754
[% ELSE %]
738
  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
755
  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
739
[% END %]
756
[% END %]
757
[% IF (combine_params) %]
758
  <li><label for="combine_params">Combine parameters:</label><select id="combine_params" name="combine_params"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
759
[% ELSE %]
760
  <li><label for="combine_params">Combine parameters:</label><select id="combine_params" name="combine_params"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
761
[% END %]
740
[% IF (usecache) %] <li>
762
[% IF (usecache) %] <li>
741
<label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
763
<label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
742
<select id="cache_expiry_units" name="cache_expiry_units">
764
<select id="cache_expiry_units" name="cache_expiry_units">
Lines 826-831 Sub report:<select name="subreport"> Link Here
826
[% ELSE %]
848
[% ELSE %]
827
  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
849
  <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
828
[% END %]
850
[% END %]
851
[% IF (combine_params) %]
852
  <li><label for="combine_params">Combine parameters:</label><select id="combine_params" name="combine_params"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</option> </select></li>
853
[% ELSE %]
854
  <li><label for="combine_params">Combine parameters:</label><select id="combine_params" name="combine_params"> <option value="0" selected="selected">No (default)</option> <option value="1">Yes</option> </select></li>
855
[% END %]
829
[% IF (usecache) %] <li>
856
[% IF (usecache) %] <li>
830
<label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
857
<label for="cache_expiry">Cache expiry:</label><input type="text" id="cache_expiry" name="cache_expiry" value="[% cache_expiry %]"></input>
831
<select id="cache_expiry_units" name="cache_expiry_units">
858
<select id="cache_expiry_units" name="cache_expiry_units">
(-)a/reports/guided_reports.pl (-2 / +34 lines)
Lines 104-109 elsif ( $phase eq 'Build new' ) { Link Here
104
        'usecache'     => $usecache,
104
        'usecache'     => $usecache,
105
        'cache_expiry' => 300,
105
        'cache_expiry' => 300,
106
        'public'       => '0',
106
        'public'       => '0',
107
        'combine_params'       => '0',
107
    );
108
    );
108
} elsif ( $phase eq 'Use saved' ) {
109
} elsif ( $phase eq 'Use saved' ) {
109
110
Lines 122-127 elsif ( $phase eq 'Build new' ) { Link Here
122
                    notes        => $report->{notes},
123
                    notes        => $report->{notes},
123
                    public       => $report->{public},
124
                    public       => $report->{public},
124
                    cache_expiry => $report->{cache_expiry},
125
                    cache_expiry => $report->{cache_expiry},
126
                    combine_params => $report->{combine_params},
125
                }
127
                }
126
            );
128
            );
127
            $template->param( report_converted => $report->{report_name} );
129
            $template->param( report_converted => $report->{report_name} );
Lines 194-199 elsif ( $phase eq 'Edit SQL'){ Link Here
194
        'notes'      => $report->{notes},
196
        'notes'      => $report->{notes},
195
        'id'         => $id,
197
        'id'         => $id,
196
        'cache_expiry' => $report->{cache_expiry},
198
        'cache_expiry' => $report->{cache_expiry},
199
        'combine_params' => $report->{combine_params},
197
        'public' => $report->{public},
200
        'public' => $report->{public},
198
        'usecache' => $usecache,
201
        'usecache' => $usecache,
199
        'editsql'    => 1,
202
        'editsql'    => 1,
Lines 208-213 elsif ( $phase eq 'Update SQL'){ Link Here
208
    my $subgroup   = $input->param('subgroup');
211
    my $subgroup   = $input->param('subgroup');
209
    my $notes      = $input->param('notes');
212
    my $notes      = $input->param('notes');
210
    my $cache_expiry = $input->param('cache_expiry');
213
    my $cache_expiry = $input->param('cache_expiry');
214
    my $combine_params = $input->param('combine_params');
211
    my $cache_expiry_units = $input->param('cache_expiry_units');
215
    my $cache_expiry_units = $input->param('cache_expiry_units');
212
    my $public = $input->param('public');
216
    my $public = $input->param('public');
213
    my $save_anyway = $input->param('save_anyway');
217
    my $save_anyway = $input->param('save_anyway');
Lines 259-264 elsif ( $phase eq 'Update SQL'){ Link Here
259
                'subgroup' => $subgroup,
263
                'subgroup' => $subgroup,
260
                'notes' => $notes,
264
                'notes' => $notes,
261
                'public' => $public,
265
                'public' => $public,
266
                'combine_params' => $combine_params,
262
                'problematic_authvals' => $problematic_authvals,
267
                'problematic_authvals' => $problematic_authvals,
263
                'warn_authval_problem' => 1,
268
                'warn_authval_problem' => 1,
264
                'phase_update' => 1
269
                'phase_update' => 1
Lines 274-279 elsif ( $phase eq 'Update SQL'){ Link Here
274
                    notes => $notes,
279
                    notes => $notes,
275
                    public => $public,
280
                    public => $public,
276
                    cache_expiry => $cache_expiry,
281
                    cache_expiry => $cache_expiry,
282
                    combine_params => $combine_params,
277
                } );
283
                } );
278
            $template->param(
284
            $template->param(
279
                'save_successful'       => 1,
285
                'save_successful'       => 1,
Lines 305-310 elsif ($phase eq 'retrieve results') { Link Here
305
elsif ( $phase eq 'Report on this Area' ) {
311
elsif ( $phase eq 'Report on this Area' ) {
306
    my $cache_expiry_units = $input->param('cache_expiry_units'),
312
    my $cache_expiry_units = $input->param('cache_expiry_units'),
307
    my $cache_expiry = $input->param('cache_expiry');
313
    my $cache_expiry = $input->param('cache_expiry');
314
    my $combine_params = $input->param('combine_params');
308
315
309
    # we need to handle converting units
316
    # we need to handle converting units
310
    if( $cache_expiry_units eq "minutes" ){
317
    if( $cache_expiry_units eq "minutes" ){
Lines 322-327 elsif ( $phase eq 'Report on this Area' ) { Link Here
322
        'build1' => 1,
329
        'build1' => 1,
323
        'areas'   => get_report_areas(),
330
        'areas'   => get_report_areas(),
324
        'cache_expiry' => $cache_expiry,
331
        'cache_expiry' => $cache_expiry,
332
        'combine_params' => $combine_params,
325
        'usecache' => $usecache,
333
        'usecache' => $usecache,
326
        'public' => scalar $input->param('public'),
334
        'public' => scalar $input->param('public'),
327
      );
335
      );
Lines 332-337 elsif ( $phase eq 'Report on this Area' ) { Link Here
332
          'area'   => scalar $input->param('area'),
340
          'area'   => scalar $input->param('area'),
333
          'types'  => get_report_types(),
341
          'types'  => get_report_types(),
334
          'cache_expiry' => $cache_expiry,
342
          'cache_expiry' => $cache_expiry,
343
          'combine_params' => $combine_params,
335
          'public' => scalar $input->param('public'),
344
          'public' => scalar $input->param('public'),
336
      );
345
      );
337
    }
346
    }
Lines 348-353 elsif ( $phase eq 'Choose this type' ) { Link Here
348
        'type'   => $type,
357
        'type'   => $type,
349
        columns  => get_columns($area,$input),
358
        columns  => get_columns($area,$input),
350
        'cache_expiry' => scalar $input->param('cache_expiry'),
359
        'cache_expiry' => scalar $input->param('cache_expiry'),
360
        'combine_params' => scalar $input->param('combine_params'),
351
        'public' => scalar $input->param('public'),
361
        'public' => scalar $input->param('public'),
352
    );
362
    );
353
}
363
}
Lines 372-377 elsif ( $phase eq 'Choose these columns' ) { Link Here
372
    if ( $usecache ) {
382
    if ( $usecache ) {
373
        $template->param(
383
        $template->param(
374
            cache_expiry => scalar $input->param('cache_expiry'),
384
            cache_expiry => scalar $input->param('cache_expiry'),
385
            combine_params => scalar $input->param('combine_params'),
375
            cache_expiry_units => scalar $input->param('cache_expiry_units'),
386
            cache_expiry_units => scalar $input->param('cache_expiry_units'),
376
        );
387
        );
377
    }
388
    }
Lines 433-438 elsif ( $phase eq 'Choose these criteria' ) { Link Here
433
        'definition'     => $definition,
444
        'definition'     => $definition,
434
        'criteriastring' => $query_criteria,
445
        'criteriastring' => $query_criteria,
435
        'public' => scalar $input->param('public'),
446
        'public' => scalar $input->param('public'),
447
        'combine_params' => scalar $input->param('combine_params'),
436
    );
448
    );
437
    if ( $usecache ) {
449
    if ( $usecache ) {
438
        $template->param(
450
        $template->param(
Lines 480-485 elsif ( $phase eq 'Choose these operations' ) { Link Here
480
        'totals'         => $totals,
492
        'totals'         => $totals,
481
        'definition'     => $definition,
493
        'definition'     => $definition,
482
        'cache_expiry' => scalar $input->param('cache_expiry'),
494
        'cache_expiry' => scalar $input->param('cache_expiry'),
495
        'combine_params' => scalar $input->param('combine_params'),
483
        'public' => scalar $input->param('public'),
496
        'public' => scalar $input->param('public'),
484
    );
497
    );
485
498
Lines 533-538 elsif ( $phase eq 'Build report' ) { Link Here
533
        'sql'        => $sql,
546
        'sql'        => $sql,
534
        'type'       => $type,
547
        'type'       => $type,
535
        'cache_expiry' => scalar $input->param('cache_expiry'),
548
        'cache_expiry' => scalar $input->param('cache_expiry'),
549
        'combine_params' => scalar $input->param('combine_params'),
536
        'public' => scalar $input->param('public'),
550
        'public' => scalar $input->param('public'),
537
    );
551
    );
538
}
552
}
Lines 548-553 elsif ( $phase eq 'Save' ) { Link Here
548
        'sql'  => $sql,
562
        'sql'  => $sql,
549
        'type' => $type,
563
        'type' => $type,
550
        'cache_expiry' => scalar $input->param('cache_expiry'),
564
        'cache_expiry' => scalar $input->param('cache_expiry'),
565
        'combine_params' => scalar $input->param('combine_params'),
551
        'public' => scalar $input->param('public'),
566
        'public' => scalar $input->param('public'),
552
        'groups_with_subgroups' => groups_with_subgroups($area), # in case we have a report group that matches area
567
        'groups_with_subgroups' => groups_with_subgroups($area), # in case we have a report group that matches area
553
    );
568
    );
Lines 563-568 elsif ( $phase eq 'Save Report' ) { Link Here
563
    my $type  = $input->param('types');
578
    my $type  = $input->param('types');
564
    my $notes = $input->param('notes');
579
    my $notes = $input->param('notes');
565
    my $cache_expiry = $input->param('cache_expiry');
580
    my $cache_expiry = $input->param('cache_expiry');
581
    my $combine_params = $input->param('combine_params'),
566
    my $cache_expiry_units = $input->param('cache_expiry_units');
582
    my $cache_expiry_units = $input->param('cache_expiry_units');
567
    my $public = $input->param('public');
583
    my $public = $input->param('public');
568
    my $save_anyway = $input->param('save_anyway');
584
    my $save_anyway = $input->param('save_anyway');
Lines 601-606 elsif ( $phase eq 'Save Report' ) { Link Here
601
            'type'      => $type,
617
            'type'      => $type,
602
            'notes'     => $notes,
618
            'notes'     => $notes,
603
            'cache_expiry' => $cache_expiry,
619
            'cache_expiry' => $cache_expiry,
620
            'combine_params' => $combine_params,
604
            'public'    => $public,
621
            'public'    => $public,
605
        );
622
        );
606
    } else {
623
    } else {
Lines 619-624 elsif ( $phase eq 'Save Report' ) { Link Here
619
                'type' => $type,
636
                'type' => $type,
620
                'notes' => $notes,
637
                'notes' => $notes,
621
                'public' => $public,
638
                'public' => $public,
639
                'combine_params' => $combine_params,
622
                'problematic_authvals' => $problematic_authvals,
640
                'problematic_authvals' => $problematic_authvals,
623
                'warn_authval_problem' => 1,
641
                'warn_authval_problem' => 1,
624
                'phase_save' => 1
642
                'phase_save' => 1
Lines 641-646 elsif ( $phase eq 'Save Report' ) { Link Here
641
                    type           => $type,
659
                    type           => $type,
642
                    notes          => $notes,
660
                    notes          => $notes,
643
                    cache_expiry   => $cache_expiry,
661
                    cache_expiry   => $cache_expiry,
662
                    combine_params => $combine_params,
644
                    public         => $public,
663
                    public         => $public,
645
                } );
664
                } );
646
                logaction( "REPORTS", "ADD", $id, "$name | $sql" ) if C4::Context->preference("ReportsLog");
665
                logaction( "REPORTS", "ADD", $id, "$name | $sql" ) if C4::Context->preference("ReportsLog");
Lines 659-664 elsif ($phase eq 'Run this report'){ Link Here
659
    my $offset     = 0;
678
    my $offset     = 0;
660
    my $report_id  = $input->param('reports');
679
    my $report_id  = $input->param('reports');
661
    my @sql_params = $input->multi_param('sql_params');
680
    my @sql_params = $input->multi_param('sql_params');
681
    my @param_name = $input->multi_param('param_name');
682
    my @param_value = $input->multi_param('param_value');
683
    my %lookup;
684
    @lookup{@param_name} = @param_value;
685
662
    # offset algorithm
686
    # offset algorithm
663
    if ($input->param('page')) {
687
    if ($input->param('page')) {
664
        $offset = ($input->param('page') - 1) * $limit;
688
        $offset = ($input->param('page') - 1) * $limit;
Lines 669-679 elsif ($phase eq 'Run this report'){ Link Here
669
        'report_id' => $report_id,
693
        'report_id' => $report_id,
670
    );
694
    );
671
695
672
    my ( $sql, $original_sql, $type, $name, $notes );
696
    my ( $sql, $original_sql, $type, $name, $notes, $combine_params );
673
    if (my $report = get_saved_report($report_id)) {
697
    if (my $report = get_saved_report($report_id)) {
674
        $sql   = $original_sql = $report->{savedsql};
698
        $sql   = $original_sql = $report->{savedsql};
675
        $name  = $report->{report_name};
699
        $name  = $report->{report_name};
676
        $notes = $report->{notes};
700
        $notes = $report->{notes};
701
        $combine_params = $report->{combine_params};
677
702
678
        my @rows = ();
703
        my @rows = ();
679
        # if we have at least 1 parameter, and it's not filled, then don't execute but ask for parameters
704
        # if we have at least 1 parameter, and it's not filled, then don't execute but ask for parameters
Lines 682-689 elsif ($phase eq 'Run this report'){ Link Here
682
            my @split = split /<<|>>/,$sql;
707
            my @split = split /<<|>>/,$sql;
683
            my @tmpl_parameters;
708
            my @tmpl_parameters;
684
            my @authval_errors;
709
            my @authval_errors;
710
            my %uniq_params;
685
            for(my $i=0;$i<($#split/2);$i++) {
711
            for(my $i=0;$i<($#split/2);$i++) {
686
                my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
712
                my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
713
                if( defined $uniq_params{$text."|".$authorised_value} && $combine_params ){
714
                    next;
715
                } else { $uniq_params{$text."|".$authorised_value} = "$i"; }
687
                my $input;
716
                my $input;
688
                my $labelid;
717
                my $labelid;
689
                if ( not defined $authorised_value ) {
718
                if ( not defined $authorised_value ) {
Lines 783-788 elsif ($phase eq 'Run this report'){ Link Here
783
                            'auth_val_errors'  => \@authval_errors,
812
                            'auth_val_errors'  => \@authval_errors,
784
                            'enter_params' => 1,
813
                            'enter_params' => 1,
785
                            'reports'      => $report_id,
814
                            'reports'      => $report_id,
815
                            'uniq_params'  => \%uniq_params,
786
                            );
816
                            );
787
        } else {
817
        } else {
788
            # OK, we have parameters, or there are none, we run the report
818
            # OK, we have parameters, or there are none, we run the report
Lines 791-797 elsif ($phase eq 'Run this report'){ Link Here
791
            my @split = split /<<|>>/,$sql;
821
            my @split = split /<<|>>/,$sql;
792
            my @tmpl_parameters;
822
            my @tmpl_parameters;
793
            for(my $i=0;$i<$#split/2;$i++) {
823
            for(my $i=0;$i<$#split/2;$i++) {
794
                my $quoted = $sql_params[$i];
824
                my $use_param  = $combine_params ? $lookup{ $split[$i*2+1] } : $i;
825
                my $quoted = $sql_params[$use_param];
795
                # if there are special regexp chars, we must \ them
826
                # if there are special regexp chars, we must \ them
796
                $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
827
                $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
797
                if ($split[$i*2+1] =~ /\|\s*date\s*$/) {
828
                if ($split[$i*2+1] =~ /\|\s*date\s*$/) {
Lines 956-961 elsif ( $phase eq 'Create report from SQL' ) { Link Here
956
        'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
987
        'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
957
        'public' => '0',
988
        'public' => '0',
958
        'cache_expiry' => 300,
989
        'cache_expiry' => 300,
990
        'combine_params' => 0,
959
        'usecache' => $usecache,
991
        'usecache' => $usecache,
960
    );
992
    );
961
}
993
}
(-)a/t/db_dependent/Reports/Guided.t (-2 / +31 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 9;
21
use Test::More tests => 10;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
Lines 354-359 count(h.reservedate) AS 'holds' Link Here
354
    is( C4::Reports::Guided::convert_sql( $sql ), $expected_converted_sql, "Query with multiple instances of marcxml and biblioitems should have them all replaced");
354
    is( C4::Reports::Guided::convert_sql( $sql ), $expected_converted_sql, "Query with multiple instances of marcxml and biblioitems should have them all replaced");
355
};
355
};
356
356
357
subtest 'add combine_params column' => sub {
358
    plan tests => 3;
359
360
    my $id = $builder->build({ source => 'Borrower' })->{ borrowernumber };
361
362
    my $new_report_params = {
363
        borrowernumber => $id,
364
        sql            => "SELECT 'CAT'",
365
        name           => "Kitty cat",
366
        type           => 1,
367
        public         => 0,
368
    };
369
370
    my $new_report_id = save_report($new_report_params);
371
    my $saved_report = get_saved_report($new_report_id);
372
    is( $saved_report->{combine_params},0,'When no combine params supplied to new report default is 0');
373
374
    $new_report_params->{combine_params} = 1;
375
    $new_report_id = save_report($new_report_params);
376
    $saved_report = get_saved_report($new_report_id);
377
    is( $saved_report->{combine_params},1,'When combine params supplied to new report, it is saved');
378
379
    $saved_report->{combine_params} = 0;
380
    $saved_report->{sql} = $saved_report->{savedsql}; #because we don't get back the same column name
381
    update_sql($new_report_id,$saved_report);
382
    $saved_report = get_saved_report($new_report_id);
383
    is( $saved_report->{combine_params},0,'When combine params updated it is correctly saved');
384
385
};
386
357
$schema->storage->txn_rollback;
387
$schema->storage->txn_rollback;
358
388
359
sub trim {
389
sub trim {
360
- 

Return to bug 9634