- <?
- /**
- * @package table
- * @filesource
- * @see HTML_TABLE_COMPONENT_PATH.'/Table.php'
- * @copyright (c) http://Finn-Rasmussen.com
- * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
- * @author http://Finn-Rasmussen.com
- * @version 1.9
- * @since 21-oct-2005
- */
-
- /**
- * The required files
- */
- require_once(HTML_PATH.'/Html.php');
- require_once(HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
- require_once(HTML_TABLE_COMPONENT_PATH.'/Tr.php');
- require_once(HTML_TABLE_COMPONENT_PATH.'/Th.php');
- require_once(HTML_TABLE_COMPONENT_PATH.'/Td.php');
- if (defined('HTML_LOG_UTIL_PATH')) {
- require_once(HTML_LOG_UTIL_PATH.'/Log.php');
- }
-
- /**
- * Generates the html for a table
- * <code>
- * Usage:
- * $table = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
- * print $table->getHtml();
- * Or
- * Table::display($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
- *
- * Generates a complete table interface
- * ---------------------------------
- * | Text header
- * ---------------------------------
- * | head1 | head2 | head3 |
- * ---------------------------------
- * | dat_1 | dat_2 | dat_3 |
- * ---------------------------------
- * </code>
- * @package table
- */
-
- class Table extends Html {
- /**
- * @var String $text The text for the table header
- */
- var $text = '';
-
- // Table data
-
- var $width = '';
- var $class = '';
- var $border = '';
- var $cellpadding = '';
- var $cellspacing = '';
- var $summary = '';
- var $caption = '';
-
- /**
- * Constructor
- * @param String $text The text header for the table
- * @param String $width The Width for the table
- * @param String $class The Class
- * @param String $border The Border
- * @param String $cellpadding The CellSpacing
- * @param String $cellspacing The CellPadding
- * @param String $summary The Summary
- * @param String $caption The Caption
- */
- function Table($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
- $this->Html();
- if (defined('HTML_LOG_UTIL_PATH') && LOG_LEVEL & LOG_LEVEL_DEBUG) {
- $this->text = $text!=''?$text:$this->getClassName().'(), you forgot to add text';
- } else {
- $this->text = $text!=''?$text:'';
- }
- $theBorder = $border!=''?$border:TABLE_BORDER;
- if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_BORDER) {
- $theBorder = '1'; // Debug, show border
- }
- $this->width = $width!=''?$width:TABLE_WIDTH;
- $this->class = $class!=''?$class:TABLE_CLASS;
- $this->border = $theBorder;
- $this->cellpadding = $cellpadding!=''?$cellpadding:TABLE_CELLPADDING;
- $this->cellspacing = $cellspacing!=''?$cellspacing:TABLE_CELLSPACING;
- $this->summary = $summary!=''?$summary:'';
- $this->caption = $caption!=''?$caption:'';
- }
-
- /**
- * Get the Table Header from class TableHeader
- * @return String the html table header
- */
- function getTableHeader() {
- $tableheader = new TableHeader($this->text,$this->width,$this->class,$this->border);
- return $tableheader->getHtml();
- }
-
- /**
- * Get the start of the table
- * @return String the html for the start of the table
- */
- function getStart() {
- $html = '';
- $html .= '<table';
- $html .= $this->getAttribute('width');
- $html .= $this->getAttribute('class');
- $html .= $this->getAttribute('border');
- $html .= $this->getAttribute('cellpadding');
- $html .= $this->getAttribute('cellspacing');
- if ($this->summary!='') {
- $html .= $this->getAttribute('summary');
- }
- $html .= ">\r\n";
- if ($this->caption!='') {
- $html .= '<caption>'.$this->caption.'</caption>'."\r\n";
- }
- return $html;
- }
-
- /**
- * Get the table end
- * @return String the html
- */
- function getEnd() {
- return "</table>\r\n";
- }
-
- /**
- * Get the Row Start
- * @param String $class The css class name for the row
- * @return String the html
- */
- function getRowStart($class='') {
- $html = new Tr($class);
- return $html->getStart();
- }
-
- /**
- * Get the Column Start
- * @param String $class The class name
- * @param String $valign The alignment of data
- * @param String $colspan The Column Span
- * @return String the html
- */
- function getColumnStart($class='',$valign='',$colspan='') {
- $html = new Td($class,$valign,$colspan);
- return $html->getStart();
- }
-
- /**
- * Get the Column End
- * @return String the html
- */
- function getColumnEnd() {
- return Td::getEnd();
- }
-
- /**
- * Get the Row End
- * @return String the html
- */
- function getRowEnd() {
- return Tr::getEnd();
- }
-
- /**
- * Get the complete html for a table
- * @return String the html
- */
- function getHtml() {
- $html = $this->html;
- $html .= $this->getTableHeader();
- $html .= $this->getStart();
- if ($this->getSizeof()==0) {
- $html .= " <tr><td><!-- ";
- if (defined('TEXT_NO_DATA')) {
- $html .= TEXT_NO_DATA;
- } else {
- $html .= TABLE_TEXT_NO_DATA;
- }
- $html .= " --> </td></tr>\r\n";
- } else {
- $html .= $this->getElements();
- }
- $html .= $this->getEnd();
- return $html;
- }
-
- /**
- * Get the start of the table tag
- * <code>
- * Usage:
- * Table::start($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
- * </code>
- * @static
- * @param String $text The text header for the table
- * @param String $width The Width for the table
- * @param String $class The Class
- * @param String $border The Border
- * @param String $cellpadding The CellSpacing
- * @param String $cellspacing The CellPadding
- * @param String $summary The Summary
- * @param String $caption The Caption
- */
- function start($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
- switch ($text) {
- case 'tr':
- Tr::start();
- break;
- case 'td':
- Td::start($class);
- break;
- case 'th':
- Th::start('',$class);
- break;
- case 'table':
- // fall through
- default:
- $html = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
- $html->addHtml($html->getStart());
- break;
- }
- }
-
- /**
- * Get the end of the table tag
- * <code>
- * Usage:
- * Table::end($type);
- * </code>
- * @static
- * @param String $type 'table', 'tr', 'td' or 'th' or empty
- */
- function end($type='') {
- switch ($type) {
- case 'tr':
- Tr::end();
- break;
- case 'td':
- Td::end();
- break;
- case 'th':
- Th::end();
- break;
- case 'table':
- // fall through
- default:
- $html = new Html();
- $html->addHtml(Table::getEnd());
- break;
- }
- }
-
- /**
- * Get the start of the TR tag
- * <code>
- * Usage:
- * Table::trstart($class);
- * </code>
- * @static
- * @param String $class The class name
- */
- function trstart($class='') {
- Tr::start($class);
- }
-
- /**
- * Display html for the TR tag
- * <code>
- * Usage:
- * Table::tr($class);
- * </code>
- * @static
- * @param String $class The class name
- */
- function tr($class='') {
- Tr::start($class);
- }
-
- /**
- * Get the end of the TR tag
- * <code>
- * Usage:
- * Table::trend();
- * </code>
- * @static
- */
- function trend() {
- Tr::end();
- }
-
- /**
- * Get the start of the TD tag
- * <code>
- * Usage:
- * Table::tdstart($class,$valign);
- * </code>
- * @static
- * @param String $class The class name
- * @param String $valign The alignment of data
- */
- function tdstart($class='',$valign='') {
- Td::start($class,$valign);
- }
-
- /**
- * Display html for the TD tag
- * <code>
- * Usage:
- * Table::td($class,$valign);
- * </code>
- * @static
- * @param String $class The class name
- * @param String $valign The alignment of data
- */
- function td($class='',$valign='') {
- Td::start($class,$valign);
- }
-
- /**
- * Get the end of the TD tag
- * <code>
- * Usage:
- * Table::tdend();
- * </code>
- * @static
- */
- function tdend() {
- Td::end();
- }
-
- /**
- * Get the start of the TH tag
- * <code>
- * Usage:
- * Table::thstart($class,$valign,$align);
- * </code>
- * @static
- * @param String $class The class name
- * @param String $valign The valignment of data
- * @param String $align The alignment of data
- */
- function thstart($class='',$valign='',$align='') {
- Th::start($class,$valign,$align);
- }
-
- /**
- * Display html for a TH
- * <code>
- * Usage:
- * Table::th($class,$valign,$align);
- * </code>
- * @static
- * @param String $class The class name
- * @param String $valign The valignment of data
- * @param String $align The alignment of data
- */
- function th($class='',$valign='',$align='') {
- Th::start($class,$valign,$align);
- }
-
- /**
- * Get the end of the TH tag
- * <code>
- * Usage:
- * Table::thend();
- * </code>
- * @static
- */
- function thend() {
- Th::end();
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Table::display($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
- * </code>
- * @static
- * @param String $text The text header for the table
- * @param String $width The width of the table
- * @param String $class The class of the table
- * @param String $border The border of the table
- * @param String $cellpadding The CellSpacing
- * @param String $cellspacing The CellPadding
- * @param String $summary The Summary
- * @param String $caption The Caption
- */
- function display($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
- $html = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
- $html->addHtml();
- }
- }
- ?>