Bugzilla – Attachment 15560 Details for
Bug 9659
Undefined authorised value category yields empty dropdown menu on SQL reports
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9659 - Better handling of non-existent authorised value categories used in SQL reports
Bug-9659---Better-handling-of-non-existent-authori.patch (text/plain), 9.19 KB, created by
Tomás Cohen Arazi (tcohen)
on 2013-02-19 19:37:28 UTC
(
hide
)
Description:
Bug 9659 - Better handling of non-existent authorised value categories used in SQL reports
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2013-02-19 19:37:28 UTC
Size:
9.19 KB
patch
obsolete
>From 99a9ac2e270c367772b4374935e60179e78f202b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@gmail.com> >Date: Tue, 19 Feb 2013 15:58:53 -0300 >Subject: [PATCH] Bug 9659 - Better handling of non-existent authorised value > categories used in SQL reports >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >A user might create a SQL report that relies on non-existent authorised value categories. >Because of a typo, or just because they copy&pasted the report from the Wiki. > >I added comments on the code, refactored some really tiny bits, and fixed an annoying warning > of uninitialised variable also. > >Sponsored-by: Universidad Nacional de Córdoba >--- > .../en/modules/reports/guided_reports_start.tt | 48 +++++++++++------ > reports/guided_reports.pl | 55 ++++++++++++++------ > 2 files changed, 71 insertions(+), 32 deletions(-) > >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 7f109d9..e968eef 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 >@@ -551,26 +551,42 @@ canned reports and writing custom SQL reports.</p> > > [% IF ( enter_params ) %] > <form action='/cgi-bin/koha/reports/guided_reports.pl'> >- <input type='hidden' name='phase' value='Run this report' /> > <input type='hidden' name='reports' value="[% reports %]" /> >- <h1>Enter parameters for report [% name %]:</h1> >- [% IF ( notes ) %]<p>[% notes %]</p>[% END %] >- <fieldset class="rows"> >+ [% IF ( auth_val_error ) %] >+ <input type='hidden' name='phase' value='Edit SQL' /> >+ <h1>Errors found when processing parameters for report: [% name %]</h1> >+ <fieldset class="rows"> >+ <div class="dialog alert"> >+ [% FOREACH auth_val_error IN auth_val_errors %] >+ <p> >+ <strong>[% auth_val_error.entry %]:</strong> The authorised value category (<strong>[% auth_val_error.auth_val %]</strong>) >+ you selected does not exist. >+ </p> >+ [% END %] >+ </div> >+ </fieldset> >+ <fieldset class="action"><input type="submit" value="Edit SQL" /></fieldset> >+ [% ELSE %] >+ <input type='hidden' name='phase' value='Run this report' /> >+ <h1>Enter parameters for report [% name %]:</h1> >+ [% IF ( notes ) %]<p>[% notes %]</p>[% END %] >+ <fieldset class="rows"> > <ol> >- [% FOREACH sql_param IN sql_params %] >- [% IF sql_param.input == 'date' %] >- <li> >- <label for="date_[% sql_param_entry %][% loop.count %]">[% sql_param.entry %]:</label> <input id="date_[% sql_param_entry %][% loop.count %]" type="text" value="" size="10" name="sql_params" class="datepicker" /> >- </li> >- [% ELSIF ( sql_param.input == 'text' ) %] >- <li><label for="sql_params[% loop.count %]">[% sql_param.entry %]: </label><input id="sql_params[% loop.count %]" type="text" name="sql_params" /></li> >- [% ELSE %] >- <li><label for="sql_params_[% sql_param.labelid %]">[% sql_param.entry %]:</label> [% sql_param.input %]</li> >+ [% FOREACH sql_param IN sql_params %] >+ [% IF sql_param.input == 'date' %] >+ <li> >+ <label for="date_[% sql_param_entry %][% loop.count %]">[% sql_param.entry %]:</label> <input id="date_[% sql_param_entry %][% loop.count %]" type="text" value="" size="10" name="sql_params" class="datepicker" /> >+ </li> >+ [% ELSIF ( sql_param.input == 'text' ) %] >+ <li><label for="sql_params[% loop.count %]">[% sql_param.entry %]: </label><input id="sql_params[% loop.count %]" type="text" name="sql_params" /></li> >+ [% ELSE %] >+ <li><label for="sql_params_[% sql_param.labelid %]">[% sql_param.entry %]:</label> [% sql_param.input %]</li> >+ [% END %] > [% END %] >- [% END %] > </ol> >- </fieldset> >- <fieldset class="action"><input type="submit" value="Run the report" /></fieldset> >+ </fieldset> >+ <fieldset class="action"><input type="submit" value="Run the report" /></fieldset> >+ [% END %] > </form> > [% END %] > >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index 23d85a9..ddf7fd8 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -29,6 +29,7 @@ use C4::Output; > use C4::Dates qw/format_date/; > use C4::Debug; > use C4::Branch; # XXX subfield_is_koha_internal_p >+use C4::Koha qw/GetAuthorisedValueCategories/; > > =head1 NAME > >@@ -549,14 +550,19 @@ elsif ($phase eq 'Run this report'){ > # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill > my @split = split /<<|>>/,$sql; > my @tmpl_parameters; >+ my @authval_errors; > for(my $i=0;$i<($#split/2);$i++) { > my ($text,$authorised_value) = split /\|/,$split[$i*2+1]; > my $input; > my $labelid; >- if ($authorised_value eq "date") { >- $input = 'date'; >- } >- elsif ($authorised_value) { >+ if ( not defined $authorised_value ) { >+ # no authorised value input, provide a text box >+ $input = "text"; >+ } elsif ( $authorised_value eq "date" ) { >+ # require a date, provide a date picker >+ $input = 'date'; >+ } else { >+ # defined $authorised_value, and not 'date' > my $dbh=C4::Context->dbh; > my @authorised_values; > my %authorised_lib; >@@ -596,16 +602,33 @@ elsif ($phase eq 'Run this report'){ > > #---- "true" authorised value > } >- else { >- my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib"); >- >- $authorised_values_sth->execute( $authorised_value); >- >- while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { >- push @authorised_values, $value; >- $authorised_lib{$value} = $lib; >- # For item location, we show the code and the libelle >- $authorised_lib{$value} = $lib; >+ else { >+ # Build a hash of authorised value categories >+ my %authorised_value_categories = map { $_ => 1 } (GetAuthorisedValueCategories()); >+ if ( exists $authorised_value_categories{$authorised_value}) { >+ my $query = ' >+ SELECT authorised_value,lib >+ FROM authorised_values >+ WHERE category=? >+ ORDER BY lib >+ '; >+ my $authorised_values_sth = $dbh->prepare($query); >+ $authorised_values_sth->execute( $authorised_value); >+ >+ while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { >+ push @authorised_values, $value; >+ $authorised_lib{$value} = $lib; >+ # For item location, we show the code and the libelle >+ $authorised_lib{$value} = $lib; >+ } >+ } else { >+ # not exists $authorised_value_categories{$authorised_value}) >+ push @authval_errors, {'entry' => $text, >+ 'auth_val' => $authorised_value }; >+ # tell the template there's an error >+ $template->param( auth_val_error => 1 ); >+ # skip scrolling list creation and params push >+ next; > } > } > $labelid = $text; >@@ -621,14 +644,14 @@ elsif ($phase eq 'Run this report'){ > -multiple => 0, > -tabindex => 1, > ); >- } else { >- $input = "text"; > } >+ > push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid }; > } > $template->param('sql' => $sql, > 'name' => $name, > 'sql_params' => \@tmpl_parameters, >+ 'auth_val_errors' => \@authval_errors, > 'enter_params' => 1, > 'reports' => $report_id, > ); >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9659
:
15560
|
15596
|
15603
|
15618
|
15621
|
15626
|
17351
|
17652
|
17660
|
17661