3d01798b016d5415f8b5510dc71284e7df18f172
[PHP-P10.git] / Tools / Table.class.php
1 <?php
2
3 class Table {
4         private $table;
5         
6         public function Table($colums) {
7                 $this->table = array();
8                 $this->table['set'] = array();
9                 $this->table['data'] = array();
10                 $this->table['set']['col'] = $colums;
11                 $this->table['set']['bold'] = array();
12                 for($i = 0; $i < $this->table['set']['col']; $i++) {
13                         $this->table['set']['max'.$i] = 0;
14                         $this->table['set']['bold'][$i] = false;
15                 }
16         }
17         
18         public function setBold($colum) {
19                 $this->table['set']['bold'][$colum] = true;
20         }
21         
22         public function add() {
23                 $args = func_get_args();
24                 $row = array();
25                 for($i = 0; $i < $this->table['set']['col']; $i++) {
26                         if(count($args) <= $i) $args[$i]= "";
27                         $row[] = $args[$i];
28                         if(count($args) >= $i)
29                                 if(strlen($args[$i]) > $this->table['set']['max'.$i]) $this->table['set']['max'.$i] = strlen($args[$i]);
30                 }
31                 $this->table['data'][] = $row;
32                 return true;
33         }
34         
35         public function end() {
36                 $space = "                                                                                       ";
37                 $output = array();
38                 for($row = 0; $row < count($this->table['data']); $row++) {
39                         $out = "";
40                         for($i = 0; $i < $this->table['set']['col']; $i++) {
41                                 if($i < $this->table['set']['col'] - 1)
42                                         $this->table['data'][$row][$i] .= substr($space,0,$this->table['set']['max'.$i] - strlen($this->table['data'][$row][$i]) + 1);
43                                 $bold = $this->table['set']['bold'][$i];
44                                 $out .= ($bold ? "\002" : "").$this->table['data'][$row][$i].($bold ? "\002" : "");
45                         }
46                         $output[] = $out;
47                 }
48                 return $output;
49         }
50         
51 }
52
53 ?>