style = $style; } public function setHeader($columns, $repeat=0) { $this->header = $columns; $this->header_repeat = $repeat; } public function addRow($row) { $this->rows[] = $row; $this->max_rowsize = max($this->max_rowsize, sizeof($row)); } public function addRows($rows) { foreach ($rows as $r) $this->addRow($r); } public function sortBy($column, $flags = SORT_ASC) { $t = array(); foreach ($this->rows as $k=>$r) $t[$r[$column].$k] = $r; if ($flags == SORT_ASC) ksort($t); else if ($flags == SORT_DESC) krsort($t); $this->rows = $t; } public function enableRowCount() { $this->rowcount = true; } public function enableColumnCount() { $this->colcount = true; } public function enableSelection($tablename, $actions) { $this->selectable = true; $this->tablename = $tablename; $this->actions = $actions; } public function render() { $t = '
| '; if ($this->selectable) $th .= ' | '; for ($i=0, $l='A'; $i<$this->max_rowsize; $i++,$l++) $th .= " | $l | "; $th .= '
|---|---|---|
| '; if ($this->selectable) $th .= ' | '; foreach ($this->header as $h) $th .= " | $h | "; $th .= '$i | "; if ($this->selectable) $td .= ''; foreach ($r as $rd) $td .= " | $rd | "; $t .= "
'; if (!empty($this->actions)) { $t .= $this->actions->render('action_'.$this->tablename); $t .= ' '; } return $t.'
'; } private $style = ''; private $header = array(); private $header_repeat = 0; private $rows = array(); private $max_rowsize = 0; private $rowcount = false; private $colcount = false; private $selectable = false; private $tablename = ''; private $actions = null; }