2 /* Table.class.php - virtual IRC Table Class - ZNCAdmin
3 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
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.
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.
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/>.
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;
34 public function setBold($colum) {
35 $this->table['set']['bold'][$colum] = true;
38 public function add() {
39 $args = func_get_args();
41 for($i = 0; $i < $this->table['set']['col']; $i++) {
42 if(count($args) <= $i) $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]);
47 $this->table['data'][] = $row;
51 public function end() {
54 for($row = 0; $row < count($this->table['data']); $row++) {
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" : "");