added current ZNCAdmin files
[ZNCAdmin.git] / zncadmin / Table.class.php
1 <?php
2 /* Table.class.php - virtual IRC Table Class - ZNCAdmin
3  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
4  * 
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License 
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
17  */
18
19 class Table {
20         private $table;
21         
22         public function Table($colums) {
23                 $this->table = array();
24                 $this->table['set'] = array();
25                 $this->table['data'] = array();
26                 $this->table['set']['col'] = $colums;
27                 $this->table['set']['bold'] = array();
28                 for($i = 0; $i < $this->table['set']['col']; $i++) {
29                         $this->table['set']['max'.$i] = 0;
30                         $this->table['set']['bold'][$i] = false;
31                 }
32         }
33         
34         public function setBold($colum) {
35                 $this->table['set']['bold'][$colum] = true;
36         }
37         
38         public function add() {
39                 $args = func_get_args();
40                 $row = array();
41                 for($i = 0; $i < $this->table['set']['col']; $i++) {
42                         if(count($args) <= $i) $args[$i]= "";
43                         $row[] = $args[$i];
44                         if(count($args) >= $i)
45                                 if(strlen($args[$i]) > $this->table['set']['max'.$i]) $this->table['set']['max'.$i] = strlen($args[$i]);
46                 }
47                 $this->table['data'][] = $row;
48                 return true;
49         }
50         
51         public function end() {
52                 $space = "                                                                                       ";
53                 $output = array();
54                 for($row = 0; $row < count($this->table['data']); $row++) {
55                         $out = "";
56                         for($i = 0; $i < $this->table['set']['col']; $i++) {
57                                 if($i < $this->table['set']['col'] - 1)
58                                         $this->table['data'][$row][$i] .= substr($space,0,$this->table['set']['max'.$i] - strlen($this->table['data'][$row][$i]) + 1);
59                                 $bold = $this->table['set']['bold'][$i];
60                                 $out .= ($bold ? "\002" : "").$this->table['data'][$row][$i].($bold ? "\002" : "");
61                         }
62                         $output[] = $out;
63                 }
64                 return $output;
65         }
66         
67 }
68
69 ?>