lib/CGI/OptimalQuery/PrinterFriendly.pm

filter: Statementstmt 100% 12 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 16 / 16 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/CGI/OptimalQuery/InteractiveQuery2Tools.pm ↑ Summary lib/CGI/OptimalQuery/ShowColumns.pm »
1 package CGI::OptimalQuery::PrinterFriendly;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶no warnings qw( uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'CGI::OptimalQuery::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 use POSIX qw( strftime );
8  
9 sub output {
10 my $o = shift;
11  
12 my $buf;
13  
14 my $fn = $o->{schema}->{title};
15 { my @t = localtime;
16 $fn .= '_'.($t[5] + 1900).($t[4] + 1).$t[3].'.html';
17 $fn =~ s/\s+/\_/g;
18 }
19  
20 my $title = ($o->{schema}->{title});
21 if ($$o{queryDescr}) {
22 $title .= " - $$o{queryDescr}";
23 }
24 my $v = $o->escape_html($o->get_filter());
25 if ($v) {
26 $title .= " - $v";
27 }
28 if ($o->get_hi_rec < $o->get_count) {
29 $title .= ' results: '.$o->commify($o->get_lo_rec)." - ".$o->commify($o->get_hi_rec);
30 }
31  
32 $buf .= $$o{q}->header(-type => 'text/html', -attachment => $fn);
33 $buf .= '<!DOCTYPE HTML>
34 <html>
35 <head>
36 <title>'.$o->escape_html($title).'</title>
37 <style>
38 body {
39 margin: 0;
40 background-white;
41 font-family: sans-serif;
42 font-size: 12px;
43 }
44 dl {
45 margin:0;
46 }
47 dt,dd {
48 float: left;
49 margin: 0;
50 }
51 dt {
52 clear:both;
53 width: 5em;
54 font-weight: bold;
55 }
56 table {
57 border-collapse: collapse;
58 }
59 td {
60 padding: 0 3px;
61 }
62 thead td {
63 font-weight: bold;
64 text-decoration: underline;
65 }
66 tbody td {
67 border-bottom: 1px solid #eee;
68 }
69 #OQdata {
70 clear: both;
71 }
72 </style>
73 </head>
74 <body>
75 <table id=OQdata>
76 <thead>
77 <tr>';
78  
79 my @userselcols = @{ $o->get_usersel_cols };
80 foreach my $i (0 .. $#userselcols) {
81 my $colAlias = $o->get_usersel_cols->[$i];
82 my $nice = $o->get_nice_name($colAlias) || $colAlias;
83 $buf .= "<td>".$o->escape_html($nice)."</td>";
84 }
85 $buf .= "
86 </tr>
87 </thead>
88 <tbody>";
89  
90 my $i = 0;
91  
92 while (my $r = $o->fetch()) {
93 $buf .= "<tr>";
94 foreach my $col (@userselcols) {
95 $buf .= "<td>".$o->get_val($col)."</td>";
96 }
97 $buf .= "</tr>\n";
98  
99 # flush
100 if (++$i == 10000) {
101 $$o{output_handler}->($buf);
102 $buf = '';
103 $i=0;
104 }
105 }
106 $o->finish();
107  
108 $$o{output_handler}->($buf);
109 $buf .= "
110 </tbody>
111 </table>
112 </body>
113 </html>";
114  
115 return undef;
116 }
117  
118 1;
« lib/CGI/OptimalQuery/InteractiveQuery2Tools.pm ↑ Summary lib/CGI/OptimalQuery/ShowColumns.pm »