| version 1.1, 2005/06/05 12:14:16 |
version 1.2, 2005/11/07 20:37:33 |
|
|
| <?php |
<?php |
| /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
| // +----------------------------------------------------------------------+ |
|
| // | PHP Version 4 | |
/** |
| // +----------------------------------------------------------------------+ |
* PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and efficient. |
| // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | |
* |
| // +----------------------------------------------------------------------+ |
* The PEAR::HTML_Table package provides methods for easy and efficient design of HTML tables. |
| // | This source file is subject to version 2.0 of the PHP license, | |
* - Lots of customization options. |
| // | that is bundled with this package in the file LICENSE, and is | |
* - Tables can be modified at any time. |
| // | available at through the world-wide-web at | |
* - The logic is the same as standard HTML editors. |
| // | http://www.php.net/license/2_02.txt. | |
* - Handles col and rowspans. |
| // | If you did not receive a copy of the PHP license and are unable to | |
* - PHP code is shorter, easier to read and to maintain. |
| // | obtain it through the world-wide-web, please send a note to | |
* - Tables options can be reused. |
| // | license@php.net so we can mail you a copy immediately. | |
* |
| // +----------------------------------------------------------------------+ |
* For auto filling of data and such then check out http://pear.php.net/package/HTML_Table_Matrix |
| // | Authors: Adam Daniel <adaniel1@eesus.jnj.com> | |
* |
| // | Bertrand Mansion <bmansion@mamasam.com> | |
* PHP versions 4 |
| // +----------------------------------------------------------------------+ |
* |
| // |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
| // $Id$ |
* that is available through the world-wide-web at the following URI: |
| |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
| |
* the PHP License and are unable to obtain it through the web, please |
| |
* send a note to license@php.net so we can mail you a copy immediately. |
| |
* |
| |
* @category HTML |
| |
* @package HTML_Table |
| |
* @author Adam Daniel <adaniel1@eesus.jnj.com> |
| |
* @author Bertrand Mansion <bmansion@mamasam.com> |
| |
* @copyright 2005 The PHP Group |
| |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| |
* @version CVS: $Id$ |
| |
* @link http://pear.php.net/package/HTML_Table |
| |
*/ |
| |
|
| require_once "PEAR.php"; |
|
| require_once "HTML/Common.php"; |
|
| |
|
| /** |
/** |
| * Builds an HTML table |
* Requires PEAR, HTML_Common and HTML_Table_Storage |
| * @author Adam Daniel <adaniel1@eesus.jnj.com> |
*/ |
| * @author Bertrand Mansion <bmansion@mamasam.com> |
require_once 'PEAR.php'; |
| * @version 1.7 |
require_once 'HTML/Common.php'; |
| * @since PHP 4.0.3pl1 |
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 <adaniel1@eesus.jnj.com> |
| |
* @author Bertrand Mansion <bmansion@mamasam.com> |
| |
* @copyright 2005 The PHP Group |
| |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| |
* @version Release: @package_version@ |
| |
* @link http://pear.php.net/package/HTML_Table |
| */ |
*/ |
| class HTML_Table extends HTML_Common { |
class HTML_Table extends HTML_Common { |
| |
|
| /** |
/** |
| * Automatically adds a new row or column if a given row or column index does not exist |
|
| * @var bool |
|
| * @access private |
|
| */ |
|
| var $_autoGrow = true; |
|
| |
|
| /** |
|
| * Value to insert into empty cells |
* Value to insert into empty cells |
| * @var string |
* @var string |
| * @access private |
* @access private |
| */ |
*/ |
| var $_autoFill = " "; |
var $_autoFill = ' '; |
| |
|
| /** |
/** |
| * Array containing the table structure |
* Array containing the table caption |
| * @var array |
* @var array |
| * @access private |
* @access private |
| */ |
*/ |
| var $_structure = array(); |
var $_caption = array(); |
| |
|
| /** |
/** |
| * Number of rows composing in the table |
* HTML_Table_Storage object for the (t)head of the table |
| * @var int |
* @var object |
| * @access private |
* @access private |
| */ |
*/ |
| var $_rows = 0; |
var $_thead = null; |
| |
|
| /** |
/** |
| * Number of column composing the table |
* HTML_Table_Storage object for the (t)foot of the table |
| * @var int |
* @var object |
| * @access private |
* @access private |
| */ |
*/ |
| var $_cols = 0; |
var $_tfoot = null; |
| |
|
| /** |
/** |
| * Tracks the level of nested tables |
* HTML_Table_Storage object for the (t)body of the table |
| * @var int |
* @var object |
| * @access private |
* @access private |
| */ |
*/ |
| var $_nestLevel = 0; |
var $_tbody = null; |
| |
|
| |
/** |
| |
* Whether to use <thead>, <tfoot> and <tbody> or not |
| |
* @var bool |
| |
* @access private |
| |
*/ |
| |
var $_useTGroups = false; |
| |
|
| /** |
/** |
| * Class constructor |
* Class constructor |
| * @param array $attributes Associative array of table tag attributes |
* @param array $attributes Associative array of table tag attributes |
| * @param int $tabOffset |
* @param int $tabOffset Tab offset of the table |
| |
* @param bool $useTGroups Whether to use <thead>, <tfoot> and |
| |
* <tbody> or not |
| * @access public |
* @access public |
| */ |
*/ |
| function HTML_Table($attributes = null, $tabOffset = 0) |
function HTML_Table($attributes = null, $tabOffset = 0, $useTGroups = false) |
| { |
{ |
| $commonVersion = 1.7; |
$commonVersion = 1.7; |
| if (HTML_Common::apiVersion() < $commonVersion) { |
if (HTML_Common::apiVersion() < $commonVersion) { |
| return PEAR::raiseError("HTML_Table version " . $this->apiVersion() . " requires " . |
return PEAR::raiseError('HTML_Table version ' . $this->apiVersion() . ' requires ' . |
| "HTML_Common version $commonVersion or greater.", 0, PEAR_ERROR_TRIGGER); |
"HTML_Common version $commonVersion or greater.", 0, PEAR_ERROR_TRIGGER); |
| } |
} |
| HTML_Common::HTML_Common($attributes, $tabOffset); |
HTML_Common::HTML_Common($attributes, (int)$tabOffset); |
| } // end constructor |
$this->_useTGroups = (boolean)$useTGroups; |
| |
$this->_tbody =& new HTML_Table_Storage($attributes, $tabOffset, $this->_useTGroups); |
| |
if ($this->_useTGroups) { |
| |
$this->_thead =& new HTML_Table_Storage($attributes, $tabOffset, $this->_useTGroups); |
| |
$this->_tfoot =& new HTML_Table_Storage($attributes, $tabOffset, $this->_useTGroups); |
| |
} |
| |
} |
| |
|
| /** |
/** |
| * Returns the API version |
* Returns the API version |
| Line 97 class HTML_Table extends HTML_Common { |
|
| Line 138 class HTML_Table extends HTML_Common { |
|
| function apiVersion() |
function apiVersion() |
| { |
{ |
| return 1.7; |
return 1.7; |
| } // end func apiVersion |
} |
| |
|
| |
/** |
| |
* Returns the HTML_Table_Storage object for <thead> |
| |
* @access public |
| |
* @return object |
| |
*/ |
| |
function &getHeader() |
| |
{ |
| |
if (is_null($this->_thead)) { |
| |
$this->_useTGroups = true; |
| |
$this->_thead =& new HTML_Table_Storage($this->_attributes, |
| |
$this->_tabOffset, $this->_useTGroups); |
| |
$this->_tbody->setUseTGroups(true); |
| |
} |
| |
return $this->_thead; |
| |
} |
| |
|
| |
/** |
| |
* Returns the HTML_Table_Storage object for <tfoot> |
| |
* @access public |
| |
* @return object |
| |
*/ |
| |
function &getFooter() |
| |
{ |
| |
if (is_null($this->_tfoot)) { |
| |
$this->_useTGroups = true; |
| |
$this->_tfoot =& new HTML_Table_Storage($this->_attributes, |
| |
$this->_tabOffset, $this->_useTGroups); |
| |
$this->_tbody->setUseTGroups(true); |
| |
} |
| |
return $this->_tfoot; |
| |
} |
| |
|
| |
/** |
| |
* Returns the HTML_Table_Storage object for <tbody> |
| |
* (or the whole table if <t{head|foot|body> is not used) |
| |
* @access public |
| |
* @return object |
| |
*/ |
| |
function &getBody() |
| |
{ |
| |
return $this->_tbody; |
| |
} |
| |
|
| /** |
/** |
| * Sets the table caption |
* Sets the table caption |
| Line 108 class HTML_Table extends HTML_Common { |
|
| Line 192 class HTML_Table extends HTML_Common { |
|
| function setCaption($caption, $attributes = null) |
function setCaption($caption, $attributes = null) |
| { |
{ |
| $attributes = $this->_parseAttributes($attributes); |
$attributes = $this->_parseAttributes($attributes); |
| $this->_structure["caption"] = array("attr" => $attributes, "contents" => $caption); |
$this->_caption = array('attr' => $attributes, 'contents' => $caption); |
| } // end func setCaption |
} |
| |
|
| /** |
/** |
| * Sets the autoFill value |
* Sets the autoFill value |
| Line 118 class HTML_Table extends HTML_Common { |
|
| Line 202 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setAutoFill($fill) |
function setAutoFill($fill) |
| { |
{ |
| $this->_autoFill = $fill; |
$this->_tbody->setAutoFill($fill); |
| } // end func setAutoFill |
} |
| |
|
| /** |
/** |
| * Returns the autoFill value |
* Returns the autoFill value |
| Line 128 class HTML_Table extends HTML_Common { |
|
| Line 212 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function getAutoFill() |
function getAutoFill() |
| { |
{ |
| return $this->_autoFill; |
return $this->_tbody->getAutoFill(); |
| } // end func getAutoFill |
} |
| |
|
| /** |
/** |
| * Sets the autoGrow value |
* Sets the autoGrow value |
| Line 138 class HTML_Table extends HTML_Common { |
|
| Line 222 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setAutoGrow($grow) |
function setAutoGrow($grow) |
| { |
{ |
| $this->_autoGrow = $grow; |
$this->_tbody->setAutoGrow($grow); |
| } // end func setAutoGrow |
} |
| |
|
| /** |
/** |
| * Returns the autoGrow value |
* Returns the autoGrow value |
| Line 148 class HTML_Table extends HTML_Common { |
|
| Line 232 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function getAutoGrow() |
function getAutoGrow() |
| { |
{ |
| return $this->_autoGrow; |
return $this->_tbody->getAutoGrow(); |
| } // end func getAutoGrow |
} |
| |
|
| /** |
/** |
| * Sets the number of rows in the table |
* Sets the number of rows in the table |
| Line 158 class HTML_Table extends HTML_Common { |
|
| Line 242 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setRowCount($rows) |
function setRowCount($rows) |
| { |
{ |
| $this->_rows = $rows; |
$this->_tbody->setRowCount($rows); |
| } // end func setRowCount |
} |
| |
|
| /** |
/** |
| * Sets the number of columns in the table |
* Sets the number of columns in the table |
| Line 168 class HTML_Table extends HTML_Common { |
|
| Line 252 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setColCount($cols) |
function setColCount($cols) |
| { |
{ |
| $this->_cols = $cols; |
$this->_tbody->setColCount($cols); |
| } // end func setColCount |
} |
| |
|
| /** |
/** |
| * Returns the number of rows in the table |
* Returns the number of rows in the table |
| Line 178 class HTML_Table extends HTML_Common { |
|
| Line 262 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function getRowCount() |
function getRowCount() |
| { |
{ |
| return $this->_rows; |
return $this->_tbody->getRowCount(); |
| } // end func getRowCount |
} |
| |
|
| /** |
/** |
| * Sets the number of columns in the table |
* 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 |
* @access public |
| * @return int |
* @return int |
| */ |
*/ |
| function getColCount() |
function getColCount($row = null) |
| { |
{ |
| return $this->_cols; |
return $this->_tbody->getColCount($row); |
| } // end func getColCount |
} |
| |
|
| /** |
/** |
| * Sets a rows type 'TH' or 'TD' |
* Sets a rows type 'TH' or 'TD' |
| Line 200 class HTML_Table extends HTML_Common { |
|
| Line 289 class HTML_Table extends HTML_Common { |
|
| |
|
| function setRowType($row, $type) |
function setRowType($row, $type) |
| { |
{ |
| for ($counter = 0; $counter < $this->_cols; $counter++) { |
$this->_tbody->setRowType($row, $type); |
| $this->_structure[$row][$counter]["type"] = $type; |
} |
| } |
|
| } // end func setRowType |
|
| |
|
| /** |
/** |
| * Sets a columns type 'TH' or 'TD' |
* Sets a columns type 'TH' or 'TD' |
| Line 213 class HTML_Table extends HTML_Common { |
|
| Line 300 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setColType($col, $type) |
function setColType($col, $type) |
| { |
{ |
| for ($counter = 0; $counter < $this->_rows; $counter++) { |
$this->_tbody->setColType($col, $type); |
| $this->_structure[$counter][$col]["type"] = $type; |
} |
| } |
|
| } // end func setColType |
|
| |
|
| /** |
/** |
| * Sets the cell attributes for an existing cell. |
* Sets the cell attributes for an existing cell. |
| Line 232 class HTML_Table extends HTML_Common { |
|
| Line 317 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setCellAttributes($row, $col, $attributes) |
function setCellAttributes($row, $col, $attributes) |
| { |
{ |
| if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return; |
$ret = $this->_tbody->setCellAttributes($row, $col, $attributes); |
| $attributes = $this->_parseAttributes($attributes); |
if (PEAR::isError($ret)) { |
| $err = $this->_adjustEnds($row, $col, 'setCellAttributes', $attributes); |
return $ret; |
| if (PEAR::isError($err)) { |
} |
| return $err; |
} |
| } |
|
| $this->_structure[$row][$col]["attr"] = $attributes; |
|
| $this->_updateSpanGrid($row, $col); |
|
| } // end func setCellAttributes |
|
| |
|
| /** |
/** |
| * Updates the cell attributes passed but leaves other existing attributes in tact |
* Updates the cell attributes passed but leaves other existing attributes in tact |
| Line 251 class HTML_Table extends HTML_Common { |
|
| Line 332 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function updateCellAttributes($row, $col, $attributes) |
function updateCellAttributes($row, $col, $attributes) |
| { |
{ |
| if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return; |
$ret = $this->_tbody->updateCellAttributes($row, $col, $attributes); |
| $attributes = $this->_parseAttributes($attributes); |
if (PEAR::isError($ret)) { |
| $err = $this->_adjustEnds($row, $col, 'updateCellAttributes', $attributes); |
return $ret; |
| if (PEAR::isError($err)) { |
} |
| return $err; |
} |
| } |
|
| $this->_updateAttrArray($this->_structure[$row][$col]["attr"], $attributes); |
|
| $this->_updateSpanGrid($row, $col); |
|
| } // end func updateCellAttributes |
|
| |
|
| /** |
/** |
| * Returns the attributes for a given cell |
* Returns the attributes for a given cell |
| Line 270 class HTML_Table extends HTML_Common { |
|
| Line 347 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function getCellAttributes($row, $col) |
function getCellAttributes($row, $col) |
| { |
{ |
| if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] != '__SPANNED__') { |
return $this->_tbody->getCellAttributes($row, $col); |
| 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; |
|
| } // end func getCellAttributes |
|
| |
|
| /** |
/** |
| * Sets the cell contents for an existing cell |
* Sets the cell contents for an existing cell |
| Line 287 class HTML_Table extends HTML_Common { |
|
| Line 358 class HTML_Table extends HTML_Common { |
|
| * error is returned. |
* error is returned. |
| * @param int $row Row index |
* @param int $row Row index |
| * @param int $col Column index |
* @param int $col Column index |
| * @param mixed $contents May contain html or any object with a toHTML method |
* @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' |
* @param string $type (optional) Cell type either 'TH' or 'TD' |
| * @access public |
* @access public |
| * @throws PEAR_Error |
* @throws PEAR_Error |
| */ |
*/ |
| function setCellContents($row, $col, $contents, $type = 'TD') |
function setCellContents($row, $col, $contents, $type = 'TD') |
| { |
{ |
| if(isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return; |
$ret = $this->_tbody->setCellContents($row, $col, $contents, $type); |
| $err = $this->_adjustEnds($row, $col, 'setCellContents'); |
if (PEAR::isError($ret)) { |
| if (PEAR::isError($err)) { |
return $ret; |
| return $err; |
} |
| } |
} |
| $this->_structure[$row][$col]['contents'] = $contents; |
|
| $this->_structure[$row][$col]['type'] = $type; |
|
| } // end func setCellContents |
|
| |
|
| /** |
/** |
| * Returns the cell contents for an existing cell |
* Returns the cell contents for an existing cell |
| Line 312 class HTML_Table extends HTML_Common { |
|
| Line 383 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function getCellContents($row, $col) |
function getCellContents($row, $col) |
| { |
{ |
| if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return; |
return $this->_tbody->getCellContents($row, $col); |
| return $this->_structure[$row][$col]["contents"]; |
} |
| } // end func getCellContents |
|
| |
|
| /** |
/** |
| * Sets the contents of a header cell |
* Sets the contents of a header cell |
| * @param int $row |
* @param int $row |
| * @param int $col |
* @param int $col |
| * @param mixed $contents |
* @param mixed $contents |
| |
* @param mixed $attributes Associative array or string of table row attributes |
| * @access public |
* @access public |
| */ |
*/ |
| function setHeaderContents($row, $col, $contents) |
function setHeaderContents($row, $col, $contents, $attributes = null) |
| { |
{ |
| $this->setCellContents($row, $col, $contents, 'TH'); |
$this->_tbody->setHeaderContents($row, $col, $contents, $attributes); |
| } // end func setHeaderContents |
} |
| |
|
| /** |
/** |
| * Adds a table row and returns the row identifier |
* Adds a table row and returns the row identifier |
| Line 334 class HTML_Table extends HTML_Common { |
|
| Line 405 class HTML_Table extends HTML_Common { |
|
| * @param mixed $attributes (optional) Associative array or string of table row attributes |
* @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 |
* This can also be an array of attributes, in which case the attributes |
| * will be repeated in a loop. |
* will be repeated in a loop. |
| * @param string $type (optional) Cell type either 'TH' or 'TD' |
* @param string $type (optional) Cell type either 'th' or 'td' |
| * @param bool $inTR false if attributes are to be applied in TD tags |
* @param bool $inTR false if attributes are to be applied in TD tags |
| * true if attributes are to be applied in TR tag |
* true if attributes are to be applied in TR tag |
| * @return int |
* @return int |
| * @access public |
* @access public |
| */ |
*/ |
| function addRow($contents = null, $attributes = null, $type = 'TD', $inTR = false) |
function addRow($contents = null, $attributes = null, $type = 'td', $inTR = false) |
| { |
{ |
| if (isset($contents) && !is_array($contents)) { |
$ret = $this->_tbody->addRow($contents, $attributes, $type, $inTR); |
| return PEAR::raiseError("First parameter to HTML_Table::addRow must be an array"); |
return $ret; |
| } |
} |
| $row = $this->_rows++; |
|
| for ($counter = 0; $counter < count($contents); $counter++) { |
|
| if ($type == 'TD') { |
|
| $this->setCellContents($row, $counter, $contents[$counter]); |
|
| } elseif ($type == 'TH') { |
|
| $this->setHeaderContents($row, $counter, $contents[$counter]); |
|
| } |
|
| } |
|
| $this->setRowAttributes($row, $attributes, $inTR); |
|
| return $row; |
|
| } // end func addRow |
|
| |
|
| /** |
/** |
| * Sets the row attributes for an existing row |
* Sets the row attributes for an existing row |
| Line 370 class HTML_Table extends HTML_Common { |
|
| Line 430 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setRowAttributes($row, $attributes, $inTR = false) |
function setRowAttributes($row, $attributes, $inTR = false) |
| { |
{ |
| $multiAttr = $this->_isAttributesArray($attributes); |
$ret = $this->_tbody->setRowAttributes($row, $attributes, $inTR); |
| if (!$inTR) { |
if (PEAR::isError($ret)) { |
| for ($i = 0; $i < $this->_cols; $i++) { |
return $ret; |
| 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, 1, 'setRowAttributes', $attributes); |
|
| if (PEAR::isError($err)) { |
|
| return $err; |
|
| } |
|
| $this->_structure[$row]['attr'] = $attributes; |
|
| } |
} |
| } // end func setRowAttributes |
} |
| |
|
| /** |
/** |
| * Updates the row attributes for an existing row |
* Updates the row attributes for an existing row |
| Line 401 class HTML_Table extends HTML_Common { |
|
| Line 447 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function updateRowAttributes($row, $attributes = null, $inTR = false) |
function updateRowAttributes($row, $attributes = null, $inTR = false) |
| { |
{ |
| $multiAttr = $this->_isAttributesArray($attributes); |
$ret = $this->_tbody->updateRowAttributes($row, $attributes, $inTR); |
| if (!$inTR) { |
if (PEAR::isError($ret)) { |
| for ($i = 0; $i < $this->_cols; $i++) { |
return $ret; |
| 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, 1, 'updateRowAttributes', $attributes); |
|
| if (PEAR::isError($err)) { |
|
| return $err; |
|
| } |
|
| $this->_updateAttrArray($this->_structure[$row]['attr'], $attributes); |
|
| } |
} |
| } // end func updateRowAttributes |
} |
| |
|
| /** |
/** |
| * Returns the attributes for a given row as contained in the TR tag |
* Returns the attributes for a given row as contained in the TR tag |
| Line 429 class HTML_Table extends HTML_Common { |
|
| Line 461 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function getRowAttributes($row) |
function getRowAttributes($row) |
| { |
{ |
| if (isset($this->_structure[$row]['attr'])) { |
return $this->_tbody->getRowAttributes($row); |
| return $this->_structure[$row]['attr']; |
} |
| } |
|
| return; |
|
| } // end func getRowAttributes |
|
| |
|
| /** |
/** |
| * Alternates the row attributes starting at $start |
* Alternates the row attributes starting at $start |
| Line 446 class HTML_Table extends HTML_Common { |
|
| Line 475 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function altRowAttributes($start, $attributes1, $attributes2, $inTR = false) |
function altRowAttributes($start, $attributes1, $attributes2, $inTR = false) |
| { |
{ |
| for ($row = $start ; $row < $this->_rows ; $row++) { |
$this->_tbody->altRowAttributes($start, $attributes1, $attributes2, $inTR); |
| $attributes = ( ($row+$start)%2 == 0 ) ? $attributes1 : $attributes2; |
} |
| $this->updateRowAttributes($row, $attributes, $inTR); |
|
| } |
|
| } // end func altRowAttributes |
|
| |
|
| /** |
/** |
| * Adds a table column and returns the column identifier |
* Adds a table column and returns the column identifier |
| * @param array $contents (optional) Must be a indexed array of valid cell contents |
* @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 mixed $attributes (optional) Associative array or string of table row attributes |
| * @param string $type (optional) Cell type either 'TH' or 'TD' |
* @param string $type (optional) Cell type either 'th' or 'td' |
| * @return int |
* @return int |
| * @access public |
* @access public |
| */ |
*/ |
| function addCol($contents = null, $attributes = null, $type = 'TD') |
function addCol($contents = null, $attributes = null, $type = 'td') |
| { |
{ |
| if (isset($contents) && !is_array($contents)) { |
return $this->_tbody->addCol($contents, $attributes, $type); |
| return PEAR::raiseError("First parameter to HTML_Table::addCol must be an array"); |
} |
| } |
|
| $col = $this->_cols++; |
|
| for ($counter = 0; $counter < count($contents); $counter++) { |
|
| $this->setCellContents($counter, $col, $contents[$counter], $type); |
|
| } |
|
| $this->setColAttributes($col, $attributes); |
|
| return $col; |
|
| } // end func addCol |
|
| |
|
| /** |
/** |
| * Sets the column attributes for an existing column |
* Sets the column attributes for an existing column |
| Line 481 class HTML_Table extends HTML_Common { |
|
| Line 499 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setColAttributes($col, $attributes = null) |
function setColAttributes($col, $attributes = null) |
| { |
{ |
| $multiAttr = $this->_isAttributesArray($attributes); |
$this->_tbody->setColAttributes($col, $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); |
|
| } |
|
| } |
|
| } // end func setColAttributes |
|
| |
|
| /** |
/** |
| * Updates the column attributes for an existing column |
* Updates the column attributes for an existing column |
| Line 500 class HTML_Table extends HTML_Common { |
|
| Line 510 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function updateColAttributes($col, $attributes = null) |
function updateColAttributes($col, $attributes = null) |
| { |
{ |
| $multiAttr = $this->_isAttributesArray($attributes); |
$this->_tbody->updateColAttributes($col, $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); |
|
| } |
|
| } |
|
| } // end func updateColAttributes |
|
| |
|
| /** |
/** |
| * Sets the attributes for all cells |
* Sets the attributes for all cells |
| Line 518 class HTML_Table extends HTML_Common { |
|
| Line 520 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function setAllAttributes($attributes = null) |
function setAllAttributes($attributes = null) |
| { |
{ |
| for ($i = 0; $i < $this->_rows; $i++) { |
$this->_tbody->setAllAttributes($attributes); |
| $this->setRowAttributes($i, $attributes); |
} |
| } |
|
| } // end func setAllAttributes |
|
| |
|
| /** |
/** |
| * Updates the attributes for all cells |
* Updates the attributes for all cells |
| Line 530 class HTML_Table extends HTML_Common { |
|
| Line 530 class HTML_Table extends HTML_Common { |
|
| */ |
*/ |
| function updateAllAttributes($attributes = null) |
function updateAllAttributes($attributes = null) |
| { |
{ |
| for ($i = 0; $i < $this->_rows; $i++) { |
$this->_tbody->updateAllAttributes($attributes); |
| $this->updateRowAttributes($i, $attributes); |
} |
| } |
|
| } // end func updateAllAttributes |
|
| |
|
| /** |
/** |
| * Returns the table structure as HTML |
* Returns the table structure as HTML |
| Line 550 class HTML_Table extends HTML_Common { |
|
| Line 548 class HTML_Table extends HTML_Common { |
|
| $strHtml .= $tabs . "<!-- $this->_comment -->" . $lnEnd; |
$strHtml .= $tabs . "<!-- $this->_comment -->" . $lnEnd; |
| } |
} |
| $strHtml .= |
$strHtml .= |
| $tabs . "<table" . $this->_getAttrString($this->_attributes) . ">" . $lnEnd; |
$tabs . '<table' . $this->_getAttrString($this->_attributes) . '>' . $lnEnd; |
| if (!empty($this->_structure["caption"])) { |
if (!empty($this->_caption)) { |
| $attr = $this->_structure["caption"]["attr"]; |
$attr = $this->_caption['attr']; |
| $contents = $this->_structure["caption"]["contents"]; |
$contents = $this->_caption['contents']; |
| $strHtml .= $tabs . $tab . "<caption" . $this->_getAttrString($attr) . ">"; |
$strHtml .= $tabs . $tab . '<caption' . $this->_getAttrString($attr) . '>'; |
| if (is_array($contents)) $contents = implode(", ", $contents); |
if (is_array($contents)) { |
| |
$contents = implode(', ', $contents); |
| |
} |
| $strHtml .= $contents; |
$strHtml .= $contents; |
| $strHtml .= "</caption>" . $lnEnd; |
$strHtml .= '</caption>' . $lnEnd; |
| } |
} |
| for ($i = 0 ; $i < $this->_rows ; $i++) { |
if ($this->_useTGroups) { |
| if (isset($this->_structure[$i]['attr'])) { |
$tHeadColCount = 0; |
| $strHtml .= $tabs . $tab . "<tr".$this->_getAttrString($this->_structure[$i]['attr']).">" . $lnEnd; |
if ($this->_thead !== null) { |
| } else { |
$tHeadColCount = $this->_thead->getColCount(); |
| $strHtml .= $tabs .$tab . "<tr>" . $lnEnd; |
} |
| } |
$tFootColCount = 0; |
| for ($j = 0 ; $j < $this->_cols ; $j++) { |
if ($this->_tfoot !== null) { |
| if (isset($this -> _structure[$i][$j]) && $this->_structure[$i][$j] == "__SPANNED__") { |
$tFootColCount = $this->_tfoot->getColCount(); |
| $strHtml .= $tabs . $tab . $tab ."<!-- span -->" . $lnEnd; |
} |
| continue; |
$tBodyColCount = 0; |
| } |
if ($this->_tbody !== null) { |
| if (isset($this->_structure[$i][$j]["type"])) { |
$tBodyColCount = $this->_tbody->getColCount(); |
| $type = (strtoupper($this->_structure[$i][$j]["type"]) == "TH" ? "th" : "td"); |
} |
| } else { |
$maxColCount = max($tHeadColCount, $tFootColCount, $tBodyColCount); |
| $type = "td"; |
if ($this->_thead !== null) { |
| } |
$this->_thead->setColCount($maxColCount); |
| if (isset($this->_structure[$i][$j]["attr"])) { |
if ($this->_thead->getRowCount() > 0) { |
| $attr = $this->_structure[$i][$j]["attr"]; |
$strHtml .= $tabs . $tab . '<thead>' . $lnEnd; |
| } else { |
$strHtml .= $this->_thead->toHtml(); |
| $attr = ""; |
$strHtml .= $tabs . $tab . '</thead>' . $lnEnd; |
| } |
|
| if (isset($this->_structure[$i][$j]["contents"])) { |
|
| $contents = $this->_structure[$i][$j]["contents"]; |
|
| } else { |
|
| $contents = ""; |
|
| } |
|
| $strHtml .= $tabs . $tab . $tab . "<$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); |
|
| $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 .= "</$type>" . $lnEnd; |
|
| } |
|
| $strHtml .= $tabs . $tab . "</tr>" . $lnEnd; |
|
| } |
|
| $strHtml .= $tabs . "</table>" . $lnEnd; |
|
| return $strHtml; |
|
| } // end func toHtml |
|
| |
|
| /** |
|
| * 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 ($this->_tfoot !== null) { |
| if (isset($colspan) && isset($rowspan)) { |
$this->_tfoot->setColCount($maxColCount); |
| for ($i = $row+1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) { |
if ($this->_tfoot->getRowCount() > 0) { |
| for ($j = $col+1; (($j <= $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) { |
$strHtml .= $tabs . $tab . '<tfoot>' . $lnEnd; |
| $this->_structure[$i][$j] = "__SPANNED__"; |
$strHtml .= $this->_tfoot->toHtml(); |
| |
$strHtml .= $tabs . $tab . '</tfoot>' . $lnEnd; |
| } |
} |
| } |
} |
| } |
if ($this->_tbody !== null) { |
| } // end func _updateSpanGrid |
$this->_tbody->setColCount($maxColCount); |
| |
if ($this->_tbody->getRowCount() > 0) { |
| /** |
$strHtml .= $tabs . $tab . '<tbody>' . $lnEnd; |
| * Adjusts ends (total number of rows and columns) |
$strHtml .= $this->_tbody->toHtml(); |
| * @param int $row Row index |
$strHtml .= $tabs . $tab . '</tbody>' . $lnEnd; |
| * @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); |
|
| } |
} |
| |
} else { |
| |
$strHtml .= $this->_tbody->toHtml(); |
| } |
} |
| } // end func _adjustEnds |
$strHtml .= $tabs . '</table>' . $lnEnd; |
| |
return $strHtml; |
| |
} |
| |
|
| /** |
} |
| * 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; |
|
| } // end func _isAttributesArray |
|
| } // end class HTML_Table |
|
| ?> |
?> |
| |
|