diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index c7ab443c95..74ffefbca6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -1638,7 +1638,9 @@
The following error was encountered:
[% FOREACH error IN errors %] - [% IF ( error.sqlerr ) %] + [% IF ( error.duplicate_running_report_ids ) %] + This report is already running. Please wait for it to finish before running it again. + [% ELSIF ( error.sqlerr ) %] This report contains the SQL keyword [% error.sqlerr | html %].
Use of this keyword is not allowed in Koha reports due to security and data integrity risks. Only SELECT queries are allowed.
Please return to the "Saved Reports" screen and delete this report or retry creating a new one. diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 53cfc9a2f5..6d2be0e376 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -824,6 +824,12 @@ if ( $op eq 'run' ) { my $template_id = $input->param('template'); my $want_full_chart = $input->param('want_full_chart') || 0; + my @duplicate_running_report_ids; + if ( C4::Context->userenv ) { + my $user_id = C4::Context->userenv ? C4::Context->userenv->{number} : undef; + @duplicate_running_report_ids = Koha::Reports->running( { report_id => $report_id, user_id => $user_id } ); + } + # offset algorithm if ( $input->param('page') ) { $offset = ( $input->param('page') - 1 ) * $limit; @@ -1009,6 +1015,18 @@ if ( $op eq 'run' ) { 'id' => $report_id, 'template_id' => $template_id, ); + } elsif (@duplicate_running_report_ids) { + $template->param( + 'sql' => $sql, + 'original_sql' => $original_sql, + 'id' => $report_id, + 'execute' => 1, + 'name' => $name, + 'notes' => $notes, + 'errors' => [ { duplicate_running_report_ids => \@duplicate_running_report_ids } ], + 'sql_params' => \@sql_params, + 'param_names' => \@param_names, + ); } else { my ( $sql, $header_types ) = $report->prep_report( \@param_names, \@sql_params ); $template->param( header_types => $header_types );