package.xml0000644000000000000000000001410611356442106012016 0ustar rootwheel HTML_Table pear.php.net PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and efficient. The PEAR::HTML_Table package provides methods for easy and efficient design of HTML tables. - Lots of customization options. - Tables can be modified at any time. - The logic is the same as standard HTML editors. - Handles col and rowspans. - PHP code is shorter, easier to read and to maintain. - Tables options can be reused. For auto filling of data and such then check out http://pear.php.net/package/HTML_Table_Matrix Bertrand Mansion mansion bmansion@mamasam.com no Klaus Guenther thesaur thesaur@php.net no Helgi Þormar dufuz dufuz@php.net no Mark Wiesemann wiesemann wiesemann@php.net yes 2010-04-05 1.8.3 1.8.1 stable stable New BSD - Request #16984: added a __toString() method, i.e. "echo $table;" is now possible (thanks to Andreas Sjöberg) - Bug #17073: enhanced E_STRICT compatibility (thanks to Andrea Bakker and Daniel O'Connor) 4.3.0 1.5.0 HTML_Common pear.php.net 1.2.3 HTML_Table-1.8.3/docs/Table_example1.php0000644000000000000000000000270511356442106016507 0ustar rootwheel $value) { $table->addRow($data[$key], array(array('bgcolor' => 'blue', 'align' => 'center'), array('bgcolor' => 'green'), array('bgcolor' => 'red'))); } foreach($data as $key => $value) { $table->addRow($data[$key], array('bgcolor = "blue"','bgcolor = "green"','bgcolor = "red"')); } foreach($data as $key => $value) { $table->addRow($data[$key], 'bgcolor = "yellow" align = "right"', 'TD', true); } foreach($data as $key => $value) { $table->addRow($data[$key], array('bgcolor' => 'pink', 'align' => 'center')); } $table->setColAttributes(1, 'bgcolor = "purple"'); $table->updateColAttributes(2, array('bgcolor = "blue"','bgcolor = "green"','bgcolor = "red"')); echo '
';
var_dump($table->getCellAttributes(2, 2));
var_dump($table->getRowAttributes(8));
echo '
'; echo $table->toHTML(); ?>HTML_Table-1.8.3/docs/Table_example2.php0000644000000000000000000000104611356442106016505 0ustar rootwheelsetCaption('256 colors table'); $i = $j = 0; for ($R = 0; $R <= 255; $R += 51) { for ($G = 0; $G <= 255; $G += 51) { for($B = 0; $B <= 255; $B += 51) { $table->setCellAttributes($i, $j, 'bgcolor = "#'.sprintf('%02X%02X%02X', $R, $G, $B).'"'); $j++; } } $i++; $j = 0; } echo $table->toHtml(); ?>HTML_Table-1.8.3/Table/Storage.php0000644000000000000000000007452211356442106015375 0ustar rootwheel..., ... and .... * * PHP versions 4 and 5 * * LICENSE: * * Copyright (c) 2005-2007, Adam Daniel , * Bertrand Mansion , * Mark Wiesemann * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_Table * @author Adam Daniel * @author Bertrand Mansion * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: Storage.php 234674 2007-04-29 16:31:06Z wiesemann $ * @link http://pear.php.net/package/HTML_Table */ /** * Storage class for HTML::Table data * * This class stores data for tables built with HTML_Table. When having * more than one instance, it can be used for grouping the table into the * parts ..., ... and .... * * @category HTML * @package HTML_Table * @author Adam Daniel * @author Bertrand Mansion * @author Mark Wiesemann * @copyright 2005-2006 The PHP Group * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_Table */ class HTML_Table_Storage extends HTML_Common { /** * Value to insert into empty cells * @var string * @access private */ var $_autoFill = ' '; /** * Automatically adds a new row or column if a given row or column index * does not exist * @var bool * @access private */ var $_autoGrow = true; /** * Array containing the table structure * @var array * @access private */ var $_structure = array(); /** * Number of rows composing in the table * @var int * @access private */ var $_rows = 0; /** * Number of column composing the table * @var int * @access private */ var $_cols = 0; /** * Tracks the level of nested tables * @var int * @access private */ var $_nestLevel = 0; /** * Whether to use , and or not * @var bool * @access private */ var $_useTGroups = false; /** * Class constructor * @param int $tabOffset * @param bool $useTGroups Whether to use , and * or not * @access public */ function HTML_Table_Storage($tabOffset = 0, $useTGroups = false) { HTML_Common::HTML_Common(null, (int)$tabOffset); $this->_useTGroups = (boolean)$useTGroups; } /** * Sets the useTGroups value * @param boolean $useTGroups * @access public */ function setUseTGroups($useTGroups) { $this->_useTGroups = $useTGroups; } /** * Returns the useTGroups value * @access public * @return boolean */ function getUseTGroups() { return $this->_useTGroups; } /** * Sets the autoFill value * @param mixed $fill * @access public */ function setAutoFill($fill) { $this->_autoFill = $fill; } /** * Returns the autoFill value * @access public * @return mixed */ function getAutoFill() { return $this->_autoFill; } /** * Sets the autoGrow value * @param bool $fill * @access public */ function setAutoGrow($grow) { $this->_autoGrow = $grow; } /** * Returns the autoGrow value * @access public * @return mixed */ function getAutoGrow() { return $this->_autoGrow; } /** * Sets the number of rows in the table * @param int $rows * @access public */ function setRowCount($rows) { $this->_rows = $rows; } /** * Sets the number of columns in the table * @param int $cols * @access public */ function setColCount($cols) { $this->_cols = $cols; } /** * Returns the number of rows in the table * @access public * @return int */ function getRowCount() { return $this->_rows; } /** * Gets the number of columns in the table * * If a row index is specified, the count will not take * the spanned cells into account in the return value. * * @param int Row index to serve for cols count * @access public * @return int */ function getColCount($row = null) { if (!is_null($row)) { $count = 0; foreach ($this->_structure[$row] as $cell) { if (is_array($cell)) { $count++; } } return $count; } return $this->_cols; } /** * Sets a rows type 'TH' or 'TD' * @param int $row Row index * @param string $type 'TH' or 'TD' * @access public */ function setRowType($row, $type) { for ($counter = 0; $counter < $this->_cols; $counter++) { $this->_structure[$row][$counter]['type'] = $type; } } /** * Sets a columns type 'TH' or 'TD' * @param int $col Column index * @param string $type 'TH' or 'TD' * @access public */ function setColType($col, $type) { for ($counter = 0; $counter < $this->_rows; $counter++) { $this->_structure[$counter][$col]['type'] = $type; } } /** * Sets the cell attributes for an existing cell. * * If the given indices do not exist and autoGrow is true then the given * row and/or col is automatically added. If autoGrow is false then an * error is returned. * @param int $row Row index * @param int $col Column index * @param mixed $attributes Associative array or string of table * row attributes * @access public * @throws PEAR_Error */ function setCellAttributes($row, $col, $attributes) { if ( isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__' ) { return; } $attributes = $this->_parseAttributes($attributes); $err = $this->_adjustEnds($row, $col, 'setCellAttributes', $attributes); if (PEAR::isError($err)) { return $err; } $this->_structure[$row][$col]['attr'] = $attributes; $this->_updateSpanGrid($row, $col); } /** * Updates the cell attributes passed but leaves other existing attributes * intact * @param int $row Row index * @param int $col Column index * @param mixed $attributes Associative array or string of table row * attributes * @access public */ function updateCellAttributes($row, $col, $attributes) { if ( isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__' ) { return; } $attributes = $this->_parseAttributes($attributes); $err = $this->_adjustEnds($row, $col, 'updateCellAttributes', $attributes); if (PEAR::isError($err)) { return $err; } $this->_updateAttrArray($this->_structure[$row][$col]['attr'], $attributes); $this->_updateSpanGrid($row, $col); } /** * Returns the attributes for a given cell * @param int $row Row index * @param int $col Column index * @return array * @access public */ function getCellAttributes($row, $col) { if ( isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] != '__SPANNED__' ) { return $this->_structure[$row][$col]['attr']; } elseif (!isset($this->_structure[$row][$col])) { return PEAR::raiseError('Invalid table cell reference[' . $row . '][' . $col . '] in HTML_Table::getCellAttributes'); } return; } /** * Sets the cell contents for an existing cell * * If the given indices do not exist and autoGrow is true then the given * row and/or col is automatically added. If autoGrow is false then an * error is returned. * @param int $row Row index * @param int $col Column index * @param mixed $contents May contain html or any object with a * toHTML() method; if it is an array (with * strings and/or objects), $col will be used * as start offset and the array elements will * be set to this and the following columns * in $row * @param string $type (optional) Cell type either 'TH' or 'TD' * @access public * @throws PEAR_Error */ function setCellContents($row, $col, $contents, $type = 'TD') { if (is_array($contents)) { foreach ($contents as $singleContent) { $ret = $this->_setSingleCellContents($row, $col, $singleContent, $type); if (PEAR::isError($ret)) { return $ret; } $col++; } } else { $ret = $this->_setSingleCellContents($row, $col, $contents, $type); if (PEAR::isError($ret)) { return $ret; } } } /** * Sets the cell contents for a single existing cell * * If the given indices do not exist and autoGrow is true then the given * row and/or col is automatically added. If autoGrow is false then an * error is returned. * @param int $row Row index * @param int $col Column index * @param mixed $contents May contain html or any object with a * toHTML() method; if it is an array (with * strings and/or objects), $col will be used * as start offset and the array elements will * be set to this and the following columns * in $row * @param string $type (optional) Cell type either 'TH' or 'TD' * @access private * @throws PEAR_Error */ function _setSingleCellContents($row, $col, $contents, $type = 'TD') { if ( isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__' ) { return; } $err = $this->_adjustEnds($row, $col, 'setCellContents'); if (PEAR::isError($err)) { return $err; } $this->_structure[$row][$col]['contents'] = $contents; $this->_structure[$row][$col]['type'] = $type; } /** * Returns the cell contents for an existing cell * @param int $row Row index * @param int $col Column index * @access public * @return mixed */ function getCellContents($row, $col) { if ( isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__' ) { return; } if (!isset($this->_structure[$row][$col])) { return PEAR::raiseError('Invalid table cell reference[' . $row . '][' . $col . '] in HTML_Table::getCellContents'); } return $this->_structure[$row][$col]['contents']; } /** * Sets the contents of a header cell * @param int $row * @param int $col * @param mixed $contents * @param mixed $attributes Associative array or string of table row * attributes * @access public */ function setHeaderContents($row, $col, $contents, $attributes = null) { $this->setCellContents($row, $col, $contents, 'TH'); if (!is_null($attributes)) { $this->updateCellAttributes($row, $col, $attributes); } } /** * Adds a table row and returns the row identifier * @param array $contents (optional) Must be a indexed array of valid * cell contents * @param mixed $attributes (optional) Associative array or string of * table row attributes. This can * also be an array of attributes, * in which case the attributes * will be repeated in a loop. * @param string $type (optional) Cell type either 'th' or 'td' * @param bool $inTR false if attributes are to be * applied in TD tags; true if * attributes are to be applied in * TR tag * @return int * @access public */ function addRow($contents = null, $attributes = null, $type = 'td', $inTR = false) { if (isset($contents) && !is_array($contents)) { return PEAR::raiseError('First parameter to HTML_Table::addRow ' . 'must be an array'); } if (is_null($contents)) { $contents = array(); } $type = strtolower($type); $row = $this->_rows++; foreach ($contents as $col => $content) { if ($type == 'td') { $this->setCellContents($row, $col, $content); } elseif ($type == 'th') { $this->setHeaderContents($row, $col, $content); } } $this->setRowAttributes($row, $attributes, $inTR); return $row; } /** * Sets the row attributes for an existing row * @param int $row Row index * @param mixed $attributes Associative array or string of table * row attributes. This can also be an * array of attributes, in which case the * attributes will be repeated in a loop. * @param bool $inTR false if attributes are to be applied * in TD tags; true if attributes are to * be applied in TR tag * @access public * @throws PEAR_Error */ function setRowAttributes($row, $attributes, $inTR = false) { if (!$inTR) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_cols; $i++) { if ($multiAttr) { $this->setCellAttributes($row, $i, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->setCellAttributes($row, $i, $attributes); } } } else { $attributes = $this->_parseAttributes($attributes); $err = $this->_adjustEnds($row, 0, 'setRowAttributes', $attributes); if (PEAR::isError($err)) { return $err; } $this->_structure[$row]['attr'] = $attributes; } } /** * Updates the row attributes for an existing row * @param int $row Row index * @param mixed $attributes Associative array or string of table * row attributes * @param bool $inTR false if attributes are to be applied * in TD tags; true if attributes are to * be applied in TR tag * @access public * @throws PEAR_Error */ function updateRowAttributes($row, $attributes = null, $inTR = false) { if (!$inTR) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_cols; $i++) { if ($multiAttr) { $this->updateCellAttributes($row, $i, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->updateCellAttributes($row, $i, $attributes); } } } else { $attributes = $this->_parseAttributes($attributes); $err = $this->_adjustEnds($row, 0, 'updateRowAttributes', $attributes); if (PEAR::isError($err)) { return $err; } $this->_updateAttrArray($this->_structure[$row]['attr'], $attributes); } } /** * Returns the attributes for a given row as contained in the TR tag * @param int $row Row index * @return array * @access public */ function getRowAttributes($row) { if (isset($this->_structure[$row]['attr'])) { return $this->_structure[$row]['attr']; } return; } /** * Alternates the row attributes starting at $start * @param int $start Row index of row in which alternating * begins * @param mixed $attributes1 Associative array or string of table * row attributes * @param mixed $attributes2 Associative array or string of table * row attributes * @param bool $inTR false if attributes are to be applied * in TD tags; true if attributes are to * be applied in TR tag * @param int $firstAttributes (optional) Which attributes should be * applied to the first row, 1 or 2. * @access public */ function altRowAttributes($start, $attributes1, $attributes2, $inTR = false, $firstAttributes = 1) { for ($row = $start; $row < $this->_rows; $row++) { if (($row + $start + ($firstAttributes - 1)) % 2 == 0) { $attributes = $attributes1; } else { $attributes = $attributes2; } $this->updateRowAttributes($row, $attributes, $inTR); } } /** * Adds a table column and returns the column identifier * @param array $contents (optional) Must be a indexed array of valid * cell contents * @param mixed $attributes (optional) Associative array or string of * table row attributes * @param string $type (optional) Cell type either 'th' or 'td' * @return int * @access public */ function addCol($contents = null, $attributes = null, $type = 'td') { if (isset($contents) && !is_array($contents)) { return PEAR::raiseError('First parameter to HTML_Table::addCol ' . 'must be an array'); } if (is_null($contents)) { $contents = array(); } $type = strtolower($type); $col = $this->_cols++; foreach ($contents as $row => $content) { if ($type == 'td') { $this->setCellContents($row, $col, $content); } elseif ($type == 'th') { $this->setHeaderContents($row, $col, $content); } } $this->setColAttributes($col, $attributes); return $col; } /** * Sets the column attributes for an existing column * @param int $col Column index * @param mixed $attributes (optional) Associative array or string * of table row attributes * @access public */ function setColAttributes($col, $attributes = null) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_rows; $i++) { if ($multiAttr) { $this->setCellAttributes($i, $col, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->setCellAttributes($i, $col, $attributes); } } } /** * Updates the column attributes for an existing column * @param int $col Column index * @param mixed $attributes (optional) Associative array or string * of table row attributes * @access public */ function updateColAttributes($col, $attributes = null) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_rows; $i++) { if ($multiAttr) { $this->updateCellAttributes($i, $col, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->updateCellAttributes($i, $col, $attributes); } } } /** * Sets the attributes for all cells * @param mixed $attributes (optional) Associative array or * string of table row attributes * @access public */ function setAllAttributes($attributes = null) { for ($i = 0; $i < $this->_rows; $i++) { $this->setRowAttributes($i, $attributes); } } /** * Updates the attributes for all cells * @param mixed $attributes (optional) Associative array or * string of table row attributes * @access public */ function updateAllAttributes($attributes = null) { for ($i = 0; $i < $this->_rows; $i++) { $this->updateRowAttributes($i, $attributes); } } /** * Returns the table rows as HTML * @access public * @return string */ function toHtml($tabs = null, $tab = null) { $strHtml = ''; if (is_null($tabs)) { $tabs = $this->_getTabs(); } if (is_null($tab)) { $tab = $this->_getTab(); } $lnEnd = $this->_getLineEnd(); if ($this->_useTGroups) { $extraTab = $tab; } else { $extraTab = ''; } if ($this->_cols > 0) { for ($i = 0 ; $i < $this->_rows ; $i++) { $attr = ''; if (isset($this->_structure[$i]['attr'])) { $attr = $this->_getAttrString($this->_structure[$i]['attr']); } $strHtml .= $tabs .$tab . $extraTab . '' . $lnEnd; for ($j = 0 ; $j < $this->_cols ; $j++) { $attr = ''; $contents = ''; $type = 'td'; if (isset($this->_structure[$i][$j]) && $this->_structure[$i][$j] == '__SPANNED__') { continue; } if (isset($this->_structure[$i][$j]['type'])) { $type = (strtolower($this->_structure[$i][$j]['type']) == 'th' ? 'th' : 'td'); } if (isset($this->_structure[$i][$j]['attr'])) { $attr = $this->_structure[$i][$j]['attr']; } if (isset($this->_structure[$i][$j]['contents'])) { $contents = $this->_structure[$i][$j]['contents']; } $strHtml .= $tabs . $tab . $tab . $extraTab . "<$type" . $this->_getAttrString($attr) . '>'; if (is_object($contents)) { // changes indent and line end settings on nested tables if (is_subclass_of($contents, 'html_common')) { $contents->setTab($tab . $extraTab); $contents->setTabOffset($this->_tabOffset + 3); $contents->_nestLevel = $this->_nestLevel + 1; $contents->setLineEnd($this->_getLineEnd()); } if (method_exists($contents, 'toHtml')) { $contents = $contents->toHtml(); } elseif (method_exists($contents, 'toString')) { $contents = $contents->toString(); } } if (is_array($contents)) { $contents = implode(', ', $contents); } if (isset($this->_autoFill) && $contents === '') { $contents = $this->_autoFill; } $strHtml .= $contents; $strHtml .= "" . $lnEnd; } $strHtml .= $tabs . $tab . $extraTab . '' . $lnEnd; } } return $strHtml; } /** * Checks if rows or columns are spanned * @param int $row Row index * @param int $col Column index * @access private */ function _updateSpanGrid($row, $col) { if (isset($this->_structure[$row][$col]['attr']['colspan'])) { $colspan = $this->_structure[$row][$col]['attr']['colspan']; } if (isset($this->_structure[$row][$col]['attr']['rowspan'])) { $rowspan = $this->_structure[$row][$col]['attr']['rowspan']; } if (isset($colspan)) { for ($j = $col + 1; (($j < $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) { $this->_structure[$row][$j] = '__SPANNED__'; } } if (isset($rowspan)) { for ($i = $row + 1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) { $this->_structure[$i][$col] = '__SPANNED__'; } } if (isset($colspan) && isset($rowspan)) { for ($i = $row + 1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) { for ($j = $col + 1; (($j <= $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) { $this->_structure[$i][$j] = '__SPANNED__'; } } } } /** * Adjusts ends (total number of rows and columns) * @param int $row Row index * @param int $col Column index * @param string $method Method name of caller * Used to populate PEAR_Error if thrown. * @param array $attributes Assoc array of attributes * Default is an empty array. * @access private * @throws PEAR_Error */ function _adjustEnds($row, $col, $method, $attributes = array()) { $colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1; $rowspan = isset($attributes['rowspan']) ? $attributes['rowspan'] : 1; if (($row + $rowspan - 1) >= $this->_rows) { if ($this->_autoGrow) { $this->_rows = $row + $rowspan; } else { return PEAR::raiseError('Invalid table row reference[' . $row . '] in HTML_Table::' . $method); } } if (($col + $colspan - 1) >= $this->_cols) { if ($this->_autoGrow) { $this->_cols = $col + $colspan; } else { return PEAR::raiseError('Invalid table column reference[' . $col . '] in HTML_Table::' . $method); } } } /** * Tells if the parameter is an array of attribute arrays/strings * @param mixed $attributes Variable to test * @access private * @return bool */ function _isAttributesArray($attributes) { if (is_array($attributes) && isset($attributes[0])) { if (is_array($attributes[0]) || (is_string($attributes[0]) && count($attributes) > 1)) { return true; } } return false; } } ?> HTML_Table-1.8.3/tests/1.phpt0000644000000000000000000000056211356442106014421 0ustar rootwheel--TEST-- 1.phpt: addRow 1 row 1 column with no extra options --FILE-- $value) { $table->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test
HTML_Table-1.8.3/tests/2.phpt0000644000000000000000000000062711356442106014424 0ustar rootwheel--TEST-- 2.phpt: addRow 1 row 2 column with no extra options --FILE-- $value) { $table->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test Test
HTML_Table-1.8.3/tests/3.phpt0000644000000000000000000000075611356442106014430 0ustar rootwheel--TEST-- 3.phpt: addRow 2 row 2 column with no extra options --FILE-- $value) { $table->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test Test
Test Test
HTML_Table-1.8.3/tests/4.phpt0000644000000000000000000000124111356442106014417 0ustar rootwheel--TEST-- 4.phpt: 2 row 2 column with various options --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } // output echo $table->toHTML(); ?> --EXPECT--
Test Test
Test Test
HTML_Table-1.8.3/tests/5.phpt0000644000000000000000000000227211356442106014425 0ustar rootwheel--TEST-- 5.phpt: 3 row 3 column, setColAttributes / updateColAttributes --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } // This overwrites attrs thus removing align="right" $table->setColAttributes(0, 'bgcolor = "purple"'); // This updates attrs thus keeping aligh="right" but change bgcolor $table->updateColAttributes(2, 'bgcolor = "blue"'); // output echo $table->toHTML(); ?> --EXPECT--
Foo Bar Test
Foo Bar Test
Foo Bar Test
HTML_Table-1.8.3/tests/6.phpt0000644000000000000000000000352311356442106014426 0ustar rootwheel--TEST-- 6.phpt: 6 row 3 column, setColAttributes / updateColAttributes (switching colors on each row) --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } // This overwrites attrs thus removing align="right" $table->setColAttributes(0, 'bgcolor = "purple"'); // This updates attrs thus keeping aligh="right" but change bgcolor $table->updateColAttributes(2, array('bgcolor = "blue"', 'bgcolor="green"', 'bgcolor="red"')); // output echo $table->toHTML(); ?> --EXPECT--
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
HTML_Table-1.8.3/tests/7.phpt0000644000000000000000000000170611356442106014430 0ustar rootwheel--TEST-- 7.phpt: 3 row 3 column, getCellAttributes / getRowAttributes --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } // This overwrites attrs thus removing align="right" $table->setColAttributes(0, 'bgcolor = "purple"'); // This updates attrs, change bgcolor, but in tr $table->updateRowAttributes(2, 'bgcolor = "blue"', true); // output // row 2, cell 2 var_dump($table->getCellAttributes(2, 2)); var_dump($table->getRowAttributes(2)); ?> --EXPECT-- array(2) { ["bgcolor"]=> string(6) "yellow" ["align"]=> string(5) "right" } array(1) { ["bgcolor"]=> string(4) "blue" }HTML_Table-1.8.3/tests/8.phpt0000644000000000000000000000054211356442106014426 0ustar rootwheel--TEST-- 8.phpt: testing taboffset --FILE-- $value) { $table->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test
HTML_Table-1.8.3/tests/9.phpt0000644000000000000000000000350711356442106014433 0ustar rootwheel--TEST-- 9.phpt: 6 row 3 column, updateAllAttributes --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } // This overwrites attrs thus removing align="right" $table->setColAttributes(0, 'bgcolor = "pink"'); // This updates attrs thus keeping aligh="right" but change bgcolor $table->updateColAttributes(2, array('bgcolor = "blue"', 'bgcolor="green"', 'bgcolor="red"')); // this updates $table->updateAllAttributes('bgcolor="pink"'); // output echo $table->toHTML(); ?> --EXPECT--
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
HTML_Table-1.8.3/tests/10.phpt0000644000000000000000000000323611356442106014502 0ustar rootwheel--TEST-- 10.phpt: 6 row 3 column, setAllAttributes --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } // This overwrites attrs thus removing align="right" $table->setColAttributes(0, 'bgcolor = "pink"'); // This updates attrs thus keeping aligh="right" but change bgcolor $table->updateColAttributes(2, array('bgcolor = "blue"', 'bgcolor="green"', 'bgcolor="red"')); // this overwrites $table->setAllAttributes('bgcolor="pink"'); // output echo $table->toHTML(); ?> --EXPECT--
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
HTML_Table-1.8.3/tests/11.phpt0000644000000000000000000000074411356442106014504 0ustar rootwheel--TEST-- 11.phpt: 2 row 1 column, setAutoFill / getAutoFill --FILE-- setAutoFill('N/A'); $data[0][] = 'Test'; $data[1][] = ''; foreach($data as $key => $value) { $table->addRow($value); } echo $table->getAutoFill() . "\n"; // output echo $table->toHTML(); ?> --EXPECT-- N/A
Test
N/A
HTML_Table-1.8.3/tests/12.phpt0000644000000000000000000000104211356442106014475 0ustar rootwheel--TEST-- 12.phpt: 2 row 2 column, setAutoGrow / getAutoGrow --FILE-- setAutoGrow(true); $data[0][] = 'Test'; $data[1][] = ''; $data[1][] = 'Test'; foreach($data as $key => $value) { $table->addRow($value); } var_dump($table->getAutoGrow()); // output echo $table->toHTML(); ?> --EXPECT-- bool(true)
Test  
  Test
HTML_Table-1.8.3/tests/13.phpt0000644000000000000000000000106711356442106014505 0ustar rootwheel--TEST-- 13.phpt: 2 row 1 column, setCellContents / getCellContents --FILE-- $value) { $table->addRow($value); } echo $table->getCellContents(0, 0) . "\n"; $table->setCellContents(0, 0, 'FOOBAR'); echo $table->getCellContents(0, 0) . "\n"; // output echo $table->toHTML(); ?> --EXPECT-- Test FOOBAR
FOOBAR
 
HTML_Table-1.8.3/tests/14.phpt0000644000000000000000000000165511356442106014511 0ustar rootwheel--TEST-- 14.phpt: 3 row 3 column, setColCount / getColCount / setRowCount / getRowCount --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow"'); } echo $table->getRowCount() . "\n"; echo $table->getColCount() . "\n"; echo $table->setRowCount(2); echo $table->setColCount(2); echo $table->getRowCount() . "\n"; echo $table->getColCount() . "\n"; // output echo $table->toHTML(); ?> --EXPECT-- 3 3 2 2
Foo Bar
Foo Bar
HTML_Table-1.8.3/tests/15.phpt0000644000000000000000000000133711356442106014507 0ustar rootwheel--TEST-- 15.phpt: 2 row 2 column, setHeaderContents --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } $table->setHeaderContents(0, 0, 'Header', 'bgcolor="blue"'); // output echo $table->toHTML(); ?> --EXPECT--
Header Test
Test Test
HTML_Table-1.8.3/tests/16.phpt0000644000000000000000000000136711356442106014513 0ustar rootwheel--TEST-- 16.phpt: 2 row 2 column, setCaption --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } $table->setCaption('Foobar', 'bgcolor="green"'); // output echo $table->toHTML(); ?> --EXPECT--
Foobar
Test Test
Test Test
HTML_Table-1.8.3/tests/17.phpt0000644000000000000000000000160711356442106014511 0ustar rootwheel--TEST-- 17.phpt: 3 row 2 column, setCaption --FILE-- $value) { $table->addRow($value, 'bgcolor = "yellow" align = "right"'); } $table->setColType(0, 'TH'); $table->setRowType(1, 'TD'); $table->setRowType(2, 'TH'); // output echo $table->toHTML(); ?> --EXPECT--
Test Test
Test Test
Test Test
HTML_Table-1.8.3/tests/18.phpt0000644000000000000000000000064711356442106014515 0ustar rootwheel--TEST-- 18.phpt: addCol 1 cell 2 column with no extra options --FILE-- $value) { $table->addCol($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test
Test
HTML_Table-1.8.3/tests/19.phpt0000644000000000000000000000076111356442106014513 0ustar rootwheel--TEST-- 19.phpt: addCol 2 cell 2 column with no extra options --FILE-- $value) { $table->addCol($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test Test
Test Test
HTML_Table-1.8.3/tests/20.phpt0000755000000000000000000000104111356442106014476 0ustar rootwheel--TEST-- 20.phpt: addRow with indexed columns (row 0, col 3; row 1, col 2) --FILE-- $value) { $table->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
      Test
    Test  
HTML_Table-1.8.3/tests/21.phpt0000755000000000000000000000107011356442106014501 0ustar rootwheel--TEST-- 21.phpt: addCol with indexed rows (row 2, col 1; row 3, col 0) --FILE-- $value) { $table->addCol($value); } // output echo $table->toHTML(); ?> --EXPECT--
   
   
  Test
Test  
HTML_Table-1.8.3/tests/22.phpt0000755000000000000000000000127711356442106014513 0ustar rootwheel--TEST-- 22.phpt: thead, tfoot, tbody and addCol --FILE-- getHeader(); $tfoot =& $table->getFooter(); $tbody =& $table->getBody(); $data[0][] = 'Test'; $data[1][] = 'Test'; foreach($data as $key => $value) { $thead->addCol($value); $tfoot->addCol($value); $tbody->addCol($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test Test
Test Test
Test Test
HTML_Table-1.8.3/tests/23.phpt0000755000000000000000000000115511356442106014507 0ustar rootwheel--TEST-- 23.phpt: thead, tbody and addRow (tfoot not in output) --FILE-- getHeader(); $tbody =& $table->getBody(); $data[0][] = 'Test'; $data[1][] = 'Test'; foreach($data as $key => $value) { $thead->addRow($value); $tbody->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test
Test
Test
Test
HTML_Table-1.8.3/tests/24.phpt0000755000000000000000000000176511356442106014517 0ustar rootwheel--TEST-- 24.phpt: thead, tfoot, 2 tbodies (with ids) and addRow --FILE-- getHeader(); $tfoot =& $table->getFooter(); $tbody1 =& $table->getBody(1); $tbody1->setAttribute('id', 'tbody1'); $tbody2 =& $table->getBody(2); $tbody2->setAttribute('id', 'tbody2'); $data[0][] = 'Test'; $data[1][] = 'Test'; foreach($data as $key => $value) { $thead->addRow($value); $tfoot->addRow($value); $tbody1->addRow($value); $tbody2->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test
Test
Test
Test
Test
Test
Test
Test
HTML_Table-1.8.3/tests/25.phpt0000755000000000000000000000115511356442106014511 0ustar rootwheel--TEST-- 25.phpt: tbody, tfoot and addRow (thead not in output) --FILE-- getBody(); $tfoot =& $table->getFooter(); $data[0][] = 'Test'; $data[1][] = 'Test'; foreach($data as $key => $value) { $tbody->addRow($value); $tfoot->addRow($value); } // output echo $table->toHTML(); ?> --EXPECT--
Test
Test
Test
Test
HTML_Table-1.8.3/tests/26.phpt0000755000000000000000000000242111356442106014507 0ustar rootwheel--TEST-- 26.phpt: thead, tfoot, tbody with mixed function calls --FILE-- getHeader(); $tfoot =& $table->getFooter(); $tbody =& $table->getBody(); $thead->setHeaderContents(2, 2, 'some th content', 'bgcolor="red"'); $tfoot->setHeaderContents(1, 1, 'another th content', 'bgcolor="yellow"'); $data[0][] = 'Test'; $data[1][] = 'Test'; foreach($data as $key => $value) { $tbody->addRow($value, 'bgcolor="darkblue"'); } // output echo $table->toHTML(); ?> --EXPECT--
     
     
    some th content
     
  another th content  
Test    
Test    
HTML_Table-1.8.3/tests/27.phpt0000755000000000000000000000302711356442106014513 0ustar rootwheel--TEST-- 27.phpt: thead, tfoot, tbody with mixed function calls --FILE-- getHeader(); $tfoot =& $table->getFooter(); $tbody =& $table->getBody(); $thead->setAutoFill('foo'); $tfoot->setAutoFill('bar'); $data[0][] = 'Test'; $data[1][] = 'Test'; $data[2][] = 'Test'; foreach($data as $key => $value) { $thead->setCellAttributes($key, $key, array('style' => 'border: 1px solid purple;')); $tfoot->setCellContents($key, $key, 'some content', 'TH'); $tbody->addRow($value, 'bgcolor="darkblue"'); } // output echo $table->toHTML(); ?> --EXPECT--
foo foo foo
foo foo foo
foo foo foo
some content bar bar
bar some content bar
bar bar some content
Test    
Test    
Test    
HTML_Table-1.8.3/tests/28.phpt0000755000000000000000000000302211356442106014507 0ustar rootwheel--TEST-- 28.phpt: thead, tfoot, tbody with array functionality of setCellContents() --FILE-- getHeader(); $tfoot =& $table->getFooter(); $tbody =& $table->getBody(); $thead->setAutoFill('foo'); $tfoot->setAutoFill('bar'); $table->setAutoFill('[empty]'); $data = array(1 => 'row1', 'row2', 'row3'); foreach($data as $key => $value) { $thead->setCellContents($key, 0, $value); $tfoot->setCellContents($key, 1, $value); $tbody->setCellContents($key, 2, $value); } // output echo $table->toHTML(); ?> --EXPECT--
foo foo foo
row1 foo foo
row2 foo foo
row3 foo foo
bar bar bar
bar row1 bar
bar row2 bar
bar row3 bar
[empty] [empty] [empty]
[empty] [empty] row1
[empty] [empty] row2
[empty] [empty] row3
HTML_Table-1.8.3/tests/29.phpt0000755000000000000000000000222311356442106014512 0ustar rootwheel--TEST-- 29.phpt: colgroup usage without a col tag --FILE-- setColGroup($colgroup, $attributes); $data[0][] = 'Foo'; $data[0][] = 'Bar'; $data[0][] = 'Test'; $data[1][] = 'Foo'; $data[1][] = 'Bar'; $data[1][] = 'Test'; $data[2][] = 'Foo'; $data[2][] = 'Bar'; $data[2][] = 'Test'; $data[3][] = 'Foo'; $data[3][] = 'Bar'; $data[3][] = 'Test'; $data[4][] = 'Foo'; $data[4][] = 'Bar'; $data[4][] = 'Test'; $data[5][] = 'Foo'; $data[5][] = 'Bar'; $data[5][] = 'Test'; foreach($data as $key => $value) { $table->addRow($value); } echo $table->toHTML(); ?> --EXPECT--
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
HTML_Table-1.8.3/tests/30.phpt0000755000000000000000000000244311356442106014506 0ustar rootwheel--TEST-- 30.phpt: colgroup usage with col tags --FILE-- setColGroup($colgroup, $attributes); $data[0][] = 'Foo'; $data[0][] = 'Bar'; $data[0][] = 'Test'; $data[1][] = 'Foo'; $data[1][] = 'Bar'; $data[1][] = 'Test'; $data[2][] = 'Foo'; $data[2][] = 'Bar'; $data[2][] = 'Test'; $data[3][] = 'Foo'; $data[3][] = 'Bar'; $data[3][] = 'Test'; $data[4][] = 'Foo'; $data[4][] = 'Bar'; $data[4][] = 'Test'; $data[5][] = 'Foo'; $data[5][] = 'Bar'; $data[5][] = 'Test'; foreach($data as $key => $value) { $table->addRow($value); } echo $table->toHTML(); ?> --EXPECT--
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
Foo Bar Test
HTML_Table-1.8.3/tests/31.phpt0000755000000000000000000000377511356442106014520 0ustar rootwheel--TEST-- 29.phpt: colgroup usage with multiple colgroups --FILE-- setColGroup($colgroup, $attributes); $colgroup = array(array('class' => 'col4'), array('class' => 'col5')); $attributes = 'span="2" class="group2"'; $table->setColGroup($colgroup, $attributes); $data[0][] = 'Foo'; $data[0][] = 'Bar'; $data[0][] = 'Test'; $data[0][] = 'Test2'; $data[0][] = 'Test3'; $data[1][] = 'Foo'; $data[1][] = 'Bar'; $data[1][] = 'Test'; $data[1][] = 'Test2'; $data[1][] = 'Test3'; $data[2][] = 'Foo'; $data[2][] = 'Bar'; $data[2][] = 'Test'; $data[2][] = 'Test2'; $data[2][] = 'Test3'; $data[3][] = 'Foo'; $data[3][] = 'Bar'; $data[3][] = 'Test'; $data[3][] = 'Test2'; $data[3][] = 'Test3'; $data[4][] = 'Foo'; $data[4][] = 'Bar'; $data[4][] = 'Test'; $data[4][] = 'Test2'; $data[4][] = 'Test3'; $data[5][] = 'Foo'; $data[5][] = 'Bar'; $data[5][] = 'Test'; $data[5][] = 'Test2'; $data[5][] = 'Test3'; foreach($data as $key => $value) { $table->addRow($value); } echo $table->toHTML(); ?> --EXPECT--
Foo Bar Test Test2 Test3
Foo Bar Test Test2 Test3
Foo Bar Test Test2 Test3
Foo Bar Test Test2 Test3
Foo Bar Test Test2 Test3
Foo Bar Test Test2 Test3
HTML_Table-1.8.3/Table.php0000644000000000000000000011336511356442106013770 0ustar rootwheel, * Bertrand Mansion , * Mark Wiesemann * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_Table * @author Adam Daniel * @author Bertrand Mansion * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: Table.php 297540 2010-04-05 19:58:39Z wiesemann $ * @link http://pear.php.net/package/HTML_Table */ /** * Requires PEAR, HTML_Common and HTML_Table_Storage */ require_once 'PEAR.php'; require_once 'HTML/Common.php'; require_once 'HTML/Table/Storage.php'; /** * PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and efficient. * * The PEAR::HTML_Table package provides methods for easy and efficient design * of HTML tables. * - Lots of customization options. * - Tables can be modified at any time. * - The logic is the same as standard HTML editors. * - Handles col and rowspans. * - PHP code is shorter, easier to read and to maintain. * - Tables options can be reused. * * For auto filling of data and such then check out * http://pear.php.net/package/HTML_Table_Matrix * * @category HTML * @package HTML_Table * @author Adam Daniel * @author Bertrand Mansion * @copyright 2005-2006 The PHP Group * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_Table */ class HTML_Table extends HTML_Common { /** * Value to insert into empty cells. This is used as a default for * newly-created tbodies. * @var string * @access private */ var $_autoFill = ' '; /** * Automatically adds a new row, column, or body if a given row, column, or * body index does not exist. * This is used as a default for newly-created tbodies. * @var bool * @access private */ var $_autoGrow = true; /** * Array containing the table caption * @var array * @access private */ var $_caption = array(); /** * Array containing the table column group specifications * * @var array * @author Laurent Laville (pear at laurent-laville dot org) * @access private */ var $_colgroup = array(); /** * HTML_Table_Storage object for the (t)head of the table * @var object * @access private */ var $_thead = null; /** * HTML_Table_Storage object for the (t)foot of the table * @var object * @access private */ var $_tfoot = null; /** * HTML_Table_Storage object for the (t)body of the table * @var object * @access private */ var $_tbodies = array(); /** * Number of bodies in the table * @var int * @access private */ var $_tbodyCount = 0; /** * Whether to use , and or not * @var bool * @access private */ var $_useTGroups = false; /** * Class constructor * @param array $attributes Associative array of table tag * attributes * @param int $tabOffset Tab offset of the table * @param bool $useTGroups Whether to use , and * or not * @access public */ function HTML_Table($attributes = null, $tabOffset = 0, $useTGroups = false) { HTML_Common::HTML_Common($attributes, (int)$tabOffset); $this->_useTGroups = (boolean)$useTGroups; $this->addBody(); if ($this->_useTGroups) { $this->_thead = new HTML_Table_Storage($tabOffset, $this->_useTGroups); $this->_tfoot = new HTML_Table_Storage($tabOffset, $this->_useTGroups); } } /** * Returns the API version * @access public * @return double * @deprecated */ function apiVersion() { return 1.7; } /** * Returns the HTML_Table_Storage object for * @access public * @return object */ function &getHeader() { if (is_null($this->_thead)) { $this->_useTGroups = true; $this->_thead = new HTML_Table_Storage($this->_tabOffset, $this->_useTGroups); for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setUseTGroups(true); } } return $this->_thead; } /** * Returns the HTML_Table_Storage object for * @access public * @return object */ function &getFooter() { if (is_null($this->_tfoot)) { $this->_useTGroups = true; $this->_tfoot = new HTML_Table_Storage($this->_tabOffset, $this->_useTGroups); for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setUseTGroups(true); } } return $this->_tfoot; } /** * Returns the HTML_Table_Storage object for the specified * (or the whole table if is not used) * @param int $body (optional) The index of the body to * return. * @access public * @return object * @throws PEAR_Error */ function &getBody($body = 0) { $ret = $this->_adjustTbodyCount($body, 'getBody'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]; } /** * Adds a table body and returns the body identifier * @param mixed $attributes (optional) Associative array or * string of table body attributes * @access public * @return int */ function addBody($attributes = null) { if (!$this->_useTGroups && $this->_tbodyCount > 0) { for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setUseTGroups(true); } $this->_useTGroups = true; } $body = $this->_tbodyCount++; $this->_tbodies[$body] = new HTML_Table_Storage($this->_tabOffset, $this->_useTGroups); $this->_tbodies[$body]->setAutoFill($this->_autoFill); $this->_tbodies[$body]->setAttributes($attributes); return $body; } /** * Adjusts the number of bodies * @param int $body Body index * @param string $method Name of calling method * @access private * @throws PEAR_Error */ function _adjustTbodyCount($body, $method) { if ($this->_autoGrow) { while ($this->_tbodyCount <= (int)$body) { $this->addBody(); } } else { return PEAR::raiseError('Invalid body reference[' . $body . '] in HTML_Table::' . $method); } } /** * Sets the table caption * @param string $caption * @param mixed $attributes Associative array or string of * table row attributes * @access public */ function setCaption($caption, $attributes = null) { $attributes = $this->_parseAttributes($attributes); $this->_caption = array('attr' => $attributes, 'contents' => $caption); } /** * Sets the table columns group specifications, or removes existing ones. * * @param mixed $colgroup (optional) Columns attributes * @param mixed $attributes (optional) Associative array or string * of table row attributes * @author Laurent Laville (pear at laurent-laville dot org) * @access public */ function setColGroup($colgroup = null, $attributes = null) { if (isset($colgroup)) { $attributes = $this->_parseAttributes($attributes); $this->_colgroup[] = array('attr' => $attributes, 'contents' => $colgroup); } else { $this->_colgroup = array(); } } /** * Sets the autoFill value * @param mixed $fill Whether autoFill should be enabled or not * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function setAutoFill($fill, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'setAutoFill'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setAutoFill($fill); } else { $this->_autoFill = $fill; for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setAutoFill($fill); } } } /** * Returns the autoFill value * @param int $body (optional) The index of the body to get. * Pass null to get the default for new bodies. * @access public * @return mixed * @throws PEAR_Error */ function getAutoFill($body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'getAutoFill'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->getAutoFill(); } else { return $this->_autoFill; } } /** * Sets the autoGrow value * @param bool $grow Whether autoGrow should be enabled or not * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function setAutoGrow($grow, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'setAutoGrow'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setAutoGrow($grow); } else { $this->_autoGrow = $grow; for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setAutoGrow($grow); } } } /** * Returns the autoGrow value * @param int $body (optional) The index of the body to get. * Pass null to get the default for new bodies. * @access public * @return mixed * @throws PEAR_Error */ function getAutoGrow($body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'getAutoGrow'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->getAutoGrow(); } else { return $this->_autoGrow; } } /** * Sets the number of rows in the table body * @param int $rows The number of rows * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function setRowCount($rows, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'setRowCount'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setRowCount($rows); } /** * Sets the number of columns in the table * @param int $cols The number of columns * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function setColCount($cols, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'setColCount'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setColCount($cols); } /** * Returns the number of rows in the table * @param int $body (optional) The index of the body to get. * Pass null to get the total number of * rows in all bodies. * @access public * @return int * @throws PEAR_Error */ function getRowCount($body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'getRowCount'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->getRowCount(); } else { $rowCount = 0; for ($i = 0; $i < $this->_tbodyCount; $i++) { $rowCount += $this->_tbodies[$i]->getRowCount(); } return $rowCount; } } /** * Gets the number of columns in the table * * If a row index is specified, the count will not take * the spanned cells into account in the return value. * * @param int $row Row index to serve for cols count * @param int $body (optional) The index of the body to get. * @access public * @return int * @throws PEAR_Error */ function getColCount($row = null, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'getColCount'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->getColCount($row); } /** * Sets a rows type 'TH' or 'TD' * @param int $row Row index * @param string $type 'TH' or 'TD' * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function setRowType($row, $type, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'setRowType'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setRowType($row, $type); } /** * Sets a columns type 'TH' or 'TD' * @param int $col Column index * @param string $type 'TH' or 'TD' * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function setColType($col, $type, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'setColType'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setColType($col, $type); } else { for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setColType($col, $type); } } } /** * Sets the cell attributes for an existing cell. * * If the given indices do not exist and autoGrow is true then the given * row and/or col is automatically added. If autoGrow is false then an * error is returned. * @param int $row Row index * @param int $col Column index * @param mixed $attributes Associative array or string of * table row attributes * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function setCellAttributes($row, $col, $attributes, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'setCellAttributes'); if (PEAR::isError($ret)) { return $ret; } $ret = $this->_tbodies[$body]->setCellAttributes($row, $col, $attributes); if (PEAR::isError($ret)) { return $ret; } } /** * Updates the cell attributes passed but leaves other existing attributes * intact * @param int $row Row index * @param int $col Column index * @param mixed $attributes Associative array or string of table row * attributes * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function updateCellAttributes($row, $col, $attributes, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'updateCellAttributes'); if (PEAR::isError($ret)) { return $ret; } $ret = $this->_tbodies[$body]->updateCellAttributes($row, $col, $attributes); if (PEAR::isError($ret)) { return $ret; } } /** * Returns the attributes for a given cell * @param int $row Row index * @param int $col Column index * @param int $body (optional) The index of the body to get. * @return array * @access public * @throws PEAR_Error */ function getCellAttributes($row, $col, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'getCellAttributes'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->getCellAttributes($row, $col); } /** * Sets the cell contents for an existing cell * * If the given indices do not exist and autoGrow is true then the given * row and/or col is automatically added. If autoGrow is false then an * error is returned. * @param int $row Row index * @param int $col Column index * @param mixed $contents May contain html or any object with a * toHTML() method; it is an array (with * strings and/or objects), $col will be * used as start offset and the array * elements will be set to this and the * following columns in $row * @param string $type (optional) Cell type either 'TH' or 'TD' * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function setCellContents($row, $col, $contents, $type = 'TD', $body = 0) { $ret = $this->_adjustTbodyCount($body, 'setCellContents'); if (PEAR::isError($ret)) { return $ret; } $ret = $this->_tbodies[$body]->setCellContents($row, $col, $contents, $type); if (PEAR::isError($ret)) { return $ret; } } /** * Returns the cell contents for an existing cell * @param int $row Row index * @param int $col Column index * @param int $body (optional) The index of the body to get. * @access public * @return mixed * @throws PEAR_Error */ function getCellContents($row, $col, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'getCellContents'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->getCellContents($row, $col); } /** * Sets the contents of a header cell * @param int $row * @param int $col * @param mixed $contents * @param mixed $attributes Associative array or string of * table row attributes * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function setHeaderContents($row, $col, $contents, $attributes = null, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'setHeaderContents'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setHeaderContents($row, $col, $contents, $attributes); } /** * Adds a table row and returns the row identifier * @param array $contents (optional) Must be a indexed array of * valid cell contents * @param mixed $attributes (optional) Associative array or string * of table row attributes. This can also * be an array of attributes, in which * case the attributes will be repeated * in a loop. * @param string $type (optional) Cell type either 'th' or 'td' * @param bool $inTR false if attributes are to be applied * in TD tags; true if attributes are to * ´be applied in TR tag * @param int $body (optional) The index of the body to use. * @return int * @access public * @throws PEAR_Error */ function addRow($contents = null, $attributes = null, $type = 'td', $inTR = false, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'addRow'); if (PEAR::isError($ret)) { return $ret; } $ret = $this->_tbodies[$body]->addRow($contents, $attributes, $type, $inTR); return $ret; } /** * Sets the row attributes for an existing row * @param int $row Row index * @param mixed $attributes Associative array or string of table row * attributes. This can also be an array of * attributes, in which case the attributes * will be repeated in a loop. * @param bool $inTR false if attributes are to be applied in * TD tags; true if attributes are to be * applied in TR tag * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function setRowAttributes($row, $attributes, $inTR = false, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'setRowAttributes'); if (PEAR::isError($ret)) { return $ret; } $ret = $this->_tbodies[$body]->setRowAttributes($row, $attributes, $inTR); if (PEAR::isError($ret)) { return $ret; } } /** * Updates the row attributes for an existing row * @param int $row Row index * @param mixed $attributes Associative array or string of table row * attributes * @param bool $inTR false if attributes are to be applied in * TD tags; true if attributes are to be * applied in TR tag * @param int $body (optional) The index of the body to set. * @access public * @throws PEAR_Error */ function updateRowAttributes($row, $attributes = null, $inTR = false, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'updateRowAttributes'); if (PEAR::isError($ret)) { return $ret; } $ret = $this->_tbodies[$body]->updateRowAttributes($row, $attributes, $inTR); if (PEAR::isError($ret)) { return $ret; } } /** * Returns the attributes for a given row as contained in the TR tag * @param int $row Row index * @param int $body (optional) The index of the body to get. * @return array * @access public * @throws PEAR_Error */ function getRowAttributes($row, $body = 0) { $ret = $this->_adjustTbodyCount($body, 'getRowAttributes'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->getRowAttributes($row); } /** * Alternates the row attributes starting at $start * @param int $start Row index of row in which alternating * begins * @param mixed $attributes1 Associative array or string of table * row attributes * @param mixed $attributes2 Associative array or string of table * row attributes * @param bool $inTR false if attributes are to be applied * in TD tags; true if attributes are to * be applied in TR tag * @param int $firstAttributes (optional) Which attributes should be * applied to the first row, 1 or 2. * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function altRowAttributes($start, $attributes1, $attributes2, $inTR = false, $firstAttributes = 1, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'altRowAttributes'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->altRowAttributes($start, $attributes1, $attributes2, $inTR, $firstAttributes); } else { for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->altRowAttributes($start, $attributes1, $attributes2, $inTR, $firstAttributes); // if the tbody's row count is odd, toggle $firstAttributes to // prevent the next tbody's first row from having the same // attributes as this tbody's last row. if ($this->_tbodies[$i]->getRowCount() % 2) { $firstAttributes ^= 3; } } } } /** * Adds a table column and returns the column identifier * @param array $contents (optional) Must be a indexed array of * valid cell contents * @param mixed $attributes (optional) Associative array or string * of table row attributes * @param string $type (optional) Cell type either 'th' or 'td' * @param int $body (optional) The index of the body to use. * @return int * @access public * @throws PEAR_Error */ function addCol($contents = null, $attributes = null, $type = 'td', $body = 0) { $ret = $this->_adjustTbodyCount($body, 'addCol'); if (PEAR::isError($ret)) { return $ret; } return $this->_tbodies[$body]->addCol($contents, $attributes, $type); } /** * Sets the column attributes for an existing column * @param int $col Column index * @param mixed $attributes (optional) Associative array or string * of table row attributes * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function setColAttributes($col, $attributes = null, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'setColAttributes'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setColAttributes($col, $attributes); } else { for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setColAttributes($col, $attributes); } } } /** * Updates the column attributes for an existing column * @param int $col Column index * @param mixed $attributes (optional) Associative array or * string of table row attributes * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function updateColAttributes($col, $attributes = null, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'updateColAttributes'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->updateColAttributes($col, $attributes); } else { for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->updateColAttributes($col, $attributes); } } } /** * Sets the attributes for all cells * @param mixed $attributes (optional) Associative array or * string of table row attributes * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function setAllAttributes($attributes = null, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'setAllAttributes'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->setAllAttributes($attributes); } else { for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setAllAttributes($attributes); } } } /** * Updates the attributes for all cells * @param mixed $attributes (optional) Associative array or string * of table row attributes * @param int $body (optional) The index of the body to set. * Pass null to set for all bodies. * @access public * @throws PEAR_Error */ function updateAllAttributes($attributes = null, $body = null) { if (!is_null($body)) { $ret = $this->_adjustTbodyCount($body, 'updateAllAttributes'); if (PEAR::isError($ret)) { return $ret; } $this->_tbodies[$body]->updateAllAttributes($attributes); } else { for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->updateAllAttributes($attributes); } } } /** * Returns the table structure as HTML * @access public * @return string */ function toHtml() { $strHtml = ''; $tabs = $this->_getTabs(); $tab = $this->_getTab(); $lnEnd = $this->_getLineEnd(); $tBodyColCounts = array(); for ($i = 0; $i < $this->_tbodyCount; $i++) { $tBodyColCounts[] = $this->_tbodies[$i]->getColCount(); } $tBodyMaxColCount = 0; if (count($tBodyColCounts) > 0) { $tBodyMaxColCount = max($tBodyColCounts); } if ($this->_comment) { $strHtml .= $tabs . "" . $lnEnd; } if ($this->getRowCount() > 0 && $tBodyMaxColCount > 0) { $strHtml .= $tabs . '_getAttrString($this->_attributes) . '>' . $lnEnd; if (!empty($this->_caption)) { $attr = $this->_caption['attr']; $contents = $this->_caption['contents']; $strHtml .= $tabs . $tab . '_getAttrString($attr) . '>'; if (is_array($contents)) { $contents = implode(', ', $contents); } $strHtml .= $contents; $strHtml .= '' . $lnEnd; } if (!empty($this->_colgroup)) { foreach ($this->_colgroup as $g => $col) { $attr = $this->_colgroup[$g]['attr']; $contents = $this->_colgroup[$g]['contents']; $strHtml .= $tabs . $tab . '_getAttrString($attr) . '>'; if (!empty($contents)) { $strHtml .= $lnEnd; if (!is_array($contents)) { $contents = array($contents); } foreach ($contents as $a => $colAttr) { $attr = $this->_parseAttributes($colAttr); $strHtml .= $tabs . $tab . $tab . '_getAttrString($attr) . ' />' . $lnEnd; } $strHtml .= $tabs . $tab; } $strHtml .= '' . $lnEnd; } } if ($this->_useTGroups) { $tHeadColCount = 0; if ($this->_thead !== null) { $tHeadColCount = $this->_thead->getColCount(); } $tFootColCount = 0; if ($this->_tfoot !== null) { $tFootColCount = $this->_tfoot->getColCount(); } $maxColCount = max($tHeadColCount, $tFootColCount, $tBodyMaxColCount); if ($this->_thead !== null) { $this->_thead->setColCount($maxColCount); if ($this->_thead->getRowCount() > 0) { $strHtml .= $tabs . $tab . '_getAttrString($this->_thead->_attributes) . '>' . $lnEnd; $strHtml .= $this->_thead->toHtml($tabs, $tab); $strHtml .= $tabs . $tab . '' . $lnEnd; } } if ($this->_tfoot !== null) { $this->_tfoot->setColCount($maxColCount); if ($this->_tfoot->getRowCount() > 0) { $strHtml .= $tabs . $tab . '_getAttrString($this->_tfoot->_attributes) . '>' . $lnEnd; $strHtml .= $this->_tfoot->toHtml($tabs, $tab); $strHtml .= $tabs . $tab . '' . $lnEnd; } } for ($i = 0; $i < $this->_tbodyCount; $i++) { $this->_tbodies[$i]->setColCount($maxColCount); if ($this->_tbodies[$i]->getRowCount() > 0) { $strHtml .= $tabs . $tab . '_getAttrString($this->_tbodies[$i]->_attributes) . '>' . $lnEnd; $strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab); $strHtml .= $tabs . $tab . '' . $lnEnd; } } } else { for ($i = 0; $i < $this->_tbodyCount; $i++) { $strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab); } } $strHtml .= $tabs . '' . $lnEnd; } return $strHtml; } /** * Returns the table structure as HTML * @access public * @return string */ function __toString() { return $this->toHtml(); } } ?>