File: table.inc

package info (click to toggle)
phplib 2%3A7.2d-3.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,612 kB
  • ctags: 198
  • sloc: php: 6,095; pascal: 186; perl: 95; makefile: 78; sh: 6
file content (987 lines) | stat: -rw-r--r-- 34,994 bytes parent folder | download
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
<?php
/*
 * PHP Base Library
 *
 * Copyright (c) 1998-2000 NetUSE AG
 *                    Boris Erdmann, Kristian Koehntopp,
 *                    Jeffrey Galbraith
 *
 * $Id: table.inc,v 1.2 2000/07/12 18:22:35 kk Exp $
 * 
 * History: 990617: Modularized entire table class. Modularity breaks larger
 *                  objects into smaller, autonomous objects in order to 
 *                  exercise OOP requirements of code reuse. This give 
 *                  programmers the ability to use the high-level code, or 
 *                  get down and dirty with the low-level code.
 *                  Everything I have changed should maintain backwards 
 *                  compatibility, except for show_table_heading_row_result(),
 *                  which was unpreventable in order to get the full 
 *                  magnitude of OOP.
 *          990618: Added table_cell_open(), table_cell_close(),
 *                  table_heading_cell_open() and table_heading_cell_close(). 
 *                  Gives better modularity to class.(JSG)
 *          990619: Added $add_extra. If set, calls extra cell functions:
 *                  table_heading_row_add_extra and table_row_add_extra.
 *                  Override these functions in a derived class to add 
 *                  additional cells to a row of output data.
 *          990620: Added column name remapping. This allows the column names
 *                  of a database to be remapped into something more useful,
 *                  or, perhaps, another language. Array variable "map_cols"
 *                  added. (JSG)
 */ 

  #==========================================================================
  # Table (class)
  #--------------------------------------------------------------------------
  # Creates an HTML table based on either a PHP array or a
  # database result.
  #==========================================================================
  
class Table
{
  var $classname = "Table";              ## Persistence Support

  var $check;                            ## if set, create checkboxes named 
                                         ## to the result of $check[$key]
  var $filter = "[A-Za-z][A-Za-z0-9_]*"; ## Regexp: Field names to show
  var $fields;                           ## Array of field names to show
  var $heading;                          ## if set, create <th> section
  var $add_extra;                        ## Call extra cell functions
  var $map_cols;                         ## remap database columns to new names

  #==========================================================================
  ## Public functions
  #==========================================================================



  #==========================================================================
  ## Page functions
  #==========================================================================

  #==========================================================================
  # Function : start
  #--------------------------------------------------------------------------
  # Purpose  : Starts the display of a two-dimensional array in an HTML table
  #            format.
  # Arguments: $ary   - The 2D array to display.
  #            $class - [optional] Used for CSS control.
  # Returns  : The number of rows displayed.
  # Comments : See function: show
  # History  :
  #==========================================================================
  function start($ary, $class="") 
  {
    return ($this->show($ary, $class));
  }

  #==========================================================================
  # Function : start_result
  #--------------------------------------------------------------------------
  # Purpose  : Starts the display of a database query result in an HTML table
  #            format.
  # Arguments: $db    - The database result.
  #            $class - [optional] Used for CSS control.
  # Returns  : The number of rows displayed.
  # Comments : See function: show_result
  # History  :
  #==========================================================================
  function start_result($db, $class="") 
  {
    return ($this->show_result($db, $class));
  }

  #==========================================================================
  # Function : show
  #--------------------------------------------------------------------------
  # Purpose  : Starts the display of a two-dimensional array in an HTML table
  #            format.
  # Arguments: $ary   - The 2D array to diaplay.
  #            $class - [optional] Used for CSS control.
  # Returns  : The number of rows displayed.
  # Comments :
  # History  : 990616 - removed redundant code.(JSG)
  #==========================================================================
  function show($ary, $class="") 
  {
    global $debug;
    
    if (!$this->verify_2d_array($ary))
      return 0;

    $rows = 0;

    $this->table_open($class);
    if ($this->show_table_heading_row($ary, $class))
      $rows = $this->show_table_rows($ary, $class);
    $this->table_close($class);
    
    return $rows;
  }
  
  #==========================================================================
  # Function : show_result
  #--------------------------------------------------------------------------
  # Purpose  : Starts the display of a database query result in an HTML table
  #            format.
  # Arguments: $db    - The database result.
  #            $class - [optional] Used for CSS control.
  # Returns  : The number of rows displayed.
  # Comments :
  # History  :
  #==========================================================================
  function show_result($db, $class="") 
  {
    if (!$this->verify_db($db))
      return 0;

    $rows = 0;

    $this->table_open($class);
	if ($this->show_table_heading_row_result($db, $class))
      $rows = $this->show_table_rows_result($db, $class);  
    $this->table_close($class);
    
    return $rows;
  }

  #==========================================================================
  # Function : show_page
  #--------------------------------------------------------------------------
  # Purpose  : Starts the display of a two-dimensional array in an HTML table
  #            format. Only the rows $start to $start+$num are displayed.
  # Arguments: $ary   - The 2D array to diaplay.
  #            $start - The starting row to display.
  #            $num   - The number of rows to display.
  #            $class - [optional] Used for CSS control.
  # Returns  : The number of rows displayed.
  # Comments :
  # History  :
  #==========================================================================
  function show_page($ary, $start, $num, $class ="") 
  {
    global $debug;
    
    if (!$this->verify_2d_array($ary))
      return 0;

    $rows = 0;
    
    $this->table_open($class);
	if ($this->show_table_heading_row($ary, $class))
      $rows = $this->show_table_page_rows($ary, $start, $num, $class="");
    $this->table_close($class);
    
    return $rows;
  }

  #==========================================================================
  # Function : show_result_page
  #--------------------------------------------------------------------------
  # Purpose  : Starts the display of a database object in an HTML table
  #            format. Only the rows $start to $start+$num are displayed.
  # Arguments: $db    - The database result.
  #            $start - The starting row to display.
  #            $num   - The number of rows to display.
  #            $class - [optional] Used for CSS control.
  # Returns  : The number of rows displayed.
  # Comments :
  # History  :
  #==========================================================================
  function show_result_page($db, $start, $num, $class="") 
  {
    global $debug;
    
    if (!$this->verify_db($db))
      return 0;

    $rows = 0;

    $this->table_open($class);
    if ($this->show_table_heading_row_result($db, $class))
		$rows = $this->show_table_page_rows_result($db, $start, $num, $class);
    $this->table_close($class);
    
    return $rows;
  }



  #==========================================================================
  ## Row functions
  #==========================================================================

  #==========================================================================
  # Function : show_table_heading_row
  #--------------------------------------------------------------------------
  # Purpose  : Uses the passed array to create an HTML header row.
  # Arguments: $ary   - The array to use.
  #            $class - [optional] Used for CSS control.
  # Returns  : 1 on success, 0 on error.
  # Comments :
  # History  :
  #==========================================================================
  function show_table_heading_row($ary, $class="")
  {
    if (!$this->verify_2d_array($ary))
      return 0;
      
    if (isset($this->heading) && $this->heading)
    {
      reset($ary);
      list($key, $val) = each($ary);
      $this->table_heading_row($val, $class);
    }

    return 1;
  }
  
  #==========================================================================
  # Function : show_table_heading_row_result
  #--------------------------------------------------------------------------
  # Purpose  : Uses the passed database object to create an HTML header row.
  # Arguments: $db    - The database object
  #            $class - [optional] Used for CSS control.
  # Returns  : 1 on success, 0 on error.
  # Comments :
  # History  :
  #==========================================================================
  function show_table_heading_row_result($db, $class="")
  {
    if (!$this->verify_db($db))
      return 0;

    if ($this->heading)
    {
// (Jeff) ------------------------------      
//      if ($db->num_rows() > 0 && $db->next_record())
// rows are confirmed in $this->verify_db(), so no need to reverify
// -------------------------------------
      if ($db->next_record())
      {
        $this->table_heading_row($db->Record, $class);
        $db->seek($db->Row-1);
        return 1;
      }
      else
      {
// (Jeff) ------------------------------      
// Shouldn't do this! Breaks modularity!
// Call: table_close() instead from 
//       calling function. Comments to 
//       be removed in next release.
// -------------------------------------
//        $this->table_close($class);
// -------------------------------------
        return 0;
      }
    }
    return 1;
  }
  
  #==========================================================================
  # Function : table_heading_row
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to create a table heading row.
  # Arguments: $data  - The array of data that represents cells within a row.
  #            $class - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  : 990618 - Fixed return on select_colnames (JSG).
  #==========================================================================
  function table_heading_row($data, $class="") 
  {
    if (!is_array($data))
      return;

    $d = $this->select_colnames($data);

    $this->table_row_open($row, $d, $class);
    $this->set_checkbox_heading($class);
    $this->show_table_heading_cells($data, $class);

    # call virtual function
    if ($this->add_extra)
      $this->table_heading_row_add_extra($data, $class);

    $this->table_row_close(0, $class);
  }

  #==========================================================================
  # Function : show_table_rows
  #--------------------------------------------------------------------------
  # Purpose  : Walks the passed array displaying each row of data as an HTML
  #            table row.
  # Arguments: $ary   - The array of data to display.
  #            $class - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  :
  #==========================================================================
  function show_table_rows($ary, $class="")
  {
    global $debug;
    
    if ($debug)
      printf("<p>show_table_rows()<br>\n");

    if (!$this->verify_2d_array($ary))
      return 0;
      
    $row = 0;
      
    reset($ary);
    while(list($key, $val) = each($ary))
    {
      ## Process a single row
      $this->table_row($row++, $key, $val, $class);
    }
    
    return $row;
  }

  #==========================================================================
  # Function : show_table_rows_result
  #--------------------------------------------------------------------------
  # Purpose  : Walks the passed database object displaying each record as an 
  #            HTML table row.
  # Arguments: $db    - The database object
  #            $class - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  : 990617 - fixed return. Was "row" changed to "$row".
  #==========================================================================
  function show_table_rows_result($db, $class="")
  {
    global $debug;
    
    if ($debug)
      printf("<p>show_table_rows_result()<br>\n");

    if (!$this->verify_db($db))
      return 0;
    
    $row = 0;
    
    while($db->next_record())
    {
      ## Process a table row
      $this->table_row($row, $row, $db->Record, $class);
      $row++;
    }
    
    return $row;
  }
  
  #==========================================================================
  # Function : show_table_page_rows
  #--------------------------------------------------------------------------
  # Purpose  : Walks the passed array displaying each row of data as an HTML
  #            table row. However, data does not start displaying until
  #            $start element and end after $num rows.
  # Arguments: $ary   - The array object.
  #            $start - Start row displaying at this element.
  #            $num   - The number of rows to display.
  #            $class - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  : 990616 - $row was incrementing (++) in for loop and within
  #                     the table_row function call.
  #==========================================================================
  function show_table_page_rows($ary, $start, $num, $class="")
  {
    global $debug;
    
    if ($debug)
      printf("<p>show_table_page_rows()<br>\n");

    if (!$this->verify_2d_array($ary))
      return 0;
      
    $row = 0;
    
    $max = count($ary);
    if (($start < 0 ) || ($start > $max))
      return 0;
    $max = min($start+$num, $max);
      
    for ($row = $start; $row < $max; $row++)
    {
      ## Process a single row
      $this->table_row($row, $key, $val, $class);
    }
    
    return ($row - $start);
  }
  
  #==========================================================================
  # Function : show_table_page_rows_result
  #--------------------------------------------------------------------------
  # Purpose  : Walks the passed database object displaying each record as an 
  #            HTML table row. However, data does not start displaying until
  #            $start record and ends after $num records have been displayed.
  # Arguments: $db    - The database object.
  #            $start - Start row displaying at this record.
  #            $num   - The number of rows to display.
  #            $class - [optional] Used for CSS control.
  # Returns  : The number of rows displayed
  # Comments :
  # History  :
  #==========================================================================
  function show_table_page_rows_result($db, $start, $num, $class="")
  {
    global $debug;
    
    if ($debug)
      printf("<p>show_table_page_rows_result()<br>\n");

    if (!$this->verify_db($db))
      return 0;
    
    $row = $start;
    $fin = $start + $num;

    $db->seek($start);
    while($db->next_record() && ($row < $fin))    
    {
      ## Process a table row
      $this->table_row($row, $row, $db->Record, $class);
      $row++;
    }
    
    return ($row - $start);
  }

  #==========================================================================
  # Function : table_row
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to create a table row. Calls all of the 
  #            cell-related functions.
  # Arguments: $row     -
  #            $row_key -
  #            $data    - The array of data that represents cells within a row.
  #            $class   - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  :
  #==========================================================================
  function table_row($row, $row_key, $data, $class="") 
  {
    global $debug;
    
    if ($debug)
      printf("<p>table_row()<br>\n");

    $d = $this->select_colnames($data);    
    $this->table_row_open($row, $d, $class);    
    $this->set_checkbox($row, $row_key, $data, $class);
    $this->show_table_cells($row, $row_key, $data, $class);

    # call virtual function
    if ($this->add_extra)
      $this->table_row_add_extra($row, $row_key, $data, $class);

    $this->table_row_close($row, $class);
  }
  


  #==========================================================================
  ## Field/Cell functions
  #==========================================================================
  
  #==========================================================================
  # Function : set_checkbox_heading
  #--------------------------------------------------------------------------
  # Purpose  : This function creates an empty header cell to coincide with
  #            the checkbox option for that column.
  # Arguments: $class   - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  :
  #==========================================================================
  function set_checkbox_heading($class="")
  {
    global $debug;
    
    if ($debug)
      printf("<p>set_checkbox_heading()<br>\n");

    ## Checkbox handling...
    if ($this->check)
      $this->table_heading_cell(0, "&nbsp;", $class);
  }

  #==========================================================================
  # Function : set_checkbox
  #--------------------------------------------------------------------------
  # Purpose  : Creates an HTML checkbox based on the passed data, only if
  #            the member variable $check is set.
  # Arguments: $row     - The row number.
  #            $row_key - The row key.
  #            $data    - The data array.
  #            $class   - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  :
  #==========================================================================
  function set_checkbox($row, $row_key, $data, $class="")
  {
    global $debug;
    
    if ($debug)
      printf("<p>set_checkbox()<br>\n");

    ## Checkbox handling...
    if ($this->check)
      $this->table_checkbox_cell($row, $row_key, $data, $class);
  }

  #==========================================================================
  # Function : show_table_heading_cells
  #--------------------------------------------------------------------------
  # Purpose  : Walks the passed array and displays each item in an HTML table
  #            header cell.
  # Arguments: $data    - The data array.
  #            $class   - [optional] Used for CSS control.
  # Returns  : 1 on success, 0 on error.
  # Comments :
  # History  : 990618 - Fixed problem with filtering headers (JSG).
  #==========================================================================
  function show_table_heading_cells($data, $class="") 
  {
    global $debug;
    
    if ($debug)
      printf("<p>show_table_heading_cells()<br>\n");

    if (!$this->verify_array($data))
      return 0;
  
    $cell = 0;
    $d = $this->select_colnames($data);
      
    ## Create regular cells
    reset($d);
    while(list($key, $val) = each($d)) 
    {
      $this->table_heading_cell($col++, $val, $class);
    }

    return 1;
  }
  
  #==========================================================================
  # Function : show_table_cells
  #--------------------------------------------------------------------------
  # Purpose  : Walks the passed array and displays each item in an HTML table
  #            cell.
  # Arguments: $row     - The row number.
  #            $row_key - The row key.                  [for derived classes]
  #            $data    - The data array.
  #            $class   - [optional] Used for CSS control.
  # Returns  : 1 on success, 0 on error.
  # Comments :
  # History  :
  #==========================================================================
  function show_table_cells($row, $row_key, $data, $class="") 
  {
    global $debug;
    
    if ($debug)
      printf("<p>show_table_cells()<br>\n");

    if (!$this->verify_array($data))
      return 0;

    $cell = 0;
    $d = $this->select_colnames($data);
      
    ## Create regular cells
    reset($d);
    while(list($key, $val) = each($d)) 
    {
      $this->table_cell($row, $cell++, $val, $data[$val], $class);
    }

    return 1;
  }
  
  #==========================================================================
  # Function : table_cell
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to render a single cell.
  # Arguments: $row   - The row number.                 [for derived classes]
  #            $col   - The column number.              [for derived classes]
  #            $key   - The key value.                  [for derived classes]
  #            $val   - The data value.
  #            $class - [optional] Used for CSS control.
  # Returns  : Nothing
  # Comments :
  # History  :
  #==========================================================================
  function table_cell($row, $col, $key, $val, $class="") 
  {
    $this->table_cell_open($class);
    printf("%s", $val);
    $this->table_cell_close($class);
  }
  
  function table_cell_open($class="")
  {
    printf("  <td%s>", 
      $class?" class=$class":"");
  }

  function table_cell_close($class="")
  {
    printf("</td>\n");
  }

  #==========================================================================
  # Function : table_heading_cell
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to render a single header cell.
  # Arguments: $col   - The column number.              [for derived classes]
  #            $val   - The data value.
  #            $class - [optional] Used for CSS control.
  # Returns  : Nothing
  # Comments :
  # History  : 990620 - Added column remapping.
  #==========================================================================
  function table_heading_cell($col, $val, $class="") 
  {
    $this->table_heading_cell_open($class);
    
    ## Check for column name remapping
    if ($this->verify_array($this->map_cols))
    {
      reset($this->map_cols);
      while(list($key, $name) = each($this->map_cols)) 
      {
        if ($key == $val)
        {
          $val = $name;
          $found = 1;
          break;
        }
      }
    }

    printf("%s", $val);
    $this->table_heading_cell_close($class);
  }
  
  #==========================================================================
  # Function : table_heading_cell_open
  #--------------------------------------------------------------------------
  # Purpose  : Starts a header cell.
  # Arguments: $class - [optional] Used for CSS control.
  # Returns  : Nothing
  # Comments : Low-level function for table_heading_cell()
  # History  : 
  #==========================================================================
  function table_heading_cell_open($class="") 
  {
    printf("  <th%s>", $class?" class=$class":"");
  }
  
  #==========================================================================
  # Function : table_heading_cell_close
  #--------------------------------------------------------------------------
  # Purpose  : Ends a header cell.
  # Arguments: $class - [optional] Used for CSS control.
  # Returns  : Nothing
  # Comments : Low-level function for table_heading_cell()
  # History  : 
  #==========================================================================
  function table_heading_cell_close($class="") 
  {
    printf("</th>\n");
  }
  
  #==========================================================================
  # Function : table_checkbox_cell
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to display a checkbox. This function runs
  #            if the member variable $check has been set. $check should be
  #            set to some key within the $data array (ex: if $data["myKey"],
  #            then set $check="myKey").
  # Arguments: $row     - The row currently being written.
  #            $row_key - If $data[$this-check] is empty, then this variable
  #                       is used instead.
  #            $data    - An array of data information.
  #            $class   - [optional] Used for CSS control.
  # Returns  :
  # Comments : 
  # History  :
  #==========================================================================
  function table_checkbox_cell($row, $row_key, $data, $class="") 
  {
    if ($this->check)
    {
      printf("  <td%s><input type=\"checkbox\" name=\"%s[%s]\" value=\"%s\"></td>\n",
        $class?" class=$class":"",
        $this->check,
        $row,
        empty($data[$this->check])?$row_key:$data[$this->check]);
    }
  }

  #==========================================================================
  ## Utility functions (used to be in util.inc, but were used only here and
  ## did create a lot of confusion on installation) -- KK
  #==========================================================================

  #==========================================================================
  # Function : verify_array
  #--------------------------------------------------------------------------
  # Purpose  : Verifies an array
  # Arguments: $ary   - The array to verify.
  # Returns  : 1 on success, 0 on error.
  # Comments : 
  # History  : 
  #==========================================================================
  function verify_array($ary)
  {
    if (!is_array($ary))
      return 0;
    
    return 1;
  }
    
  #==========================================================================
  # Function : verify_2d_array
  #--------------------------------------------------------------------------
  # Purpose  : Verifies a 2D array
  # Arguments: $ary   - The array to verify.
  # Returns  : 1 on success, 0 on error.
  # Comments : 
  # History  : 990616 - Removed "$this->" from "verify_array". (JSG)
  #==========================================================================
  function verify_2d_array($ary)
  {
    if (!$this->verify_array($ary))
      return 0;
    
    reset($ary);
    if (!is_array(current($ary)))
      return 0;

    reset($ary);
    
    return 1;
  }
    
  #==========================================================================
  # Function : verify_db
  #--------------------------------------------------------------------------
  # Purpose  : Verifies a database object for results.
  # Arguments: $db   - The database object to verify.
  # Returns  : 1 on success, 0 on error.
  # Comments : 
  # History  : 
  #==========================================================================
  function verify_db($db)
  {
    if (!isset($db) && !$db)
      return 0;
    
    if ($db->num_rows() > 0)
      return 1;   

    return 0;
  }

  ## Debugging function that prints an array
  ##   Recursive is_array found within array
  function print_array($ary)
  {
    if (is_array($ary))
    {
      while(list($key, $val) = each($ary))
      {
        echo "&nbsp;&nbsp;$key = $val<br>\n";
        if (is_array($val))
          print_array($val);
      }
    }
  }

  #==========================================================================
  ## Helper functions
  #==========================================================================
  
  #==========================================================================
  # Function : select_colnames
  #--------------------------------------------------------------------------
  # Purpose  : Selects the column names that should be displayed in an HTML
  #            table. This is based on the $fields variable, if set. If it
  #            is not set, then all fields names are used. This is how you
  #            filter displayed data.
  # Arguments: $data - A array containing information about the column 
  #                    names. If $fields is not used, then this variable is
  #                    used instead.
  # Returns  : An array containing the column names.
  # Comments :
  # History  :
  #==========================================================================
  function select_colnames($data) 
  {
    global $debug;
    
    if ($debug)
      printf("<p>select_colnames()<br>\n");

    if (!is_array($this->fields) && is_array($data)) 
    {
      reset($data);
      while(list($key, $val) = each($data)) 
      {
        if (ereg($this->filter, $key))
          $this->fields[] = $key;
      }
    } 
    $d = $this->fields;

    if ($debug)
    {
      print_array($d);
      printf("select_colnames() return<br>");
    }
    
    return $d;
  }

  #==========================================================================
  # Misc. functions
  #==========================================================================

  #--------------------------------------------------------------------------
  ## The following functions provide a very basic rendering
  ## of a HTML table with CSS class tags. Table is useable
  ## with them or the functions can be overridden for a
  ## more complex functionality.
  #--------------------------------------------------------------------------

  #--------------------------------------------------------------------------
  ## Table open and close functions.
  #--------------------------------------------------------------------------

  #==========================================================================
  # Function : table_open
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to open a table.
  # Arguments: $class - [optional] Used for CSS control.
  # Returns  : Nothing
  # Comments :
  # History  :
  #==========================================================================
  function table_open($class="")
  {
    global $debug;
    
    if ($debug)
      printf("<p>table_open()<br>\n");
      
    printf("<table%s>\n", $class?" class=$class":"");
  }

  #==========================================================================
  # Function : table_close
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to close a table.
  # Arguments: $class - [optional] Used for CSS control.
  # Returns  : Nothing
  # Comments : $class is not used by this function, but is available for
  #            derived classes that override this function.
  # History  :
  #==========================================================================
  function table_close($class="") 
  {
    global $debug;
    
    if ($debug)
      printf("<p>table_close()<br>\n");
      
    printf("</table>\n");
  }

  ## Row open and close functions.

  #==========================================================================
  # Function : table_row_open
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to open a table row.
  # Arguments: $row -   This variable is for derived classes that override 
  #                     this function that want access to the row number for 
  #                     the row about to be opened.
  #            $data -  This variable is for derived classes that override 
  #                     this function that want access to the row data for 
  #                     the row about to be opened.
  #            $class - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  :
  #==========================================================================
  function table_row_open($row, $data, $class="") 
  {
    printf(" <tr%s>\n", $class?" class=$class":"");
  }

  #==========================================================================
  # Function : table_row_close
  #--------------------------------------------------------------------------
  # Purpose  : Outputs HTML code to close a table row.
  # Arguments: $row -     This variable is for derived classes that override 
  #                       this function that want access to the row number 
  #                       for the row about to be closed.
  #            $class   - [optional] Used for CSS control.
  # Returns  :
  # Comments : $class is not used by this function, but is available for
  #            derived classes that override this function.
  # History  :
  #==========================================================================
  function table_row_close($row, $class="") 
  {
    printf(" </tr>\n");
  }

  #==========================================================================
  ## Function overrides
  #==========================================================================
    
  #==========================================================================
  # Function : table_heading_row_add_extra
  #--------------------------------------------------------------------------
  # Purpose  : Virtual function for derived classes. This function is called 
  #            after all header cells have been created. It allows the 
  #            programmer to add additional HTML code to the header row 
  #            before it is closed.
  # Arguments: $data
  #            $class   - [optional] Used for CSS control.
  # Returns  :
  # Comments :
  # History  :
  #==========================================================================
  function table_heading_row_add_extra($data, $class="")
  {}

  #==========================================================================
  # Function : table_row_add_extra
  #--------------------------------------------------------------------------
  # Purpose  : Virtual function for derived classes. This function is called 
  #            after all cells have been created. It allows the programmer to 
  #            add additional HTML code to the row before it is closed.
  # Arguments: $row
  #            $row_key
  #            $data
  #            $class   - [optional] Used for CSS control.
  # Returns  : 
  # Comments :
  # History  :
  #==========================================================================
  function table_row_add_extra($row, $row_key, $data, $class="")
  {}
}
?>