Bugzilla – Attachment 146135 Details for
Bug 27510
Download the report in HTML format
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27510: Download the report in HTML format
Bug-27510-Download-the-report-in-HTML-format.patch (text/plain), 9.50 KB, created by
Magnus Enger
on 2023-02-03 14:01:15 UTC
(
hide
)
Description:
Bug 27510: Download the report in HTML format
Filename:
MIME Type:
Creator:
Magnus Enger
Created:
2023-02-03 14:01:15 UTC
Size:
9.50 KB
patch
obsolete
>From fb15c03790031edb4c198b8cb64754a21a9db247 Mon Sep 17 00:00:00 2001 >From: Ivan Dziuba <ivan.dziuba@inlibro.com> >Date: Thu, 21 Jan 2021 20:23:27 -0500 >Subject: [PATCH] Bug 27510: Download the report in HTML format > >TEST PLAN: >1. Apply this patch >2. Update database ./updatedatabase.pl >Now we have new preference 'ReportUserCSS' where we can add style for our HTML report. >3. Go on the page - <intranet>/reports/guided_reports.pl >4. Download -> Document HTML > >Signed-off-by: Magnus Enger <magnus@libriotech.no> >I have fixed some conflicts and put in the test plan that was on >Bugzilla. Feature works as advertised. HTML file can be downloaded >and is a full HTML document. Formatting can be done with the syspref. >Links generated in SQL carry over to the document (but links need to >be absolute to work, of course.) >--- > ...bug_27510_download_report_html_format.perl | 8 ++ > installer/data/mysql/mandatory/sysprefs.sql | 3 +- > .../prog/en/includes/reports-toolbar.inc | 1 + > .../admin/preferences/staff_interface.pref | 7 +- > reports/guided_reports.pl | 94 +++++++++++++++++++ > 5 files changed, 111 insertions(+), 2 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_27510_download_report_html_format.perl > >diff --git a/installer/data/mysql/atomicupdate/bug_27510_download_report_html_format.perl b/installer/data/mysql/atomicupdate/bug_27510_download_report_html_format.perl >new file mode 100644 >index 0000000000..643eebe12f >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_27510_download_report_html_format.perl >@@ -0,0 +1,8 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ # you can use $dbh here like: >+ $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('ReportUserCSS','',NULL,'','free')}); >+ >+ # Always end with this (adjust the bug info) >+ NewVersion( $DBversion, 27510, "Download the report in HTML format"); >+} >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index beebd27a6f..b8a9573c48 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -791,5 +791,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'), > ('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'), > ('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'), >-('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo') >+('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'), >+('ReportUserCSS','',NULL,'Add CSS to be included on the report in HTML format.','free') > ; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >index 5291fda6f8..dbe6b4a22a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >@@ -117,6 +117,7 @@ > <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=csv&report_id=[% id | html %]&reportname=[% name |uri %][% PROCESS params %]">[% PROCESS 'delimiter_text.inc' %]</a></li> > <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=tab&report_id=[% id | html %]&reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li> > <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=ods&report_id=[% id | html %]&reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li> >+ <li><a id="html" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=html&report_id=[% id | html %]&reportname=[% name |uri %][% PROCESS params %]">Document HTML</a></li> > [% IF (results.json) %] > <li><a id="download-chart" href="#">Chart (.svg)</a></li> > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref >index 0e5bb27f4c..2f3795f543 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref >@@ -199,7 +199,6 @@ Staff interface: > 1: Show > 0: "Don't show" > - a search field pulldown for 'Search the catalog' boxes. >- Authentication: > - > - pref: staffShibOnly > choices: >@@ -213,3 +212,9 @@ Staff interface: > "enabled": Enable > "disabled": "Don't enable" > - two-factor authentication (2FA) for staff members. >+ - >+ - "Include the following CSS on the report in HTML format:" >+ - pref: ReportUserCSS >+ type: textarea >+ syntax: css >+ class: code >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index ab79b0f463..419f9564f4 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -38,6 +38,8 @@ use Koha::Patron::Categories; > use Koha::SharedContent; > use Koha::Util::OpenDocument qw( generate_ods ); > use C4::ClassSource qw( GetClassSources ); >+use HTML::Table; >+use utf8; > > =head1 NAME > >@@ -958,6 +960,10 @@ elsif ($phase eq 'Export'){ > $content .= $_ while <$ods_fh>; > unlink $ods_filepath; > } >+ elsif ( $format eq 'html' ) { >+ $type = 'text/html'; >+ $content = _to_html($sth, $input); >+ } > } > print $input->header( > -type => $type, >@@ -1094,3 +1100,91 @@ sub create_non_existing_group_and_subgroup { > } > } > >+# pass $sth and sql_params, get back an executable query >+sub get_prepped_report { >+ my ($sql, $param_names, $sql_params ) = @_; >+ >+ # First we split out the placeholders >+ # This part of the code supports using [[ table.field | alias ]] in the >+ # query and replaces it by table.field AS alias. Not sure why we would >+ # need it if we can type the latter (which is simpler)? >+ my @split = split /\[\[|\]\]/,$sql; >+ my $headers; >+ for(my $i=0;$i<$#split/2;$i++){ #The placeholders are always the odd elements of the array >+ my ($type,$name) = split /\|/,$split[$i*2+1]; # We split them on '|' >+ $headers->{$name} = $type; # Store as a lookup for the template >+ $headers->{$name} =~ s/^\w*\.//; # strip the table name just as in $sth->{NAME} array >+ $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; #Quote any special characters so we can replace the placeholders >+ $name = C4::Context->dbh->quote($name); >+ $sql =~ s/\[\[$split[$i*2+1]\]\]/$type AS $name/; # Remove placeholders from SQL >+ } >+ >+ my %lookup; >+ @lookup{@$param_names} = @$sql_params; >+ @split = split /<<|>>/,$sql; >+ my @tmpl_parameters; >+ for(my $i=0;$i<$#split/2;$i++) { >+ my $quoted = @$param_names ? $lookup{ $split[$i*2+1] } : @$sql_params[$i]; >+ # if there are special regexp chars, we must \ them >+ $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; >+ if ($split[$i*2+1] =~ /\|\s*date\s*$/) { >+ $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted; >+ } >+ $quoted = C4::Context->dbh->quote($quoted); >+ $sql =~ s/<<$split[$i*2+1]>>/$quoted/; >+ } >+ return $sql,$headers; >+} >+ >+sub _to_html { >+ my ($sth, $input) = @_; >+ my $header_type = "application/x-download"; >+ my $rep_name = Encode::encode_utf8($input->param('reportname')); >+ my $file = $rep_name . ".html"; >+ my $html_start = >+ "<!DOCTYPE html> >+ <html> >+ <head> >+ <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> >+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> >+ <title>$rep_name - Koha</title>"; >+ my $html_end = >+ "\n</body> >+ \n</html>"; >+ my $h1 = "\n<h1>" . $rep_name . "</h1>"; >+ my @head = header_cell_values($sth); >+ my $con = join(" ", @head); >+ my $cols = scalar @head; >+ >+ my $css = C4::Context->preference('ReportUserCSS'); >+ if ($css eq ''){ >+ $css = >+ "\ntable, th, td { >+ border: 1px solid black; >+ } >+ table { >+ border-collapse: collapse; >+ }"; >+ } >+ my $content = $html_start; >+ $content .= >+ "\n<style>" . >+ $css . >+ "\n</style>" . >+ "\n</head> >+ \n<body>"; >+ my $table = HTML::Table->new( >+ -cols => $cols, >+ ); >+ $table->addSectionRow('thead', 0, @head); >+ $table->setSectionRCellsHead('thead', 0, 1); >+ my ($tmp_str, @tmp_arr); >+ while (my $row = $sth->fetchrow_arrayref()) { >+ $tmp_str = join ('*replace*', @$row); >+ $tmp_str = Encode::encode_utf8($tmp_str); >+ @tmp_arr = split (/\*replace\*/, $tmp_str); >+ $table->addSectionRow( 'tbody', 0, @tmp_arr); >+ } >+ $content .= $h1 . $table . $html_end; >+ return $content; >+} >-- >2.34.1
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 27510
:
115696
|
115702
|
116079
|
116091
|
116849
|
116850
| 146135 |
146142