SAL/WebDDR.pm untested

filter: Statementstmt 0.0% 0 / 380 Branchbran 0.0% 0 / 162 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 622 CC 81 SCAR 57.2
CC
81
Cov
0%
build_record_html
650.0
build_field_html
462.0
build_data_table
272.0
CRAP 305.8
1 package SAL::WebDDR;
2  
3 # This module is licensed under the FDL (Free Document License)
4 # The complete license text can be found at http://www.gnu.org/copyleft/fdl.html
5 # Contains excerpts from various man pages, tutorials and books on perl
6 # FUNCTIONAL, BUT NOT TERRIBLY EASY TO FOLLOW. LOTS OF THINGS TO FIX AND CLEAN OUT.
7  
8 use strict;
9 use DBI;
10 use Carp;
11 use Data::Dumper;
12  
13 BEGIN {
14 use Exporter ();
15 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
16 $VERSION = '3.03';
17 @ISA = qw(Exporter);
18 @EXPORT = qw();
19 %EXPORT_TAGS = ();
20 @EXPORT_OK = qw();
21 }
22 our @EXPORT_OK;
23  
24 END { }
25  
26 =pod
27  
28 =head1 Name
29  
30 SAL::WebDDR - Web-based reporting abstraction for SAL::DBI database objects
31  
32 =head1 Synopsis
33  
34 use CGI;
35 use CGI::Carp qw(fatalsToBrowser);
36 use SAL::DBI;
37 use SAL::WebDDR;
38  
39 my $dbo_factory = new SAL::DBI;
40 my $dbo_data = $dbo_factory->spawn_odbc('REPORTING_DSN',$report_user, $report_pass);
41 $dbo_data->execute("sp_FinancialResults 'Q3'");
42  
43 my $report = new SAL::WebDDR;
44 $report->{datasource} = $dbo_data;
45 $report->{dfm_column} = '0'; # Data Formatting Markup is in column 0
46 $report->{skip_fields} = 's 0 1 12 14 15 16 s'; # Do not display columns specified between the s's
47  
48 print "Content-type: text/html\n\n";
49 my $canvas = $report->build_report();
50  
51 print qq[
52 <html>
53 <head>
54 <title>SampleCorp: Financial Results for Q3 2005</title>
55 </head>
56 <body>
57 $canvas
58 </body>
59 </html>
60 ];
61  
62 =head1 Eponymous Hash
63  
64 This section describes some useful items in the SAL::WebDDR eponymous hash. Arrow syntax is used here for readability,
65 but is not strictly required.
66  
67 Note: Replace $SAL::WebDDR with the name of your database object... eg. $report->{datasource} = $dbo_data
68  
69 =over 1
70  
71 =item Datasource
72  
73 $SAL::WebDDR->{datasource} is a reference to a SAL::DBI object
74  
75 =item Formatting Control
76  
77 $SAL::WebDDR->{dfm_column} tells SAL::WebDDR where to look for DFM (Data Formatting Markup) tags
78 $SAL::WebDDR->{skip_fields} specifies columns you want to skip in the reports output.
79  
80 =back
81  
82 =cut
83  
84 our %WebDDR = (
85 ######################################
86 'datasource' => '',
87 ######################################
88 'data' => {
89 'th' => '',
90 'td' => '',
91 'table' => '',
92 },
93 ######################################
94 'window' => {
95 'border' => '',
96 'titlebar' => '',
97 'statusbar' => '',
98 'canvas' => '',
99 'decoration' => '',
100 },
101 ######################################
102 'misc' => {
103 'ucfirst' => '',
104 'highlight' => '',
105 'negatives' => '',
106  
107 'dfm_column' => '',
108 'num_skip_fields' => '',
109 'skip_fields' => (),
110 'pf_flag' => '',
111 'page_table_html' => '',
112 'global_number_fields' => '',
113 'global_number_records' => '',
114 'first_page_break' => '',
115 'default_font_style' => '',
116  
117 'block_commify' => '',
118 },
119 ######################################
120 );
121  
122 # Setup accessors via closure (from perltooc manpage)
123 sub _classobj {
124 my $obclass = shift || __PACKAGE__;
125 my $class = ref($obclass) || $obclass;
126 no strict "refs";
127 return \%$class;
128 }
129  
130 for my $datum (keys %{ _classobj() }) {
131 no strict "refs";
132 *$datum = sub {
133 my $self = shift->_classobj();
134 $self->{$datum} = shift if @_;
135 return $self->{$datum};
136 }
137 }
138  
139 ##########################################################################################################################
140 # Constructors (Public)
141  
142 =pod
143  
144 =head1 Constructors
145  
146 =head2 new()
147  
148 Builds a data-driven reporting object.
149  
150 =cut
151  
152 sub new {
153 my $obclass = shift || __PACKAGE__;
154 my $class = ref($obclass) || $obclass;
155 my $self = {};
156  
157 bless($self, $class);
158  
159 $self->{data}{table} = 'background-color: #fff;';
160 $self->{data}{th} = 'background-color: #ddd; border: 2px outset #fff; text-align: center; font-size: 12px;';
161 $self->{data}{td} = 'background-color: #fff; border-right: 1px solid #aaa; border-bottom: 1px solid #aaa; font-size: 10px;';
162  
163 $self->{window}{border} = '';
164 $self->{window}{titlebar} = 'background-color: #337; border: 2px outset #fff; background-image: url(/images/window_top.png); background-repeat: no-repeat;';
165 $self->{window}{canvas} = 'background-color: #fff; border: 2px inset #fff;';
166 $self->{window}{statusbar} = 'background-color: #eee; border: 1px solid #aaa;';
167 $self->{window}{decoration} = 'background-color: #337; background-image: url(/images/window_side.png); background-repeat: repeat-x;';
168  
169 $self->{misc}{highlight} = 'background-color: #aa0;';
170 $self->{misc}{negatives} = '#FF0000';
171  
172 $self->{dfm_column} = '0',
173 $self->{num_skip_fields} = '0',
174 $self->{skip_fields} = qw(),
175 $self->{pf_flag} = '0',
176 $self->{page_table_html} = '<table cellspacing=0 width=100% border=0>',
177 $self->{global_number_fields} = '',
178 $self->{global_number_records} = '',
179 $self->{first_page_break} = '1',
180 $self->{default_font_style} = 'font-size: 10px;',
181  
182 # Update formatting at the field level
183 my $w = $self->{datasource}->{internal}{width};
184 my $h = $self->{datasource}->{internal}{height};
185  
186 for (my $field = 0; $field < $w; $field++) {
187 $self->{datasource}->{fields}[$field]{'precision'} = '2';
188 $self->{datasource}->{fields}[$field]{'commify'} = '1';
189 }
190  
191 return $self;
192 }
193  
194 ##########################################################################################################################
195 # Destructor (Public)
196 sub destruct {
197 my $self = shift;
198  
199 }
200  
201 ##########################################################################################################################
202 # Public Methods
203  
204 =pod
205  
206 =head1 Methods
207  
208 =head2 $canvas = build_window($titlebar, $canvas, $statusbar, $width)
209  
210 Builds a window-like html table using 3 scalars: $titelbar, $canvas, $statusbar. $width is optional.
211  
212 =cut
213  
214 sub build_window {
215 my ($self, $titlebar, $canvas, $statusbar, $width) = @_;
216 if (! $width) { $width = '100%'; }
217  
218 my $content = qq[
219 <center>
220 <table width=$width border=0 cellspacing=0 cellpadding=2 style="border: 3px outset #fff;">
221 <td width=32 style="$self->{window}{decoration}"> </td>
222 <td>
223 <table width=100% border=0 cellpadding=5 cellspacing=0 style="$self->{window}{border}">
224 <tr>
225 <td style="$self->{window}{titlebar}">$titlebar</td>
226 </tr>
227 <tr>
228 <td style="$self->{window}{canvas}">$canvas</td>
229 </tr>
230 <tr>
231 <td style="$self->{window}{statusbar}">$statusbar</td>
232 </tr>
233 </table>
234 </td>
235 </tr>
236 </table>
237 </center>
238 ];
239  
240 return $content;
241 }
242  
243 =pod
244  
245 =head2 $canvas = build_scroll_window($titlebar, $canvas, $statusbar, $width)
246  
247 Same as build_window() but uses an iframe for the main window content ($canvas). JScript is used to copy the contents
248 of $canvas into the iframe.
249  
250 =cut
251  
252 sub build_scroll_window {
253 my ($self, $titlebar, $canvas, $statusbar, $width) = @_;
254 if (! $width) { $width = '100%'; }
255  
256 my @scrolling_content = split(/\n/, $canvas);
257  
258 my $content = qq[
259 <center>
260 <table width=$width border=0 cellspacing=0 cellpadding=2 style="border: 3px outset #fff;">
261 <td width=32 style="$self->{window}{decoration}"> </td>
262 <td>
263 <table width=100% border=0 cellpadding=5 cellspacing=0 style="$self->{window}{border}">
264 <tr>
265 <td style="$self->{window}{titlebar}">$titlebar</td>
266 </tr>
267 <tr>
268 <td><iframe width=100% height=350 frameborder=1 marginwidth=2 marginheight=2 name="canvas">$canvas</iframe></td>
269 </tr>
270 <tr>
271 <td style="$self->{window}{statusbar}">$statusbar</td>
272 </tr>
273 </table>
274 </td>
275 </tr>
276 </table>
277 </center>
278 <!-- Copy canvas content into iframe -->
279 <script language="JavaScript">
280 <!--
281 document.frames[0].document.open();
282 document.frames[0].document.write('<html>');
283 document.frames[0].document.write('<head>');
284 document.frames[0].document.write('<title>Query Results</title>');
285 document.frames[0].document.write('</head>');
286 document.frames[0].document.write('<body>');
287 ];
288  
289 foreach my $line (@scrolling_content) {
290 $content .= "document.frames[0].document.write('$line');\n";
291 }
292  
293 $content .= qq[
294 document.frames[0].document.write('</body>');
295 document.frames[0].document.write('</html>');
296 document.frames[0].document.close();
297 //--></script>
298 ];
299  
300 return $content;
301 }
302  
303 =pod
304  
305 =head2 $canvas = build_iframe_window($titlebar, $url, $statusbar, $width)
306  
307 Same as build_scroll_window() but the embedded iframe retrieves it's content from $url.
308  
309 =cut
310  
311 sub build_iframe_window {
312 my ($self, $titlebar, $url, $statusbar, $width) = @_;
313 if (! $width) { $width = '100%'; }
314  
315 my $content = qq[
316 <center>
317 <table width=$width border=0 cellspacing=0 cellpadding=2 style="border: 3px outset #fff;">
318 <td width=32 style="$self->{window}{decoration}"> </td>
319 <td>
320 <table width=100% border=0 cellpadding=5 cellspacing=0 style="$self->{window}{border}">
321 <tr>
322 <td style="$self->{window}{titlebar}">$titlebar</td>
323 </tr>
324 <tr>
325 <td><iframe width=100% height=350 frameborder=1 marginwidth=2 marginheight=2 src="$url" name="canvas"><a href="$url">$url</a></iframe></td>
326 </tr>
327 <tr>
328 <td style="$self->{window}{statusbar}">$statusbar</td>
329 </tr>
330 </table>
331 </td>
332 </tr>
333 </table>
334 </center>
335 ];
336  
337 return $content;
338 }
339  
340 =pod
341  
342 =head2 $canvas = build_data_table($datasource, $commify, $highlight_negatives, $width)
343  
344 Build's a simple spreadsheet-like table using $datasource (a SAL::DBI object).
345  
346 B<NOTE:> This method B<does not> use it's internal datasource connection. (~fixme)
347  
348 If you want your numbers with commas, set $commify to a non-zero value.
349  
350 If you'd like negative numbers highlighted, set $highlight_negatives to a non-zero value.
351  
352 $width is optional, defaulting to 100%
353  
354 =cut
355  
356 sub build_data_table {
357 my ($self, $dbo, $commify, $highlight_negatives, $width) = @_;
358  
359 if (! $width) { $width = '100%'; }
360  
361 my $w = $dbo->{internal}{width};
362 my $h = $dbo->{internal}{height};
363  
364 my $content = qq[<table border=0 width=$width cellpadding=5 cellspacing=0 style="$self->{data}{table}"><tr>];
365  
366 for (my $field = 0; $field <= $w; $field++) {
367  
368 my $field_name = $dbo->{fields}->[$field]->{name};
369  
370 # If the gui's misc setting for ucfirst is set, make sure all headers start with an uppercase letter
371 if ($self->{misc}{ucfirst}) { $field_name = ucfirst($field_name); }
372  
373 # If the field is defined as being visible...
374 if ($dbo->{fields}->[$field]->{visible}) {
375  
376 # And if the field's header is defined as being visible
377 if ($dbo->{fields}->[$field]->{header}) {
378 # Then display the header
379 $content .= qq[<td style="$self->{data}{th}">$field_name</td>\n];
380 } else {
381 # Otherwise, add a blank cell
382 $content .= qq[<td> </td>\n];
383 }
384 }
385 }
386  
387 $content .= qq[</tr>];
388  
389 for (my $record = 0; $record < $h; $record++) {
390 $content .= qq[<tr>];
391 for (my $field = 0; $field <= $w; $field++) {
392  
393 # Skip this field if it is defined as not being visible
394 if (! $dbo->{fields}->[$field]->{visible}) {
395 next;
396 }
397  
398 my $cell_align = 'left';
399 my $cell_data = $dbo->{data}->[$record][$field];
400 my $cell_type = $dbo->{fields}->[$field]->{type};
401 my $cell_style = $self->{data}{td};
402  
403 # Fix blank cells
404 if (! $cell_data) {
405 if ($cell_type =~ /char/i) {
406 $cell_data = ' ';
407 } else {
408 $cell_data = '0';
409 }
410 }
411  
412 # Remove any 00:00:00 times
413 if ($cell_data =~ /(.*)\s+00:00:00/) {
414 $cell_data = $1;
415 }
416  
417 # Set cell to right-aligned if cell data is numerical
418 if ($cell_type !~ /char/i) {
419 $cell_align = 'right';
420 }
421  
422 # If the commify flag is set and the cell is numeric, commify the number
423 if ($commify) {
424 if (($cell_type !~ /time/i) or ($cell_type !~ /date/i)) {
425 $cell_data = commify($cell_data);
426 }
427 }
428  
429 # If a precision size was defined for this field, set the displayed precision
430 my $precision = $dbo->{fields}->[$field]->{precision};
431 if ($precision) {
432 if (($cell_type !~ /char/i) and ($cell_type !~ /date/i)) {
433 $cell_data = sprintf('%.' . $precision . 'f', $cell_data);
434 }
435 }
436  
437 # highlight negatives if the flag was passed
438 if ($highlight_negatives) {
439 if ($cell_data =~ /^-\d(.*)/) {
440 $cell_data = qq[<font color="$self->{misc}{negatives}">$cell_data</font>];
441 }
442 }
443  
444 $content .= qq[<td align=$cell_align style="$cell_style">$cell_data</td>];
445 }
446 $content .= "</tr>\n";
447 }
448  
449 $content .= qq[</table>];
450  
451 return $content;
452 }
453  
454 =head2 $canvas = build_report()
455  
456 Build's a data driven report. Please see the file 'salreport.cgi' in the samples directory.
457  
458 =cut
459  
460 sub build_report {
461 my $self = shift;
462  
463 my $content;
464 my $current_report_page = '1';
465 my $record_html;
466  
467 if(! $self->{global_number_fields}) {
468 $self->{global_number_fields} = $self->{datasource}->{internal}->{width};
469 $self->{global_number_records} = $self->{datasource}->{internal}->{height};
470 }
471  
472 # open the first table
473 $content .= "$self->{page_table_html}\n";
474  
475 # We need to pass the current report page back through this loop
476 for (my $index = 0; $index <= $self->{global_number_records}; $index++) {
477 ($record_html, $current_report_page) = $self->build_record_html($index, $current_report_page);
478 $content .= $record_html;
479 }
480  
481 # close the last table
482 $content .= "</table>\n";
483  
484 return $content;
485 }
486  
487 ##########################################################################################################################
488 # Private Methods
489  
490 sub build_record_html {
491 my $self = shift;
492  
493 my $record = shift || '0';
494 my $current_report_page = shift;
495 my $previous_report_page;
496  
497 my $totals_flag = 0;
498 my $span_flag = 0;
499 my $spacer_underline_flag = 0;
500 my $spacer_flag = 0;
501 my $pre_spacer_flag = 0;
502 my $page_flag = 0;
503 my $headers_flag = 0;
504 my $hnum_flag = 0;
505 my $span_interface_flag = 1;
506 my $zero2space_flag = 0;
507  
508 my $content;
509  
510 if ($record ne '(undefined)') {
511 # reset flags
512 $totals_flag = 0;
513 $span_flag = 0;
514 $spacer_flag = 0;
515 $pre_spacer_flag = 0;
516 $page_flag = 0;
517 $headers_flag = 0;
518 $hnum_flag = 0;
519 $span_interface_flag = 1;
520 $zero2space_flag = 0;
521 $spacer_underline_flag = 0;
522  
523 # page control
524 $previous_report_page = $current_report_page;
525  
526 if ($current_report_page ne $previous_report_page) {
527 $pre_spacer_flag = 1;
528 $page_flag = 1;
529 }
530  
531 # currently, formatting tags are in column 2 (0-index)
532 my $dfm_tags;
533 my $formatting = $self->{datasource}->{data}->[$record][$self->{dfm_column}];
534  
535 if ($formatting =~ /totals/i) {
536 $totals_flag = 1;
537  
538 # test ahead, does next line have another totals in it?
539 my $next_record = $record + 1;
540 my $next_record_keys = $self->{datasource}->{data}->[$next_record][$self->{dfm_column}];
541  
542 if ($next_record_keys !~ /totals/i) {
543 # if not, force a spacer
544 $spacer_flag = 1;
545 }
546 if ($next_record_keys =~ /h\d/i) {
547 $spacer_underline_flag = 0;
548 }
549 }
550  
551 if ($formatting =~ /\[(.*)\]/) {
552  
553 # extract the dfm tags
554 $formatting = $1;
555 $dfm_tags = $formatting;
556  
557 # set any special record-wide display flags;
558  
559 # headers
560 if ($formatting =~ /h(\d)/) {
561  
562 # key first page col headers on h4 tag
563 if ($1 == '4') {
564 $headers_flag = 1;
565 }
566 $span_flag = 1;
567 $spacer_flag = 1;
568 # $hnum_flag = 1; # put line over headers
569 # headers
570 # $headers_flag = 1;
571 }
572  
573 # linefeeds
574 # NOTE: Possible new dfm tag
575 if ($formatting =~ /line/i) {
576 $spacer_flag = 1;
577 # headers?
578 # $headers_flag = 1;
579 }
580  
581 # pagefeeds
582 if ($formatting =~ /page/i) {
583 $spacer_flag = 1;
584 $page_flag = 1;
585 }
586  
587 # get the style html tag
588 $formatting = $self->build_format_string($formatting);
589 if ($hnum_flag) {
590 $formatting =~ s/"$/border-top: 2px solid black;"/;
591 }
592 } else {
593 $formatting = "style=\"$self->{default_font_style}\"";
594 }
595  
596 # handle pre-spacer (leading page-breaks)
597 if ($pre_spacer_flag) {
598 my $formatting;
599  
600 if ($page_flag) {
601 # page
602 # $formatting = 'style="page-break-after: always;"';
603 } else {
604 # dots
605 $formatting = 'style="border-top: 2px solid #000; border-bottom: 1px dotted #aaa;"';
606 }
607  
608 $span_interface_flag = 0;
609 $content .= '<tr>' . build_spanned_field_html(" ",$formatting, $span_interface_flag) . "</tr>\n";
610 # headers
611 if ($page_flag) {
612 $content .= "</table>\n" . $self->{page_table_html} . $self->do_page_break();
613 $page_flag = 0;
614 }
615 }
616  
617 # cells
618 # open tr html tag
619 $content .= "<tr>";
620  
621 if (! $span_flag) {
622 for (my $index = 0; $index <= $self->{global_number_fields}; $index++) {
623 # only display the column if it is not in the exclusion list
624 if ($self->{skip_fields} !~ /\s$index\s/) {
625  
626 if (($totals_flag) and ($formatting !~ /border-top/)) {
627 $formatting =~ s/"$//; # remove trailing quote
628 $formatting .= " border-top: 1px dotted #000;\"";
629 }
630 # zero2space - remove?
631 # if the record is being formatted on a h? dfm tag
632 if ($dfm_tags =~ /h\d/) {
633 $zero2space_flag = 1;
634 }
635  
636 $content .= $self->build_field_html($record, $index, $formatting, $zero2space_flag);
637 }
638 }
639 } else {
640 # do table-wide colspan for headers
641 $content .= $self->build_spanned_field_html($self->{datasource}->{data}->[$record][$self->{dfm_column}], $formatting, $span_interface_flag);
642 }
643  
644 } else {
645 # simulate/display error record
646 $content .= "<!-- record was not passed -->\n";
647 }
648  
649 $content .= "</tr>\n";
650  
651 # add a spacer line after the record we just built
652 if ($spacer_flag) {
653 my $formatting;
654  
655 if ($page_flag) {
656 if ($spacer_underline_flag) {
657 $formatting = 'style="border-top: 2px solid #000;"';
658 } else {
659 $formatting = 'style=""';
660 }
661 } else {
662 # dots
663 if ($spacer_underline_flag) {
664 $formatting = 'style="border-top: 2px solid #000; border-bottom: 1px dotted #aaa;"';
665 } else {
666 $formatting = 'style="border-top: 2px solid #000;"';
667 }
668 }
669 $content .= '<tr>' . $self->build_spanned_field_html(" ",$formatting, 0) . "</tr>\n";
670  
671 # headers
672 # if ($page_flag) { $content .= "</table>\n" . $self->{page_table_html} . $self->do_page_break(); }
673 if ($page_flag) { $content .= "</table>\n" . $self->{page_table_html}; }
674  
675 }
676  
677 # add a page headers line after the record we just built.
678 if ($headers_flag) {
679 # headers
680 $content .= $self->do_page_break();
681 }
682  
683 # a better way would be to have $current_report_page declared a local static
684 # or global variable. need to find out how it's done in perl...
685 #
686 # we need to return $current_report_page to the caller, so that
687 # the caller can let us know what the last page processed was
688 # during the next iteration.
689 return ($content, $current_report_page);
690 }
691  
692 sub build_field_html { # No parameter checking....
693 my $self = shift;
694  
695 my $record = shift;
696 my $field = shift;
697 my $formatting = shift;
698 my $zero2space_flag = shift;
699  
700 my $cell_width = 0;
701  
702 my $field_data = $self->{datasource}->{data}->[$record][$field];
703 my $field_type = $self->{datasource}->{fields}->[$field]->{type};
704  
705 if (! $field_data) { $field_data = ' '; }
706 if ($field_data =~ /NULL/i) { $field_data = ' '; }
707  
708 if ($field_data =~ /^\[.*\](.*)/) {
709 $field_data = $1;
710 }
711  
712 if ($field_data =~ /^(.*)\s+00:00:00/) {
713 $field_data = $1;
714 }
715  
716 if (! $self->{pf_flag}) {
717 # color negative values red if device is not printer
718 if ($field_data =~ /^\-/) { $field_data = "<font color=#FF0000>$field_data</font>"; }
719 }
720  
721  
722 # Test the data - if it contains /[a-zA-Z][a-zA-Z][a-zA-Z]\s+\d+\s+\d\d\d\d/ set it to a date type
723 if ($field_data =~ /[a-zA-Z][a-zA-Z][a-zA-Z]\s+\d+\s+\d\d\d\d/) {
724 $field_type = 'datetime';
725 }
726  
727 # A commify flag needs to be in the gui properties... should be tested here.
728 if ($field_type !~ /date/i) {
729 if ($field_data !~ /[a-zA-Z]/) {
730 if($self->{misc}{block_commify} < 1) {
731 if($self->{datasource}->{fields}[$field]{commify} > 0) {
732 $field_data = $self->commify($field_data);
733 }
734 }
735 }
736 }
737  
738 # If a precision size was defined for this field, set the displayed precision
739 my $precision = $self->{datasource}->{fields}->[$field]->{precision};
740 if ($precision) {
741 if ($field_data !~ /[a-zA-Z]/) {
742 $field_data = sprintf('%.' . $precision . 'f', $field_data);
743 }
744 }
745  
746 # If a prefix string was defined for this field, prepend it
747 my $prefix = $self->{datasource}->{fields}->[$field]->{prefix};
748 if ($prefix) {
749 if ($field_data =~ / /) {
750 $field_data = $prefix . $field_data;
751 }
752 }
753  
754 # If a postfix string was defined for this field, append it
755 my $postfix = $self->{datasource}->{fields}->[$field]->{postfix};
756 if ($postfix) {
757 if ($field_data =~ / /) {
758 $field_data .= $postfix;
759 }
760 }
761  
762 # If an alignment was defined for this field, set it
763 if ($formatting !~ /align/) {
764 my $align = $self->{datasource}->{fields}->[$field]->{align};
765 if ($align) {
766 $formatting =~ s/"$//;
767 $formatting .= " text-align: $align;\"";
768 }
769 }
770  
771 my $content;
772 if ($cell_width) {
773 $content = "<td width=$cell_width valign=top $formatting>$field_data</td>";
774 } else {
775 $content = "<td valign=top $formatting>$field_data</td>";
776 }
777  
778 return $content;
779 }
780  
781 sub build_spanned_field_html {
782 my $self = shift;
783  
784 my $field_data = shift;
785 my $formatting = shift;
786 my $interface_control = shift;
787  
788 if (! $field_data) { $field_data = ' '; }
789 if ($field_data =~ /NULL/i) { $field_data = ' '; }
790  
791 if ($field_data =~ /^\[.*\](.*)/) {
792 $field_data = $1;
793 }
794  
795 if ($interface_control) {
796 # $field_data .= "<br/>\n<a href=\"#interface\">( Options )</a>\n";
797 }
798  
799 # force left aligned text
800 $formatting =~ s/"$//; # remove the trailing quote
801 $formatting .= " text-align: left;\""; # add text-align and trailing quote
802 my $content = "<td colspan=" . (($self->{global_number_fields} + 1) - $self->{num_skip_fields}) . " $formatting>$field_data</td>";
803  
804 return $content;
805 }
806  
807 sub do_page_break {
808 my $self = shift;
809  
810 my $content;
811  
812 $content = "<tr>";
813  
814 for (my $index = 0; $index <= $self->{global_number_fields}; $index++) {
815  
816 my $cell_width = 50;
817  
818 # only display the column label if it is not in the exclusion list
819 if ($self->{skip_fields} !~ /\s+$index\s+/) {
820  
821 my $label = $self->{datasource}->{column_info}->[$index]->{label};
822 $label = ucfirst($label);
823  
824 if ($index == 2) {
825 $label = ' ';
826 }
827  
828 my $align;
829 if ($index == 2) {
830 $align = 'left';
831 $cell_width = 255;
832 } else {
833 $align = 'right';
834 }
835  
836 if ($self->{first_page_break}) {
837 # fix this :(
838 if ($index == 2) {
839 $content .= "<td width=$cell_width style=\"text-align: $align;\">$label</td>";
840 } else {
841 $content .= "<td width=$cell_width style=\"text-align: $align; border-bottom: 1px dotted #000;\">$label</td>";
842 }
843 } else {
844 # fix this :(
845 if ($index == 2) {
846 $content .= "<td width=$cell_width style=\"page-break-before: always; text-align: $align;\">$label</td>";
847 } else {
848 $content .= "<td width=$cell_width style=\"page-break-before: always; text-align: $align; border-bottom: 1px dotted #000;\">$label</td>";
849 }
850 }
851 } else {
852 # skip
853 }
854 }
855  
856 $content .= "</tr>\n";
857  
858 if ($self->{first_page_break}) { $self->{first_page_break} = 0; } # clear 1st pgbreak flag
859  
860 return $content;
861 }
862  
863 sub build_format_string {
864 my $self = shift;
865  
866 my $formatting = shift || '(undefined)';
867 my @tags = split(/\s+/, $formatting);
868 my $num_tags = $#tags;
869 my $fstring;
870  
871 my %tag_styles = (
872 'italics' => 'font-style: italic',
873 'cite' => 'font-style: italic',
874 'bold' => 'font-weight: bold',
875 'strong' => 'font-weight: bold',
876 'fgcolor' => 'color',
877 'bgcolor' => 'background-color',
878 'fg' => 'color', # short-form for fgcolor
879 'bg' => 'background-color', # short-form for bgcolor
880 'h1' => 'font-size: 32px', # largest heading
881 'h2' => 'font-size: 24px',
882 'h3' => 'font-size: 18px',
883 'h4' => 'font-size: 16px',
884 'h5' => 'font-size: 12px', # smallest heading
885  
886 # new 09/13/2004
887 'solid_under' => 'border-bottom: 1px solid #000', # line under cells
888 'solid_over' => 'border-top: 1px solid #000', # line over cells
889 'dashed_under' => 'border-bottom: 1px dashed #000', # line under cells
890 'dashed_over' => 'border-top: 1px dashed #000', # line over cells
891 'double_under' => 'border-bottom: 3px double #000', # line under cells
892 'double_over' => 'border-top: 3px double #000', # line over cells
893 );
894  
895 # quick-search: index-lists
896 my $device_excludes; # simpler exclusion list
897 if ($self->{pf_flag}) { # than the columns since
898 $device_excludes = 's bg fg s'; # we don't need to know
899 } # how many items are in
900 # the list.
901 if ($formatting ne '(undefined)') {
902  
903 # open the style html tag segment
904 $fstring = 'style="';
905  
906 # build the css settings
907 for (my $index = 0; $index <= $num_tags; $index++) {
908 my $current_tag = $tags[$index];
909 next if ($device_excludes =~ /\s+$current_tag\s+/);
910  
911 if ($current_tag =~ /=/) {
912 # tag has associated value
913 my ($tmp_tag, $tmp_value) = split(/=/, $current_tag);
914 next if ($device_excludes =~ /\s+$tmp_tag\s+/);
915 $fstring .= $tag_styles{$tmp_tag} . ': ' . $tmp_value . '; ';
916 } else {
917 # tag does not have assoc value
918 $fstring .= $tag_styles{$current_tag} . '; ';
919 }
920 }
921  
922 # if no heading dfm tag was found, we need to append default text size
923 if ($fstring !~ /font\-size/) {
924 $fstring .= $self->{default_font_style};
925 }
926  
927 # clean up the trailing space
928 $fstring =~ s/\s$//;
929  
930 # close the style html tag segment
931 $fstring .= '"';
932 } else {
933  
934 # the formatting string was undefined, set to default
935 $fstring = "style=\"$self->{default_font_style}\"";
936 }
937  
938 return $fstring;
939 }
940  
941 sub commify {
942 my $self = shift;
943  
944 my $number = reverse $_[0];
945 $number =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
946 return scalar reverse $number;
947 }
948  
949 =pod
950  
951 =head1 Author
952  
953 Scott Elcomb <psema4@gmail.com>
954  
955 =head1 See Also
956  
957 SAL, SAL::DBI, SAL::Graph, SAL::WebApplication
958  
959 =cut
960  
961 1;