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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc (-3 / +7 lines)
Lines 47-58 Link Here
47
        [% END %]
47
        [% END %]
48
48
49
        [% IF ( execute ) %]
49
        [% IF ( execute ) %]
50
            [% BLOCK params %]
51
                [% FOREACH param IN sql_params %]&sql_params=[% param %][% END %]
52
            [% END %]
53
50
            <div class="btn-group">
54
            <div class="btn-group">
51
                <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" id="format"><i class="fa fa-upload"></i> Download <span class="caret"></span></button>
55
                <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" id="format"><i class="fa fa-upload"></i> Download <span class="caret"></span></button>
52
                <ul class="dropdown-menu">
56
                <ul class="dropdown-menu">
53
                    <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=csv&amp;sql=[% sql |uri %]&amp;reportname=[% name |uri %]">Comma separated text</a></li>
57
                    <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=csv&amp;report_id=[% id %]&amp;reportname=[% name |uri %][% PROCESS params %]">Comma separated text</a></li>
54
                    <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=tab&amp;sql=[% sql |uri %]&amp;reportname=[% name |uri %]">Tab separated text</a></li>
58
                    <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=tab&amp;report_id=[% id %]&amp;reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li>
55
                    <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=ods&amp;sql=[% sql |uri %]&amp;reportname=[% name |uri %]">Open Document Spreadsheet</a></li>
59
                    <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=ods&amp;report_id=[% id %]&amp;reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li>
56
                </ul>
60
                </ul>
57
            </div>
61
            </div>
58
            <div class="btn-group">
62
            <div class="btn-group">
(-)a/reports/guided_reports.pl (-19 / +26 lines)
Lines 785-805 elsif ($phase eq 'Run this report'){ Link Here
785
                            'reports'      => $report_id,
785
                            'reports'      => $report_id,
786
                            );
786
                            );
787
        } else {
787
        } else {
788
            # OK, we have parameters, or there are none, we run the report
788
            my $sql = get_prepped_report( $sql, @sql_params );
789
            # if there were parameters, replace before running
790
            # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
791
            my @split = split /<<|>>/,$sql;
792
            my @tmpl_parameters;
793
            for(my $i=0;$i<$#split/2;$i++) {
794
                my $quoted = $sql_params[$i];
795
                # if there are special regexp chars, we must \ them
796
                $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
797
                if ($split[$i*2+1] =~ /\|\s*date\s*$/) {
798
                    $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted;
799
                }
800
                $quoted = C4::Context->dbh->quote($quoted);
801
                $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
802
            }
803
            my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id );
789
            my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id );
804
            my $total = nb_rows($sql) || 0;
790
            my $total = nb_rows($sql) || 0;
805
            unless ($sth) {
791
            unless ($sth) {
Lines 841-850 elsif ($phase eq 'Run this report'){ Link Here
841
elsif ($phase eq 'Export'){
827
elsif ($phase eq 'Export'){
842
828
843
	# export results to tab separated text or CSV
829
	# export results to tab separated text or CSV
844
	my $sql    = $input->param('sql');  # FIXME: use sql from saved report ID#, not new user-supplied SQL!
830
    my $report_id      = $input->param('report_id');
845
    my $format = $input->param('format');
831
    my $report         = get_saved_report($report_id);
846
    my $reportname = $input->param('reportname');
832
    my $sql            = $report->{savedsql};
833
    my @sql_params     = $input->multi_param('sql_params');
834
    my $format         = $input->param('format');
835
    my $reportname     = $input->param('reportname');
847
    my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ;
836
    my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ;
837
838
    $sql = get_prepped_report( $sql, @sql_params );
848
	my ($sth, $q_errors) = execute_query($sql);
839
	my ($sth, $q_errors) = execute_query($sql);
849
    unless ($q_errors and @$q_errors) {
840
    unless ($q_errors and @$q_errors) {
850
        my ( $type, $content );
841
        my ( $type, $content );
Lines 1053-1055 sub create_non_existing_group_and_subgroup { Link Here
1053
        }
1044
        }
1054
    }
1045
    }
1055
}
1046
}
1056
- 
1047
1048
# pass $sth and sql_params, get back an executable query
1049
sub get_prepped_report {
1050
    my ($sql, @sql_params ) = @_;
1051
    my @split = split /<<|>>/,$sql;
1052
    for(my $i=0;$i<$#split/2;$i++) {
1053
        my $quoted = $sql_params[$i];
1054
        # if there are special regexp chars, we must \ them
1055
        $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
1056
        if ($split[$i*2+1] =~ /\|\s*date\s*$/) {
1057
            $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted;
1058
        }
1059
        $quoted = C4::Context->dbh->quote($quoted);
1060
        $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
1061
    }
1062
    return $sql;
1063
}

Return to bug 18497