/**
* The required files
*/
require_once(HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
require_once(HTML_TABLE_COMPONENT_PATH.'/Table.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:
* $tableTag = new TableTag($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
* print $tableTag->getHtml();
* Or
* TableTag::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 TableTag extends Table {
/**
* 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 TableTag($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
$this->Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
}
/**
* 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 TableTag($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(TableTag::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:
* TableTag::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 TableTag($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
$html->addHtml();
}
}
?>
HTML source code
Den fulde HTML kildekode for TableTag klassen
<?
<!-- No text in TableHeader -->
<table width="100%" class="theTable" border="0" cellpadding="2" cellspacing="0">
<tr><td><!-- Der er ikke fundet noget --> </td></tr>
</table>