From 0a405d25f11d4d58e7007007b1177f1f71cc91da Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 23 Dec 2021 17:50:33 -0300 Subject: [PATCH] Bug 18320: Remove calls to CGI->param from the templates in patron cards This patch removes calls to CGI->param from within the templates (patroncards-errors.inc) and passes error_* variables with the same codes from the controllers to the template instead. This way we can be sure CGI->param is not called in list context. To test, try those pages and see they don't show warnings anymore. Verify that error situations still show the error messages. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- .../prog/en/includes/patroncards-errors.inc | 16 ++++++++-------- patroncards/edit-batch.pl | 7 +++++++ patroncards/image-manage.pl | 7 +++++++ patroncards/manage.pl | 7 +++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patroncards-errors.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patroncards-errors.inc index 3c987d705e5..768c83bbd4f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patroncards-errors.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patroncards-errors.inc @@ -5,17 +5,17 @@ [% BLOCK b_layout %]Layout: [% END %] [% BLOCK b_template %]Template: [% END %] -[% IF ( error || CGI.param('pdferr') ) %] +[% IF ( error || error_pdferr ) %]

WARNING: - [% IF CGI.param('pdferr') %]Error while creating PDF file. - [% IF CGI.param('errnocards') %]No cards created (empty batch or list?) [% END %] - [% IF CGI.param('errba') %][% INCLUDE b_batch %][%- CGI.param('errba') | html -%][% END %] - [% IF CGI.param('errpl') %][% INCLUDE b_patronlist %][%- CGI.param('errpl') | html -%]][% END %] - [% IF CGI.param('errpt') %][% INCLUDE b_patronnumber %][%- CGI.param('errpt') | html -%][% END %] - [% IF CGI.param('errlo') %][% INCLUDE b_layout %][%- CGI.param('errlo') | html -%][% END %] - [% IF CGI.param('errtpl') %][% INCLUDE b_template %][%- CGI.param('errtpl') | html -%][% END %] + [% IF error_pdferr %]Error while creating PDF file. + [% IF error_errnocards %]No cards created (empty batch or list?) [% END %] + [% IF error_errba %][% INCLUDE b_batch %][%- error_errba | html -%][% END %] + [% IF error_errpl %][% INCLUDE b_patronlist %][%- error_errpl | html -%]][% END %] + [% IF error_errpt %][% INCLUDE b_patronnumber %][%- error_errpt | html -%][% END %] + [% IF error_errlo %][% INCLUDE b_layout %][%- error_errlo | html -%][% END %] + [% IF error_errtpl %][% INCLUDE b_template %][%- error_errtpl | html -%][% END %] [% INCLUDE asksysadmin %] [% END %] diff --git a/patroncards/edit-batch.pl b/patroncards/edit-batch.pl index d90d37cf266..dbb3d9cc876 100755 --- a/patroncards/edit-batch.pl +++ b/patroncards/edit-batch.pl @@ -61,6 +61,13 @@ my $errstr = $cgi->param('error') || ''; my $bor_num_list = $cgi->param('bor_num_list') || undef; my $branch_code = C4::Context->userenv->{'branch'}; +my @errors = ( 'pdferr', 'errnocards', 'errba', 'errpl', 'errpt', 'errlo', 'errtpl', ); +foreach my $param (@errors) { + my $error = $cgi->param($param) ? 1 : 0; + $template->param( 'error_' . $param => $error ) + if $error; +} + if ($op eq 'remove') { $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id); foreach my $label_id (@label_ids) { diff --git a/patroncards/image-manage.pl b/patroncards/image-manage.pl index 3f3c288136c..8c2d72456a4 100755 --- a/patroncards/image-manage.pl +++ b/patroncards/image-manage.pl @@ -26,6 +26,13 @@ my $upload_file = $cgi->upload('uploadfile') || ''; my $op = $cgi->param('op') || 'none'; my @image_ids = $cgi->multi_param('image_id'); +my @errors = ( 'pdferr', 'errnocards', 'errba', 'errpl', 'errpt', 'errlo', 'errtpl', ); +foreach my $param (@errors) { + my $error = $cgi->param($param) ? 1 : 0; + $template->param( 'error_' . $param => $error ) + if $error; +} + my $source_file = "$file_name"; # otherwise we end up with what amounts to a pointer to a filehandle rather than a user-friendly filename my $display_columns = { image => [ #{db column => {label => 'col label', is link? }}, diff --git a/patroncards/manage.pl b/patroncards/manage.pl index f4d21c644d7..4366955d87d 100755 --- a/patroncards/manage.pl +++ b/patroncards/manage.pl @@ -45,6 +45,13 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); +my @errors = ( 'pdferr', 'errnocards', 'errba', 'errpl', 'errpt', 'errlo', 'errtpl', ); +foreach my $param (@errors) { + my $error = $cgi->param($param) ? 1 : 0; + $template->param( 'error_' . $param => $error ) + if $error; +} + my $op = $cgi->param('op') || 'none'; my $card_element = $cgi->param('card_element') || 'template'; # default to template management my $element_id = $cgi->param('element_id') || 0; # there should never be an element with a id of 0 so this is a safe default -- 2.25.1