12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- <?php
- require_once 'PEAR.php';
- require_once 'HTML/Common.php';
- require_once 'HTML/Table/Storage.php';
- class HTML_Table extends HTML_Common {
-
- var $_autoFill = ' ';
-
- var $_autoGrow = true;
-
- var $_caption = array();
-
- var $_colgroup = array();
-
- var $_thead = null;
-
- var $_tfoot = null;
-
- var $_tbodies = array();
-
- var $_tbodyCount = 0;
-
- var $_useTGroups = false;
-
- function HTML_Table($attributes = null, $tabOffset = 0, $useTGroups = false)
- {
- HTML_Common::HTML_Common($attributes, (int)$tabOffset);
- $this->_useTGroups = (boolean)$useTGroups;
- $this->addBody();
- if ($this->_useTGroups) {
- $this->_thead = new HTML_Table_Storage($tabOffset, $this->_useTGroups);
- $this->_tfoot = new HTML_Table_Storage($tabOffset, $this->_useTGroups);
- }
- }
-
- function apiVersion()
- {
- return 1.7;
- }
-
- function &getHeader()
- {
- if (is_null($this->_thead)) {
- $this->_useTGroups = true;
- $this->_thead = new HTML_Table_Storage($this->_tabOffset,
- $this->_useTGroups);
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setUseTGroups(true);
- }
- }
- return $this->_thead;
- }
-
- function &getFooter()
- {
- if (is_null($this->_tfoot)) {
- $this->_useTGroups = true;
- $this->_tfoot = new HTML_Table_Storage($this->_tabOffset,
- $this->_useTGroups);
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setUseTGroups(true);
- }
- }
- return $this->_tfoot;
- }
-
- function &getBody($body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'getBody');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body];
- }
-
- function addBody($attributes = null)
- {
- if (!$this->_useTGroups && $this->_tbodyCount > 0) {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setUseTGroups(true);
- }
- $this->_useTGroups = true;
- }
- $body = $this->_tbodyCount++;
- $this->_tbodies[$body] = new HTML_Table_Storage($this->_tabOffset,
- $this->_useTGroups);
- $this->_tbodies[$body]->setAutoFill($this->_autoFill);
- $this->_tbodies[$body]->setAttributes($attributes);
- return $body;
- }
-
- function _adjustTbodyCount($body, $method)
- {
- if ($this->_autoGrow) {
- while ($this->_tbodyCount <= (int)$body) {
- $this->addBody();
- }
- } else {
- return PEAR::raiseError('Invalid body reference[' .
- $body . '] in HTML_Table::' . $method);
- }
- }
-
- function setCaption($caption, $attributes = null)
- {
- $attributes = $this->_parseAttributes($attributes);
- $this->_caption = array('attr' => $attributes, 'contents' => $caption);
- }
-
- function setColGroup($colgroup = null, $attributes = null)
- {
- if (isset($colgroup)) {
- $attributes = $this->_parseAttributes($attributes);
- $this->_colgroup[] = array('attr' => $attributes,
- 'contents' => $colgroup);
- } else {
- $this->_colgroup = array();
- }
- }
-
- function setAutoFill($fill, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'setAutoFill');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setAutoFill($fill);
- } else {
- $this->_autoFill = $fill;
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setAutoFill($fill);
- }
- }
- }
-
- function getAutoFill($body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'getAutoFill');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->getAutoFill();
- } else {
- return $this->_autoFill;
- }
- }
-
- function setAutoGrow($grow, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'setAutoGrow');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setAutoGrow($grow);
- } else {
- $this->_autoGrow = $grow;
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setAutoGrow($grow);
- }
- }
- }
-
- function getAutoGrow($body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'getAutoGrow');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->getAutoGrow();
- } else {
- return $this->_autoGrow;
- }
- }
-
- function setRowCount($rows, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'setRowCount');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setRowCount($rows);
- }
-
- function setColCount($cols, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'setColCount');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setColCount($cols);
- }
-
- function getRowCount($body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'getRowCount');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->getRowCount();
- } else {
- $rowCount = 0;
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $rowCount += $this->_tbodies[$i]->getRowCount();
- }
- return $rowCount;
- }
- }
-
- function getColCount($row = null, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'getColCount');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->getColCount($row);
- }
-
- function setRowType($row, $type, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'setRowType');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setRowType($row, $type);
- }
-
- function setColType($col, $type, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'setColType');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setColType($col, $type);
- } else {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setColType($col, $type);
- }
- }
- }
-
- function setCellAttributes($row, $col, $attributes, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'setCellAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $ret = $this->_tbodies[$body]->setCellAttributes($row, $col, $attributes);
- if (PEAR::isError($ret)) {
- return $ret;
- }
- }
-
- function updateCellAttributes($row, $col, $attributes, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'updateCellAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $ret = $this->_tbodies[$body]->updateCellAttributes($row, $col, $attributes);
- if (PEAR::isError($ret)) {
- return $ret;
- }
- }
-
- function getCellAttributes($row, $col, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'getCellAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->getCellAttributes($row, $col);
- }
-
- function setCellContents($row, $col, $contents, $type = 'TD', $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'setCellContents');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $ret = $this->_tbodies[$body]->setCellContents($row, $col, $contents, $type);
- if (PEAR::isError($ret)) {
- return $ret;
- }
- }
-
- function getCellContents($row, $col, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'getCellContents');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->getCellContents($row, $col);
- }
-
- function setHeaderContents($row, $col, $contents, $attributes = null,
- $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'setHeaderContents');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setHeaderContents($row, $col, $contents, $attributes);
- }
-
- function addRow($contents = null, $attributes = null, $type = 'td',
- $inTR = false, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'addRow');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $ret = $this->_tbodies[$body]->addRow($contents, $attributes, $type, $inTR);
- return $ret;
- }
-
- function setRowAttributes($row, $attributes, $inTR = false, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'setRowAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $ret = $this->_tbodies[$body]->setRowAttributes($row, $attributes, $inTR);
- if (PEAR::isError($ret)) {
- return $ret;
- }
- }
-
- function updateRowAttributes($row, $attributes = null, $inTR = false,
- $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'updateRowAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $ret = $this->_tbodies[$body]->updateRowAttributes($row, $attributes, $inTR);
- if (PEAR::isError($ret)) {
- return $ret;
- }
- }
-
- function getRowAttributes($row, $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'getRowAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->getRowAttributes($row);
- }
-
- function altRowAttributes($start, $attributes1, $attributes2, $inTR = false,
- $firstAttributes = 1, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'altRowAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->altRowAttributes($start, $attributes1,
- $attributes2, $inTR, $firstAttributes);
- } else {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->altRowAttributes($start, $attributes1,
- $attributes2, $inTR, $firstAttributes);
-
-
-
- if ($this->_tbodies[$i]->getRowCount() % 2) {
- $firstAttributes ^= 3;
- }
- }
- }
- }
-
- function addCol($contents = null, $attributes = null, $type = 'td', $body = 0)
- {
- $ret = $this->_adjustTbodyCount($body, 'addCol');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- return $this->_tbodies[$body]->addCol($contents, $attributes, $type);
- }
-
- function setColAttributes($col, $attributes = null, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'setColAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setColAttributes($col, $attributes);
- } else {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setColAttributes($col, $attributes);
- }
- }
- }
-
- function updateColAttributes($col, $attributes = null, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'updateColAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->updateColAttributes($col, $attributes);
- } else {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->updateColAttributes($col, $attributes);
- }
- }
- }
-
- function setAllAttributes($attributes = null, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'setAllAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->setAllAttributes($attributes);
- } else {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setAllAttributes($attributes);
- }
- }
- }
-
- function updateAllAttributes($attributes = null, $body = null)
- {
- if (!is_null($body)) {
- $ret = $this->_adjustTbodyCount($body, 'updateAllAttributes');
- if (PEAR::isError($ret)) {
- return $ret;
- }
- $this->_tbodies[$body]->updateAllAttributes($attributes);
- } else {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->updateAllAttributes($attributes);
- }
- }
- }
-
- function toHtml()
- {
- $strHtml = '';
- $tabs = $this->_getTabs();
- $tab = $this->_getTab();
- $lnEnd = $this->_getLineEnd();
- $tBodyColCounts = array();
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $tBodyColCounts[] = $this->_tbodies[$i]->getColCount();
- }
- $tBodyMaxColCount = 0;
- if (count($tBodyColCounts) > 0) {
- $tBodyMaxColCount = max($tBodyColCounts);
- }
- if ($this->_comment) {
- $strHtml .= $tabs . "<!-- $this->_comment -->" . $lnEnd;
- }
- if ($this->getRowCount() > 0 && $tBodyMaxColCount > 0) {
- $strHtml .=
- $tabs . '<table' . $this->_getAttrString($this->_attributes) . '>' . $lnEnd;
- if (!empty($this->_caption)) {
- $attr = $this->_caption['attr'];
- $contents = $this->_caption['contents'];
- $strHtml .= $tabs . $tab . '<caption' . $this->_getAttrString($attr) . '>';
- if (is_array($contents)) {
- $contents = implode(', ', $contents);
- }
- $strHtml .= $contents;
- $strHtml .= '</caption>' . $lnEnd;
- }
- if (!empty($this->_colgroup)) {
- foreach ($this->_colgroup as $g => $col) {
- $attr = $this->_colgroup[$g]['attr'];
- $contents = $this->_colgroup[$g]['contents'];
- $strHtml .= $tabs . $tab . '<colgroup' . $this->_getAttrString($attr) . '>';
- if (!empty($contents)) {
- $strHtml .= $lnEnd;
- if (!is_array($contents)) {
- $contents = array($contents);
- }
- foreach ($contents as $a => $colAttr) {
- $attr = $this->_parseAttributes($colAttr);
- $strHtml .= $tabs . $tab . $tab . '<col' . $this->_getAttrString($attr) . ' />' . $lnEnd;
- }
- $strHtml .= $tabs . $tab;
- }
- $strHtml .= '</colgroup>' . $lnEnd;
- }
- }
- if ($this->_useTGroups) {
- $tHeadColCount = 0;
- if ($this->_thead !== null) {
- $tHeadColCount = $this->_thead->getColCount();
- }
- $tFootColCount = 0;
- if ($this->_tfoot !== null) {
- $tFootColCount = $this->_tfoot->getColCount();
- }
- $maxColCount = max($tHeadColCount, $tFootColCount, $tBodyMaxColCount);
- if ($this->_thead !== null) {
- $this->_thead->setColCount($maxColCount);
- if ($this->_thead->getRowCount() > 0) {
- $strHtml .= $tabs . $tab . '<thead' .
- $this->_getAttrString($this->_thead->_attributes) .
- '>' . $lnEnd;
- $strHtml .= $this->_thead->toHtml($tabs, $tab);
- $strHtml .= $tabs . $tab . '</thead>' . $lnEnd;
- }
- }
- if ($this->_tfoot !== null) {
- $this->_tfoot->setColCount($maxColCount);
- if ($this->_tfoot->getRowCount() > 0) {
- $strHtml .= $tabs . $tab . '<tfoot' .
- $this->_getAttrString($this->_tfoot->_attributes) .
- '>' . $lnEnd;
- $strHtml .= $this->_tfoot->toHtml($tabs, $tab);
- $strHtml .= $tabs . $tab . '</tfoot>' . $lnEnd;
- }
- }
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $this->_tbodies[$i]->setColCount($maxColCount);
- if ($this->_tbodies[$i]->getRowCount() > 0) {
- $strHtml .= $tabs . $tab . '<tbody' .
- $this->_getAttrString($this->_tbodies[$i]->_attributes) .
- '>' . $lnEnd;
- $strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab);
- $strHtml .= $tabs . $tab . '</tbody>' . $lnEnd;
- }
- }
- } else {
- for ($i = 0; $i < $this->_tbodyCount; $i++) {
- $strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab);
- }
- }
- $strHtml .= $tabs . '</table>' . $lnEnd;
- }
- return $strHtml;
- }
- }
- ?>
|