-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl7tablerender.PRG
More file actions
1559 lines (1467 loc) · 58.1 KB
/
l7tablerender.PRG
File metadata and controls
1559 lines (1467 loc) · 58.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
* L7TableRender.PRG
*
* Object-oriented, programmatic creation of HTML tables from VFP cursors.
#IF .F.
***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is "Level 7 Framework for Web Connection" and
"Level 7 Toolkit" (collectively referred to as "L7").
The Initial Developer of the Original Code is Randy Pearson of
Cycla Corporation.
Portions created by the Initial Developer are Copyright (C) 2004 by
the Initial Developer. All Rights Reserved.
***** END LICENSE BLOCK *****
#ENDIF
* See L7Table.PRG for revision notes.
#INCLUDE L7.H
*** ====================================================== ***
DEFINE CLASS L7TableRender AS CUSTOM
cCellTag = ""
cRowTag = ""
cEmptyContent = ""
lAllowRepeatSuppression = .T.
* ---------------------------------------------------------- *
FUNCTION OpenTable
ENDFUNC && OpenTable
* ---------------------------------------------------------- *
FUNCTION InsertExtraRow( ii, lnLocation, lnLevel)
WITH THIS.Parent
.Write( .aExtraRows[ m.ii].GetOutput( m.lnLocation, m.lnLevel ) )
ENDWITH
RETURN
ENDFUNC && InsertExtraRow
* ---------------------------------------------------------- *
FUNCTION RepeatTableHeader
ENDFUNC && RepeatTableHeader
* ---------------------------------------------------------- *
FUNCTION BeforeFirstRecord
ENDFUNC
* ---------------------------------------------------------- *
FUNCTION ProcessRecord
* Template method.
WITH THIS.Parent
LOCAL lcText, lcTemp
* Note that we build the whole record and *then* write
* it, so we are not adding too many bite-sized pieces to a
* long stream.
lcText = ""
lcText = m.lcText + THIS.OpenRow()
IF .lSimple
LOCAL loElem
FOR EACH loElem IN .aElements
IF loElem.lActive = .F.
LOOP
ENDIF
* avoid recursion/concat bug via 2-step (if tables are nested):
lcTemp = loElem.Process()
lcText = m.lcText + m.lcTemp
ENDFOR
ELSE
LOCAL loCol
FOR EACH loCol IN .aColumns
IF loCol.lActive = .F.
LOOP
ENDIF
lcTemp = loCol.Process()
lcText = m.lcText + m.lcTemp
ENDFOR
ENDIF
lcText = m.lcText + THIS.CloseRow()
.Write( m.lcText )
ENDWITH
RETURN
ENDFUNC && ProcessRecord
* ---------------------------------------------------------- *
FUNCTION ColumnHeadingRow
* Template method.
WITH THIS.Parent
THIS.OpenColumnHeadingRow()
LOCAL loItem
IF .lSimple
FOR EACH loItem IN .aElements
IF loItem.lActive = .F.
LOOP
ENDIF
THIS.ItemHeading(loItem)
ENDFOR
ELSE
FOR EACH loItem IN .aColumns
IF loItem.lActive = .F.
LOOP
ENDIF
THIS.ItemHeading(loItem)
ENDFOR
ENDIF
THIS.CloseColumnHeadingRow()
ENDWITH
RETURN
ENDFUNC && ColumnHeadingRow
* ---------------------------------------------------------- *
FUNCTION OpenRow
RETURN THIS.Parent.cBeforeFirstColumn && access method in parent
ENDFUNC && OpenRow
* ---------------------------------------------------------- *
FUNCTION CloseRow
RETURN THIS.Parent.cAfterLastColumn && access method in parent
ENDFUNC && CloseRow
* ---------------------------------------------------------- *
FUNCTION GetElement(loElem)
LOCAL lcText, lnCount, llRepeat, lvVal, lcExpr
WITH loElem
* If we're using supression, compare to previous value and decide
* whether we're dealing with a repeat that should be supressed:
IF THIS.lAllowRepeatSuppression AND .lSupressRepeats
IF ISNULL( .vNewValue) OR ISNULL( .vOldValue) OR ;
.oTable.nGroupRowCount = 1 OR ;
NOT .vOldValue == .vNewValue
*
llRepeat = .F.
ELSE
llRepeat = .T.
ENDIF
.vOldValue = .vNewValue
ENDIF
* Now decide what value we're going to show, based on display type.
lvVal = .vNewValue
DO CASE
CASE .nDisplayType = 2 && running total
lvVal = IIF( .nResetLevel = 0, .nGrandTotal, ;
.aGroupTotal[ .nResetLevel - 2] )
* If it's an AVERAGE, need to divide by running count:
IF .nCalcType = L7_CALCTYPE_AVG
lnCount = IIF( .nResetLevel = 0, .nGrandCount, ;
.aGroupCount[ .nResetLevel - 2] )
IF m.lnCount > 0 AND VARTYPE( m.lvVal) = "N"
lvVal = m.lvVal / m.lnCount
ENDIF
ENDIF
ENDCASE
* Finally, apply any optional transforming, including
* replacement strings for NULL and empty values:
DO CASE
CASE ISNULL( m.lvVal) && NULL
IF NOT EMPTY( .cNullDisplay)
IF LEFT(.cNullDisplay,1) = "="
TRY
lcText = EVALUATE(SUBSTR(.cNullDisplay, 2))
CATCH
lcText = "Error in " + .cNullDisplay
ENDTRY
ELSE && static NULL string
lcText = .cNullDisplay
ENDIF
ELSE
lcText = TRANSFORM( m.lvVal) && should honor SET NULLDISPLAY
ENDIF
CASE m.llRepeat
lcText = THIS.cEmptyContent
CASE NOT EMPTY( .cDisplayExpression)
* This CASE comes before "empty" case for a reason--assuming if
* you create an expression, it is robust.
* [2/16/2006 - I don't like this argument. -RP]
* [8/5/2009 - additional logic added below, after running the expression--best of both worlds]
LOCAL lcDispExpr, loExc && so we get debug info
IF .lDisplayTextmerge
lcDispExpr = .cDisplayExpression
lcText = TextMergeX( m.lcDispExpr)
ELSE
lcDispExpr = .cDisplayExpression
TRY
lcText = EVALUATE(m.lcDispExpr)
* 8/5/2009, add:
IF EMPTY(m.lcText) AND NOT EMPTY(.cEmptyDisplay)
* If expression returns empty text and an alternative is specified we should use it.
* That way the expression doesn't need to be aware of container (cell) display needs.
lcText = .cEmptyDisplay
ENDIF
* [[probably should treat nulls this way too?? (currently nulls don't even make it to this CASE)
CATCH TO loExc
lcText = "ERR (" + m.loExc.Message + "): " + m.lcDispExpr
ENDTRY
ENDIF
CASE EMPTY( m.lvVal) AND NOT EMPTY(.cEmptyDisplay)
lcText = .cEmptyDisplay
CASE NOT EMPTY( .cFormatString ) && eval string with %1
** lcExpr = STRTRAN(.cFormatString, [%1], [m.lvVal])
lcExpr = STRTRAN(.cFormatString, [%1], TRANSFORM(m.lvVal))
lcText = EVALUATE(m.lcExpr)
CASE EMPTY( .cTransform )
IF VARTYPE( m.lvVal) <> "C"
lcText = TRANSFORM( m.lvVal)
ELSE
lcText = RTRIM( m.lvVal)
ENDIF
OTHERWISE && an explicit format is specified
lcText = TRANSFORM( m.lvVal, .cTransform )
ENDCASE
ENDWITH
RETURN m.lcText
ENDFUNC && GetElement
* ---------------------------------------------------------- *
ENDDEFINE && L7TableRender
*** ====================================================== ***
DEFINE CLASS L7TableHtmlRender AS L7TableRender
cCellTag = "td"
cRowTag = "tr"
cEmptyContent = CHR(38) + "nbsp;" && non-breaking space
lBodyOpen = .f.
* ---------------------------------------------------------- *
FUNCTION OpenTable
LOCAL loItem
WITH THIS.Parent
.WriteLn( CHR(13) + CHR(10) + [<] + .cRootElement + ;
IIF( VARTYPE( .nTableBorder) = "N", [ border="] + TRANSFORM( .nTableBorder) + ["], []) + ;
IIF( EMPTY( .cTableBorderColor), [], [ bordercolor="] + .cTableBorderColor + ["]) + ;
IIF( VARTYPE( .nTableCellPadding) = "N", [ cellpadding="] + TRANSFORM( .nTableCellPadding) + ["], []) + ;
IIF( VARTYPE( .nTableCellSpacing) = "N", [ cellspacing="] + TRANSFORM( .nTableCellSpacing) + ["], []) + ;
IIF( EMPTY( .cTableBgColor), [], [ bgcolor="] + .cTableBgColor + ["] ) + ;
IIF( EMPTY( .cTableWidth), [], [ width="] + .cTableWidth + ["] ) + ;
IIF( EMPTY( .cTableAlign), [], [ align="] + .cTableAlign + ["] ) + ;
IIF( NOT .lUseCss, [], ;
IIF( EMPTY( .cTableClass), [], [ class="] + .cTableClass + ["] ) + ;
IIF( EMPTY( .cTableStyle), [], [ style="] + .cTableStyle + ["] ) ;
) + ;
[ id="] + NVL(.cTableID, "tbl_" + SYS(3)) + ["] + ;
IIF( EMPTY( .cTableSummary), [], [ summary="] + .cTableSummary + ["] ) + ;
IIF( EMPTY( .cTableAttributes), [], [ ] + .cTableAttributes ) + ;
[>] + CHR(13) + CHR(10) )
** [ cols="] + TRANS( .nActiveColumns) + ["] +
* Add a caption, if specified:
IF NOT EMPTY( .cTableCaption)
.WriteLn( [<caption] + ;
IIF( NOT .lUseCss, [], ;
IIF( EMPTY( .cTableCaptionClass), [], [ class="] + .cTableCaptionClass + ["]) ;
) + ;
IIF( EMPTY( .cTableCaptionAttributes), [], [ ] + .cTableCaptionAttributes) + ;
[>] + .cTableCaption + [</caption>] + CHR(13) + CHR(10) )
ENDIF
* Insert <colgroup> and <col> tags.
IF .F. && some decision on whether to use??
IF .lEqualWidthColumns
.WriteLn( [<colgroup ] + ;
[ span="] + TRANSFORM(.nActiveColumns) + ["] + ;
[ width="] + TRANSFORM(100/MAX(1,.nActiveColumns)) + [%"] + [>])
.WriteLn( [</colgroup>])
ELSE
.WriteLn( [<colgroup>]) && should we specify table defaults here??
FOR EACH loItem IN .aColumns
IF loItem.lActive = .F.
LOOP
ENDIF
.WriteLn( [<col] + ;
IIF(VARTYPE(loItem.cWidth)="C", [ width="] + loItem.cWidth + ["], []) + ;
[>])
ENDFOR
.WriteLn( [</colgroup>])
ENDIF
ENDIF
.WriteLn([<thead>])
#IF L7_SHAREWARE
.WriteLn( CHR(13) + CHR(10) + ;
[<!-- This table was produced by an unlicensed evaluation copy of the Level 7 Components.] + ;
[ Please contact Cycla Corporation to obtain a licensed copy. -->] + ;
CHR(13) + CHR(10) + CHR(13) + CHR(10) )
#ENDIF
ENDWITH && THIS.Parent
RETURN
ENDFUNC && OpenTable
* ---------------------------------------------------------- *
FUNCTION InsertExtraRow( ii, lnLocation, lnLevel)
WITH THIS.Parent
.Write( .aExtraRows[ m.ii].GetOutput( m.lnLocation, m.lnLevel ) )
ENDWITH
RETURN
ENDFUNC && InsertExtraRow
* ---------------------------------------------------------- *
FUNCTION TitleRow
WITH THIS.Parent
LOCAL lcTitle, lcStr
IF NOT EMPTY( .cTitle )
lcTitle = .cTitle
* Wrap title with attributes:
IF VARTYPE( .cTitleFontAttributes) = "C"
IF "B" $ .cTitleFontAttributes
lcTitle = [<b>] + m.lcTitle + [</b>]
ENDIF
IF "I" $ .cTitleFontAttributes
lcTitle = [<i>] + m.lcTitle + [</i>]
ENDIF
IF "U" $ .cTitleFontAttributes
lcTitle = [<u>] + m.lcTitle + [</u>]
ENDIF
ENDIF
* See if we need a <font> tag:
lcStr = IIF( VARTYPE( .cTitleFontColor) = "C", [ color="] + .cTitleFontColor + ["], []) + ;
IIF( VARTYPE( .cTitleFontFace) = "C", [ face="] + .cTitleFontFace + ["], []) + ;
IIF( VARTYPE( .cTitleFontSize) = "C", [ size="] + .cTitleFontSize + ["], [])
IF NOT EMPTY( m.lcStr)
lcTitle = [<font] + m.lcStr + [>] + CR + m.lcTitle + [</font>] + CR
ENDIF
* Check Style or Class:
IF .lUseCss
lcStr = IIF( EMPTY( .cTitleFontClass), [], [ class="] + .cTitleFontClass + ["]) + ;
IIF( EMPTY( .cTitleFontStyle), [], [ style="] + .cTitleFontStyle + ["])
IF NOT EMPTY( m.lcStr)
lcTitle = [<span] + m.lcStr + [>] + CR + m.lcTitle + [</span>] + CR
ENDIF
ENDIF
.Write( [<tr><th] + ;
IIF( NOT .lUseCss, [], ;
IIF( EMPTY( .cTitleClass), [], [ class="] + .cTitleClass + ["] ) + ;
IIF( EMPTY( .cTitleStyle), [], [ style="] + .cTitleStyle + ["] ) ;
) + ;
[ colspan=] + TRANS( .nActiveColumns) + ;
IIF( VARTYPE( .cTitleBgColor) = "C", [ bgcolor="] + .cTitleBgColor + ["], []) + ;
IIF( VARTYPE( .cTitleAlign) = "C", [ align="] + .cTitleAlign + ["], []) + ;
[>] + ;
m.lcTitle + ;
[</td></th>] + CHR(13) + CHR(10) )
ENDIF
ENDWITH
RETURN
ENDFUNC && TitleRow
* ---------------------------------------------------------- *
FUNCTION RepeatTableHeader
* Doesn't work, problem with multiple THEAD
THIS.ColumnHeadingRow()
RETURN
ENDFUNC && RepeatTableHeader
* ---------------------------------------------------------- *
FUNCTION OpenColumnHeadingRow
WITH THIS.Parent
.WriteLn( [<tr] + ;
IIF( EMPTY( .cHeadingRowBgColor), [], [ bgcolor="] + .cHeadingRowBgColor + ["] ) + ;
IIF( EMPTY( .cHeadingRowValign), [], [ valign="] + .cHeadingRowValign + ["] ) + ;
IIF( NOT .lUseCss, [], ;
IIF( EMPTY( .cHeadingRowClass), [], [ class="] + .cHeadingRowClass + ["] ) + ;
IIF( EMPTY( .cHeadingRowStyle), [], [ style="] + .cHeadingRowStyle + ["] ) ;
) + ;
[>] )
ENDWITH
RETURN
ENDFUNC && OpenColumnHeadingRow
* ---------------------------------------------------------- *
FUNCTION CloseColumnHeadingRow
WITH THIS.Parent
.WriteLn( [</tr>] + CHR(13) + CHR(10) )
ENDWITH
RETURN
ENDFUNC && CloseColumnHeadingRow
* ---------------------------------------------------------- *
FUNCTION ItemHeading(loItem)
WITH loItem
LOCAL lcTag, lcStr
* Use a TH tag unless otherwise specified:
lcTag = IIF( EMPTY( .cHeadingTag), [th], .cHeadingTag )
IF LOWER(m.lcTag) <> [th] AND VARTYPE( .cHeadingAlign) <> "C"
* Non-TH cells are not centered by default. Adjust this.
.cHeadingAlign = "center"
ENDIF
* Now create the entire heading with opening and closing elements:
* [NOTE: More is going on here than it may appear! The cHeading property uses
* an ACCESS method which accumulates heading properties from any contained
* element properties.]
** need some unqiue ID--this isn't:
** [ id="] + THIS.Parent.Name + "_" + m.loItem.Name + ["] +
lcStr = .cHeading
lcStr = [<] + m.lcTag + ;
IIF( VARTYPE( .cWidth) = "C", ;
[ width="] + .cWidth + ["], []) + ;
IIF( VARTYPE( .cHeadingBgColor) = "C", ;
[ bgcolor="] + .cHeadingBgColor + ["], []) + ;
IIF( VARTYPE( .cHeadingAlign) = "C", ;
[ align="] + .cHeadingAlign + ["], []) + ;
IIF( NOT .oTable.lUseCss, [], ;
IIF( EMPTY( .cHeadingFontClass), [], [ class="] + .cHeadingFontClass + ["]) + ;
IIF( EMPTY( .cHeadingFontStyle), [], [ style="] + .cHeadingFontStyle + ["]) ;
) + ;
[>] + m.lcStr + [</] + m.lcTag + [>]
ENDWITH
THIS.Parent.WriteLn( m.lcStr)
RETURN
ENDFUNC && ItemHeading
* ---------------------------------------------------------- *
FUNCTION WrapColumnHeading( loItem, lcText)
WITH loItem
IF VARTYPE( .cHeadingFontColor) = "C" OR VARTYPE( .cHeadingFontFace) = "C" OR ;
VARTYPE( .cHeadingFontSize) = "C" OR ;
( VARTYPE( .cHeadingFontClass ) = "C" AND .oTable.lUseCss )
* at least one FONT property
lcText = [<font] + ;
IIF( VARTYPE( .cHeadingFontColor) = "C" AND NOT EMPTY( .cHeadingFontColor), ;
[ color="] + .cHeadingFontColor + ["], []) + ;
IIF( VARTYPE( .cHeadingFontSize) = "C" AND NOT EMPTY( .cHeadingFontSize), ;
[ size="] + .cHeadingFontSize + ["], []) + ;
IIF( VARTYPE( .cHeadingFontFace) = "C" AND NOT EMPTY( .cHeadingFontFace), ;
[ face="] + .cHeadingFontFace + ["], []) + ;
[>] + m.lcText + [</font>]
IF VARTYPE( .cHeadingFontAttributes) = "C"
IF "B" $ .cHeadingFontAttributes
lcText = [<b>] + m.lcText + [</b>]
ENDIF
IF "I" $ .cHeadingFontAttributes
lcText = [<i>] + m.lcText + [</i>]
ENDIF
IF "U" $ .cHeadingFontAttributes
lcText = [<u>] + m.lcText + [</u>]
ENDIF
ENDIF
ENDIF
ENDWITH
RETURN m.lcText
ENDFUNC
* ---------------------------------------------------------- *
FUNCTION BeforeFirstRecord
LOCAL lcStr
WITH this.Parent
.WriteLn([</thead>])
this.lBodyOpen = .t.
lcStr = [<tbody] + ;
IIF(EMPTY(.cBodyClass), [], [ class="] + .cBodyClass + ["]) + ;
IIF(EMPTY(.cBodyStyle), [], [ style="] + .cBodyStyle + ["]) + ;
[>]
.WriteLn(m.lcStr)
ENDWITH
RETURN
ENDFUNC
* ---------------------------------------------------------- *
FUNCTION CloseTable
WITH THIS.Parent
if this.lBodyOpen
.WriteLn([</tbody>])
this.lBodyOpen = .f.
endif
.WriteLn([</] + .cRootElement + [>] + CHR(13) + CHR(10) )
ENDWITH
RETURN
ENDFUNC && CloseTable
* ---------------------------------------------------------- *
FUNCTION GroupHeader(ii)
LOCAL lcText, lcGroupValue
WITH THIS.Parent
IF .aGroups[ m.ii].lHeaderRow
IF NOT EMPTY( .aGroups[ m.ii].cDisplayExpression )
lcGroupValue = .aGroups[ m.ii].cDisplayValue
ELSE
lcGroupValue = TRANS( .aGroups[ m.ii].vValue )
ENDIF
lcText = ""
lcText = m.lcText + ;
[<tr] + ;
IIF( EMPTY( .aGroups[ m.ii].cHeaderRowClass), [], ;
[ class="] + .aGroups[ m.ii].cHeaderRowClass + ["]) + ;
[>] + CRLF + ;
[<td colspan="] + TRANSFORM(.nActiveColumns) + [">] + m.lcGroupValue + ;
[</td>] + CRLF + ;
[</tr>]
.Write( m.lcText)
ENDIF
ENDWITH
RETURN
ENDFUNC && GroupHeader
* ---------------------------------------------------------- *
FUNCTION GroupFooter(ii)
LOCAL lcText, lcGroupValue, lnColCount, lnConsumedByColspan, loGrp
lnColCount = 0
lnConsumedByColspan = 0
WITH THIS.Parent
loGrp = .aGroups[ m.ii]
IF NOT EMPTY( loGrp.cDisplayExpression )
lcGroupValue = loGrp.cDisplayValue
ELSE
lcGroupValue = TRANSFORM(loGrp.vValue )
ENDIF
lcText = ""
* -- Special case where we need a label, but all columns are "used up"
* -- with their own group total display needs:
IF NOT EMPTY( loGrp.cTotalText )
* Some text is specified, such as "Totals:".
IF .nFooterTextColumn = -1
* No space found, so insert special row:
lcText = m.lcText + [<tr><td align="left" colspan="] + ;
TRANSFORM(.nActiveColumns) + ["] + ;
IIF( EMPTY( loGrp.cFooterRowClass), [], ;
[ class="] + loGrp.cFooterRowClass + ["]) + ;
IIF( EMPTY( loGrp.cFooterRowStyle), [], ;
[ style="] + loGrp.cFooterRowStyle + ["]) + ;
[>] + ;
IIF(loGrp.lValueInFooter, m.lcGroupValue + [ ], []) + ;
loGrp.cTotalText + ;
[</td></tr>] + CRLF
ENDIF
ENDIF
lcText = m.lcText + [<tr] + ;
IIF( VARTYPE( loGrp.cValign) = "C", ;
[ valign="] + loGrp.cValign + ["], []) + ;
IIF( VARTYPE( loGrp.cRowBgColor) = "C", ;
[ bgcolor="] + loGrp.cRowBgColor + ["], []) + ;
IIF( NOT .lUseCss, [], ;
IIF( VARTYPE( loGrp.cRowClass) = "C", ;
[ class="] + loGrp.cRowClass + ["], []) + ;
IIF( VARTYPE( loGrp.cRowStyle) = "C", ;
[ style="] + loGrp.cRowStyle + ["], []) ;
) + ;
[>] + CHR(13) + CHR(10)
FOR EACH loCol IN .aColumns
IF loCol.lActive = .F.
LOOP
ENDIF
lnColCount = m.lnColCount + 1
IF m.lnConsumedByColspan > 0
lnConsumedByColspan = m.lnConsumedByColspan - 1
LOOP
ENDIF
IF (.lSimple AND loCol.nCalcType = L7_CALCTYPE_NONE) ;
OR ;
(NOT .lSimple AND loCol.nCalcElements = 0)
* This column has no data requirements for group footer row. See if it
* can be used for group label instead:
IF NOT EMPTY( loGrp.cTotalText ) AND .nFooterTextColumn = m.lnColCount
* This column is available for showing group label.
lcText = m.lcText + [<td] + ;
IIF( VARTYPE( loGrp.cLabelClass) = "C", [ class="] + loGrp.cLabelClass + ["], []) + ; && was hardcoded "groupFooterLabel"
IIF( VARTYPE( loGrp.cLabelStyle) = "C", [ style="] + loGrp.cLabelStyle + ["], []) + ;
[ colspan="] + TRANSFORM(.nFooterTextColspan ) + ["] + ;
[><span>] + ;
IIF(loGrp.lValueInFooter, m.lcGroupValue + [ ], []) + ;
loGrp.cTotalText + [</span></td>] + CHR(13) + CHR(10)
IF .nFooterTextColspan > 1
* Colspan available for string. Reserve the space to extra TDs are not written.
lnConsumedByColspan = .nFooterTextColspan - 1
ENDIF
ELSE && this column has no group footer content
lcText = m.lcText + [<td> </td>] + CHR(13) + CHR(10)
ENDIF
ELSE && This column has data requirements for group footer.
lcText = m.lcText + [<td] + ;
IIF( VARTYPE( loCol.cAlign) = "C", [ align="] + loCol.cAlign + ["], [] ) + ;
IIF( VARTYPE( loCol.cCellClass) = "C", [ class="] + loCol.cCellClass + ["], [] ) + ;
IIF( VARTYPE( loCol.cCellStyle) = "C", [ style="] + loCol.cCellStyle + ["], [] ) + ;
IIF( VARTYPE( loGrp.cCellBgColor) = "C", [ bgcolor="] + loGrp.cCellBgColor + ["], [] ) + ;
[>]
IF .lSimple
IF loCol.nCalcType > L7_CALCTYPE_NONE
lcText = m.lcText + THIS.GetElemGroupFooter( loCol, m.ii )
ENDIF && loElem.nCalcType > L7_CALCTYPE_NONE
ELSE
FOR EACH loElem IN m.loCol.aElements
IF loElem.nCalcType > L7_CALCTYPE_NONE
lcText = m.lcText + THIS.GetElemGroupFooter( loElem, m.ii)
ENDIF && loElem.nCalcType > L7_CALCTYPE_NONE
ENDFOR && EACH loElem IN m.loCol.aElements
ENDIF
lcText = m.lcText + [</td>] + CHR(13) + CHR(10)
ENDIF && loCol.nCalcElements = 0
ENDFOR && EACH loCol IN .aColumns
lcText = m.lcText + [</tr>] + CHR(13) + CHR(10)
.Write( m.lcText )
ENDWITH
RETURN
ENDFUNC && GroupFooter
* --------------------------------------------------------- *
FUNCTION GetElemGroupFooter(loElem, ii)
WITH THIS.Parent
LOCAL llCount, lvVal, lcElemText, loGrp
loGrp = .aGroups[m.ii]
llCount = loElem.nCalcType = L7_CALCTYPE_COUNT
IF m.llCount
lvVal = NVL(loElem.aGroupTotal[ m.ii], 0)
ELSE
lvVal = loElem.aGroupTotal[ m.ii]
IF loElem.nCalcType = L7_CALCTYPE_AVG
IF VARTYPE( m.lvVal) $ "NIYBD" AND loElem.aGroupCount[ m.ii] > 0
lvVal = m.lvVal / loElem.aGroupCount[ m.ii]
ENDIF
ENDIF
ENDIF
IF NOT m.llCount AND VARTYPE(loElem.cTransform) = "C"
*[[ really we should allow some group-element transform
lcElemText = TRANSFORM( m.lvVal, loElem.cTransform )
ELSE
lcElemText = TRANSFORM( m.lvVal )
ENDIF
IF VARTYPE( loGrp.cFontAttributes) = "C"
IF "B" $ loGrp.cFontAttributes
lcElemText = [<b>] + m.lcElemText + [</b>]
ENDIF
IF "I" $ loGrp.cFontAttributes
lcElemText = [<i>] + m.lcElemText + [</i>]
ENDIF
IF "U" $ loGrp.cFontAttributes
lcElemText = [<u>] + m.lcElemText + [</u>]
ENDIF
ENDIF
IF VARTYPE( loGrp.cFontColor) = "C"
lcElemText = [<font color="] + loGrp.cFontColor + [">] + ;
m.lcElemText + [</font>]
ENDIF
IF .lUseCss AND ( ;
NOT EMPTY( loGrp.cFontClass) OR ;
NOT EMPTY( loGrp.cFontStyle) )
*
lcElemText = [<span] + ;
IIF( EMPTY( loGrp.cFontClass), ;
[], [ class="] + loGrp.cFontClass + ["] ) + ;
IIF( EMPTY( loGrp.cFontStyle), ;
[], [ style="] + loGrp.cFontStyle + ["] ) + ;
[>] + m.lcElemText + [</span>]
ENDIF
ENDWITH
RETURN m.lcElemText
ENDFUNC && GetElemGroupFooter
* ---------------------------------------------------------- *
FUNCTION OnZeroRecords
WITH THIS.Parent
IF NOT EMPTY( .cZeroRecordString )
LOCAL lcText
IF .lZeroRecordTable && render inside table, as a spanned cell
lcText = [<tr><td align=center colspan=] + TRANS( .nActiveColumns) + [>] + ;
[<span class="] + .cZeroRecordMessageClass + [">] + ;
.cZeroRecordString + [</span></td></tr>] + CHR(13) + CHR(10)
ELSE && no table
lcText = [<div class="] + .cZeroRecordMessageClass + [">] + ;
.cZeroRecordString + [</div>] + CHR(13) + CHR(10)
ENDIF
.Write( m.lcText )
ENDIF
ENDWITH
RETURN
ENDFUNC && OnZeroRecords
* ---------------------------------------------------------- *
FUNCTION GrandTotals
LOCAL lcText, lcLabel, loCol, loElem, lcElemText, lvVal, ;
lnColCount, lnConsumedByColspan, lcRowAttr, lcLabelAttr
lnColCount = 0
lnConsumedByColspan = 0
WITH THIS.Parent
if this.lBodyOpen
.WriteLn([</tbody>])
this.lBodyOpen = .f.
endif
.WriteLn([<tfoot>])
lcRowAttr = ;
IIF( VARTYPE( .cGrandValign) = "C", [ valign="] + .cGrandValign + ["], []) + ;
IIF( VARTYPE( .cGrandRowBgColor) = "C", [ bgcolor="] + .cGrandRowBgColor + ["], []) + ;
IIF( VARTYPE( .cGrandRowClass) = "C", [ class="] + .cGrandRowClass + ["], []) + ;
IIF( VARTYPE( .cGrandRowStyle) = "C", [ sytle="] + .cGrandRowStyle + ["], [])
lcLabelAttr = ;
IIF( VARTYPE( .cGrandLabelClass) = "C", [ class="] + .cGrandLabelClass + ["], []) + ;
IIF( VARTYPE( .cGrandLabelStyle) = "C", [ style="] + .cGrandLabelStyle + ["], [])
lcText = ""
lcLabel = ""
IF NOT EMPTY( .cGrandTotalText ) && text is specified (e.g. "Grand Totals:")
lcLabel = [<span>] + .cGrandTotalText + [</span>]
IF .nFooterTextColumn = -1 && no Hz space found, so insert special row:
lcText = m.lcText + [<tr] + m.lcRowAttr + [>] + ;
[<td colspan="] + TRANSFORM(.nActiveColumns) + ["] + m.lcLabelAttr + ;
[>] + m.lcLabel + [</td></tr>] + CRLF
ENDIF
ENDIF
* Grand row:
lcText = m.lcText + [<tr] + m.lcRowAttr + [>] + CHR(13) + CHR(10)
* See GroupFooter method for logic explanation.
FOR EACH loCol IN .aColumns
IF loCol.lActive = .F.
LOOP
ENDIF
lnColCount = m.lnColCount + 1
IF m.lnConsumedByColspan > 0
lnConsumedByColspan = m.lnConsumedByColspan - 1
LOOP
ENDIF
IF .lSimple AND loCol.nCalcType = L7_CALCTYPE_NONE OR ;
NOT .lSimple AND loCol.nCalcElements = 0
*
IF NOT EMPTY( .cGrandTotalText ) AND .nFooterTextColumn = m.lnColCount
* Here is open column where label text can go:
lcText = m.lcText + [<td colspan="] + TRANSFORM(.nFooterTextColspan) + ["] + m.lcLabelAttr + ;
[>] + m.lcLabel + [</td>]
IF .nFooterTextColspan > 1
* Colspan available for string. Reserve the space to extra TDs are not written.
lnConsumedByColspan = .nFooterTextColspan - 1
ENDIF
ELSE && unoccupied cell in grand footer
lcText = m.lcText + [<td> </td>] + CHR(13) + CHR(10)
ENDIF
ELSE && actual data total for column
lcText = m.lcText + [<td] + ;
IIF( VARTYPE( loCol.cAlign) = "C", [ align="] + loCol.cAlign + ["], [] ) + ;
IIF( VARTYPE( loCol.cCellClass) = "C", [ class="] + loCol.cCellClass + ["], [] ) + ;
IIF( VARTYPE( loCol.cCellStyle) = "C", [ style="] + loCol.cCellStyle + ["], [] ) + ;
IIF( VARTYPE( .cGrandCellBgColor) = "C", [ bgcolor="] + .cGrandCellBgColor + ["], [] ) + ;
[>]
IF .lSimple
IF loCol.nCalcType > L7_CALCTYPE_NONE
lcText = m.lcText + THIS.GetElemGrandTotal( m.loCol )
ENDIF
ELSE
FOR EACH loElem IN m.loCol.aElements
IF loElem.nCalcType > L7_CALCTYPE_NONE
lcText = m.lcText + THIS.GetElemGrandTotal( m.loElem )
ENDIF
ENDFOR
ENDIF
lcText = m.lcText + [</td>] + CHR(13) + CHR(10)
ENDIF
ENDFOR
lcText = m.lcText + [</tr>] + CHR(13) + CHR(10)
.Write( m.lcText )
.WriteLn([</tfoot>])
ENDWITH
RETURN
ENDFUNC && GrandTotals
* --------------------------------------------------------- *
FUNCTION GetElemGrandTotal(loElem)
LOCAL lvVal, lcElemText, llCount
lvVal = loElem.GetGrandTotal()
WITH THIS.Parent
IF NOT loElem.nCalcType = L7_CALCTYPE_COUNT AND VARTYPE( loElem.cTransform) = "C"
lcElemText = TRANSFORM( m.lvVal, loElem.cTransform )
ELSE
lcElemText = TRANSFORM( m.lvVal )
ENDIF
IF VARTYPE( .cGrandFontAttributes) = "C"
IF "B" $ .cGrandFontAttributes
lcElemText = [<b>] + m.lcElemText + [</b>]
ENDIF
IF "I" $ .cGrandFontAttributes
lcElemText = [<i>] + m.lcElemText + [</i>]
ENDIF
IF "U" $ .cGrandFontAttributes
lcElemText = [<u>] + m.lcElemText + [</u>]
ENDIF
ENDIF
IF VARTYPE( .cGrandFontColor) = "C"
lcElemText = [<font color="] + .cGrandFontColor + [">] + ;
m.lcElemText + [</font>]
ENDIF
IF .lUseCss AND ( ;
NOT EMPTY( .cGrandFontClass) OR ;
NOT EMPTY( .cGrandFontStyle) )
*
lcElemText = [<span] + ;
IIF( EMPTY( .cGrandFontClass), ;
[], [ class="] + .cGrandFontClass + ["] ) + ;
IIF( EMPTY( .cGrandFontStyle), ;
[], [ style="] + .cGrandFontStyle + ["] ) + ;
[>] + m.lcElemText + [</span>]
ENDIF
ENDWITH
RETURN m.lcElemText
ENDFUNC && GetElemGrandTotal
* ---------------------------------------------------------- *
FUNCTION WritePageLinks
LOCAL lcText, ii
lcText = ""
WITH THIS.Parent
DO CASE
CASE .nPage_AutoGeneration = 1 && simple previous/next
CASE .nPage_AutoGeneration = 2 && one link per page
lcText = m.lcText + .cPage_PageLabel
FOR ii = 1 TO .nPage_TotalPages
IF m.ii = .nPage_ShowPage && current page
lcText = m.lcText + '<b>[' + TRANS( m.ii) + ']</b> '
ELSE
lcText = m.lcText + '<a href="' + .aPage_URLs[ m.ii] + ;
'">[' + TRANS( m.ii) + ']</A> '
ENDIF
ENDFOR
ENDCASE
lcText = [<tr><td align=center colspan=] + TRANS( .nActiveColumns) + ;
[>] + m.lcText + [</td></tr>]
.Write( m.lcText )
ENDWITH
RETURN
ENDFUNC && WritePageLinks
* ---------------------------------------------------------- *
FUNCTION GetExtraRow( loRow, pnLocation, pnGroup)
LOCAL lcText
WITH loRow
lcText = ""
lcText = m.lcText + [<tr] + ;
IIF( VARTYPE( .cRowClass) = "C", ;
[ class="] + .cRowClass + ["], [] ) + ;
IIF( VARTYPE( .cRowStyle) = "C", ;
[ style="] + .cRowStyle + ["], [] ) + ;
IIF( VARTYPE( .cValign) = "C", ;
[ valign="] + .cValign + ["], [] ) + ;
IIF( VARTYPE( .cBgColor) = "C", ;
[ bgcolor="] + .cBgColor + ["], [] ) + ;
[>] + CR
lcText = m.lcText + [<td] + ;
IIF( VARTYPE( .cCellClass) = "C", ;
[ class="] + .cCellClass + ["], [] ) + ;
IIF( VARTYPE( .cCellStyle) = "C", ;
[ style="] + .cCellStyle + ["], [] ) + ;
IIF( VARTYPE( .cAlign) = "C", ;
[ align="] + .cAlign + ["], [] ) + ;
[ colspan=] + TRANS( .oTable.nActiveColumns ) + ;
[>] + CR
DO CASE
CASE VARTYPE( .cDynamicText) = "C"
lcText = m.lcText + TRANS( EVAL( .cDynamicText ))
CASE VARTYPE( .cText) = "C"
lcText = m.lcText + .cText
OTHERWISE
lcText = m.lcText + "<b><i>Special Row at Location " + TRANS( m.pnLocation ) + " [no content]</b></i>"
ENDCASE
lcText = m.lcText + [</td></tr>]
ENDWITH
RETURN m.lcText
ENDFUNC && GetExtraRow
* ---------------------------------------------------------- *
FUNCTION PreProcessCellTags(loItem)
* Handles either a column (complex table) or an element (simple table).
* Now we'll also deal with the TD wrapper, since in a simple table
* there is no separate column object that contains the element object:
LOCAL lcText1, lcText2
lcText1 = '[<' + THIS.cCellTag + ']'
lcText2 = '[</' + THIS.cCellTag + '>]+CHR(13)+CHR(10)'
WITH loItem
IF VARTYPE( .cAlign) = "C" AND NOT EMPTY( .cAlign)
lcText1 = m.lcText1 + '+[ align="' + .cAlign + '"]'
ENDIF
IF .oTable.lUseCss
IF VARTYPE( .cCellClass) = "C" AND NOT EMPTY( .cCellClass )
IF "(" $ .cCellClass && dynamic CSS class name
lcText1 = m.lcText1 + '+[ class="]+' + .cCellClass + '+["]'
ELSE && static CSS class name
lcText1 = m.lcText1 + '+[ class="' + .cCellClass + '"]'
ENDIF
ENDIF
IF VARTYPE( .cCellStyle ) = "C" AND NOT EMPTY( .cCellStyle )
IF "(" $ .cCellStyle && dynamic CSS style
lcText1 = m.lcText1 + '+[ style="]+' + .cCellStyle + '+["]'
ELSE && static CSS style
lcText1 = m.lcText1 + '+[ style="' + .cCellStyle + '"]'
ENDIF
ENDIF
ENDIF
IF VARTYPE( .cBgColor) = "C" AND NOT EMPTY( .cBgColor)
IF "(" $ .cBgColor && dynamic background color
lcText1 = m.lcText1 + '+[ bgcolor="]+' + .cBgColor + '+["]'
ELSE && static background color
lcText1 = m.lcText1 + '+[ bgcolor="' + .cBgColor + '"]'
ENDIF
ENDIF
lcText1 = m.lcText1 + '+[>]'
.cBeforeTags = m.lcText1 + [+] + .cBeforeTags
.cAfterTags = .cAfterTags + [+] + m.lcText2
ENDWITH
RETURN
ENDFUNC && PreProcessCellTags
* ---------------------------------------------------------- *
FUNCTION PreProcessElementTags(loItem)
LOCAL lcText1, lcText2, lcFontText
lcText1 = '""'
lcText2 = '""'
WITH loItem
* Check FONT Face, Size and Color to see if we need a FONT tag:
lcFontText = ""
IF VARTYPE( .cFontColor) = "C" AND NOT EMPTY( .cFontColor)
IF "(" $ .cFontColor && Expression - need to EVAL for each record!
lcFontText = m.lcFontText + '+[ color="]+' + .cFontColor + '+["]'
ELSE
lcFontText = m.lcFontText + '+[ color="' + .cFontColor + '"]'
ENDIF
ENDIF
IF VARTYPE( .cFontFace) = "C" AND NOT EMPTY( .cFontFace)
IF "(" $ .cFontFace && Expression - need to EVAL for each record!
lcFontText = m.lcFontText + '+[ face="]+' + .cFontFace + '+["]'
ELSE
lcFontText = m.lcFontText + '+[ face="' + .cFontFace + '"]'
ENDIF
ENDIF
IF VARTYPE( .cFontSize) = "C" AND NOT EMPTY( .cFontSize)
IF "(" $ .cFontSize && Expression - need to EVAL for each record!
lcFontText = m.lcFontText + '+[ size="]+' + .cFontSize + '+["]'
ELSE
lcFontText = m.lcFontText + '+[ size="' + .cFontSize + '"]'
ENDIF
ENDIF
IF .oTable.lUseCss
IF VARTYPE( .cFontClass) = "C" AND NOT EMPTY( .cFontClass)
IF "(" $ .cFontClass && Expression - need to EVAL for each record!
lcFontText = m.lcFontText + '+[ class="]+' + .cFontClass + '+["]'
ELSE
lcFontText = m.lcFontText + '+[ class="' + .cFontClass + '"]'
ENDIF
ENDIF
IF VARTYPE( .cFontStyle) = "C" AND NOT EMPTY( .cFontStyle)
IF "(" $ .cFontStyle && Expression - need to EVAL for each record!
lcFontText = m.lcFontText + '+[ style="]+' + .cFontStyle + '+["]'
ELSE
lcFontText = m.lcFontText + '+[ style="' + .cFontStyle + '"]'
ENDIF
ENDIF
ENDIF
IF NOT EMPTY( m.lcFontText)
lcText1 = m.lcText1 + '+[<font]' + m.lcFontText + '+[>]'
lcText2 = '[</font>]+' + m.lcText2
ENDIF
* Bold and italics, if requested:
IF VARTYPE( .cFontAttributes ) = "C" AND NOT EMPTY( .cFontAttributes )
IF "(" $ .cFontAttributes && Expression - need to EVAL for each record!
lcText1 = m.lcText1 + '+IIF([B]$' + .cFontAttributes + ',[<b>],[])'
lcText2 = 'IIF([B]$' + .cFontAttributes + ',[</b>],[])+' + m.lcText2
lcText1 = m.lcText1 + '+IIF([I]$' + .cFontAttributes + ',[<i>],[])'
lcText2 = 'IIF([I]$' + .cFontAttributes + ',[</i>],[])+' + m.lcText2
lcText1 = m.lcText1 + '+IIF([U]$' + .cFontAttributes + ',[<u>],[])'
lcText2 = 'IIF([U]$' + .cFontAttributes + ',[</u>],[])+' + m.lcText2
ELSE && Static attributes.
IF "B" $ .cFontAttributes
lcText1 = m.lcText1 + '+[<b>]'
lcText2 = '[</b>]+' + m.lcText2
ENDIF
IF "I" $ .cFontAttributes
lcText1 = m.lcText1 + '+[<i>]'
lcText2 = '[</i>]+' + m.lcText2
ENDIF
IF "U" $ .cFontAttributes
lcText1 = m.lcText1 + '+[<u>]'
lcText2 = '[</u>]+' + m.lcText2
ENDIF
ENDIF
ENDIF
.cBeforeTags = m.lcText1
.cAfterTags = m.lcText2
IF VARTYPE( .cPrefix) <> "C"
.cPrefix = ""
ENDIF