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 |
} |