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

(-)a/installer/data/mysql/atomicupdate/bug_27510_download_report_html_format.perl (+8 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    # you can use $dbh here like:
4
    $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('ReportUserCSS','',NULL,'','free')});
5
6
    # Always end with this (adjust the bug info)
7
    NewVersion( $DBversion, 27510, "Download the report in HTML format");
8
}
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-1 / +2 lines)
Lines 791-795 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
791
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
791
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
792
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
792
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
793
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
793
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
794
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
794
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
795
('ReportUserCSS','',NULL,'Add CSS to be included on the report in HTML format.','free')
795
;
796
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc (+1 lines)
Lines 117-122 Link Here
117
                    <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=csv&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">[% PROCESS 'delimiter_text.inc' %]</a></li>
117
                    <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=csv&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">[% PROCESS 'delimiter_text.inc' %]</a></li>
118
                    <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=tab&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li>
118
                    <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=tab&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li>
119
                    <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=ods&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li>
119
                    <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=ods&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li>
120
                    <li><a id="html" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=html&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Document HTML</a></li>
120
                    [% IF (results.json) %]
121
                    [% IF (results.json) %]
121
                        <li><a id="download-chart" href="#">Chart (.svg)</a></li>
122
                        <li><a id="download-chart" href="#">Chart (.svg)</a></li>
122
                    [% END %]
123
                    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref (-1 / +6 lines)
Lines 199-205 Staff interface: Link Here
199
                  1: Show
199
                  1: Show
200
                  0: "Don't show"
200
                  0: "Don't show"
201
            - a search field pulldown for 'Search the catalog' boxes.
201
            - a search field pulldown for 'Search the catalog' boxes.
202
    Authentication:
203
        -
202
        -
204
            - pref: staffShibOnly
203
            - pref: staffShibOnly
205
              choices:
204
              choices:
Lines 213-215 Staff interface: Link Here
213
                  "enabled": Enable
212
                  "enabled": Enable
214
                  "disabled": "Don't enable"
213
                  "disabled": "Don't enable"
215
            - two-factor authentication (2FA) for staff members.
214
            - two-factor authentication (2FA) for staff members.
215
        -
216
            - "Include the following CSS on the report in HTML format:"
217
            - pref: ReportUserCSS
218
              type: textarea
219
              syntax: css
220
              class: code
(-)a/reports/guided_reports.pl (-1 / +94 lines)
Lines 38-43 use Koha::Patron::Categories; Link Here
38
use Koha::SharedContent;
38
use Koha::SharedContent;
39
use Koha::Util::OpenDocument qw( generate_ods );
39
use Koha::Util::OpenDocument qw( generate_ods );
40
use C4::ClassSource qw( GetClassSources );
40
use C4::ClassSource qw( GetClassSources );
41
use HTML::Table;
42
use utf8;
41
43
42
=head1 NAME
44
=head1 NAME
43
45
Lines 958-963 elsif ($phase eq 'Export'){ Link Here
958
                $content .= $_ while <$ods_fh>;
960
                $content .= $_ while <$ods_fh>;
959
                unlink $ods_filepath;
961
                unlink $ods_filepath;
960
            }
962
            }
963
            elsif ( $format eq 'html' ) {
964
                $type = 'text/html';
965
                $content = _to_html($sth, $input);
966
            }
961
        }
967
        }
962
        print $input->header(
968
        print $input->header(
963
            -type => $type,
969
            -type => $type,
Lines 1094-1096 sub create_non_existing_group_and_subgroup { Link Here
1094
    }
1100
    }
1095
}
1101
}
1096
1102
1097
- 
1103
# pass $sth and sql_params, get back an executable query
1104
sub get_prepped_report {
1105
    my ($sql, $param_names, $sql_params ) = @_;
1106
1107
    # First we split out the placeholders
1108
    # This part of the code supports using [[ table.field | alias ]] in the
1109
    # query and replaces it by table.field AS alias. Not sure why we would
1110
    # need it if we can type the latter (which is simpler)?
1111
    my @split = split /\[\[|\]\]/,$sql;
1112
    my $headers;
1113
    for(my $i=0;$i<$#split/2;$i++){ #The placeholders are always the odd elements of the array
1114
        my ($type,$name) = split /\|/,$split[$i*2+1]; # We split them on '|'
1115
        $headers->{$name} = $type; # Store as a lookup for the template
1116
        $headers->{$name} =~ s/^\w*\.//; # strip the table name just as in $sth->{NAME} array
1117
        $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; #Quote any special characters so we can replace the placeholders
1118
        $name = C4::Context->dbh->quote($name);
1119
        $sql =~ s/\[\[$split[$i*2+1]\]\]/$type AS $name/; # Remove placeholders from SQL
1120
    }
1121
1122
    my %lookup;
1123
    @lookup{@$param_names} = @$sql_params;
1124
    @split = split /<<|>>/,$sql;
1125
    my @tmpl_parameters;
1126
    for(my $i=0;$i<$#split/2;$i++) {
1127
        my $quoted = @$param_names ? $lookup{ $split[$i*2+1] } : @$sql_params[$i];
1128
        # if there are special regexp chars, we must \ them
1129
        $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
1130
        if ($split[$i*2+1] =~ /\|\s*date\s*$/) {
1131
            $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted;
1132
        }
1133
        $quoted = C4::Context->dbh->quote($quoted);
1134
        $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
1135
    }
1136
    return $sql,$headers;
1137
}
1138
1139
sub _to_html {
1140
    my ($sth, $input) = @_;
1141
    my $header_type = "application/x-download";
1142
    my $rep_name = Encode::encode_utf8($input->param('reportname'));
1143
    my $file = $rep_name . ".html";
1144
    my $html_start =
1145
        "<!DOCTYPE html>
1146
        <html>
1147
        <head>
1148
        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
1149
        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1150
        <title>$rep_name - Koha</title>";
1151
    my $html_end =
1152
        "\n</body>
1153
        \n</html>";
1154
    my $h1 = "\n<h1>" . $rep_name . "</h1>";
1155
    my @head = header_cell_values($sth);
1156
    my $con = join(" ", @head);
1157
    my $cols = scalar @head;
1158
1159
    my $css = C4::Context->preference('ReportUserCSS');
1160
    if ($css eq ''){
1161
        $css =
1162
            "\ntable, th, td {
1163
                border: 1px solid black;
1164
            }
1165
            table {
1166
                border-collapse: collapse;
1167
            }";
1168
    }
1169
    my $content = $html_start;
1170
    $content .=
1171
        "\n<style>"  .
1172
            $css     .
1173
        "\n</style>" .
1174
        "\n</head>
1175
         \n<body>";
1176
    my $table = HTML::Table->new(
1177
        -cols => $cols,
1178
    );
1179
    $table->addSectionRow('thead', 0, @head);
1180
    $table->setSectionRCellsHead('thead', 0, 1);
1181
    my ($tmp_str, @tmp_arr);
1182
    while (my $row = $sth->fetchrow_arrayref()) {
1183
        $tmp_str = join ('*replace*', @$row);
1184
        $tmp_str = Encode::encode_utf8($tmp_str);
1185
        @tmp_arr = split (/\*replace\*/, $tmp_str);
1186
        $table->addSectionRow( 'tbody', 0, @tmp_arr);
1187
    }
1188
    $content .= $h1 . $table . $html_end;
1189
    return $content;
1190
}

Return to bug 27510