$Id$
- Ver que pasa con SAMURAI.
-- Pasar forks de PEAR a pear_lib_tmp
- Ver que archivos componen Tiempo/ y sacar la dependencia de HE_DB.
--- /dev/null
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.0 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Author: Adam Daniel <adaniel1@eesus.jnj.com> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+/**
+ * Base class for all HTML classes
+ *
+ * @author Adam Daniel <adaniel1@eesus.jnj.com>
+ * @version 1.7
+ * @since PHP 4.0.3pl1
+ * @abstract
+ */
+class HTML_Common {
+
+ /**
+ * Associative array of table attributes
+ *
+ * @var array
+ * @access private
+ */
+ var $_attributes = array();
+
+ /**
+ * Tab offset of the object
+ *
+ * @var int
+ * @access private
+ */
+ var $_tabOffset = 0;
+
+ /**
+ * Tab string
+ *
+ * @var string
+ * @since 1.7
+ * @access private
+ */
+ var $_tab = "\11";
+
+ /**
+ * HTML comment on the object
+ * @var string
+ * @since 1.5
+ * @access private
+ */
+ var $_comment = '';
+
+ /**
+ * Contains the line end string
+ *
+ * @var string
+ * @since 1.7
+ * @access private
+ */
+ var $_lineEnd = "\12";
+
+ /**
+ * Class constructor
+ * @param mixed $attributes Associative array of table tag attributes
+ * or HTML attributes name="value" pairs
+ * @param int $tabOffset Indent offset in tabs
+ * @access public
+ */
+ function HTML_Common($attributes = null, $tabOffset = 0)
+ {
+ $this->setAttributes($attributes);
+ $this->setTabOffset($tabOffset);
+ } // end constructor
+
+ /**
+ * Returns the current API version
+ * @access public
+ * @returns double
+ */
+ function apiVersion()
+ {
+ return 1.7;
+ } // end func apiVersion
+
+ /**
+ * Returns the lineEnd
+ *
+ * @since 1.7
+ * @access private
+ * @return string
+ * @throws
+ */
+ function _getLineEnd()
+ {
+ return $this->_lineEnd;
+ } //end func getLineEnd
+
+ /**
+ * Returns a string containing the unit for indenting HTML
+ *
+ * @since 1.7
+ * @access private
+ * @return string
+ */
+ function _getTab()
+ {
+ return $this->_tab;
+ } // end func _getTab
+
+ /**
+ * Returns a string containing the offset for the whole HTML code
+ *
+ * @access private
+ * @return string
+ */
+ function _getTabs()
+ {
+ return str_repeat($this->_getTab(), $this->_tabOffset);
+ } // end func _getTabs
+
+ /**
+ * Returns an HTML formatted attribute string
+ * @param array $attributes
+ * @return string
+ * @access private
+ */
+ function _getAttrString($attributes)
+ {
+ $strAttr = '';
+ if (is_array($attributes)) {
+ foreach ($attributes as $key => $value) {
+ $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
+ }
+ }
+ return $strAttr;
+ } // end func _getAttrString
+
+ /**
+ * Returns a valid atrributes array from either a string or array
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
+ * @access private
+ */
+ function _parseAttributes($attributes)
+ {
+ if (is_array($attributes)) {
+ $ret = array();
+ foreach ($attributes as $key => $value) {
+ if (is_int($key)) {
+ $key = $value = strtolower($value);
+ } else {
+ $key = strtolower($key);
+ }
+ $ret[$key] = $value;
+ }
+ return $ret;
+
+ } elseif (is_string($attributes)) {
+ $preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
+ "([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";
+ if (preg_match_all($preg, $attributes, $regs)) {
+ for ($counter=0; $counter<count($regs[1]); $counter++) {
+ $name = $regs[1][$counter];
+ $check = $regs[0][$counter];
+ $value = $regs[7][$counter];
+ if (trim($name) == trim($check)) {
+ $arrAttr[strtolower(trim($name))] = strtolower(trim($name));
+ } else {
+ if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") {
+ $value = substr($value, 1, -1);
+ }
+ $arrAttr[strtolower(trim($name))] = trim($value);
+ }
+ }
+ return $arrAttr;
+ }
+ }
+ } // end func _parseAttributes
+
+ /**
+ * Returns the array key for the given non-name-value pair attribute
+ *
+ * @param string $attr Attribute
+ * @param array $attributes Array of attribute
+ * @since 1.0
+ * @access private
+ * @return array key
+ * @throws
+ */
+ function _getAttrKey($attr, $attributes)
+ {
+ if (isset($attributes[strtolower($attr)])) {
+ return true;
+ } else {
+ return null;
+ }
+ } //end func _getAttrKey
+
+ /**
+ * Updates the attributes in $attr1 with the values in $attr2 without changing the other existing attributes
+ * @param array $attr1 Original attributes array
+ * @param array $attr2 New attributes array
+ * @access private
+ * @return array
+ */
+ function _updateAttrArray(&$attr1, $attr2)
+ {
+ if (!is_array($attr2)) {
+ return false;
+ }
+ foreach ($attr2 as $key => $value) {
+ $attr1[$key] = $value;
+ }
+ } // end func _updateAtrrArray
+
+ /**
+ * Removes the given attribute from the given array
+ *
+ * @param string $attr Attribute name
+ * @param array $attributes Attribute array
+ * @since 1.4
+ * @access public
+ * @return void
+ * @throws
+ */
+ function _removeAttr($attr, &$attributes)
+ {
+ $attr = strtolower($attr);
+ if (isset($attributes[$attr])) {
+ unset($attributes[$attr]);
+ }
+ } //end func _removeAttr
+
+ /**
+ * Returns the value of the given attribute
+ *
+ * @param string $attr Attribute name
+ * @since 1.5
+ * @access public
+ * @return void
+ * @throws
+ */
+ function getAttribute($attr)
+ {
+ $attr = strtolower($attr);
+ if (isset($this->_attributes[$attr])) {
+ return $this->_attributes[$attr];
+ }
+ return null;
+ } //end func getAttribute
+
+ /**
+ * Sets the HTML attributes
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
+ * @access public
+ */
+ function setAttributes($attributes)
+ {
+ $this->_attributes = $this->_parseAttributes($attributes);
+ } // end func _setAttributes
+
+ /**
+ * Returns an assoc array of attributes
+ *
+ * @since 1.6
+ * @access public
+ * @return void
+ * @throws
+ */
+ function getAttributes()
+ {
+ return $this->_attributes;
+ } //end func getAttributes
+
+ /**
+ * Updates the passed attributes without changing the other existing attributes
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
+ * @access public
+ */
+ function updateAttributes($attributes)
+ {
+ $this->_updateAttrArray($this->_attributes, $this->_parseAttributes($attributes));
+ } // end func updateAttributes
+
+ /**
+ * Removes an attribute
+ *
+ * @param string $attr Attribute name
+ * @since 1.4
+ * @access public
+ * @return void
+ * @throws
+ */
+ function removeAttribute($attr)
+ {
+ $this->_removeAttr($attr, $this->_attributes);
+ } //end func removeAttribute
+
+ /**
+ * Sets the line end style to Windows, Mac, Unix or a custom string.
+ *
+ * @param string $style "win", "mac", "unix" or custom string.
+ * @since 1.7
+ * @access public
+ * @return void
+ */
+ function setLineEnd($style)
+ {
+ switch ($style) {
+ case 'win':
+ $this->_lineEnd = "\15\12";
+ break;
+ case 'unix':
+ $this->_lineEnd = "\12";
+ break;
+ case 'mac';
+ $this->_lineEnd = "\15";
+ break;
+ default:
+ $this->_lineEnd = $style;
+ break;
+ }
+ } // end func setLineEnd
+
+ /**
+ * Sets the tab offset
+ *
+ * @param int $offset
+ * @access public
+ */
+ function setTabOffset($offset)
+ {
+ $this->_tabOffset = $offset;
+ } // end func setTabOffset
+
+ /**
+ * Returns the tabOffset
+ *
+ * @since 1.5
+ * @access public
+ * @return void
+ * @throws
+ */
+ function getTabOffset()
+ {
+ return $this->_tabOffset;
+ } //end func getTabOffset
+
+ /**
+ * Sets the string used to indent HTML
+ *
+ * @since 1.7
+ * @param string $string String used to indent ("\11", "\t", ' ', etc.).
+ * @access public
+ * @return void
+ */
+ function setTab($string)
+ {
+ $this->_tab = $string;
+ } // end func setTab
+
+ /**
+ * Sets the HTML comment to be displayed at the beginning of the HTML string
+ *
+ * @param string
+ * @since 1.4
+ * @access public
+ * @return void
+ * @throws
+ */
+ function setComment($comment)
+ {
+ $this->_comment = $comment;
+ } // end func setHtmlComment
+
+ /**
+ * Returns the HTML comment
+ *
+ * @since 1.5
+ * @access public
+ * @return void
+ * @throws
+ */
+ function getComment()
+ {
+ return $this->_comment;
+ } //end func getComment
+
+ /**
+ * Abstract method. Must be extended to return the objects HTML
+ *
+ * @access public
+ * @return string
+ * @abstract
+ */
+ function toHtml()
+ {
+ return '';
+ } // end func toHtml
+
+ /**
+ * Displays the HTML to the screen
+ *
+ * @access public
+ */
+ function display()
+ {
+ print $this->toHtml();
+ } // end func display
+
+} // end class HTML_Common
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997 - 2003 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.0 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
+// | Klaus Guenther <klaus@capitalfocus.org> |
+// +----------------------------------------------------------------------+
+//
+
+require_once 'PEAR.php';
+require_once 'Common.php';
+
+/**
+ * Base class for XHTML pages
+ *
+ * This class handles the details for creating a properly constructed XHTML page.
+ * Page caching, stylesheets, client side script, and Meta tags can be
+ * managed using this class.
+ *
+ * The body may be a string, object, or array of objects or strings. Objects with
+ * toHtml() and toString() methods are supported.
+ *
+ *
+ * XHTML Examples:
+ * ---------------
+ *
+ * Simplest example:
+ * -----------------
+ * <code>
+ * // the default doctype is XHTML 1.0 Transitional
+ * // All doctypes and defaults are set in HTML/Page/Doctypes.php
+ * $p = new HTML_Page();
+ *
+ * //add some content
+ * $p->addBodyContent("<p>some text</p>");
+ *
+ * // print to browser
+ * $p->display();
+ * </code>
+ *
+ * Complex XHTML example:
+ * ----------------------
+ * <code>
+ * // The initializing code can also be in in the form of an HTML
+ * // attr="value" string.
+ * // Possible attributes are: charset, lineend, tab, doctype, language and cache
+ *
+ * $p = new HTML_Page(array (
+ *
+ * // Sets the charset encoding
+ * 'charset' => 'utf-8',
+ *
+ * // Sets the line end character
+ * // unix (\n) is default
+ * 'lineend' => 'unix',
+ *
+ * // Sets the tab string for autoindent
+ * // tab (\t) is default
+ * 'tab' => ' ',
+ *
+ * // This is where you define the doctype
+ * 'doctype' => "XHTML 1.0 Strict",
+ *
+ * // Global page language setting
+ * 'language' => 'en',
+ *
+ * // If cache is set to true, the browser may
+ * // cache the output. Else
+ * 'cache' => 'false'
+ * ));
+ *
+ * // Here we go
+ *
+ * // Set the page title
+ * $p->setTitle("My page");
+ *
+ * // Add optional meta data
+ * $p->addMetaData("author", "My Name");
+ *
+ * // Put something into the body
+ * $p->addBodyContent = "<p>some text</p>";
+ *
+ * // If at some point you want to clear the page content
+ * // and output an error message, you can easily do that
+ * // See the source for {@link toHtml} and {@link _getDoctype}
+ * // for more details
+ * if ($error) {
+ * $p->setTitle("Error!");
+ * $p->setBodyContent("<p>oops, we have an error: $error</p>");
+ * $p->display();
+ * die;
+ * } // end error handling
+ *
+ * // print to browser
+ * $p->display();
+ * </code>
+ *
+ * Simple XHTML declaration example:
+ * <code>
+ * $p = new HTML_Page();
+ * // An XHTML compliant page (with title) is automatically generated
+ *
+ * // This overrides the XHTML 1.0 Transitional default
+ * $p->setDoctype('xhtml');
+ *
+ * // Put some content in here
+ * $p->addBodyContent("<p>some text</p>");
+ *
+ * // print to browser
+ * $p->display();
+ * </code>
+ *
+ *
+ * HTML examples:
+ * --------------
+ *
+ * HTML 4.01 example:
+ * ------------------
+ * <code>
+ * $p = new HTML_Page('doctype="HTML 4.01 Strict"');
+ * $p->addBodyContent = "<p>some text</p>";
+ * $p->display();
+ * </code>
+ *
+ * nuke doctype declaration:
+ * -------------------------
+ * <code>
+ * $p = new HTML_Page('doctype="none"');
+ * $p->addBodyContent = "<p>some text</p>";
+ * $p->display();
+ * </code>
+ *
+ * @author Adam Daniel <adaniel1@eesus.jnj.com>
+ * @author Klaus Guenther <klaus@capitalfocus.org>
+ * @version 0.8b2
+ * @since PHP 4.0.3pl1
+ */
+class HTML_Page extends HTML_Common {
+
+ /**
+ * Contains the content of the <body> tag.
+ *
+ * @var array
+ * @access private
+ */
+ var $_body = array();
+
+ /**
+ * Controls caching of the page
+ *
+ * @var bool
+ * @access private
+ */
+ var $_cache = false;
+
+ /**
+ * Contains the character encoding string
+ *
+ * @var string
+ * @access private
+ */
+ var $_charset = 'utf-8';
+
+ /**
+ * Contains the !DOCTYPE definition
+ *
+ * @var array
+ * @access private
+ */
+ var $_doctype = array('type'=>'xhtml','version'=>'1.0','variant'=>'transitional');
+
+ /**
+ * Contains the page language setting
+ *
+ * @var string
+ * @access private
+ */
+ var $_language = 'en';
+
+ /**
+ * Array of meta tags
+ *
+ * @var array
+ * @access private
+ */
+ var $_metaTags = array( 'standard' => array ( 'Generator' => 'PEAR HTML_Page' ) );
+
+ /**
+ * Array of linked scripts
+ *
+ * @var array
+ * @access private
+ */
+ var $_scripts = array();
+
+ /**
+ * Array of linked scripts
+ *
+ * @var array
+ * @access private
+ */
+ var $_simple = false;
+
+ /**
+ * Array of included style declarations
+ *
+ * @var array
+ * @access private
+ */
+ var $_style = array();
+
+ /**
+ * Array of linked style sheets
+ *
+ * @var array
+ * @access private
+ */
+ var $_styleSheets = array();
+
+ /**
+ * HTML page title
+ *
+ * @var string
+ * @access private
+ */
+ var $_title = '';
+
+ /**
+ * Class constructor
+ * Possible attributes are:
+ * - general options:
+ * - "lineend" => "unix|win|mac" (Sets line ending style; defaults to unix.)
+ * - "tab" => string (Sets line ending style; defaults to \t.)
+ * - "cache" => "false|true"
+ * - "charset" => charset string (Sets charset encoding; defaults to utf-8)
+ * - XHTML specific:
+ * - "doctype" => mixed (Sets XHTML doctype; defaults to XHTML 1.0 Transitional.)
+ * - "language" => two letter language designation. (Defines global document language; defaults to "en".)
+ *
+ * @param mixed $attributes Associative array of table tag attributes
+ * or HTML attributes name="value" pairs
+ * @access public
+ */
+ function HTML_Page($attributes = "")
+ {
+ $commonVersion = 1.7;
+ if (HTML_Common::apiVersion() < $commonVersion) {
+ return PEAR::raiseError("HTML_Page version " . $this->apiVersion() . " requires " .
+ "HTML_Common version $commonVersion or greater. You can get the (still) unofficial ".
+ "update here: http://www.geist.uni-freiburg.de/pear/HTML/Common.txt", 0, PEAR_ERROR_TRIGGER);
+ }
+
+ if ($attributes) {
+ $attributes = $this->_parseAttributes($attributes);
+ }
+
+ if (isset($attributes['lineend'])) {
+ $this->setLineEnd($attributes['lineend']);
+ }
+
+ if (isset($attributes['charset'])) {
+ $this->setCharset($attributes['charset']);
+ }
+
+ if (isset($attributes['doctype'])){
+ if ($attributes['doctype'] == 'none') {
+ $this->_simple = true;
+ } elseif ($attributes['doctype']) {
+ $this->setDoctype($attributes['doctype']);
+ }
+ }
+
+ if (isset($attributes['language'])) {
+ $this->setLang($attributes['language']);
+ }
+
+ if (isset($attributes['cache'])) {
+ $this->setCache($attributes['cache']);
+ }
+
+ }
+
+ /**
+ * Generates the HTML string for the <body< tag
+ *
+ * @access private
+ * @return string
+ */
+ function _generateBody()
+ {
+
+ // get line endings
+ $lnEnd = $this->_getLineEnd();
+ $tab = $this->_getTab();
+
+ // If body attributes exist, add them to the body tag.
+ // Depreciated because of CSS
+ $strAttr = $this->_getAttrString($this->_attributes);
+
+ if ($strAttr) {
+ $strHtml = "<body $strAttr>" . $lnEnd;
+ } else {
+ $strHtml = '<body>' . $lnEnd;
+ }
+
+ // Allow for mixed content in the body array
+ // Iterate through the array and process each element
+ foreach ($this->_body as $element) {
+ if (is_object($element)) {
+ if (is_subclass_of($element, "html_common")) {
+ $element->setTab($tab);
+ $element->setTabOffset(1);
+ $element->setLineEnd($lnEnd);
+ }
+ if (method_exists($element, "toHtml")) {
+ $strHtml .= $element->toHtml() . $lnEnd;
+ } elseif (method_exists($element, "toString")) {
+ $strHtml .= $element->toString() . $lnEnd;
+ }
+ } elseif (is_array($element)) {
+ foreach ($element as $level2) {
+ if (is_subclass_of($level2, "html_common")) {
+ $level2->setTabOffset(1);
+ $level2->setTab($tab);
+ $level2->setLineEnd($lnEnd);
+ }
+ if (is_object($level2)) {
+ if (method_exists($level2, "toHtml")) {
+ $strHtml .= $level2->toHtml() . $lnEnd;
+ } elseif (method_exists($level2, "toString")) {
+ $strHtml .= $level2->toString() . $lnEnd;
+ }
+ } else {
+ $strHtml .= $tab . $level2 . $lnEnd;
+ }
+ }
+ } else {
+ $strHtml .= $tab . $element . $lnEnd;
+ }
+ }
+
+ // Close tag
+ $strHtml .= '</body>' . $lnEnd;
+
+ // Let's roll!
+ return $strHtml;
+ } // end func _generateHead
+
+ /**
+ * Outputs a page containing the error message and then dies
+ *
+ * @return void
+ * @access private
+ */
+ function _error(&$error){
+
+ $this->setTitle('HTML_Page doctype Error');
+ $this->setBody('<p>' . $error->getMessage() . '</p>');
+ $this->setDoctype();
+ $this->display();
+ die;
+
+ } //
+
+ /**
+ * Generates the HTML string for the <head< tag
+ *
+ * @return string
+ * @access private
+ */
+ function _generateHead()
+ {
+
+ // get line endings
+ $lnEnd = $this->_getLineEnd();
+ $tab = $this->_getTab();
+
+ $strHtml = '<head>' . $lnEnd;
+ $strHtml .= $tab . '<title>' . $this->getTitle() . '</title>' . $lnEnd;
+
+ // Generate META tags
+ foreach ($this->_metaTags as $type => $tag) {
+ foreach ($tag as $name => $content) {
+ if ($type == 'http-equiv') {
+ $strHtml .= $tab . "<meta http-equiv=\"$name\" content=\"$content\" />" . $lnEnd;
+ } elseif ($type == 'standard') {
+ $strHtml .= $tab . "<meta name=\"$name\" content=\"$content\" />" . $lnEnd;
+ }
+ }
+ }
+
+ // Generate stylesheet links
+ for($intCounter=0; $intCounter<count($this->_styleSheets); $intCounter++) {
+ $strStyleSheet = $this->_styleSheets[$intCounter];
+ $strHtml .= $tab . "<link rel=\"stylesheet\" href=\"$strStyleSheet\" type=\"text/css\" />" . $lnEnd;
+ }
+
+ // Generate stylesheet declarations
+ foreach ($this->_style as $type => $content) {
+ $strHtml .= $tab . '<style type="' . $type . '">' . $lnEnd;
+ $strHtml .= $tab . $tab . '<!--' . $lnEnd;
+ if (is_object($content)) {
+ if (is_subclass_of($content, "html_common")) {
+ $content->setTab($tab);
+ $content->setTabOffset(3);
+ $content->setLineEnd($lnEnd);
+ }
+ if (method_exists($content, "toString")) {
+ $strHtml .= $content->toString() . $lnEnd;
+ }
+ } else {
+ $strHtml .= $content . $lnEnd;
+ }
+ $strHtml .= $tab . $spacer . "-->" . $lnEnd;
+ $strHtml .= $tab . "</style>" . $lnEnd;
+ }
+
+ // Generate script file links
+ for($intCounter=0; $intCounter<count($this->_scripts); $intCounter++) {
+ $strType = $this->_scripts[$intCounter]["type"];
+ $strSrc = $this->_scripts[$intCounter]["src"];
+ $strHtml .= $tab . "<script type=\"$strType\" src=\"$strSrc\"></script>" . $lnEnd;
+ }
+
+ // Close tag
+ $strHtml .= '</head>' . $lnEnd;
+
+ // Let's roll!
+ return $strHtml;
+ } // end func _generateHead
+
+ /**
+ * Returns the doctype declaration
+ *
+ * @return string
+ * @access private
+ */
+ function _getDoctype()
+ {
+ include('Page/Doctypes.php');
+
+ $type = $this->_doctype['type'];
+ $version = $this->_doctype['version'];
+ $variant = $this->_doctype['variant'];
+
+ $strDoctype = '';
+
+ if ($variant != '') {
+ if (isset($doctype[$type][$version][$variant][0])) {
+ foreach ( $doctype[$type][$version][$variant] as $string) {
+ $strDoctype .= $string.$this->_getLineEnd();
+ }
+ }
+ } elseif ($version != '') {
+ if (isset($doctype[$type][$version][0])) {
+ foreach ( $doctype[$type][$version] as $string) {
+ $strDoctype .= $string.$this->_getLineEnd();
+ }
+ } else {
+ if (isset($default[$type][$version][0])) {
+ $this->_doctype = $this->_parseDoctypeString($default[$type][$version][0]);
+ $strDoctype = $this->_getDoctype();
+ }
+ }
+ } elseif ($type != '') {
+ if (isset($default[$type][0])){
+ $this->_doctype = $this->_parseDoctypeString($default[$type][0]);
+ $strDoctype = $this->_getDoctype();
+ }
+ } else {
+ $this->_doctype = $this->_parseDoctypeString($default['default'][0]);
+ $strDoctype = $this->_getDoctype();
+ }
+
+ if ($strDoctype) {
+ return $strDoctype;
+ } else {
+ return PEAR::raiseError('Error: "'.$this->getDoctypeString().'" is an unsupported or illegal document type.',
+ 0,PEAR_ERROR_RETURN);
+ }
+
+ } // end func _getDoctype
+
+ /**
+ * Parses a doctype declaration like "XHTML 1.0 Strict" to an array
+ *
+ * @param string $string The string to be parsed
+ * @return string
+ * @access private
+ */
+ function _parseDoctypeString($string)
+ {
+ $split = explode(' ',strtolower($string));
+ $elements = count($split);
+
+ $array = array('type'=>$split[0],'version'=>$split[1],'variant'=>$split[2]);
+
+ return $array;
+ } // end func _parseDoctypeString
+
+ /**
+ * Sets the content of the <body> tag. If content already exists,
+ * the new content is appended.
+ * If you wish to overwrite whatever is in the body, use {@link setBody};
+ * {@link unsetBody} completely empties the body without inserting new content.
+ * It is possible to add objects, strings or an array of strings and/or objects
+ *
+ * @param mixed $content New <body> tag content.
+ * @access public
+ */
+ function addBodyContent($content)
+ {
+ $this->_body[] =& $content;
+ } // end addBodyContent
+
+ /**
+ * Depreciated. Sets or alters a meta tag. Use {@link setMetaData} instead.
+ * This function only allows for standard META tags.
+ *
+ * @param string $name Value of name or http-equiv tag
+ * @param string $content Value of the content tag
+ * @access public
+ */
+ function addMetaData($name, $content)
+ {
+ $this->setMetaData($name, $content);
+ } // end func addMetaData
+
+ /**
+ * Adds a linked script to the page
+ *
+ * @param string $url URL to the linked style sheet
+ * @param string $type Type of script. Defaults to 'text/javascript'
+ * @access public
+ */
+ function addScript($url, $type="text/javascript")
+ {
+ $this->_scripts[] = array("type"=>$type, "src"=>$url);
+ } // end func addScript
+
+ /**
+ * Adds a linked style sheet to the page
+ *
+ * @param string $url URL to the linked style sheet
+ * @access public
+ */
+ function addStyleSheet($url)
+ {
+ $this->_styleSheets[] = $url;
+ } // end func addStyleSheet
+
+ /**
+ * Adds a linked style sheet to the page
+ *
+ * @param string $type Type of stylesheet (e.g., text/css)
+ * @param string $content Style declarations
+ * @access public
+ */
+ function addStyleDeclaration($type, $content)
+ {
+ $this->_style[$type] =& $content;
+ } // end func addStyleDeclaration
+
+ /**
+ * Returns the current API version
+ *
+ * @access public
+ * @returns double
+ */
+ function apiVersion()
+ {
+ return 0.8;
+ } // end func apiVersion
+
+ /**
+ * Outputs the HTML content to the screen.
+ *
+ * @access public
+ */
+ function display()
+ {
+ if(! $this->_cache) {
+ header("Expires: Tue, 1 Jan 1980 12:00:00 GMT");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+ header("Cache-Control: no-cache");
+ header("Pragma: no-cache");
+ }
+
+ // set character encoding
+ header("Content-Type: text/html; charset=" . $this->_charset);
+
+ $strHtml = $this->toHTML();
+ print $strHtml;
+ } // end func display
+
+ /**
+ * Defines if the document should be cached by the browser. Defaults to false.
+ *
+ * @param string $cache Options are currently 'true' or 'false'. Defaults to 'false'.
+ * @access public
+ */
+ function getCharset()
+ {
+ return $this->_charset;
+ } // end setCache
+
+ /**
+ * Returns the document type string
+ *
+ * @access private
+ * @return string
+ */
+ function getDoctypeString()
+ {
+ $strDoctype = strtoupper($this->_doctype['type']);
+ $strDoctype .= ' '.ucfirst(strtolower($this->_doctype['version']));
+ if ($this->_doctype['variant']) {
+ $strDoctype .= ' ' . ucfirst(strtolower($this->_doctype['variant']));
+ }
+ return trim($strDoctype);
+ } // end func getDoctypeString
+
+ /**
+ * Returns the document language.
+ *
+ * @return string
+ * @access public
+ */
+ function getLang ()
+ {
+ return $this->_language;
+ } // end func getLang
+
+ /**
+ * Return the title of the page.
+ *
+ * @returns string
+ * @access public
+ */
+ function getTitle()
+ {
+ if (!$this->_title){
+ if ($this->_simple) {
+ return 'New Page';
+ } else {
+ return 'New '. $this->getDoctypeString() . ' Compliant Page';
+ }
+ } else {
+ return $this->_title;
+ }
+ } // end func getTitle
+
+ /**
+ * Sets or alters the XHTML !DOCTYPE declaration. Can be set to "strict",
+ * "transitional" or "frameset". Defaults to "transitional". This must come
+ * _after_ declaring the character encoding with {@link setCharset} or directly
+ * when the class is initiated {@link HTML_Page}.
+ *
+ * @param mixed $type String containing a document type. Defaults to "XHTML 1.0 Transitional"
+ * @access public
+ */
+ function setDoctype($type = "XHTML 1.0 Transitional")
+ {
+ $this->_doctype = $this->_parseDoctypeString($type);
+ } // end func setDoctype
+
+ /**
+ * Sets the global document language declaration. Default is English.
+ *
+ * @access public
+ * @param string $lang Two-letter language designation.
+ */
+ function setLang($lang = "en")
+ {
+ $this->_language = strtolower($lang);
+ } // end setLang
+
+ /**
+ * Sets the content of the <body> tag. If content exists, it is overwritten.
+ * If you wish to use a "safe" version, use {@link addBodyContent}
+ *
+ * @param mixed &$content New <body> tag content.
+ * @access public
+ */
+ function setBody(&$content)
+ {
+ $this->_body = '';
+ $this->_body[] =& $content;
+ } // end setBody
+
+ /**
+ * Defines if the document should be cached by the browser. Defaults to false.
+ *
+ * @param string $cache Options are currently 'true' or 'false'. Defaults to 'false'.
+ * @access public
+ */
+ function setCache($cache = 'false')
+ {
+ if ($cache == 'true'){
+ $this->_cache = true;
+ } else {
+ $this->_cache = false;
+ }
+ } // end setCache
+
+ /**
+ * Defines if the document should be cached by the browser. Defaults to false.
+ *
+ * @param string $cache Options are currently 'true' or 'false'. Defaults to 'false'.
+ * @access public
+ */
+ function setCharset($type = 'utf-8')
+ {
+ $this->_charset = $type;
+ } // end setCache
+
+ /**
+ * Sets or alters a meta tag.
+ *
+ * @param string $name Value of name or http-equiv tag
+ * @param string $content Value of the content tag
+ * @param bool $http_equiv META type "http-equiv" defaults to NULL
+ * @access public
+ */
+ function setMetaData($name, $content, $http_equiv = false)
+ {
+ if ($http_equiv == true) {
+ $this->_meta['http-equiv'][$name] = $content;
+ } else {
+ $this->_meta['standard'][$name] = $content;
+ }
+ } // end func setMetaData
+
+ /**
+ * Easily sets or alters a refresh meta tag.
+ * If no $url is passed, "self" is presupposed, and the appropriate URL
+ * will be automatically generated.
+ *
+ * @param string $time Time till refresh (in seconds)
+ * @param string $url Absolute URL or "self"
+ * @param bool $https If $url = self, this allows for the https protocol
+ * @access public
+ */
+ function setMetaRefresh($time, $url = 'self', $https = false)
+ {
+ if ($url == 'self') {
+ if ($https) {
+ $protocol = 'https://';
+ } else {
+ $protocol = 'http://';
+ }
+ $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+ }
+ $this->setMetaData("Refresh", "$time; url=$url", true);
+ } // end func setMetaRefresh
+
+ /**
+ * Sets the title of the page
+ *
+ * @param string $title
+ * @access public
+ */
+ function setTitle($title)
+ {
+ $this->_title = $title;
+ } // end func setTitle
+
+ /**
+ * Generates and returns the complete page as a string.
+ *
+ * @return string
+ * @access private
+ */
+ function toHTML()
+ {
+
+ // get line endings
+ $lnEnd = $this->_getLineEnd();
+ $strDoctype = $this->_getDoctype();
+ if (!PEAR::isError($strDoctype)){
+
+ if ($this->_simple) {
+ $strHtml = '<html>' . $lnEnd;
+ } elseif ($this->_doctype['type'] == 'xhtml') {
+ $strHtml = '<?xml version="1.0" encoding="' . $this->_charset . '"?>' . $lnEnd;
+ $strHtml .= $strDoctype . $lnEnd;
+ $strHtml .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$this->_language.'">';
+ } else {
+ $strHtml = $strDoctype . $lnEnd;
+ $strHtml .= '<html>' . $lnEnd;
+ }
+
+ } else {
+
+ $this->_error($strDoctype);
+
+ }
+ $strHtml .= $this->_generateHead();
+ $strHtml .= $this->_generateBody();
+ $strHtml .= '</html>';
+ return $strHtml;
+ } // end func toHtml
+
+ /**
+ * Unsets the content of the <body> tag.
+ *
+ * @access public
+ */
+ function unsetBody()
+ {
+ $this->_body = '';
+ } // end unsetBody
+}
+?>
--- /dev/null
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.0 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
+// | Bertrand Mansion <bmansion@mamasam.com> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+require_once "PEAR.php";
+require_once "HTML/Common.php";
+
+/**
+ * Builds an HTML table
+ * @author Adam Daniel <adaniel1@eesus.jnj.com>
+ * @author Bertrand Mansion <bmansion@mamasam.com>
+ * @version 1.7
+ * @since PHP 4.0.3pl1
+ */
+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
+ * @var string
+ * @access private
+ */
+ var $_autoFill = " ";
+
+ /**
+ * 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;
+
+ /**
+ * Class constructor
+ * @param array $attributes Associative array of table tag attributes
+ * @param int $tabOffset
+ * @access public
+ */
+ function HTML_Table($attributes = null, $tabOffset = 0)
+ {
+ $commonVersion = 1.7;
+ if (HTML_Common::apiVersion() < $commonVersion) {
+ return PEAR::raiseError("HTML_Table version " . $this->apiVersion() . " requires " .
+ "HTML_Common version $commonVersion or greater.", 0, PEAR_ERROR_TRIGGER);
+ }
+ HTML_Common::HTML_Common($attributes, $tabOffset);
+ } // end constructor
+
+ /**
+ * Returns the API version
+ * @access public
+ * @return double
+ */
+ function apiVersion()
+ {
+ return 1.7;
+ } // end func apiVersion
+
+ /**
+ * 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->_structure["caption"] = array("attr" => $attributes, "contents" => $caption);
+ } // end func setCaption
+
+ /**
+ * Sets the autoFill value
+ * @param mixed $fill
+ * @access public
+ */
+ function setAutoFill($fill)
+ {
+ $this->_autoFill = $fill;
+ } // end func setAutoFill
+
+ /**
+ * Returns the autoFill value
+ * @access public
+ * @return mixed
+ */
+ function getAutoFill()
+ {
+ return $this->_autoFill;
+ } // end func getAutoFill
+
+ /**
+ * Sets the autoGrow value
+ * @param bool $fill
+ * @access public
+ */
+ function setAutoGrow($grow)
+ {
+ $this->_autoGrow = $grow;
+ } // end func setAutoGrow
+
+ /**
+ * Returns the autoGrow value
+ * @access public
+ * @return mixed
+ */
+ function getAutoGrow()
+ {
+ return $this->_autoGrow;
+ } // end func getAutoGrow
+
+ /**
+ * Sets the number of rows in the table
+ * @param int $rows
+ * @access public
+ */
+ function setRowCount($rows)
+ {
+ $this->_rows = $rows;
+ } // end func setRowCount
+
+ /**
+ * Sets the number of columns in the table
+ * @param int $cols
+ * @access public
+ */
+ function setColCount($cols)
+ {
+ $this->_cols = $cols;
+ } // end func setColCount
+
+ /**
+ * Returns the number of rows in the table
+ * @access public
+ * @return int
+ */
+ function getRowCount()
+ {
+ return $this->_rows;
+ } // end func getRowCount
+
+ /**
+ * Sets the number of columns in the table
+ * @access public
+ * @return int
+ */
+ function getColCount()
+ {
+ return $this->_cols;
+ } // end func getColCount
+
+ /**
+ * 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;
+ }
+ } // end func setRowType
+
+ /**
+ * 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;
+ }
+ } // end func setColType
+
+ /**
+ * 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);
+ } // end func setCellAttributes
+
+ /**
+ * Updates the cell attributes passed but leaves other existing attributes in tact
+ * @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);
+ } // end func updateCellAttributes
+
+ /**
+ * 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;
+ } // end func getCellAttributes
+
+ /**
+ * 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
+ * @param string $type (optional) Cell type either 'TH' or 'TD'
+ * @access public
+ * @throws PEAR_Error
+ */
+ function setCellContents($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;
+ } // end func setCellContents
+
+ /**
+ * 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;
+ return $this->_structure[$row][$col]["contents"];
+ } // end func getCellContents
+
+ /**
+ * Sets the contents of a header cell
+ * @param int $row
+ * @param int $col
+ * @param mixed $contents
+ * @access public
+ */
+ function setHeaderContents($row, $col, $contents)
+ {
+ $this->setCellContents($row, $col, $contents, 'TH');
+ } // end func setHeaderContents
+
+ /**
+ * 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");
+ }
+ $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
+ * @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)
+ {
+ $multiAttr = $this->_isAttributesArray($attributes);
+ if (!$inTR) {
+ 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, 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
+ * @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)
+ {
+ $multiAttr = $this->_isAttributesArray($attributes);
+ if (!$inTR) {
+ 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, 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
+ * @param int $row Row index
+ * @return array
+ * @access public
+ */
+ function getRowAttributes($row)
+ {
+ if (isset($this->_structure[$row]['attr'])) {
+ return $this->_structure[$row]['attr'];
+ }
+ return;
+ } // end func getRowAttributes
+
+ /**
+ * 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
+ * @access public
+ */
+ function altRowAttributes($start, $attributes1, $attributes2, $inTR = false)
+ {
+ for ($row = $start ; $row < $this->_rows ; $row++) {
+ $attributes = ( ($row+$start)%2 == 0 ) ? $attributes1 : $attributes2;
+ $this->updateRowAttributes($row, $attributes, $inTR);
+ }
+ } // end func altRowAttributes
+
+ /**
+ * 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");
+ }
+ $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
+ * @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);
+ }
+ }
+ } // end func setColAttributes
+
+ /**
+ * 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);
+ }
+ }
+ } // end func updateColAttributes
+
+ /**
+ * 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);
+ }
+ } // end func setAllAttributes
+
+ /**
+ * 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);
+ }
+ } // end func updateAllAttributes
+
+ /**
+ * Returns the table structure as HTML
+ * @access public
+ * @return string
+ */
+ function toHtml()
+ {
+ $strHtml = '';
+ $tabs = $this->_getTabs();
+ $tab = $this->_getTab();
+ $lnEnd = $this->_getLineEnd();
+ if ($this->_comment) {
+ $strHtml .= $tabs . "<!-- $this->_comment -->" . $lnEnd;
+ }
+ $strHtml .=
+ $tabs . "<table" . $this->_getAttrString($this->_attributes) . ">" . $lnEnd;
+ if (!empty($this->_structure["caption"])) {
+ $attr = $this->_structure["caption"]["attr"];
+ $contents = $this->_structure["caption"]["contents"];
+ $strHtml .= $tabs . $tab . "<caption" . $this->_getAttrString($attr) . ">";
+ if (is_array($contents)) $contents = implode(", ", $contents);
+ $strHtml .= $contents;
+ $strHtml .= "</caption>" . $lnEnd;
+ }
+ for ($i = 0 ; $i < $this->_rows ; $i++) {
+ if (isset($this->_structure[$i]['attr'])) {
+ $strHtml .= $tabs . $tab . "<tr".$this->_getAttrString($this->_structure[$i]['attr']).">" . $lnEnd;
+ } else {
+ $strHtml .= $tabs .$tab . "<tr>" . $lnEnd;
+ }
+ for ($j = 0 ; $j < $this->_cols ; $j++) {
+ if (isset($this -> _structure[$i][$j]) && $this->_structure[$i][$j] == "__SPANNED__") {
+ $strHtml .= $tabs . $tab . $tab ."<!-- span -->" . $lnEnd;
+ continue;
+ }
+ if (isset($this->_structure[$i][$j]["type"])) {
+ $type = (strtoupper($this->_structure[$i][$j]["type"]) == "TH" ? "th" : "td");
+ } else {
+ $type = "td";
+ }
+ if (isset($this->_structure[$i][$j]["attr"])) {
+ $attr = $this->_structure[$i][$j]["attr"];
+ } else {
+ $attr = "";
+ }
+ 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 (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__";
+ }
+ }
+ }
+ } // end func _updateSpanGrid
+
+ /**
+ * 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);
+ }
+ }
+ } // end func _adjustEnds
+
+ /**
+ * 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
+?>